PAY PAL IPN stop working - paypal-ipn

My code stop working, I have made some changes like $res=trim($res); as I saw in another question but still not working.
The code was perfectly working including automatic post in Facebook and Tweeter.
Please, could someone check my code and help me to fix it?
<?php
// Revision Notes
// 11/04/11 - changed post back url from https://www.paypal.com/cgi-bin/webscr to https://ipnpb.paypal.com/cgi-bin/webscr
// For more info see below:
// https://www.x.com/content/bulletin-ip-address-expansion-paypal-services
// "ACTION REQUIRED: if you are using IPN (Instant Payment Notification) for Order Management and your IPN listener script is behind a firewall that uses ACL (Access Control List) rules which restrict outbound traffic to a limited number of IP addresses, then you may need to do one of the following:
// To continue posting back to https://www.paypal.com to perform IPN validation you will need to update your firewall ACL to allow outbound access to *any* IP address for the servers that host your IPN script
// OR Alternatively, you will need to modify your IPN script to post back IPNs to the newly created URL https://ipnpb.paypal.com using HTTPS (port 443) and update firewall ACL rules to allow outbound access to the ipnpb.paypal.com IP ranges (see end of message)."
/////////////////////////////////////////////////
/////////////Begin Script below./////////////////
/////////////////////////////////////////////////
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Host: www.paypal.com\r\n";
//$header .= "Host: www.sandbox.paypal.com\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
// If testing on Sandbox use:
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://ipnpb.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$business = $_POST['business'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$mc_gross = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$receiver_id = $_POST['receiver_id'];
$quantity = $_POST['quantity'];
$num_cart_items = $_POST['num_cart_items'];
$payment_date = $_POST['payment_date'];
$first_name = $_POST['fir st_name'];
$last_name = $_POST['last_name'];
$payment_type = $_POST['payment_type'];
$payment_status = $_POST['payment_status'];
$payment_gross = $_POST['payment_gross'];
$payment_fee = $_POST['payment_fee'];
$settle_amount = $_POST['settle_amount'];
$memo = $_POST['memo'];
$payer_email = $_POST['payer_email'];
$txn_type = $_POST['txn_type'];
$payer_status = $_POST['payer_status'];
$address_street = $_POST['address_street'];
$address_city = $_POST['address_city'];
$address_state = $_POST['address_state'];
$address_zip = $_POST['address_zip'];
$address_country = $_POST['address_country'];
$address_status = $_POST['address_status'];
$item_number = $_POST['item_number'];
$tax = $_POST['tax'];
$option_name1 = $_POST['option_name1'];
$option_selection1 = $_POST['option_selection1'];
$option_name2 = $_POST['option_name2'];
$option_selection2 = $_POST['option_selection2'];
$for_auction = $_POST['for_auction'];
$invoice = $_POST['invoice'];
$custom = $_POST['custom'];
$notify_version = $_POST['notify_version'];
$verify_sign = $_POST['verify_sign'];
$payer_business_name = $_POST['payer_business_name'];
$payer_id =$_POST['payer_id'];
$mc_currency = $_POST['mc_currency'];
$mc_fee = $_POST['mc_fee'];
$exchange_rate = $_POST['exchange_rate'];
$settle_currency = $_POST['settle_currency'];
$parent_txn_id = $_POST['parent_txn_id'];
$pending_reason = $_POST['pending_reason'];
$reason_code = $_POST['reason_code'];
// subscription specific vars
$subscr_id = $_POST['subscr_id'];
$subscr_date = $_POST['subscr_date'];
$subscr_effective = $_POST['subscr_effective'];
$period1 = $_POST['period1'];
$period2 = $_POST['period2'];
$period3 = $_POST['period3'];
$amount1 = $_POST['amount1'];
$amount2 = $_POST['amount2'];
$amount3 = $_POST['amount3'];
$mc_amount1 = $_POST['mc_amount1'];
$mc_amount2 = $_POST['mc_amount2'];
$mc_amount3 = $_POST['mcamount3'];
$recurring = $_POST['recurring'];
$reattempt = $_POST['reattempt'];
$retry_at = $_POST['retry_at'];
$recur_times = $_POST['recur_times'];
$username = $_POST['username'];
$password = $_POST['password'];
//auction specific vars
$for_auction = $_POST['for_auction'];
$auction_closing_date = $_POST['auction_closing_date'];
$auction_multi_item = $_POST['auction_multi_item'];
$auction_buyer_id = $_POST['auction_buyer_id'];
//DB connect creds and email
$notify_email = "xxxxxx#gmail.com"; //email address to which debug emails are sent to
$DB_Server = "localhost"; //your MySQL Server
$DB_Username = "xxxxx"; //your MySQL User Name
$DB_Password = "xxxxx"; //your MySQL Password
$DB_DBName = "xxxxx"; //your MySQL Database Name
if (!$fp)
{
// HTTP ERROR
}
else
{
fputs ($fp, $header . $req);
while (!feof($fp))
{
$res = fgets ($fp, 1024);
$res=trim($res);
if (strcmp ($res, "VERIFIED") == 0)
//if (strcmp ($res, "VERIFIED\r\n") == 0)
{
//create MySQL connection
$Connect = #mysql_connect($DB_Server, $DB_Username, $DB_Password)
or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno());
//select database
$Db = #mysql_select_db($DB_DBName, $Connect)
or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno());
$fecha = date("m")."/".date("d")."/".date("Y");
$fecha = date("Y").date("m").date("d");
//check if transaction ID has been processed before
$checkquery = "select txnid from paypal_payment_info where txnid='".$txn_id."'";
$sihay = mysql_query($checkquery) or die("Duplicate txn id check query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
$nm = mysql_num_rows($sihay);
if ($nm == 0)
{
//execute query
$strQuery = "insert into paypal_payment_info(paymentstatus,buyer_email,receiver_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,quantity,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation) values ('".$payment_status."','".$payer_email."','".$receiver_email."','".$first_name."','".$last_name."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."','".$quantity."','".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')";
$result = mysql_query("insert into paypal_payment_info(paymentstatus,buyer_email,receiver_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,quantity,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation) values ('".$payment_status."','".$payer_email."','".$receiver_email."','".$first_name."','".$last_name."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."','".$quantity."','".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')")
or die("Default - paypal_payment_info, Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
{
$consumerKey = 'ccYgLrtBUrgIPJDQ';
$consumerSecret = '4qXLLXdQPcKqAqKscYQH9p9m3cznyVWYc4v8';
$oAuthToken = 'uVgkQTC0BLNT9V9vTpc25poxDgIomCgMbw';
$oAuthSecret = 'L8rfc6A1Ii5cMeuYEhf6hwkc3aATyo';
require_once('twitteroauth.php');
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);
$tweet->post('statuses/update', array('status' => 'Last donation US$ '.$mc_gross.' to '.$item_name.' '));
}
mail($notify_email, "VERIFIED IPN", "$res\n $req\n $strQuery\n $struery\n $strQuery2");
$sql = mysql_query(" UPDATE cadastros SET amount='$mc_gross'-'$mc_fee'+amount, mc_gross = '$mc_gross' , mc_fee ='$mc_fee', payment_date = '$payment_date',pay_date = now() WHERE receiver_email='$receiver_email'");
$result = mysql_query($sql) or die( mysql_error() );
}
else
{
// send an email
mail($notify_email, "VERIFIED DUPLICATED TRANSACTION", "$res\n $req\n $strQuery\n $struery\n $strQuery2");
}
// if the IPN POST was 'INVALID'...do this
}
else if (strcmp ($res, "INVALID") == 0)
{
// log for manual investigation
mail($notify_email, "INVALID IPN", "$res\n $req");
}
}
fclose ($fp);
}
?>

The HOST tag in the header has to match the URL you are using with fsockopen.
Try this:
$sandbox = 1;
$paypalURL = $sandbox ? 'www.sandbox.paypal.com' : 'www.paypal.com';
// Create http header
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Host: $paypalURL\r\n";
$header .= "Connection: close\r\n\r\n";
// Post back to PayPal system to verify
$fp = fsockopen('ssl://'.$paypalURL, 443, $errno, $errstr, 30);

Related

page has Too many redirects from mail.php file?

I hope someone can help me. I have a page with a form and then the information
is emailed to me. the code below seems to be redirecting to the same page over and over again. It used to work for years now its not always working.
any help appreciated. Thanks Steve
<?php
//****************************************
//edit here
$senderName = 'WEB';
$senderEmail = 'site#example.com';
$targetEmail = 'contact#sellmydiabeticteststrips.com';
$messageSubject = 'Message from web-site';
$redirectToReferer = true;
$redirectURL = 'contact.html';
//****************************************
// mail content
$ufname = $_POST['ufname'];
$uaddress = $_POST['uaddress'];
$uemail = $_POST['uemail'];
$utel = $_POST['utel'];
$ucity = $_POST['ucity'];
$ustate = $_POST['ustate'];
$uzip = $_POST['uzip'];
$ubrand = $_POST['ubrand'];
$unumber = $_POST['unumber'];
$ucheck = $_POST['ucheck'];
$agree = $_POST['agree'];
// collect interests data
$interestsString = '';
for($i = 0; $i < count($interests); $i++) {
$interestsString .= $interests[$i].($i < count($interests) - 1 ? ', ' : '');
}
// prepare message text
$messageText = 'First Name: '.$ufname."\n".
'Address: '.$uaddress."\n".
'Email: '.$uemail."\n".
'Telephone: '.$utel."\n".
'City: '.$ucity."\n".
'State: '.$ustate."\n".
'Zip: '.$uzip."\n".
'Brand of test strips: '.$ubrand."\n".
'Number of boxes: '.$unumber."\n".
'Check: '.$ucheck."\n".
'Terms and Conditions: '.$agree."\n";
if($interestsString) {
$messageText .= 'Kinderen wonen bij mij: '.$interestsString."\n";
}
// send email
$senderName = "=?UTF-8?B?" . base64_encode($senderName) . "?=";
$messageSubject = "=?UTF-8?B?" . base64_encode($messageSubject) . "?=";
$messageHeaders = "From: " . $senderName . " <" . $senderEmail . ">\r\n"
. "MIME-Version: 1.0" . "\r\n"
. "Content-type: text/plain; charset=UTF-8" . "\r\n";
if (preg_match('/^[_.0-9a-z-]+#([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/',$targetEmail,$matches))
mail($targetEmail, $messageSubject, $messageText, $messageHeaders);
// redirect
if($redirectToReferer) {
header("Location: ".#$_SERVER['HTTP_REFERER'].'#sent');
} else {
header("Location: ".$redirectURL);
}
?>

PayPal integration - instant payment notification (IPN)

I am having doubts on how to implement PayPal IPN. I have created a button, and it has the variable notify_url defined:
<input type="hidden" name="notify_url" value="./ipn.php" />
In ipn.php file I have put this code (from Integrate paypal):
<?php
// read the post from paypal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// 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.sandbox.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// 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
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>
The question is how do I receive the notifications in the user's account? What kind of code do I need additionally?

Paypal sandbox not giving a responce

I know this has been covered quite a lot on here but I've spent most of the day trying to fix this error and don't seem to be getting anywhere.
When I use the PayPals IPN simulator to send a Simulation IPN I keep receiving the response Live-INVALID IPN
Now I thought that this was due to the fact that I'm sending it as a test from sandbox so I tried using the sandbox url as you can see below but if I do this I don't receive a responce at all.
Can someone tell me where I'm going wrong please?
<?php // PHP 4.1
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$email = ****;
// 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);
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// 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
mail($email, "Live-VERIFIED IPN", $res . "\n\n" . $req);
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
mail($email, "Live-INVALID IPN", $res . "\n\n" . $req);
}
}
fclose ($fp);
}
?>
After posting this question I found the following example on paypal developers which uses curl instead, this worked first time for me and I received a response of verified.
Please find the link below for anyone who encounters the same issue:
https://developer.paypal.com/webapps/developer/docs/classic/ipn/ht_ipn/

PayPal sends multiple IPN's

I have this code, everything works fine. It's just that PayPal keeps resending multiple IPNs. I have read the forum of PayPal and they say that PayPal isn't getting a HTTP/1.1 200 OK from me, so it keeps resending the IPN. How would I go about this?
function sql_execute($sql){
$sql_connect = #mysql_connect($_SERVER['HTTP_HOST'].':3306','root', '****') or
die('Could not connect: ' . mysql_error());
mysql_select_db('4bkk');
mysql_query($sql);
$rows = mysql_affected_rows($sql_connect); //mysql_insert_id();
mysql_close();
return $rows;
}
function sql_query($sql){
// echo $sql;
$sql_connect = #mysql_connect($_SERVER['HTTP_HOST'].':3306','****', 'zzz111') or
die('Could not connect: ' . mysql_error());
mysql_select_db('4bkk');
$rs = mysql_query($sql) or die(mysql_error());
mysql_close();
return $rs;
}
function logtrace($o){
$q = "INSERT INTO log (trace, trace_time) VALUES ('$o', NOW() )";
sql_query($q);
}
function send_email($t,$s,$m,$h){
//mail($t, $s, $m, $h);
$fh = fopen('result_ipn_test.txt', 'w');
fwrite($fh, $t.' '.$s.' '.$m.' '.$h);
fclose($fh);
logtrace('Mail is sent and exit called');
exit();
}
logtrace('__________NEW SESSION__________');
$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$postFields = 'cmd=_notify-validate';
foreach($_POST as $key => $value)
{
$postFields .= "&$key=".urlencode($value);
}
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postFields
));
$result = curl_exec($ch);
$info = curl_getinfo($ch);
logtrace($info['url']);
curl_close($ch);
//get buyers information from PAYPAL checkout
$email = $_POST['payer_email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$amount = $_POST['amount3'];
$plan = $_POST['option_selection1'];
logtrace($email.' -- '.$active);
$q = "SELECT * FROM users WHERE email='$email' AND user_level='' AND active='unverified'"; //Unprocessed record = no user_level and active = 'unverified'
$ex = sql_execute($q);
//logtrace("THIS ".$q." => ".$ex);
if(sql_execute($q)){
logtrace('IT IS TRUE');
$flag = TRUE;
}
else{
logtrace('FALSE');
$flag = FALSE;
}
logtrace($result.' RESPONSE FROM PAYPAL');
if(($result=='VERIFIED') && $flag){ //Checks first if PayPal is valid, email address exists in
//records and checks if user_level='' and active='unverified',
//if not enters.
logtrace('USER IS READY FOR VERIFICATION');
$q = "SELECT * FROM users WHERE email='$email'";
$data = sql_query($q);
$con = mysql_fetch_array($data);
//Get buyers information from the database
$email2 = $con['email'];
$first_name = $con['first_name'];
$last_name = $con['last_name'];
$active = $con['active'];
$user_level = $con['user_level'];
logtrace('Emails match');
$u = "UPDATE users SET active='verified', user_level='$plan' WHERE email='$email' LIMIT 1";
if (sql_query($u)) { //Successful verification
logtrace('|| Update was sucessful');
}
else{ // Unsuccessful verification.
logtrace('|| Something went wrong with update.');
}
}
else{ // The user doesn't have any record in the database.
$q = "SELECT * FROM users WHERE email='$email' AND (user_level='Monthly' OR user_level='Quarterly' OR user_level='Yearly')";
if(sql_execute($q)){ // The user is already verified
logtrace('THE USER IS ALREADY VERIFIED');
}
else{ // The user does not exist.
logtrace('THE USER HAS NO RECORD ON DATABASE');
}
}
Please refer the sample code https://www.x.com/instant-payment-notification-4
Based on the above code you can try setting curl options for
CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1
CURLOPT_HTTPHEADER, array('Connection: Close')
in your above code where you set as curl_setopt_array ...
This should resolve your HTTP/1.1 200 OK issue I think.

PayPal Parallel Payment IPN

I have been stuck for days! I am trying to get the details from PayPal IPN from a parallel payment.
I need the two email addresses that money was sent to and the amount, also the status.
I am looking here:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_APIPN
These are the lines in my code where I try and get email and amount:
$Email1 = $_POST['transaction[0].receiver'];
$Email2 = $_POST['transaction[1].receiver'];
And amount part:
$Amount1 = $_POST['transaction[0].amount'];
$Amount2 = $_POST['transaction[1].amount'];
I am use the IPN code from this page.
https://cms.paypal.com/cms_content/AU/en_AU/files/developer/IPN_PHP_41.txt
Any help? The POST variables come up blank?
Update: I Have found this:
<source lang="php">
<?php
error_reporting(E_ALL ^ E_NOTICE);
// By Gleb Esman, gleb#memberwing.com, http://www.memberwing.com/
//
// Pull raw POST data.
// We need to pull raw data and build our own copy of $_POST in order to
// workaround of invalid POST keys that Adaptive IPN request uses.
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$_YOUR_POST = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode('=', $keyval);
if (count($keyval) == 2)
$_YOUR_POST[$keyval[0]] = urldecode($keyval[1]);
}
if (count($_YOUR_POST) < 3) {
$_YOUR_POST = $_POST;
$original_post_used = TRUE;
}
else
$original_post_used = FALSE;
// Build final $_req postback request
// Paypal's IPN Sample
// read the post from PayPal system and add 'cmd'
if ($original_post_used) {
$_req = 'cmd=_notify-validate';
foreach ($_YOUR_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$_req .= "&$key=$value";
}
}
else
$_req = $raw_post_data . '&cmd=_notify-validate';
// $_req is ready for postback to Paypal here...
$req = $_req;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// PHP 4.1
// read the post from PayPal system and add 'cmd'
//$req = 'cmd=_notify-validate';
//
//foreach ($_POST as $key => $value) {
// $value = urlencode(stripslashes($value));
// $req .= "&$key=$value";
//}
// 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);
// throw all this junk into the local error log so we can see what happened!
function log_arr($item, $key) {
$p .= "$key = $item";
error_log(urldecode($p));
}
array_walk_recursive($_YOUR_POST, 'log_arr');
error_log(urldecode($req));
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
if (!$fp) {
// HTTP ERROR
} else {
fputs($fp, $header . $req);
while (!feof($fp)) {
$res = fgets($fp, 1024);
if (strcmp($res, "VERIFIED") == 0) {
// 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
} else if (strcmp($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose($fp);
}
?>
</source>
which produces this in log file:
[10-Dec-2011 07:13:50] transaction[0].id_for_sender_txn = xxxxx
[10-Dec-2011 07:13:50] log_default_shipping_address_in_transaction = xxx
[10-Dec-2011 07:13:50] transaction[0].receiver = xxxxx
[10-Dec-2011 07:13:50] action_type = xxxx
[10-Dec-2011 07:13:50] transaction[1].paymentType = xxx
[10-Dec-2011 07:13:50] transaction[0].amount = xxxx
[10-Dec-2011 07:13:50] charset = xxx
Can anyone tell me how to get these into variables as this is what is printed in log file?
Try $_POST['transaction']['0']['receiver'] and so on. Also, enable E_ALL error messages so you see notices about things like this. If that were enabled, and you checked your error log, you would have seen an undefined index notice. Also, if you're ever desperate to debug $_POST/$_GET/whatever stuff and it's not you controlling the request, you can always write the content to a file and examine it.