NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page PayPal Transaction Information on Return

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search
8 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 03-10-2007, 09:21 AM THREAD STARTER               #1 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


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$errstr30);
// 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 ($fp1024);
if (
strcmp($line"\r\n") == 0) {
// read the header
$headerdone true;
}
else if (
$headerdone)
????: NamePros.com http://www.namepros.com/code/303367-paypal-transaction-information-on-return.html
{
// 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$errstr30);
// 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 ($fp1024);
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");
????: NamePros.com http://www.namepros.com/showthread.php?t=303367
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.
mholt is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 03:35 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger