PHP Paypal IPN fails sometimes -


i have php script have been using 2 years , modified work when paypal changed http 1.1. has worked every transaction, failed , cannot figure out why. below code.

it fails when trying @ response. invalid

could have non standard characters in address?

i have tried sending ipn request again , again , fails

function paypal_ipn() {     $req = 'cmd=_notify-validate';      foreach($_post $key => $value) {         $value = urlencode(stripslashes($value));         $req .= "&{$key}={$value}";     }      $res = '';     $ch = curl_init(paypal_url());     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'));        $res = curl_exec($ch);     curl_close($ch);      if(paypal_ipn_debug && !empty($_post)) {         $fname = 'ipn_intial_' . date('y.m.d-h.i.s', time()) . '.txt';         file_put_contents('log/' . $fname, $req);          $fname = 'ipn_intial_result_' . date('y.m.d-h.i.s', time()) . '.txt';         file_put_contents('log/' . $fname, $res);      }      if(strcmp($res, "verified") == 0) {          switch($_post['txn_type'])  {         case 'web_accept':             $data = array();             $data['name'] = $_post['first_name'] . ' ' . $_post['last_name'];             $data['email'] = $_post['payer_email'];             $data['txn_id'] = $_post['txn_id'];             $data['payment_status'] = 'completed';             $res = save_payment($data);             if ($res) {                 $data = payment_details(array('txn_id' => $data['txn_id']));                 mail_notification($data);             }                         break;          case 'subscr_signup':             $params = array();             $params['name'] = $_post['first_name'] . ' ' . $_post['last_name'];             $params['email'] = $_post['payer_email'];             $params['subscr_id'] = $_post['subscr_id'];             $params['subscr_status'] = 'payment';              $data = save_subscription($params);             subscr_notification($data);             break;         case 'subscr_cancel':             $data = subscr_details(array('subscr_id' => $_post['subscr_id']));              if ($data)             {                 mysql_update('subscriptions', array('subscr_id' => $_post['subscr_id']), array('subscr_status' => 'cancelled', 'cancel_date' => date('y-m-d h:i:s')));             }             break;         }      }      if(paypal_ipn_debug && !empty($_post)) {         $fname = 'ipn_' . date('y.m.d-h.i.s', time()) . '.txt';         file_put_contents('log/' . $fname, serialize($_post));     } } 

this tricky one. magic quotes turned off , script assumes magic quotes on. therefore there no need called stripslashes causing error


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -