[insert_php]
require_once(‘Connections/connReturnDownload.php’);
// read the post from PayPal system and add ‘cmd’
$req = ‘cmd=_notify-synch’;
$tx_token = $_GET[‘tx’];
$auth_token = “cOlzMyawiIbQI2wkdFR0H2nz7IhE4hjX_lDv4gObkFA3yPyXfjvo3Uq89pO”;
$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 (‘ssl://www.paypal.com’, 443, $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;
}
elseif ($headerdone)
{
// “header has been read. now read the contents”
$res .= $line;
}
}
$itemnumber = “00”;
$paymentstatus = “none”;
// parse the data
$lines = explode(“\n”, $res);
$keyarray = array();
if (strcmp ($lines[0], “SUCCESS”) == 0) {
for ($i=1; $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’];
$paymentstatus = $keyarray[‘payment_status’];
$lastname = $keyarray[‘last_name’];
$firstname = $keyarray[‘first_name’];
$addresscity = $keyarray[‘address_city’];
$addresscountry = $keyarray[‘address_country’];
$addressstate = $keyarray[‘address_state’];
$addressstreet = $keyarray[‘address_street’];
$addresszip = $keyarray[‘address_zip’];
$payerbusinessname = $keyarray[‘payer_business_name’];
$contactphone = $keyarray[‘contact_phone’];
$residencecountry = $keyarray[‘residence_country’];
$quantity = $keyarray[‘quantity’];
$itemname = $keyarray[‘item_name’];
$email = $keyarray[‘payer_email’];
$itemnumber = $keyarray[‘item_number’];
$amount = $keyarray[‘mc_gross’];
$payerid = $keyarray[‘payer_id’];
$zipcode = $keyarray[‘zip_code’];
$countrycode = $keyarray[‘country_code’];
$paymentdate = $keyarray[‘payment_date’];
$localtime = localtime();
}
else if (strcmp ($lines[0], “FAIL”) == 0) {
// log for manual investigation
}
}
if ($paymentstatus == “Completed”) {
$sql=(“INSERT INTO Customer_Table (dbpayer_email, first_name, last_name, address_street, address_city, address_state, address_zip, address_country, payer_id, zip_code, country_code, dbitem_number, tx_token, datetime) VALUES (‘$email’,’$firstname’,’$lastname’,’$addressstreet’,’$addresscity’,’$addressstate’,’$addresszip’,’$addresscountry’,’$payerid’,’$zipcode’,’$countrycode’,’$itemnumber’,’$tx_token’,’$paymentdate’)”);
mysql_select_db($database_connReturnDownload, $connReturnDownload);
$result=mysql_query($sql, $connReturnDownload) or die(mysql_error());
goto a;
}
else
{
exit;
}
a:
echo (”
Thank you for your purchase of $itemname!
“);
echo (“Payment Details
\n”);
echo (”
- Name: $firstname $lastname
\n”);
echo (”
- Item: $itemname
\n”);
echo (”
- Amount: $amount
\n”);
echo (”
- Payment Status: $paymentstatus
\n”);
echo (”
\n”);
//sleep(10);
//$headers = “MIME-Version: 1.0\r\n”;
//$headers .= “Content-type: text/html; charset=iso-8859-1\r\n”;
//if ($itemnumber == 03) {
//echo ‘Link‘;
//}
//elseif ($itemnumber == 02) {
//echo ‘Link‘;
//}
//elseif ($itemnumber == 06) {
//echo ‘Link‘;
//}
fclose ($fp);
?>
Your transaction has been completed, and a receipt for your purchase has been emailed to you.
You may log into your account
at www.paypal.com to view details of this transaction.
[/insert_php]
Leave a Reply
You must be logged in to post a comment.