Getting Invalid Response on Instant Payment response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am getting delivery status "Sent" when sending IPN Notification for the given Notify_url on form submission for Paypal checkout. Below is my code Please Have a look and help me out for this.
public function paypalResponse($ord_id){
$raw_post_data = file_get_contents('php://input');//print_r($_REQUEST);die('opop');
$raw_post_array = explode('&', $raw_post_data);print_r($raw_post_array);//die();
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = rawurldecode($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 = rawurlencode(stripslashes($value));
} else {
$value = rawurlencode($value);
}
$req .= "&$key=$value";
}
// Step 2: POST IPN data back to PayPal to validate
$ch = curl_init('https://ipnpb.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(
'User-Agent: PHP-IPN-VerificationScript',
'Connection: Close'));
if ( !($res = curl_exec($ch)) ) {
curl_close($ch);
exit;
}
curl_close($ch);
print_r($res);
if (strcmp ($res, "VERIFIED") == 0) {
$item_name = $_POST['item_name'];
$Receiver_email = $_POST['receiver_email'];
$Item_number = $_POST['item_number'];
$Invoice = $_POST['invoice'];
$Payment_status = $_POST['payment_status'];
$Payment_gross = $_POST['payment_gross'];
$Txn_id = $_POST['txn_id'];
$Payer_email = $_POST['payer_email'];
$custom = $_POST['custom'];
// further checks
if($payment_status == 'Completed') {
$data = array(
'item_name' => $item_name,
'receiver_email' => $Receiver_email,
'item_number' => '123',//$Item_number,
'invoice' => $Invoice,
'payment_status' => $Payment_status,
'payment_gross' => $Payment_gross,
'txn_id' => $Txn_id,
'payer_email' => $Payer_email,
'custom' => $custom,
);
$this->Sale_model->save_payment_details('tbl_payment_details',$data);
// IPN message values depend upon the type of notification sent.
// To loop through the &_POST array and print the NV pairs to the screen:
foreach($_POST as $key => $value) {
echo $key . " = " . $value . "<br>";
}
} else if (strcmp ($res, "INVALID") == 0) {
// IPN invalid, log for manual investigation
echo "The response from IPN was: <b>" .$res ."</b>";
}
}
}
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.