IPN works in sandbox but not live
justgotloud
New Community Member
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
Apr-15-2024
09:18 PM
Everything was working great in sandbox, moved it over to live and no data coming in. My IPN is:
<?php
include('db.php');
// Read the POST data from PayPal
$raw_post_data = file_get_contents('php://input');
mysqli_query($con, "INSERT INTO salesdata (datas, bid, UID, status, tid) VALUES ('$raw_post_data', '0', '0', '0', '4')");
// Check if it's a test IPN (sandbox)
$test_ipn = isset($_POST['test_ipn']) && (int) $_POST['test_ipn'] === 1;
// Set the PayPal endpoint URL based on test mode
$paypal_url = $test_ipn ? 'https://www.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr';
// Build the validation request
$req = 'cmd=_notify-validate&';
foreach ($_POST as $key => $value) {
$req .= urlencode($key) . '=' . urlencode($value) . '&';
}
$json_data = json_decode($raw_post_data, true);
$amount = $json_data['resource']['amount']['total'];
// Use CURL to send the validation request to PayPal
$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); // Verify PayPal's SSL certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // Check for hostname mismatch
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Check the response from PayPal
//if ($status == 200 && $response == 'VERIFIED') {
if ($status == 200) {
$status = 'paid';
// The message is VALID from PayPal
// Process the IPN data from $_POST
//
mysqli_query($con, "INSERT INTO salesdata (datas, bid, UID, status, tid) VALUES ('$json_data', '$amount', '0', '$status', '3')");
// Handle the transaction based on payment_status
// ... (Your logic to update order status, send notifications, etc.)
// IMPORTANT: After processing, return an empty HTTP 200 OK response
echo '';
} else {
mysqli_query($con, "INSERT INTO salesdata (datas, bid, UID, status, tid) VALUES ('$raw_post_data', '0', '0', '0', '5')");
// The message is INVALID or there was a problem
// You can log for investigation or notify admins
error_log("Invalid IPN: " . $response, 1);
}
?>
0 REPLIES 0
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
Related Content
- How do I resolve RESOURCE_NOT_FOUND Error? in REST APIs
- Unauthorized error when use multiparty APIs in Sandbox Environment
- PayPal Rest API: Popup "Bei uns ist ein Problem aufgetreten" in REST APIs
- Advance Integration not working with live credentials in PayPal Payments Standard
- How do I generate PayPal Client ID & Secret Key? in REST APIs