I’ve looked into this, and I’ve seen some places saying you can use CURL for this, but I’m not convinced that’d work the way I’m after.
What I want to do is to have a temporary holding page between the website I’m working on and the PayPal website. The sole purpose of this holding page is to cache the data about the item being bought in the database so it can be checked against the returned data from PayPal as an additional security measure. (The buttons are already dynamically encrypted)
So, what I’m looking to do is have a scenario along these lines:
- Buy Now button clicked
- Form submits data to holding page
- Holding page adds data to database
- Holding page sends user and data to PayPal to process the transaction
The problem, of course, is that transferring the $_POST data isn’t straightforward. Does anyone have any suggestions for how to go about this using PHP?
Create your own button and hide the real paypal button. On clicking your button do an AJAX post and do server side processing.
If the response is ok, render an HTTP 200 response and in your onsuccess in $.ajax, trigger a click to the real buy now button (or trigger the paypal API, however this works in your setup)
If the response i bad, render an HTTP 402 response and in your onerror, do whatever you would do to alert the user that it failed.
This way, you don’t need to redirect the user twice – which is kinda jarring…
Whatever form you have, you can use jQuery to send the form as AJAX..
Something like this should do: