[advanced search]
21 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming > CODE
User Name
Password

Old 03-10-2007, 09:21 AM   · #1
mholt
DNOA Member
 
Name: Matthew Holt
Location: 127.0.0.1
Trader Rating: (75)
Join Date: May 2004
Posts: 4,850
NP$: 17.21 (Donate)
mholt has much to be proud ofmholt has much to be proud ofmholt has much to be proud ofmholt has much to be proud ofmholt has much to be proud ofmholt has much to be proud ofmholt has much to be proud ofmholt has much to be proud ofmholt has much to be proud ofmholt has much to be proud ofmholt has much to be proud of
Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
PayPal Transaction Information on Return

Found a script here: http://paypaltech.com/PDTGen/

Not sure if it's been posted before but some folks here might find it helpful. Set a return URL in your Profile settings at PayPal (enable it too, of course) and put the code you get in that URL on your server.

Customers will also see this page after the transaction is complete.

Most people use PHP here, so I'll post that code for you to use. Be sure to read the comments for info.

The difference between live transactions and sandbox in this script is just the URLs the data is posted to and received from, really... not much difference, but I put extra useful comments in this first snippet of code; refer to them if you use the second snippet so you know what to do.

REAL TRANSACTIONS (real monetary transactions)
PHP Code:
<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-synch';

$tx_token = $_GET['tx'];

// ** GET YOUR PRIVATE AUTH TOKEN FROM PP PROFILE, PUT IT HERE ** //
$auth_token = "put auth token here";

$req .= "&tx=$tx_token&at=$auth_token";


// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
// If possible, securely post back to paypal using HTTPS
// Your PHP server will need to be SSL enabled
// $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
// read the body data
$res = '';
$headerdone = false;
while (!
feof($fp)) {
$line = fgets ($fp, 1024);
if (
strcmp($line, "\r\n") == 0) {
// read the header
$headerdone = true;
}
else if (
$headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}

// parse the data
$lines = explode("\n", $res);
$keyarray = array();
if (
strcmp ($lines[0], "SUCCESS") == 0) {
for (
$i=1; $i<count($lines);$i++){
list(
$key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}

// DON'T FORGET TO DO ALL THESE THINGS.
// FOR LIST OF VARIABLES, SEE: https://www.paypal.com/IntegrationCenter/ic_ipn-pdt-variable-reference.html

// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment

// TO PROCESS, DO WHAT YOU WANT TO DO. ADD TO DB, UPDATE IT, etc.

$firstname = $keyarray['first_name'];
$lastname = $keyarray['last_name'];
$itemname = $keyarray['item_name'];
$amount = $keyarray['mc_gross'];

// THIS SHOULD ALL BE CUSTOMIZED FOR YOUR OWN PROJECT.

echo ("<p><h3>Thank you for your purchase!</h3></p>");

echo (
"<b>Payment Details</b><br>\n");
echo (
"<li>Name: $firstname $lastname</li>\n");
echo (
"<li>Item: $itemname</li>\n");
echo (
"<li>Amount: $amount</li>\n");
echo (
"");
}
else if (
strcmp ($lines[0], "FAIL") == 0) {
// log for manual investigation
}

}

fclose ($fp);

?>

<!-- You are required by PayPal's TOS to include this line visibly to customer. -->
Your transaction has been completed, and a receipt for your purchase has been emailed to you.<br>You may log into your account at <a href='https://www.paypal.com'>www.paypal.com</a> to view details of this transaction.<br>




SANDBOX (not real money; use for development testing)

PHP Code:
<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-synch';

$tx_token = $_GET['tx'];

$auth_token = "auth code here";

$req .= "&tx=$tx_token&at=$auth_token";


// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
// If possible, securely post back to paypal using HTTPS
// Your PHP server will need to be SSL enabled
// $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
// read the body data
$res = '';
$headerdone = false;
while (!
feof($fp)) {
$line = fgets ($fp, 1024);
if (
strcmp($line, "\r\n") == 0) {
// read the header
$headerdone = true;
}
else if (
$headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}

// parse the data
$lines = explode("\n", $res);
$keyarray = array();
if (
strcmp ($lines[0], "SUCCESS") == 0) {
for (
$i=1; $i<count($lines);$i++){
list(
$key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
$firstname = $keyarray['first_name'];
$lastname = $keyarray['last_name'];
$itemname = $keyarray['item_name'];
$amount = $keyarray['mc_gross'];

echo (
"<p><h3>Thank you for your purchase!</h3></p>");

echo (
"<b>Payment Details</b><br>\n");
echo (
"<li>Name: $firstname $lastname</li>\n");
echo (
"<li>Item: $itemname</li>\n");
echo (
"<li>Amount: $amount</li>\n");
echo (
"");
}
else if (
strcmp ($lines[0], "FAIL") == 0) {
// log for manual investigation
}

}

fclose ($fp);

?>

Your transaction has been completed, and a receipt for your purchase has been emailed to you.<br>You may log into your account at <a href='https://www.paypal.com'>www.paypal.com</a> to view details of this transaction.<br>


If you have questions feel free to ask.

.chulium.


Please register or log-in into NamePros to hide ads
__________________
FREE: Help With Code

Includes other technical topics:
programming, development, Windows, domain names, and Internet
mholt is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


Site Sponsors
Proof is in the Parking http://www.internetinvestments.com/ Proof is in the Parking
Advertise your business at NamePros
All times are GMT -7. The time now is 03:07 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0