Welcome Guest, Not a member yet? Register   Sign In
PayPal IPN and CodeIgniter
#1

[eluser]YellowShadow[/eluser]
Hey all,

I'm trying to email the cart contents to the user after the PayPal IPN result but it just sends a blank email. I don't think it actually gets the session data for the cart if the user is not on my website. Is there a workaround for this?

Here is the current code I'm using...

Code:
public function ProcessOrder()
    {
        if ($this->paypal_ipn->validateIPN())
        {
            $this->paypal_ipn->extractOrder();
            $this->paypal_ipn->saveOrder();
            
            if ($this->paypal_ipn->orderStatus == PayPal_IPN::PAID)
            {
                $this->load->library('email');
                $this->load->model('OrdersModel');
                
                //Inser the order into the database
                $this->OrdersModel->InsertOrder();
                //Send an email as a recipt
                $this->email->from('[email protected]', 'Modern Engine');
                $this->email->subject('Your recent order from Modern Engine');
                $this->email->to($this->MembershipModel->GetEmail());
                
                $message = 'Dear '.$this->MembershipModel->GetFullName($this->session->userdata('username')).',<br /><br />Below is the recipt for your recent purchase from Modern Engine. Please keep it for your records.<br /><br />';
                
                $message .= '
                <table border="0" cellpadding="5" cellspacing="0">  
                    <thead>  
                        <th>Qty</th>  
                        <th>Item Description</th>  
                        <th>Item Price</th>  
                        <th>Sub-Total</th>
                    </thead>  
                    <tbody>';
                    foreach($this->cart->contents() as $items)
                    {
                     $message .= '   <tr>  
                            <td>'.  
                                 $items['qty'].'</td>  
                  
                            <td>'.$items['name'].'</td>  
                  
                            <td>$'.$this->cart->format_number($items['price']).'</td>  
                            <td>$'.$this->cart->format_number($items['subtotal']).'</td>  
                        </tr>';
                     }
                  
                     $message .= '<tr>  
                            <td</td>  
                            <td></td>  
                            <td><strong>Total</strong></td>  
                            <td>$'.$this->cart->format_number($this->cart->total()).'</td>  
                        </tr>  
                    </tbody>  
                </table>';
                
                $message .= 'Thanks,<br />Modern Engine<br /><br />If you have any questions please contact us at <a href="mailto:[email protected]">[email protected]</a>';
                
                $this->email->message($message);
                $this->email->send();
                
                $this->cart->destroy();
            }
        }
    }

Any help would be greatly appreciated!

Thanks!
#2

[eluser]Mat-Moo[/eluser]
IPN callbacks are from the Paypal server, so there is NO session data. You need to use an order number in the paypal data to process who it is for etc.
#3

[eluser]pickupman[/eluser]
[quote author="Mat-Moo" date="1313067398"]IPN callbacks are from the Paypal server, so there is NO session data. You need to use an order number in the paypal data to process who it is for etc.[/quote]

That's exactly right. In addition to that, you should be destroying your users cart once they have placed the order. Your cart shouldn't exists after you have checked out. Using the IPN posted back to you, make sure you are comparing the order id and amount against the db. Then use that order record to populate the email.
#4

[eluser]YellowShadow[/eluser]
Alright so what would be the best way to loop through all the cart contents and add them to the PayPal shopping cart? I tried a simple foreach loop to add them before the checkout button is pressed, but it only shows one item at the PayPal screen.
#5

[eluser]pickupman[/eluser]
Here's the information from [url="https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_cart_upload#id08A3F700OYK"]Paypal[/url].

Just need to add a hidden field for each item to your form.




Theme © iAndrew 2016 - Forum software by © MyBB