tags:

views:

138

answers:

2

I've got a product page set up where you click a product (radio button) and click checkout with Paypal. What I'd like at this point is to create the purchase in the database (add the table row with purchase details, minus the Paypal receipt id), then send the user to Paypal to pay. When user returns to the site the receipt id will be added to the purchase.

The thing is, I need to send the user to Paypal and POST some data to the Paypal page.

Can all this be done in 1 click of the user?

My Thoughts: 1) I can't just submit the payment form the a PHP page on my server, because although I will be able to add the purchase to DB, I won't be able to redirect the user to Paypal and POST variables (from what I know). 2) I think AJAX would be the way to go, but I'm not sure if it's possible. Can I do some server side processing AND send the user to the Paypal site AND POST variables to the page?

Thanks for any help.

+1  A: 

Ajax is one way, but you won't be able to catch errors and stop the user from going to paypal if there is an error in your server side processing.

One way that springs to mind is to post the data to your server, process, then return a form with a bit of JavaScript that submits onload of the resulting page.

So

  • Send data to server.
  • Server processes data, and returns an html page with a form and a bunch of hidden fields.
  • Add am onload handler to form that does a submit().
  • Optionally add a processing animation if you want.
Byron Whitlock
+1  A: 

You would use AJAX to submit the data to your server for saving. Then you would use javascript to update values in an HTML form on the page the user is on and submit the form. The form would have the "action" parameter set to Paypal.