PAYPAL PAYMENT DATA TRANSFERS (PDT)

To use PDT, you must activate PDT and Auto Return in your PayPal account profile. You must also acquire a PDT identity token, which is used in all PDT communication you send to PayPal.

Follow these steps to configure your account for PDT:

1)Log in to your PayPal account.
2)Click the Profile subtab.
3)Click the My Selling Tools button in the left column.
4)Find the Selling online section and click Update in the Website preferences row.
5)Under Auto Return for Website Payments, click the On radio button.
6)For the Return URL, enter the URL on your site that will receive the transaction ID posted by PayPal after a customer payment.
7)Under Payment Data Transfer, click the On radio button.
8)Click Save.
9)Find the Selling online section and click Update in the Website preferences row again.
10)Scroll down to the Payment Data Transfer section of the page and take note of your PDT identity token.

Create the form now with notify url and cancel url

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" accept-charset="utf-8"> 
    <p> 
    <input type="hidden" name="cmd" value="_xclick" /> 
    <input type="hidden" name="charset" value="utf-8" /> 
    <input type="hidden" name="business" value="paypal@business.example.com" /> 
    <input type="hidden" name="item_name" value="Stuffed bear" />
    <input type="hidden" name="item_number" value="BEAR05" />
    <input type="hidden" name="amount" value="20.00" />
    <input type="hidden" name="currency_code" value="USD" />
    <input type="hidden" name="return" value="http://business.example.com/order/123/" /> 
    <input type="hidden" name="cancel_return" value="http://business.example.com/order/123/" />
    <input type="hidden" name="bn" value="Business_BuyNow_WPS_SE" /> 
    <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" name="submit" alt="Buy Now" />
    </p> 
</form>

Catch the return now as $_GET[‘tx’] and repost to paypal

if(isset($_GET['tx']))
{
  $tx = $_GET['tx'];
  $request = curl_init();
  curl_setopt_array($request, array
(
  CURLOPT_URL => 'https://www.sandbox.paypal.com/cgi-bin/webscr',
  CURLOPT_POST => TRUE,
  CURLOPT_POSTFIELDS => http_build_query(array
    (
      'cmd' => '_notify-synch',
      'tx' => $tx,
      'at' => $your_pdt_identity_token,
    )),
  CURLOPT_RETURNTRANSFER => TRUE,
  CURLOPT_HEADER => FALSE,
  // CURLOPT_SSL_VERIFYPEER => TRUE,
  // CURLOPT_CAINFO => 'cacert.pem',
));

// Execute request and get response and status code
$response = curl_exec($request);
$status   = curl_getinfo($request, CURLINFO_HTTP_CODE);
if($status == 200 AND strpos($response, 'SUCCESS') === 0)
{
    // Further processing
}
else
{
    // Log the error, ignore it, whatever 
}
// Close connection
curl_close($request);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s