Reputation: 11
For several hours the script below worked very well and suddenly it has stopped working.
I have not changed anything.
Is there anything below that looks wrong that could prevent it from working properly?
<?php
// STEP 1: read POST data
// Reading POSTed data directly from $_POST causes serialization issues with array data in the POST.
// Instead, read raw POST data from the input stream.
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
}
foreach ($myPost as $key => $value) {
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
$value = urlencode(stripslashes($value));
} else {
$value = urlencode($value);
}
$req .= "&$key=$value";
}
// Step 2: POST IPN data back to PayPal to validate
$ch = curl_init('https://www.sandbox.paypal.com/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'));
// In wamp-like environments that do not come bundled with root authority certificates,
// please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set
// the directory path of the certificate as shown below:
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
if( !($res = curl_exec($ch)) ) {
// error_log("Got " . curl_error($ch) . " when processing IPN data");
curl_close($ch);
exit;
}
curl_close($ch);
if (strcmp ($res, "VERIFIED") == 0) {
// The IPN is verified, process it:
// check whether the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process the notification
// assign posted variables to 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'];
// process payment
// Added pp_trans_id which is the unique Transaction ID provided by PayPal
// Added reg_date which is in UNIX_TIME()
// Set WHERE to be equal to $id for perfect match
mysql_connect('localhost', 'wgaxzhpl_registe', '****');
mysql_select_db('wgaxzhpl_register');
$id = $_POST['custom'];
$insert = mysql_query("INSERT INTO `log` (txn_id, active) VALUES ('".$txn_id."', 1);");
}
else if (strcmp ($res, "INVALID") == 0) {
// IPN invalid, log for manual investigation
}
?>
Upvotes: 0
Views: 915
Reputation: 1
See http://forums.oscommerce.com/topic/395932-paypal-ipns-have-stopped-working-for-us-yesterday/
It seems it is sending extraneous data
I was logging the paypal response to the verification and it sends something around the important bit I record as
Content-Type: text/html; charset=UTF-8 -blank line- 8 VERIFIED 0
Upvotes: 0
Reputation: 26036
Check the IPN History in your PayPal account to see if IPN's are actually getting sent or not and what response is coming back. If it's showing that they're getting sent and including a 200 response then that means your script is getting hit and completing successfully. In such a case you would need to check the logic of your script to see why it's not doing what you think.
If it's not sending at all you would need to double check your IPN configuration in the PayPal account or the notify URL used on payment requests.
If it is showing that it's sending but getting something other than 200 response that means your IPN script is failing. You can check your web server logs for details on exactly what the error is and get it resolved.
Upvotes: 1