Reputation: 865
I'm trying to develop a checkout system for a customer site, and I want to know the best way to do this. Please let me know of any alternatives to what I've tried below.
Currently I have:
1) Items in cart saved to $_SESSION variable
2) When a user presses 'checkout', they are taken to a page with an invisible form that POSTs the information saved in $_SESSION to https://www.paypal.com/cgi-bin/webscr
3) When payment is confirmed, they are redirected to confirm.php on the site that triggers an email to the client and the store containing the information from the cart (stored in $_SESSION) and the address data passed back (as I cannot pass all of the attribute information in the cart to paypal in the first POST) from PayPal.
The issue with my solution is that it doesn't appear to work on mobile safari, iPads, iPhones or older systems. So I'm looking for an alternative, or for a way for the data to remain persistent, as the emails sent out at the end contain no data when performed from one of these devices.
Upvotes: 0
Views: 198
Reputation: 491
Using a database you can store the entire cart as temporal or incomplete before calling the PayPal payment, and then get all the info via confirm.php, modify the state of the cart, etc.
Also in your PayPal account you can activate automatic IPN upon every payment.
An IPN is a listener that runs on your site and makes calls to paypal. You can find a lot of examples of these on the web.
The idea is that you pass all the fields you want on the PayPal form, and paypal will send it back using the IPN call.
In the PayPal form you can add a custom hidden input:
<input type="hidden" name="cart_id" value="<?php echo $id ?>">
And in the IPN listener you will get cart_id = 4, so you can automatically know which cart payment is done, and which user the cart belongs, change the cart status and email user.
Hope this helps you.
Upvotes: 1