Paypal PHP not working. No response received from Sandbox; only Connection: close -
i've been @ 24 hours , pull hair out. i've checked on web , within stackoverflow , can find nil helps. i've checked previous posts such not receiving response paypal ipn sandbox responses aren't working me. perhaps i've missed the post that'll help me; if have, please excuse me repeating same question, matter rather urgent , i'm @ end of rope.
anyway, issue this:
i have php cart going , sends clients paypal. working perfectly. i've built according paypal's instructions when comes sending codes them. fine except when comes final step, homecoming post
paypal server check everything's ok. there i've copied entire paypal code , added functions that'll check matches on part. however, can't work. seek sending results db , nil happens. placed php mail
command right lastly action should if everything's ok , don't receive e-mail. i've placed same mail
command everywhere else seek , find out what's going on , have received different clues different places.
first, when phone call print e-mail vars paypal's supposed send server, e-mail vars except item_name
, item_number
, blank; strange, because point paypal sandbox showing me every single product i'm supposedly purchasing. tried giving these vars on php code fixed value in lite of fact paypal not posting value them, @ to the lowest degree @ point. wanted see if lack of these 2 values reason error; error persisted, however, set values.
second, there's while
loop in paypal code (the loop response in link given above says 1 should replace $res=stream_get_contents($fp, 1024);
, this, however, didn't work me either), placed mail
command in there see got back. asked print $res
var , payment_status
, got, expected, several e-mails, collected results of follows:
payment_status = pending $res = http/1.0 302 found location: https://www.sandbox.paypal.com server: bigip connection: close content-length: 0
so i'm guessing error occurring @ point. happening (or not happening) not not returning completed
status payment_status
code looks in order go on checking , etc., it's not returning invalid
response. i'm getting no response , nil show me whether everything's ok or not. and, what's strange, , worse, fact sandbox still fake-charging me every single 1 of these payment attempts, though it's clear there's error somewhere , process not beingness fulfilled. (this, of course, brings out dilemma: 1 time solved, if there server error @ point x reason, paypal still charge client , won't know has bought on website?)
well, suppose that's much can explain on matter. @ point can't see have gone wrong. code should create pretty straightforward thing. don't see how have messed re-create & paste. suppose @ to the lowest degree should have no errors, unless come original code. moreover, because else point working 100% fine, place error within php file paypal has phone call 1 time payment process completed user.
any thought on matter extremely appreciated!
here goes code.
php code:
include('../inc/db_fns.inc'); //<--all db work in here. include('../inc/shipping.inc'); $paypal_email = "seller_1360198925_biz@hotmail.com"; $paypal_currency = 'usd'; //here begin functions i'm using check , pass info db. function no_paypal_trans_id($trans_id) { $connection = db_connect(); $query = sprintf("select id orders paypal_trans_id = '%s'", mysql_real_escape_string($trans_id)); $result = mysql_query($query); $num_results = mysql_num_rows($result); if($num_results == 0) { homecoming true; } homecoming false; } function payment_amount_correct($shipping, $params) { $amount = 0.00; ($i=1; $i <= $params['num_cart_items']; $i++) { $query = sprintf("select precio products id='%s'", mysql_real_escape_string($params["item_number{$i}"])); $result = mysql_query($query); if($result) { $item_price = mysql_result($result, 0, 'precio'); $amount += $item_price * $params["quantity{$i}"]; } } if(($amount+$shipping) == $params['mc_gross']) { homecoming true; } else { homecoming false; } } function create_order($params) { db_connect(); $query = sprintf("insert orders set orders.firstname = '%s', orders.lastname = '%s', orders.email = '%s', orders.country = '%s', orders.address = '%s', orders.city = '%s', orders.zip_code = '%s', orders.state = '%s', orders.status = '%s', orders.amount = '%s', orders.paypal_trans_id = '%s', created_at = now()", mysql_real_escape_string($params['first_name']), mysql_real_escape_string($params['last_name']), mysql_real_escape_string($params['payer_email']), mysql_real_escape_string($params['address_country']), mysql_real_escape_string($params['address_street']), mysql_real_escape_string($params['address_city']), mysql_real_escape_string($params['address_zip']), mysql_real_escape_string($params['address_state']), mysql_real_escape_string($params['payment_status']), mysql_real_escape_string($params['mc_gross']), mysql_real_escape_string($params['txn_id'])); $result = mysql_query($query); if(!$result) { homecoming false; } $order_id = mysql_insert_id(); ($i=1; $i <= $params['num_cart_items'] ; $i++) { $product = find_product($params["item_number{$i}"]); $query = sprintf("insert items set order_id = '%s', product_id = '%s', title = '%s', cost = '%s', qty = '%s'", mysql_real_escape_string($order_id), mysql_real_escape_string($product['id']), mysql_real_escape_string($product['title']), mysql_real_escape_string($product['price']), mysql_real_escape_string($params["quantity{$i}"])); $result = mysql_query($query); if(!$result) { homecoming false; } } homecoming true; } //here begins paypal code // read post paypal scheme , add together 'cmd' $req = 'cmd=_notify-validate'; foreach ($_post $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post paypal scheme 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); //<--here tried out other response question linked above , returned 'invalid host' $res var- // assign posted variables local variables $item_name = $_post['item_name']; //<--these 2 vars $item_number = $_post['item_number'];// paypal sandbox posts no value. $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) { if ($_post['payment_status'] == 'completed' && no_paypal_trans_id($_post['txn_id']) && $paypal_email == $_post['receiver_email'] && $paypal_currency == $_post['mc_currency'] && payment_amount_correct($shipping, $_post)) { // process payment create_order($_post); } } else if (strcmp ($res, "invalid") == 0) { // log manual investigation } } fclose ($fp); }
edit 1: gave go: no luck!
i've tried original, untouched paypal code. i've copied , pasted php , run sandbox buy. same outcome. no response, no info inserted tables, no way of me knowing has bought off cart, paypal still fake-charges buy. supports suspicion error comes in original code , has nil functions i've added. hope can create sense of soon. one thousand in advance person!
edit 2: next 1st response.
a kind user has deleted his/her response kind plenty give first try. he/she recommended paypal documentation mentions https://www.sandbox.paypal.com/cgi-bin/webscr
have http://www.sandbox.paypal.com
. perhaps have older version of code, tried out his/her recommendation. comment happened:
first of all, lot response. unfortunately, no luck it. having substituted 1 address other, process doesn't while
loop, stops @ fsockopen
. placed mail
command print out $errno
, $errstr
contained in command. https://www.sandbox.paypal.com/cgi-bin/webscr
substituting http://www.sandbox.paypal.com
unable find socket transport "https" - did forget enable when configured php? stripped "https://" , tried again. php_network_getaddresses: getaddrinfo failed: name or service not known. ideas?
edit 3: next conversation @hexacyanide in comments section:
$req = cmd=_notify-validate&test_ipn=1&payment_type=instant&payment_date=20%3a55%3a22+feb+08%2c+2013+pst&payment_status=completed&address_status=confirmed&payer_status=verified&first_name=john&last_name=smith&payer_email=buyer%40paypalsandbox.com&payer_id=testbuyerid01&address_name=john+smith&address_country=united+states&address_country_code=us&address_zip=95131&address_state=ca&address_city=san+jose&address_street=123%2c+any+street&receiver_email=seller%40paypalsandbox.com&receiver_id=testsellerid1&residence_country=us&item_name1=something&item_number1=ak-1234&quantity1=1&tax=2.02&mc_currency=usd&mc_fee=0.44&mc_gross_1=9.34&mc_handling=2.06&mc_handling1=1.67&mc_shipping=3.02&mc_shipping1=1.02&txn_type=cart&txn_id=2229455¬ify_version=2.4&custom=xyz123&invoice=abc1234&charset=windows-1252&verify_sign=asdnkkd2ktcz.aub.9wywy-g8mhoaa-tsvsjuggstsejvduhqtq3acww
sorry, $req
, not $res
var. $res
var returned while
loop. placed mail
command there , several e-mails $res
values. these are:
x-frame-options: sameorigin http/1.0 200 ok strict-transport-security: max-age=14400 invalid content-type: text/html; charset=utf-8 date: sat, 09 feb 2013 05:44:33 gmt connection: close content-length: 7
edit 4: absolutely dumbfounded: not simple paypal ipn code straight paypal developer website , tested paypal developer website ipn tester works...
i've used paypal ipn script generator found here. i chose generate script mail service me valid or invalid response. i copied in entirety , pasted php file saved in server. i checked , re-checked no part of code left behind. i targeted php file on server ipn simulator found here. simulator shows check , says "ipn sent." i go check mail service see response got, whether valid or invalid... got no response @ all. ipn reaches php purchase @ point process broken doesn't valid/invalid functions. however, code paypal gives , tested sim has designed it. what's going on? day 2 of odysseyo.k. needless say: no luck yet. i've decided exhaustively track that's going php code , out paypal. thought response of valid
occurs when code sends paypal initial values paypal inserted , in same order (this according paypal documentation).
the first issue receiving no response @ code. supposition code failing @ start. happened first issue sandbox links no work. (i got point aid of @hexacyanide, kind follow along yesterday progress or lack thereof. whenever plenty reputation positively mark his/her response, will.) stripped off sandbox.
and, voilĂ , returning response, response invalid
.
from time i've understood ipn seller-side transaction checking , info logging. paypal doesn't care outcome of ipn. cart working 100%. user can purchase , paypal charge user it. ipn check me if purchase info in fact coming paypal , there , (in script) send info db can fulfill side of service. so, though transaction happens without ipn, ipn invaluable mechanism facilitate overall selling process. however, lastly info settles suspicion cart's code o.k., , issue here, code, or way paypal handling it. (the fact paypal's "virgin" code passed through paypal's own ipn simulator returns no response, same error @ initial state of not beingness able connect the paypal server makes me inclined think issue has wrong on paypal's side.)
so, log of going , out of php. located mail
commands @ every single important point in code in order create checkpoints. within foreach()
command included incremental variable in order have , ordered list of posted info coming in. , got:
this info beingness posted code paypal (in order it's beingness posted)
test_ipn=1 payment_type=instant payment_date=08%3a42%3a23+feb+09%2c+2013+pst payment_status=completed payer_status=verified first_name=john last_name=smith payer_email=buyer%40paypalsandbox.com payer_id=testbuyerid01 business=seller%40paypalsandbox.com receiver_email=seller%40paypalsandbox.com receiver_id=testsellerid1 residence_country=us item_name1=something item_number1=ak-1234 quantity1=1 tax=2.02 mc_currency=usd mc_fee=0.44 mc_gross=15.34 mc_gross_1=12.34 mc_handling=2.06 mc_handling1=1.67 mc_shipping=3.02 mc_shipping1=1.02 txn_type=cart txn_id=23291642 notify_version=2.4 custom=xyz123 invoice=abc1234 charset=windows-1252
at glance, seem getting info should paypal. , order in pp sends it. if send info in order , pp check same order, should, in theory, valid
response.
so code add together "cmd=_notify-validate", add-on (the pp documentation makes clear necessary add-on necessary), , passes info var called $req
in way: a=x&b=y&c=z...
.
here message next checkpoint, added after foreach()
command closes.
$req = cmd=_notify-validate&test_ipn=1&payment_type=instant&payment_date=08%3a42%3a23+feb+09%2c+2013+pst&payment_status=completed&payer_status=verified&first_name=john&last_name=smith&payer_email=buyer%40paypalsandbox.com&payer_id=testbuyerid01&business=seller%40paypalsandbox.com&receiver_email=seller%40paypalsandbox.com&receiver_id=testsellerid1&residence_country=us&item_name1=something&item_number1=ak-1234&quantity1=1&tax=2.02&mc_currency=usd&mc_fee=0.44&mc_gross=15.34&mc_gross_1=12.34&mc_handling=2.06&mc_handling1=1.67&mc_shipping=3.02&mc_shipping1=1.02&txn_type=cart&txn_id=23291642¬ify_version=2.4&custom=xyz123&invoice=abc1234&charset=windows-1252&verify_sign=afcwxv21c7fd0v3byyyrcpssrl31acyrxuq6lvdwuz.i78mjqlsn9akb
note verify_sign=afcwxv21c7fd0v3byyyrcpssrl31acyrxuq6lvdwuz.i78mjqlsn9akb
@ end. can't business relationship piece of info because not spit out in form of e-mail during foreach()
loop. come from? culprit piece of info returns invalid
response? open question. @ point, info passed code @ "data coming in" checkpoint; if info what's coming in , code sends out, should fine.
so next checkpoint "data coming out." located checkpoint right before fputs ($fp, $header . $req);
code writes $req
pp. , coming out of code:
$req = cmd=_notify-validate&test_ipn=1&payment_type=instant&payment_date=08%3a42%3a23+feb+09%2c+2013+pst&payment_status=completed&payer_status=verified&first_name=john&last_name=smith&payer_email=buyer%40paypalsandbox.com&payer_id=testbuyerid01&business=seller%40paypalsandbox.com&receiver_email=seller%40paypalsandbox.com&receiver_id=testsellerid1&residence_country=us&item_name1=something&item_number1=ak-1234&quantity1=1&tax=2.02&mc_currency=usd&mc_fee=0.44&mc_gross=15.34&mc_gross_1=12.34&mc_handling=2.06&mc_handling1=1.67&mc_shipping=3.02&mc_shipping1=1.02&txn_type=cart&txn_id=23291642¬ify_version=2.4&custom=xyz123&invoice=abc1234&charset=windows-1252&verify_sign=afcwxv21c7fd0v3byyyrcpssrl31acyrxuq6lvdwuz.i78mjqlsn9akb
hum! missing something? eyes skipping on tiniest hiccough makes code trip? output seems same input. let's assume pp worked code fine, posted info turned string in way pp expects and, therefore, checks for... assuming this, wrong?
let's see... again: open questions:
could issue header? according documentation, header 1 should use... unless they're off on this, should work fine. could issue url given? o.k., in fact issue, or rather @ point. there @ to the lowest degree 6 or 7 different urls running around net supposed work , not work. have worked people , not others, seem never work, etc. not pp sure url supposed used, in own documentation varies. clear usingsandbox.
urls homecoming nothing--one suppose these broken. could issue charset? there incompatibility? occurred me seeing info come in , out hex codes. thing should create compatible, right? however, yesterday, checking going on in while()
loop, , catching info sent pp $res
var wasn't getting hex codes, can see farther in testament. the next checkpoint classic 1 @ if()
valid , if()
invalid. and, of course, 1 tells me came out invalid, 1 time again.
hopefully detailed info i'm giving create someone's lite bulb shine brightly! me, i'm still dumbfounded.
thanks in advance!
thanks lot both of responses!
i haven't tried sec 1 out, though sounds pretty sensible. sounds have been issue original code got paypal. if have time seek out , see if code works it, i'll post feedback here. find useful.
after week banging head against walls , little time off cool issue in brain, have finally, couple of days ago, found way solve issue somewhere in web pretty similar sec part of hexacyanide's response. i'm posting below who's next string. however, must say, the paypal code pretty buggy. @ to the lowest degree 1 received. have since had several other issues i've had solve via workarounds. worst part paypal has no back upwards @ all. called 3 times: first, person hung on me; then, told me virus issue (typical response when don't know what's going on).
anyway, wish rate both responses need more +15 points that, i'll praise them verbally here. tried out hexacynide's response code didn't work or me, can't mark checked. if have time seek out other in future, , works, i'll mark correct.
until then, here code update using curl.
$ch = curl_init('https://www.paypal.com/pe/cgi-bin/webscr'); curl_setopt($ch, curlopt_http_version, curl_http_version_1_1); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_returntransfer,1); curl_setopt($ch, curlopt_postfields, $req); curl_setopt($ch, curlopt_ssl_verifypeer, 1); curl_setopt($ch, curlopt_ssl_verifyhost, 2); curl_setopt($ch, curlopt_forbid_reuse, 1); curl_setopt($ch, curlopt_httpheader, array('connection: close')); if( !($res = curl_exec($ch)) ) { // error_log("got " . curl_error($ch) . " when processing ipn data"); curl_close($ch); exit; } curl_close($ch);
note: here it's targeted real thing because it's , running, however, using sandbox.
works well.
i'm new stackoverflow, didn't realize 1 can reply one's own question. anyway, had answered @ end of original post editing lastly week. include here who's having such problem can refer , realize way able solve issue.
i tried first solution given here fellow contributor unfortunately didn't work me. sec solution arrived 1 time had been able solve way, haven't tried it. perhaps i'll sometime in future. if tries it, please leave comments here other benefit wisdom.
here solution:after week banging head against walls , little time off cool issue in brain, have finally, couple of days ago, found way solve issue somewhere in web pretty similar sec part of hexacyanide's response. i'm posting below who's next string. however, must say, the paypal code pretty buggy. @ to the lowest degree 1 received. have since had several other issues i've had solve via workarounds. worst part paypal has no back upwards @ all. called 3 times: first, person hung on me; then, told me virus issue (typical response when don't know what's going on).
anyway, wish rate both responses need more +15 points that, i'll praise them verbally here. tried out hexacynide's response code didn't work or me, can't mark checked. if have time seek out other in future, , works, i'll mark correct.
until then, here code update using curl.
$ch = curl_init('https://www.paypal.com/pe/cgi-bin/webscr'); curl_setopt($ch, curlopt_http_version, curl_http_version_1_1); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_returntransfer,1); curl_setopt($ch, curlopt_postfields, $req); curl_setopt($ch, curlopt_ssl_verifypeer, 1); curl_setopt($ch, curlopt_ssl_verifyhost, 2); curl_setopt($ch, curlopt_forbid_reuse, 1); curl_setopt($ch, curlopt_httpheader, array('connection: close')); if( !($res = curl_exec($ch)) ) { // error_log("got " . curl_error($ch) . " when processing ipn data"); curl_close($ch); exit; } curl_close($ch);
note: here it's targeted real thing because it's , running, however, using sandbox.
works well.
php paypal
No comments:
Post a Comment