php - sandbox / stage of paypal super slow. Around 20 seconds to respond to my IPN handler. Now does not respond at all -


i took example implementation of ipn handler paypals official website

now worked in beginning. answers got slower , slower. while worked fine 20 seconds delay. getting no traffic @ minutes. going on? maybe sandbox ipn handler of paypal close down? have bad setup?

i want mention post (it kinda shed light)

note not initial log. paypal seems not call side @ longer.

the ipn callable, can call from, incognito window, , write logfile.

for completeness, here file:

<?php      use ...;     // config: enable debug mode. means we'll log requests 'ipn.log' in same directory.     // useful if encounter network errors or other intermittent problems ipn (validation).     // set 0 once go live or don't require logging.     define("debug", 1);     // set 0 once you're ready go live     define("use_sandbox", 1);     define("log_file", "./ipn.log");     require_once(__dir__ . "/../../bootstrap.php");        //define("log_file", __dir__ . "/../../../../../japi/logs/ipn.log");     error_log(date('[y-m-d h:i e] '). "lukas: initial call log". php_eol, 3, log_file);     // read post data     // reading posted data directly $_post causes serialization     // issues array data in post. reading raw post data input stream instead.     $raw_post_data = file_get_contents('php://input');     $raw_post_array = explode('&', $raw_post_data);     $mypost = array();     foreach ($raw_post_array $keyval) {       $keyval = explode ('=', $keyval);       if (count($keyval) == 2)         $mypost[$keyval[0]] = urldecode($keyval[1]);     }     //$mmessage ="hi lukas <br/>";     //     //    include_once jcr_kint_class;     //$mmessage .= @\kint::dump($mypost);     //mail("lukas.meier@gmail.com", "ipn paypal test", $mmessage);     // read post paypal system , add 'cmd'     $req = 'cmd=_notify-validate';     if(function_exists('get_magic_quotes_gpc')) {       $get_magic_quotes_exists = true;     }     foreach ($mypost $key => $value) {       if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {         $value = urlencode(stripslashes($value));       } else {         $value = urlencode($value);       }       $req .= "&$key=$value";     }     // post ipn data paypal validate ipn data genuine     // without step can fake ipn data     if(use_sandbox == true) {       $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";     } else {       $paypal_url = "https://www.paypal.com/cgi-bin/webscr";     }     $ch = curl_init($paypal_url);     if ($ch == false) {       return false;     }     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);     if(debug == true) {       curl_setopt($ch, curlopt_header, 1);       curl_setopt($ch, curlinfo_header_out, 1);     }     // config: optional proxy configuration     //curl_setopt($ch, curlopt_proxy, $proxy);     //curl_setopt($ch, curlopt_httpproxytunnel, 1);     // set tcp timeout 30 seconds     curl_setopt($ch, curlopt_connecttimeout, 30);     curl_setopt($ch, curlopt_httpheader, array('connection: close'));     // config: please download 'cacert.pem' "http://curl.haxx.se/docs/caextract.html" , set directory path     // of certificate shown below. ensure file readable webserver.     // mandatory environments.     //$cert = __dir__ . "./cacert.pem";     //curl_setopt($ch, curlopt_cainfo, $cert);     $res = curl_exec($ch);     if (curl_errno($ch) != 0) // curl error     {       if(debug == true) {         error_log(date('[y-m-d h:i e] '). "can't connect paypal validate ipn message: " . curl_error($ch) . php_eol, 3, log_file);       }       curl_close($ch);       exit;     } else {       // log entire http response if debug switched on.       if(debug == true) {         error_log(date('[y-m-d h:i e] '). "http request of validation request:". curl_getinfo($ch, curlinfo_header_out) ." ipn payload: $req" . php_eol, 3, log_file);         error_log(date('[y-m-d h:i e] '). "http response of validation request: $res" . php_eol, 3, log_file);       }       curl_close($ch);     }     // inspect ipn validation result , act accordingly     // split response headers , payload, better way strcmp     $tokens = explode("\r\n\r\n", trim($res));     $res = trim(end($tokens));     if (strcmp ($res, "verified") == 0) {       // check whether payment_status completed       // check txn_id has not been processed       // check receiver_email paypal email       // check payment_amount/payment_currency correct       // process payment , mark item paid.       // 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'];       //$txn_id = $_post['txn_id'];       //$receiver_email = $_post['receiver_email'];       //$payer_email = $_post['payer_email'];         $jppa = new jcrpaypalanswer();       $jppa->createfrompaypalipnresponsearray($mypost);        if($jppa->is_completed){         //content of file: paykey => array($project_id, serialize($fd), $statisticsid);         $r = parse_ini_file(jcr_paykey_inifile);         if($r){           $pkarr = $r[$jppa->pay_key];           $project_id = $pkarr[0];           /** @var fundingdetails $fd */           $fd = unserialize(base64_decode($pkarr[1]));           $statisticsid = $pkarr[2];           $jcrp = new jewcerproject($project_id);           $jewcerfee = $jcrppa->amount_fee_account;           $fundingamount = $jcrppa->amount_funding_account_brutto;            $x = null;           $js = new jcrstatistic($x, $statisticsid);            //fna [$amount, $paypalfee, $jewcerfeeamount]           $fna = jcrpaypalservice::getfeesandamount($fd->amount, $fd->coverfee, $jcrp->getfundingfee());           $amount = $fna[0];           $paypalfee = $fna[3];           $jewcerfeeamount = $fna[2];            $fd->wepayfee = $paypalfee;           $fd->jcrfee = $jewcerfeeamount;           $amount_with_fee = $amount;           if ($fd->coverfee) {             $fd->amount_without_fees = $amount - $paypalfee - $jewcerfeeamount;           } else {             $fd->amount_without_fees = $fd->amount;           }           $fd->amount = $amount_with_fee;           $jcrf = new jcrfunder($project_id);           $jcrf->setbasicfundervalues($fd);           $jcrf->save();           $js->add_stats_from_fundingdetails($fd, "jfp3");           emailservice::senddonationsuccessemails($jcrp, $fd);            unset($r[$jppa->pay_key]);           utilityservice::write_ini_file($r, jcr_paykey_inifile);           utilityservice::write_ini_file(array('ok',  $jcrf->id ), jcr_paypal_status_folder . $jppa->pay_key);         }else{           error_log(date('[y-m-d h:i e] '). "jewcer error 3200: couldn't find entry paykey in inifile, inifile val: " . var_export($r, true). php_eol, 3, log_file);         }     //    mail("lukas.meier@gmail.com", "ipn completed", serialize($jppa));     //    jcrpaypalkeypool::$keys[$jppa->pay_key] = $jppa; //eventually verify emails     //    jcrpaypalkeypool::$keys[$jppa->pay_key] = $jppa; //eventually verify emails        }        if(debug == true) {         error_log(date('[y-m-d h:i e] '). "verified ipn: $req ". php_eol, 3, log_file);       }     } else if (strcmp ($res, "invalid") == 0) {       // log manual investigation       // add business logic here deals invalid ipn messages       if(debug == true) {         error_log(date('[y-m-d h:i e] '). "invalid ipn: $req" . php_eol, 3, log_file);       }     } 

i have been using ipn many years wide variety of projects. in experience, if configured correctly , ipn script has no problems work close real-time without many hiccups.

what can run into, though, if ipn script failing reason, or sending paypal response code other 200 when gets hit, re-try, each time re-tries delays time in sends. might send 1 instantly, if doesn't provide 200 response it'll send 1 in 5 seconds, 10 seconds, 20 seconds, 40 seconds, etc. (that's not exact increment uses it's example of does.)

if script not returning 200 response @ point, or if happening lot ipns getting sent script, paypal's system move ipns slower queue others working well.

eventually, if still isn't fixed, they'll disable altogether on account.

check ipn history in paypal account see response you're getting there on ipns getting sent. of course, allow verify indeed getting sent well.

you'll want check php error logs on server see if going on when ipn script gets hit causes fail reason. happening ipn types or when particular characters included in data, example.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -