Test Instant Payment Notification (IPN) and Payment Data Transfer (PDT) in the PayPal Sandbox.
Once you've deposited money into the Personal account in your Sandbox [Hack #87], you'll need to configure your Sandbox Business account to use either PDT or IPN (both of which are discussed at length in Chapter 7). This hack shows how to configure PDT.
As with the live PayPal site, to use PDT with the PayPal Sandbox, you must first configure some options in your Sandbox Business account Profile.
To enable Auto Return and the PDT feature, follow these steps:
Open the Sandbox, launch the Sandbox Business account, and log in.
Click the My Account tab, and then click Profile.
Click Website Payment Preferences and turn on the Auto Return option.
Finally, turn on the Payment Data Transfer option.
Click Save when you're done.
See [Hack #85] for additional PDT setup instructions and tips.
Now, when sending order information to PayPal, you can do it through a URL (GET) or via an HTML form (POST). Either way, you need to tell PayPal that the payment is going to a Sandbox account. Just add the parameter test_pdt=1 (or test_ipn=1 if you are using the IPN) to the URL (or include it as a variable in your HTML form).
When the transaction is complete, the pseudobuyer will be redirected to the URL you supplied in the ReturnURL parameter, along with several transaction parameters appended to the URL, including:
You'll use the transaction number to get the full set of transaction information [Hack #93] .
The status of the transaction is normally Completed. See [Hack #65] for explanations of the other status flags you might see here.
The dollar (or whatever currency used) amount of the sale.
The currency used for the sale.
Once the Sandbox has sent you this information, you can set up your IPN or PDT logic as you need without worrying about real orders and real money being transacted. The return information from PayPal won't specify that it's a Sandbox transaction, though, so if it's important to you to know this, you can append a flag to your return URL, like this:
PayPal appends its transaction information to this URL for both PDT and IPN, preserving your test parameter and thus helping you to distinguish test transactions from real ones.
--Rob Conery and Dave Nielsen