* @copyright Copyright (c) 2021 Brady Miller * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 */ require_once(__DIR__ . "/../interface/globals.php"); use OpenEMR\Common\Acl\AclMain; use OpenEMR\Common\Csrf\CsrfUtils; use OpenEMR\Core\Header; use OpenEMR\PaymentProcessing\PaymentProcessing; use OpenEMR\PaymentProcessing\Sphere\SphereRevert; if (!CsrfUtils::verifyCsrfToken($_GET["csrf_token"], 'sphere_revert')) { CsrfUtils::csrfNotVerified(); } if ($GLOBALS['payment_gateway'] != 'Sphere') { die(xlt("Feature not activated")); } if (!AclMain::aclCheckCore('acct', 'rep_a')) { die(xlt("Unauthorized access.")); } ?> $_GET, 'post' => $_POST]; if (!empty($_POST['status']) && (($_POST['status'] == 'baddata') || ($_POST['status'] == 'error'))) { PaymentProcessing::saveRevertAudit($_POST['uuid_tx'], $_POST['action'], $auditData, 0); echo ""; } else if (!empty($_POST['hash']) && !empty($_POST['token'])) { $sphereRevert = new SphereRevert($_GET['front']); // verify that the querystring hash from sphere is authentic and not modified if (!$sphereRevert->checkQuerystringHash($_POST['hash'], $_POST['querystring'])) { $auditData['check_querystring_hash'] = false; PaymentProcessing::saveRevertAudit($_POST['uuid_tx'], $_POST['action'], $auditData, 0); echo ""; exit; } $auditData['check_querystring_hash'] = true; // complete the transaction $completeRevert = $sphereRevert->completeTransaction($_POST['token']); $auditData['complete_transaction'] = $completeRevert; if ($completeRevert['status'] != 'accepted') { PaymentProcessing::saveRevertAudit($_POST['uuid_tx'], $_POST['action'], $auditData, 0, $completeRevert['transid']); $completeRevertToString = "\n"; foreach ($completeRevert as $key => $value) { if (!empty($key) || !empty($value)) { $completeRevertToString .= $key . ": " . $value . "\n"; } } echo ""; exit; } // Successful revert PaymentProcessing::saveRevertAudit($_POST['uuid_tx'], $_POST['action'], $auditData, 1, $completeRevert['transid']); echo ""; } else { // catch all for errors that are not caught above $auditData['error_custom'] = "Unclear revert error with following querystring: " . $_POST['querystring']; PaymentProcessing::saveRevertAudit($_POST['uuid_tx'], $_POST['action'], $auditData, 0); echo ""; } ?>