Hack 99 Test IPN and PDT in the Sandbox

figs/moderate.gif figs/hack99.gif

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.

PDT works only when Auto Return is turned on. You must set this before using PDT in your web site.

To enable Auto Return and the PDT feature, follow these steps:

  1. Open the Sandbox, launch the Sandbox Business account, and log in.

  2. Click the My Account tab, and then click Profile.

  3. Click Website Payment Preferences and turn on the Auto Return option.

  4. Finally, turn on the Payment Data Transfer option.

  5. Click Save when you're done.

When you save your PDT preferences, an ITidentity token is generated and appears in a message at the top of the Website Payment Preferences page. In future visits, your ITidentity token will appear in the Payment Data Transfer section, below the On and Off options.

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:

Transaction number (tx)

You'll use the transaction number to get the full set of transaction information [Hack #93] .

Status (st)

The status of the transaction is normally Completed. See [Hack #65] for explanations of the other status flags you might see here.

Amount of sale (amt)

The dollar (or whatever currency used) amount of the sale.

Currency (cc)

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