CodeIgniter Forums

Full Version: PayPal IPN and accessing custom session variables asynchronously
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Jacob Graf[/eluser]
I am trying to integrate PayPal IPN into an application I am developing with CodeIgniter. To make a long story short, the user creates an account by registering and then they need to pay $10 to activate their account for 1 year. I am using the following IPN code...

Code:
function activate()
    {
        // Verify shared secret
        if ($this->uri->segment(3) === 'SHARED-SECRET')
        {
            // Verify payment
            if ($this->input->post('payment_status') === "Completed")
            {
                // SUCCESS
                $data = array(
                    'active' => TRUE
                );
                $this->db->where('id', $this->session->userdata('participant_id'));
                $this->db->update('participants', $data);
                $data = $this->user->load($this->session->userdata('username'));

                // Send email to administrator
                $recipient = 'MY-EMAIL-ADDRESS';
                $subject = 'New registration received!';
                $body = "Name: ".$data->first_name." ".$data->last_name."\nAddress: ".$data->address_1." ".$data->address_2."\nCity: ".$data->city."\nState: ".$data->state."\nZip: ".$data->zip."\nTelephone: ".$data->telephone;
                $this->miscel->email($recipient, $subject, $body);
                
                $this->session->set_flashdata('alert', 'You have successfully activated your account. Thank you for your support!');
            }
        }
        else
        {
            // Notify administrator of error
            $recipient = 'MY-EMAIL-ADDRESS';
            $subject = "PayPal Shared Secret Error! (Activation)";
            $body = 'Just a quick note to tell you someone was trying to access the payment processing script and the shared secret could not be validated. You may want to look into it! Thanks!';
            $this->miscel->email($recipient, $subject, $body);
        }
    }

Basically, I am using a shared secret in the 3rd URL segment to verify the request is authentic. I then make sure the payment went through and if it did, I check the logged-in users session variables and use those to activate the account in the database.

Here is the issue, for some reason, it isn't pulling up my custom session variables. PayPal gets payment information from the customer and when it has received a successful payment, it makes a request asynchronously to the code above. I could see the session variables not being accessible from PayPal's servers, but the code resides on my server.

After that, I set a success message in a flash session variable hoping that would still be accessible when the user is directed back to my site from PayPal's site.

Any ideas on why I can't get to my session data would help! I appreciate it!

El Forum

[eluser]InsiteFX[/eluser]
Hi,

It is possible that your session variables are being destoryed when
it goes to PayPal's site.

If PayPal returns to your site you should know that it was ok!

You can also check out the CodeIgniter's SVN Cart here

http://dev.ellislab.com/svn/CodeIgniter/...s/Cart.php

It uses session data for the cart.

Hope this helps.

Enjoy
InsiteFX