Reputation: 51
G'day all,
THE BACKGROUND:
I have built a custom shop which has a PayPal option for payment. In general, the PayPal option works as follows:
The "Pay with PayPal" button is what I want to adapt. At present, I have a php function which takes all the items from the users cart and converts it into a PayPal form which is then echo'd onto the page. This form contains all the PayPal info including items, quantities, sizes, shipping cost, business details, return/cancel/IPN urls etc.
THE PROBLEM:
If the user populates their shopping cart on a certain day and goes through the checkout procedure up to the payment page, the PayPal form sits there freshly generated (including item prices and quantities, which are currently okay)
They walk away from their computer without clicking the "Pay with PayPal" button, maybe taking a few days to think about it. In the meantime, the prices/stock changes for the items in their cart.
Even if I set unfinished carts to delete after say 24hrs, the user already has the PayPal form loaded, so can still click "Pay with PayPal" even several months later using the old stock levels and prices!
THE SOLUTION:
I see a couple of options here and am open to suggestions to each (or indeed a better solution!)
Set the Payment and Cart pages with the horrible "Refresh" meta tag to ensure they are updated each day, and have php check the stock/price before the page loads. This way, if the stock or prices have changed, the user would be presented with the most recent prices. (This is not my preferred option)
Instead of generating the PayPal form on the Payment page, have the "Pay with PayPal" button direct the user to another php page (say "process_paypal.php") which does all the required checks and if there are any problems, a message can be sent to the user. (So far, so good). Then (and this is the part I'm struggling with), if everything is okay, generate the form and submit it automatically, redirecting the user to the PayPal website to log in. (I know this can be done pretty easily using jQuery or Javascript, but if possible, I'd prefer a PHP solution if such a thing exists? I'm not really familiar with cURL so don't know if that's what it is used for)
You tell me?! :)
Appreciate any help you can give on this one.
Ben Avery
Upvotes: 4
Views: 754
Reputation: 2505
Personally, in this case I've used the paypal callback url to reject the purchase if the cart doesn't exist.
What you would do is only respond to their IPN call with a success if the cart exists in your system. Otherwise respond with a failure.
I believe there is a setting in PayPal to reject payments that don't get a successful response.
Edit: just looked at the code (been a while since I did it). What we eventually ended up doing was triggering a Refund using the PayPal API based on the IPN call. In my opinion it is perfectly acceptable to do this as there is no charge to the customer.
Upvotes: 1