<?php require 'config.php'; require 'bp_lib.php'; require 'functions.php'; // get invoice number from file $file = $_GET['ecwidInvoiceId'] . '.inv'; if (file_exists($file)) { $invoiceId = file_get_contents($file); deleteOldInvs(); $invoice = bpGetInvoice($invoiceId, $apiKey); if ($invoice['status'] == 'confirmed' or $invoice['status'] == 'completed') { postToEcwid($invoice); // this will redirect to a confirmation page die; } } else { debuglog('no file found for invoice ' . $_GET['ecwidInvoiceId']); } header('Location: ' . $storeURL); // if the transaction speed is medium/low, they'll be redirected w/o confirmation
function bpVerifyNotification($apiKey = false) { global $bpOptions; if (!$apiKey) { $apiKey = $bpOptions['apiKey']; } $post = file_get_contents("php://input"); if (!$post) { return array('error' => 'No post data'); } $json = json_decode($post, true); if (is_string($json)) { return array('error' => $json); } // error if (!array_key_exists('posData', $json)) { return array('error' => 'no posData'); } // decode posData $posData = json_decode($json['posData'], true); if ($bpOptions['verifyPos'] and $posData['hash'] != crypt(serialize($posData['posData']), $apiKey)) { return array('error' => 'authentication failed (bad hash)'); } $json['posData'] = $posData['posData']; if (!array_key_exists('id', $json)) { return 'Cannot find invoice ID'; } return bpGetInvoice($json['id'], $apiKey); }
/** * Call from your notification handler to convert $_POST data to an object containing invoice data * * @param string $apiKey * @param null $network * @return array */ function bpVerifyNotification($apiKey = false, $network = null) { global $bpOptions; if (!$apiKey) { $apiKey = $bpOptions['apiKey']; } $post = file_get_contents("php://input"); if (!$post) { return 'No post data'; } $json = json_decode($post, true); if (is_string($json)) { return $json; // error } if (!array_key_exists('posData', $json)) { return 'no posData'; } $posData = json_decode($json['posData'], true); if ($bpOptions['verifyPos'] and $posData['hash'] != crypt($posData['posData'], $apiKey)) { return 'ERROR: authentication failed (bad hash)'; } $json['posData'] = $posData['posData']; if (!array_key_exists('id', $json)) { return 'Cannot find invoice ID'; } return bpGetInvoice($json['id'], $apiKey, $network); }
/** * * Call from your notification handler to convert $_POST data to an object containing invoice data * * @param boolean $apiKey * @return mixed $json * @throws Exception $e * */ function bpVerifyNotification($apiKey = false, $network = false) { //function currently not being used global $bpOptions; try { if (!$apiKey) { $apiKey = $bpOptions['apiKey']; } $post = file_get_contents("php://input"); if (!$post) { return 'No post data'; } if (function_exists('json_decode')) { $json = json_decode($post, true); } else { $json = bpJSONdecode($post); } if (is_string($json)) { return $json; } // error if (!array_key_exists('posData', $json)) { return 'no posData'; } if (function_exists('json_decode')) { $posData = json_decode($json['posData'], true); } else { $posData = bpJSONdecode($json['posData']); } if ($bpOptions['verifyPos'] and $posData['hash'] != bpHash(serialize($posData['posData']), $apiKey)) { return 'authentication failed (bad hash)'; } $json['posData'] = $posData['posData']; if (!array_key_exists('id', $json)) { return 'Cannot find invoice ID'; } return bpGetInvoice($json['id'], $apiKey, $network); } catch (Exception $e) { if ($bpOptions['useLogging']) { bpLog('Error: ' . $e->getMessage()); } return array('error' => $e->getMessage()); } }