Skip to content

Instantly share code, notes, and snippets.

@0x46
Created November 20, 2018 13:47
Show Gist options
  • Save 0x46/1253bb2c10c48b57dd1df042cf6e341e to your computer and use it in GitHub Desktop.
Save 0x46/1253bb2c10c48b57dd1df042cf6e341e to your computer and use it in GitHub Desktop.
Working PayPal IPN script
<?php
require_once 'PaypalIPN.php'; // from https://github.com/paypal/ipn-code-samples/blob/master/php/PaypalIPN.php
$env = 'sandbox'; // set somewhere else normally
$ipn = new PaypalIPN();
if ($env == 'sandbox') {
$ipn->useSandbox(); // use sandbox endpoint to verify
$ipn->usePHPCerts(); // use local certs for testing
}
$verified = $ipn->verifyIPN();
$paypal_ipn_status = "VERIFICATION FAILED";
if ($verified) { // verified
$paypal_ipn_status = "VERIFIED";
/* do something */
} elseif ($env == 'sandbox') {
if ($_POST["test_ipn"] != 1) {
$paypal_ipn_status = "RECEIVED FROM LIVE WHILE SANDBOXED";
}
} elseif ($env == 1) {
$paypal_ipn_status = "RECEIVED FROM SANDBOX WHILE LIVE";
}
if ($env == 'sandbox') {
/* logging */
}
// Reply with an empty 200 response to indicate to paypal the IPN was received correctly
header("HTTP/1.1 200 OK");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment