php - Paypal IPN Sandbox - IPN Listener - no verified or invalid -
i have set test accounts business , personal in developer trying out sandbox mode.
i have made payment button on site. click button , go paypal. test user personal account used paying. payment goes through , completed when in paypal business account. redirect site works good.
so in eyes should have "working" system.
my ipn listener though not return either verified or invalid.
this listener:
<?php require("../widgets/init.inc.php"); //test script launced $log_query = mysql_query("insert `log` values (' ','zz','ff','rr', 'rr')"); // link paypal codes // // https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_id=developer/e_howto_html_ipnandpdtvariables // // read post paypal system , add 'cmd' // $req = 'cmd=_notify-validate'; foreach ($_post $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post paypal system 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"; //for below line have tried "www.sandbox.paypal" "www.paypal" $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); // assign posted variables 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']; $txnid = $_post['txn_id']; $receiveremail = $_post['receiver_email']; $payeremail = $_post['payer_email']; //$id = ($_post['custom']); if (!$fp) { } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "verified") == 0) { if ($payment_status=='completed') { //$txnidcheck = mysql_query("select `txnid` `log` `txnid`='".$txnid."'"); //if (mysql_num_rows($txnidcheck) !=1) { // enter email address associated paypal account here // if ($receiveremail=='biztester1@mydomain.dk') { /* when new premium member makes payment paypal update our database. txn_id paypal, members email address, date of payment , members id gave them when joined our site inserted log table. @ same time memberadmin table member updated adding '1' premium , date of payment new premium member have access premium areas of site. */ //check if verified launced $log_query_2 = mysql_query("insert `log` values (' ','yes','yes','yes', 'yes')"); //$log_query = mysql_query("insert `log` values (' ','".intval($id)."','".$txnid."','".$payeremail."', now())"); //$update_premium = mysql_query("update `memberadmin` set `premium`=1, `premiumdate`=now() `id`=".intval($id).""); } //} } } else if (strcmp ($res, "invalid") == 0) { //check if invalid launced $log_query_2 = mysql_query("insert `log` values (' ','no','no','no', 'no'"); } } fclose ($fp); } ?>
i have activated ipn @ paypal business account site. have made txt file of returned information paypal, , looks this:
==== thu, 18 jul 2013 01:34:21 +0200 ==== post: mc_gross = 0.01 post: protection_eligibility = ineligible post: payer_id = 73wppk8hksw7c post: tax = 0.00 post: payment_date = 15:15:20 jul 17, 2013 pdt post: payment_status = completed post: charset = windows-1252 post: first_name = niels post: mc_fee = 0.01 post: notify_version = 3.7 post: payer_status = verified post: business = biztester1@mydomain.dk post: quantity = 1 post: verify_sign = a-ddkawtxju4tphgjogq6c3ewj26ayihsd.xo90coz.4rvzot7vyooko post: payer_email = tester1@mydomain.dk post: txn_id = 6wh41489re087103m post: payment_type = instant post: last_name = tester post: receiver_email = biztester1@mydomain.dk post: payment_fee = 0.01 post: receiver_id = pcx638b2m7wpa post: txn_type = web_accept post: item_name = 500credits post: mc_currency = usd post: item_number = 1 post: residence_country = de post: test_ipn = 1 post: handling_amount = 0.00 post: transaction_subject = 500credits post: payment_gross = 0.01 post: shipping = 0.00 post: ipn_track_id = 2dffcbf8767d3 invoiceid: custom1: custom2: custom3:
it seems lot harder work think should be.
i found problem.. , annoying thing paypal documentation wrong again.. don't understand documentation can state press button , press button.. when there no buttons in site...
for problem - documentation state wrong method / not include full code needed.
the problem: $res returned this:
http/1.0 400 bad request server: bigip connection: close content-length: 19 invalid host header
what needs added :
$header .= "host: www.sandbox.paypal.com\r\n";
and above code looks this:
// post paypal system validate // $header .= "post /cgi-bin/webscr http/1.0\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"; $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
this full code ended using:
<?php require("../widgets/init.inc.php"); // link paypal codes // // https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_id=developer/e_howto_html_ipnandpdtvariables // // read post paypal system , add 'cmd' // $req = 'cmd=_notify-validate'; foreach ($_post $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post paypal system validate // $header .= "post /cgi-bin/webscr http/1.0\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"; $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); // assign posted variables 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']; $txnid = $_post['txn_id']; $receiveremail = $_post['receiver_email']; $payeremail = $_post['payer_email']; //$id = ($_post['custom']); if (!$fp) { } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); $log_query_pre = mysql_query("insert `log` values (' ','$receiveremail','$payment_status','$res', 'yes')"); if (strcmp ($res, "verified") == 0) { if ($payment_status=='completed') { //$txnidcheck = mysql_query("select `txnid` `log` `txnid`='".$txnid."'"); //if (mysql_num_rows($txnidcheck) !=1) { // enter email address associated paypal account here // if ($receiveremail=='biztester1@mydomain.dk') { /* when new premium member makes payment paypal update our database. txn_id paypal, members email address, date of payment , members id gave them when joined our site inserted log table. @ same time memberadmin table member updated adding '1' premium , date of payment new premium member have access premium areas of site. */ //check if verified launced $log_query_2 = mysql_query("insert `log` values (' ','yes','yes','yes', 'yes')"); //$log_query = mysql_query("insert `log` values (' ','".intval($id)."','".$txnid."','".$payeremail."', now())"); //$update_premium = mysql_query("update `memberadmin` set `premium`=1, `premiumdate`=now() `id`=".intval($id).""); } //} } } else if (strcmp ($res, "invalid") == 0) { //check if invalid launced $log_query_2 = mysql_query("insert `log` values (' ','no','no','no', 'no')"); } } fclose ($fp); } ?>
Comments
Post a Comment