1 changed files with 66 additions and 0 deletions
@ -0,0 +1,66 @@ |
|||||
|
<?php |
||||
|
$invoiceid = $_GET['invoiceid'] ?? $_REQUEST['invoiceId'] ?? null; |
||||
|
|
||||
|
if ($invoiceid) { |
||||
|
$settings = function_exists('getPaymentGateway') ? getPaymentGateway('zinipay') : []; |
||||
|
$apiKey = $settings['api_key'] ?? ''; |
||||
|
$sandbox = ($settings['sandbox'] ?? '') == 'on'; |
||||
|
$debug = ($settings['debug'] ?? '') == 'on'; |
||||
|
|
||||
|
$verifyEndpoint = $sandbox |
||||
|
? "https://secure.zinipay.com/demo/payment/verify" |
||||
|
: "https://secure.zinipay.com/payment/verify"; |
||||
|
|
||||
|
$payload = json_encode(['metadata'=>['invoiceId'=>$invoiceid]]); |
||||
|
|
||||
|
$ch = curl_init($verifyEndpoint); |
||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||||
|
curl_setopt($ch, CURLOPT_POST, true); |
||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); |
||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [ |
||||
|
'Content-Type: application/json', |
||||
|
'zini-api-key: ' . $apiKey, |
||||
|
]); |
||||
|
|
||||
|
$response = curl_exec($ch); |
||||
|
$error = curl_error($ch); |
||||
|
curl_close($ch); |
||||
|
|
||||
|
zinipay_log("Return Page Verification", ['invoice'=>$invoiceid,'response'=>$response,'error'=>$error]); |
||||
|
|
||||
|
if (!$error) { |
||||
|
$data = json_decode($response,true); |
||||
|
if (isset($data['status']) && $data['status'] === 'success') { |
||||
|
$transactionId = $data['transactionId'] ?? uniqid('zinipay_'); |
||||
|
$amount = $data['amount'] ?? 0; |
||||
|
|
||||
|
$recorded = false; |
||||
|
if (function_exists('addPayment')) { |
||||
|
@addPayment($invoiceid, $transactionId, $amount, 0, 'zinipay'); $recorded = true; |
||||
|
} elseif (function_exists('invoicePaymentAdd')) { |
||||
|
@invoicePaymentAdd($invoiceid, $transactionId, $amount, 0, 'zinipay'); $recorded = true; |
||||
|
} |
||||
|
|
||||
|
if ($recorded) zinipay_log("Payment Verified & Recorded", ['invoice'=>$invoiceid,'transaction'=>$transactionId,'amount'=>$amount]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (defined('U')) { |
||||
|
header('Location: '.U.'client/iview/'.intval($invoiceid).'/'); exit; |
||||
|
} else { |
||||
|
$host = $_SERVER['HTTP_HOST'] ?? ''; |
||||
|
$proto = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https://' : 'http://'; |
||||
|
header('Location: '.$proto.$host.'/client/iview/'.intval($invoiceid).'/'); exit; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
echo "<h2>Payment Completed</h2><p>If your invoice hasn't updated automatically, contact support.</p>"; |
||||
|
|
||||
|
function zinipay_log($title, $data = []) { |
||||
|
$logDir = realpath(__DIR__ . '/../../storage/logs') ?: (__DIR__ . '/../../storage/logs'); |
||||
|
if (!is_dir($logDir)) @mkdir($logDir, 0777, true); |
||||
|
$logFile = $logDir . '/gateway_zinipay.log'; |
||||
|
$time = date("Y-m-d H:i:s"); |
||||
|
$entry = "[$time] $title\n".print_r($data,true)."\n-------------------\n"; |
||||
|
@file_put_contents($logFile, $entry, FILE_APPEND | LOCK_EX); |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue