diff --git a/callback/zinipay_return.php b/callback/zinipay_return.php new file mode 100644 index 0000000..5bdc103 --- /dev/null +++ b/callback/zinipay_return.php @@ -0,0 +1,66 @@ +['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 "

Payment Completed

If your invoice hasn't updated automatically, contact support.

"; + +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); +}