feat: add payurl and checkurl xml response

This commit is contained in:
2026-04-06 12:11:14 +03:00
parent 7c494c0b53
commit 473e28824c
4 changed files with 859 additions and 113 deletions
+33 -43
View File
@@ -1,51 +1,41 @@
<?php
# Required File Includes
include("../../../includes/functions.php");
include("../../../includes/gatewayfunctions.php");
include("../../../includes/invoicefunctions.php");
/**
* PayAnyWay - WHMCS Callback Handler
*
* Receives payment status and check notifications from PayAnyWay
* and automatically marks WHMCS invoices as paid upon successful payments.
*
* Notification URL to configure in your app:
* https://your_whmcs_site/modules/gateways/callback/payanyway.php
*/
$gatewaymodule = "payanyway"; # Enter your gateway module name here replacing template
require_once __DIR__ . '/../../../init.php';
require_once __DIR__ . '/../../../includes/gatewayfunctions.php';
require_once __DIR__ . '/../../../includes/invoicefunctions.php';
require_once __DIR__ . '/../payanyway.php';
$GATEWAY = getGatewayVariables($gatewaymodule);
if (!$GATEWAY["type"]) die("Module Not Activated"); # Checks gateway module is active before accepting callback
$requestData = ($_SERVER['REQUEST_METHOD'] === 'POST') ? $_POST : $_GET;
# Get Returned Variables - Adjust for Post Variable Names from your Gateway's Documentation
$invoiceid = $_GET["MNT_TRANSACTION_ID"];
$transid = $_GET["MNT_OPERATION_ID"];
$amount = $_GET["MNT_AMOUNT"];
try {
$gatewayModuleName = 'payanyway';
$gatewayParams = getGatewayVariables($gatewayModuleName);
if (!$gatewayParams['type']) {
payanyway_sendResponse('FAIL', 500); // Module Not Activated
}
$invoiceid = checkCbInvoiceID($invoiceid, $GATEWAY["name"]); # Checks invoice ID is a valid invoice number or ends processing
$gatewayName = payanyway_getWhmcsVariableOrFail($gatewayParams, 'name');
$integrityCode = payanyway_getPayAnyWayIntegrityCodeOrFail($gatewayParams);
checkCbTransID($transid); # Checks transaction number isn't already in the database and ends processing if it does
$callbackData = payanyway_getCallbackData($requestData);
if (_checkSignature($GATEWAY)) {
# Successful
addInvoicePayment($invoiceid, $transid, $amount, null, $gatewaymodule); # Apply Payment to Invoice: invoiceid, transactionid, amount paid, fees, modulename
logTransaction($GATEWAY["name"], $_GET, "Successful"); # Save to Gateway Log: name, data array, status
die("SUCCESS");
} else {
# Unsuccessful
logTransaction($GATEWAY["name"], $_GET, "Unsuccessful"); # Save to Gateway Log: name, data array, status
}
die("FAIL");
function _checkSignature($GATEWAY) {
$params = '';
if (isset($_GET['MNT_COMMAND'])) $params .= $_GET['MNT_COMMAND'];
$params .= $_GET['MNT_ID'] . $_GET['MNT_TRANSACTION_ID'];
if (isset($_GET['MNT_OPERATION_ID'])) $params .= $_GET['MNT_OPERATION_ID'];
if (isset($_GET['MNT_AMOUNT'])) $params .= $_GET['MNT_AMOUNT'];
$params .= $_GET['MNT_CURRENCY_CODE'];
if (isset($_GET['MNT_SUBSCRIBER_ID'])) $params .= $_GET['MNT_SUBSCRIBER_ID'];
$params .= $_GET['MNT_TEST_MODE'];
$signature = md5($params . $GATEWAY['mnt_dataintegrity_code']);
if (strcasecmp($signature, $_GET['MNT_SIGNATURE']) == 0) {
return true;
}
return false;
}
('CHECK' === $callbackData['MNT_COMMAND'])
? payanyway_handleCheckCallback($callbackData, $gatewayName, $integrityCode)
: payanyway_handlePayCallback($callbackData, $gatewayName, $integrityCode, $gatewayModuleName);
} catch (\PayAnyWayException $e) {
logTransaction($gatewayModuleName, $requestData, 'Error: ' . $e->getMessage());
payanyway_sendResponse('FAIL', 500);
} catch (\Exception $e) {
logTransaction($gatewayModuleName, $requestData, 'Error: ' . $e->getMessage());
payanyway_sendResponse('FAIL', 500);
}