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:
- the user is eventually pushed back to your site, with a transaction ID
- 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:
- send user off to Paypal with unique ID '
my_defined_transaction_id
'
- when the user finishes payment, have them come back to
user_finished.php
(Paypal with give me an ID)
- 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).
- 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).
- 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.