paypal ipn - PAY PAL IPN stop working -
my code stop working, have made changes $res=trim($res);
saw in question still not working. code working including automatic post in facebook , tweeter.
please, check code , me fix it?
<?php // revision notes // 11/04/11 - changed post url https://www.paypal.com/cgi-bin/webscr https://ipnpb.paypal.com/cgi-bin/webscr // more info see below: // https://www.x.com/content/bulletin-ip-address-expansion-paypal-services // "action required: if using ipn (instant payment notification) order management , ipn listener script behind firewall uses acl (access control list) rules restrict outbound traffic limited number of ip addresses, may need 1 of following: // continue posting https://www.paypal.com perform ipn validation need update firewall acl allow outbound access *any* ip address servers host ipn script // or alternatively, need modify ipn script post ipns newly created url https://ipnpb.paypal.com using https (port 443) , update firewall acl rules allow outbound access ipnpb.paypal.com ip ranges (see end of message)." ///////////////////////////////////////////////// /////////////begin script below.///////////////// ///////////////////////////////////////////////// // read post paypal system , add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_post $key => $value) { $value = urlencode(stripslashes($value)); $value = preg_replace('/(.*[^%^0^d])(%0a)(.*)/i','${1}%0d%0a${3}',$value);// ipn fix $req .= "&$key=$value"; } // post paypal system 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 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 , email $notify_email = "xxxxxx@gmail.com"; //email address debug emails sent $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 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 paypal_payment_info 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 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 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.' '.$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() receiver_email='$receiver_email'"); $result = mysql_query($sql) or die( mysql_error() ); } else { // send email mail($notify_email, "verified duplicated transaction", "$res\n $req\n $strquery\n $struery\n $strquery2"); } // if ipn post 'invalid'...do } else if (strcmp ($res, "invalid") == 0) { // log manual investigation mail($notify_email, "invalid ipn", "$res\n $req"); } } fclose ($fp); } ?>
the host tag in header has match url using 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 paypal system verify $fp = fsockopen('ssl://'.$paypalurl, 443, $errno, $errstr, 30);
Comments
Post a Comment