Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * A simple but yet pretty advanced and secure IPN Handler for CoinPayments
- * Including features as cancel product when payment was reversed/refunded.
- *
- * Author: Punkbastard
- */
- abstract class OrderStatus {
- const PAYPAL_REVERSED = -2; // PayPal Refund or Reversal
- const CANCELLED = -1; // Cancelled/Timed Out
- const WAITING_FOR_FUNDS = 0; // Waiting for buyer funds
- const CONFIRMED_COIN_RECEPTION = 1; // We have confirmed coin reception from the buyer
- const QUEUED_FOR_NIGHTLY_PAYOUT = 2; // Queued for nightly payout (if payout mode is set to Nightly)
- const PAYPAL_PENDING = 3; // PayPal pending (eChecks or other types of holds)
- const PAYMENT_COMPLETE = 100; // Payment complete. Coins sent to payment address or 3rd party payment system reports the payment complete
- }
- $MERCHANT_ID = ""; // Your public Merchant ID
- $IPN_SECRET = ""; // Your secret IPN key, setup in Coinpayments setttings.
- $ORDER_CURRENCY = 'USD'; // Set to your preferred currency
- $ORDER_TOTAL = 10.00; // Set to your preferred amount
- if (!isset($_POST['ipn_mode']) || $_POST['ipn_mode'] != 'hmac') {
- die('IPN Mode is not HMAC');
- }
- if (!isset($_SERVER['HTTP_HMAC']) || empty($_SERVER['HTTP_HMAC'])) {
- die('No HMAC signature sent');
- }
- $request = file_get_contents('php://input');
- if ($request === FALSE || empty($request)) {
- die('Error reading POST data');
- }
- if (!isset($_POST['merchant']) || $_POST['merchant'] != trim($MERCHANT_ID)) {
- die('No or incorrect Merchant ID passed');
- }
- $hmac = hash_hmac("sha512", $request, trim($IPN_SECRET));
- if ($hmac != $_SERVER['HTTP_HMAC']) {
- die('HMAC signature does not match');
- }
- $txn_id = $_POST['txn_id']; // The unique ID of the payment.
- $item_name = $_POST['item_name']; // The name of the item that was purchased.
- $item_number = $_POST['item_number']; // Passthru variable for own use. (Visible to buyer)
- $amount1 = floatval($_POST['amount1']); // The total amount of the payment in your original currency.
- $amount2 = floatval($_POST['amount2']); // The total amount of the payment in the buyer's selected coin.
- $currency1 = $_POST['currency1']; // The original currency submitted.
- $currency2 = $_POST['currency2']; // The coin the buyer chose to pay with.
- $status = intval($_POST['status']); // The status of the payment.
- $status_text = $_POST['status_text']; // A text string describing the status of the payment.
- // Check the original currency to make sure the buyer didn't change it.
- if ($currency1 != $ORDER_CURRENCY) {
- die('Original currency mismatch');
- }
- // Check the amount against order total
- if ($amount1 < $ORDER_TOTAL) {
- die('Amount is less than order total');
- }
- if ($status >= OrderStatus::PAYMENT_COMPLETE || $status == OrderStatus::QUEUED_FOR_NIGHTLY_PAYOUT) {
- // payment is complete or queued for nightly payout, ship product
- } else if ($status == OrderStatus::PAYPAL_REVERSED) {
- // paypal payment reversed or refunded, cancel shipping/product
- }
Add Comment
Please, Sign In to add comment