Question

This is my IPN code(modified version of the example):

<?php
$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, "cmd=_notify-validate&" . file_get_contents("php://input"));
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 (strcmp ($res, "VERIFIED") == 0) {
$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'];
file_put_contents("ipn.txt", "cmd=_notify-validate&" . file_get_contents("php://input"));
}else{
file_put_contents("ipn.txt", "fail: " . $res);
}
?>

The $res variable always seems to be empty, although it should either be INVALID or VERIFIED. I've outputted it to a file, and is always empty. I've double and triple-checked that I have curl enabled, I do. I don't play with PHP too often, so I might have done something stupid I haven't seen. Does anyone know what's wrong with it?

Was it helpful?

Solution

It turns out I needed to specify a cacert file. It was causing the ssl verification to fail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top