views:

207

answers:

3

Is it possible to get an instant response from a paypal transaction and do they have to leave your site to pay by paypal?

I am working on a site where the user needs to make a one off payment so I have been looking for donation scripts, but most of them are pay for and the only one I found does not give an instant response http://www.ibdhost.com/donation/. If you have any related scripts that you have used before It would be greatly appreciated if you could post them.

Thanks

+1  A: 

In order to be certain you're paying securely, it is necessary for the user to be transferred to paypal's site, otherwise phishing-type attacks would be much easier!

I'm not sure what you mean by instant response, I was under the impression that PayPal merchant accounts can inform the merchant in real time in order for things like registration keys and such to be generated and sent?

MalphasWats
yes, I agree, an instant response must be possible or those ebook sites would not work... but I can't find a free script or tutorial with such a feature. Thanks for the reply
Mark
+1  A: 

Firstly, take this all with a grain of salt: I haven't actively used Paypal for at least a year...

You can (or could) use Paypal without having the user leave your site: it was called something like "Merchant Services Pro" and had a monthly fee associated with it.

Not bad timing to ask, actually, with Paypal announcing their Open API yesterday (see http://www.pcworld.com/businesscenter/article/181382/paypal_introduces_open_api_to_put_payments_into_apps.html ).

Anyway, as far as 'instant' notification is concerned: it doesn't technically happen. When the user is pushed off to Paypal and make their payment, two things happen:

  1. the user is eventually pushed back to your site, with a transaction ID
  2. when the transaction is cleared (although this normally occurs 'instantly', it can take a couple of days), Paypal hits your site, asynchronously, totally separated from the user, to another predetermined URL with a different ID (I'm pretty sure it's different)

Anyway, between the two you normally are OK. Normally my coding workflow would be something like:

  1. send user off to Paypal with unique ID 'my_defined_transaction_id'
  2. when the user finishes payment, have them come back to user_finished.php (Paypal with give me an ID)
  3. have my Paypal settings set so that on transaction clearance, Paypal will hit transaction_cleared.php with a GET parameter indicating 'my_defined_transaction_id' (again Paypal will give me an ID).
  4. Paypal generally hits transaction_cleared.php well before the user gets to user_finished.php: when Paypal hits that URL, I mark 'my_defined_transaction_id' as "OK" (after cross referencing back to Paypal to ensure validity).
  5. When the user ends up back at user_finished.php, I can cross reference the transaction ID back to Paypal, ensure validity and then mark 'my_defined_transaction_id' as "OK".

Doing this all in two steps allows the user to close the browser without going back to my site and still having the transaction marked as "OK".

Sorry... haven't started my coffee yet, but I hope that makes some sense.

Narcissus
Thanks for your thorough answer. I found this script http://www.micahcarrick.com/04-19-2005/php-paypal-ipn-integration-class.html. Which is excellent... but I like this double transaction id idea... but I can't quite understand the process. Could you take me through it again? Thanks.
Mark
@Mark: I'd have to dig up some old code for the "get information when the user is returned to the page" process, but I would start with the IPN link that Christopher Altman gave... it details the "asynchronous though normally done before the user is returned" process.Good luck with it. To be honest, I had nothing but trouble trying to get my stuff working the first time :)
Narcissus
+1  A: 

My application, www.perqworks.com, uses Paypal Website Payment Pro. In the API is a notion of Instant Payment Notification (IPN). https://cms.paypal.com/us/cgi-bin/?&cmd=%5Frender-content&content%5FID=developer/library%5Fcode%5Fipn%5Fcode%5Fsamples

How it works is that a person pays with a credit card. Paypal sends an https response to a 'listener' on my server. With the listener, you can decide to continue the process or throw an error based on the response codes from Paypal.

The documentation and sandbox helped, but the Paypal API can be a little tricky to get your head wrapped around.

Christopher Altman
Oliver
I endorse this response. I just finished implementing my first IPN listener and it's working great (I replaced the fopen with a curl for the IPN verification). Use the PayPal Sandbox/Developer Tools to test it.
Steven Xu