Easy PayPal PDT

IMPORTANT UPDATE: I’ve since updated the code substantially, please read my new blog post.

[divider type=”dashed” spacing=”10″]

Many of you should be familiar with PayPal and the shopping cart services they offer, namely PDT and IPN. I’ve already dealt with IPN in this post, so now it’s time for PDT. PDT allows visitors to return to your site after a transaction and see the details of what they just purchased.

Simply create a directory, I recommend something simple. For instance, http://cart.mysite.com/success/. Then copy the following pdt.class.php and pdt.interface.php files into that folder.


Now, all you need to do is create an index.php file (or whatever you want to call it) and place code similar to this in it:


include( 'pdt.class.php' );
include( 'pdt.interface.php' );    

class pdt_class extends paypal_pdt_class implements paypal_pdt_interface
	public function _validate_success( $paypal_response )
		echo '<pre>';
		print_r( $paypal_response );
		echo '</pre>';

	public function _validate_failure()
		echo 'That wasn\'t a real PayPal PDT request!';

$pdt = new pdt_class( 'YOUR_PDT_IDENTIFICATION_CODE_HERE' , $_GET['tx'] );
$pdt->set_sandbox_mode( true );


Obviously substituting your own code in. You should have _validate_success create a nice page with all the recent transaction data clearly visible.

Transaction data will be stored in $paypal_response and will look like this:

    [mc_gross] => 19.99
    [settle_amount] => 16.71
    [protection_eligibility] => Eligible
    [address_status] => confirmed
    [item_number1] => 
    [payer_id] => YWEWKERGPAJC6
    [tax] => 0.00
    [address_street] => 1 Main St
    [payment_date] => 16:48:33 Jun 08, 2010 PDT
    [payment_status] => Completed
    [charset] => windows-1252
    [address_zip] => 95131
    [mc_shipping] => 0.00
    [mc_handling] => 0.00
    [first_name] => Brandon
    [mc_fee] => 0.88
    [address_country_code] => US
    [exchange_rate] => 0.874542
    [address_name] => Test User
    [settle_currency] => USD
    [custom] => 
    [payer_status] => unverified
    [business] => [email protected]
    [address_country] => Canada
    [num_cart_items] => 1
    [mc_handling1] => 0.00
    [address_city] => Halifax
    [payer_email] => [email protected]
    [mc_shipping1] => 0.00
    [btn_id1] => #######
    [txn_id] => L617297YX5069944
    [payment_type] => instant
    [last_name] => Wamboldt
    [address_state] => CA
    [item_name1] => Something that is awesome
    [receiver_email] => [email protected]
    [payment_fee] => 
    [quantity1] => 1
    [receiver_id] => MNMHRPFXYK4G8
    [txn_type] => cart
    [mc_gross_1] => 19.99
    [mc_currency] => CAD
    [residence_country] => CA
    [transaction_subject] => Shopping Cart
    [payment_gross] => 

Use PayPal Sandbox for testing

3 Replies to “Easy PayPal PDT”

  1. […] long time ago, I wrote a few PHP scripts to help me work with PayPal IPN & PDT requests. I’ve been using them in my projects ever since, but they’ve been in desperate […]

  2. Hey Brandon, nice article, you got me started with all this.
    I might need a little help though and wondering if you would help.

    I’m building a website for a client. He sells product online and want to use the paypal cart. When users complete their transaction, I’ve been asked to create a xml or csv file that would contain the order details. So I started to read and found your site. So basically I was trying to setup your script. I got into 1 problem, I’m stuck now. For some reason I always fail at “That wasn’t a real PayPal PDT request!”. In your code, you have a place that I need to use my info… $pdt = new pdt_class( ‘YOUR_PDT_IDENTIFICATION_CODE_HERE’ , $_GET[‘tx’] );

    I think my problem is with the “YOUR_PDT_IDENTIFICATION_CODE_HERE”. I’m using a sandbox account and I used my merchand ID – failed, then I used my Identity Token – failed again….so I’m not sure what else would be my PDT_IDENTIFICATION_CODE….

    Maybe my problem is elsewhere, but I don’t understand why I’m failing at this stage on all transaction

    Please help me out
    And thank you very much for your time

    1. Hey Jeff,

      Please consider using the newer version of my code, see the blog post here: http://brandonwamboldt.ca/paypal-ipnpdt-libraries-1214/

      YOUR_PDT_IDENTIFICATION_CODE_HERE should be your PDT identification token. I’m not sure about the sandbox, but for the real PayPal, that’s under My Account > Profile > My Selling Tools > Website Payment Preferences. If you have PDT enabled, you should see “Identity Token: SOMETHING”.

      Let me know if this helps.

Leave a Reply