From 6be3ccea1c75cdb05acceee45564adcb477730ee Mon Sep 17 00:00:00 2001 From: alamin Date: Wed, 17 Sep 2025 04:20:59 +0000 Subject: [PATCH] Upload files to '' --- zinipay.php | 96 +++++++++++++---------------------------------------- 1 file changed, 23 insertions(+), 73 deletions(-) diff --git a/zinipay.php b/zinipay.php index 3a8757e..6645d8e 100644 --- a/zinipay.php +++ b/zinipay.php @@ -1,80 +1,30 @@ ["Type"=>"System","Value"=>"ZiniPay"], - "debug" => ["FriendlyName"=>"Enable Debug Logging","Type"=>"yesno","Value"=>"0"] - ]; -} - -function zinipay_validate_config($params = []) { - // No API key field since it is hardcoded - return []; -} - -function zinipay_link($params) { - $debug = ($params['debug'] ?? '') == 'on'; - - $invoiceid = $params['invoiceid']; - $amount = number_format($params['amount'], 2, '.', ''); - $description = "Invoice #$invoiceid"; - - $systemurl = rtrim($params['systemurl'], '/'); - $return_url = $systemurl . "/system/paymentgateway/callback/zinipay_return.php?invoiceid=" . urlencode($invoiceid); - $notify_url = $systemurl . "/system/paymentgateway/callback/zinipay.php"; - - // Live-only endpoint - $endpoint = "https://secure.zinipay.com/payment/"; - - // Hardcoded API key - $apiKey = "40369d7a7cf89e1dbbd97e1ae47b9ea15af0a49264fcdbcf"; - - $payload = [ - 'redirect_url' => $return_url, - 'cancel_url' => $return_url . '&status=cancel', - 'webhook_url' => $notify_url, - 'metadata' => ['invoiceId' => $invoiceid], - 'amount' => $amount, - 'description' => $description - ]; - - if ($debug) zinipay_log("Create Payment Request", ['endpoint'=>$endpoint,'payload'=>$payload]); - - $ch = curl_init($endpoint); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($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); - - if ($error) { - zinipay_log("cURL Error", ['error'=>$error]); - return "Error initiating payment. Check logs."; - } - - $data = json_decode($response, true); - - if ($debug) zinipay_log("Create Payment Response", ['response'=>$data]); - - if (isset($data['url'])) { - return ""; - } else { - $msg = $data['message'] ?? 'Failed to create payment request'; - zinipay_log("Payment Creation Failed", ['response'=>$data]); - return "Payment failed: {$msg}"; +$request = file_get_contents('php://input'); +$payload = json_decode($request, true) ?: $_POST ?: []; + +zinipay_log('Incoming Webhook', $payload); + +$settings = function_exists('getPaymentGateway') ? getPaymentGateway('zinipay') : []; +$invoiceId = $payload['metadata']['invoiceId'] ?? $_REQUEST['invoiceId'] ?? null; +$transactionId = $payload['transactionId'] ?? $payload['val_id'] ?? null; +$amount = $payload['amount'] ?? 0; + +if ($invoiceId) { + $recorded = false; + if (function_exists('addPayment')) { + @addPayment($invoiceId, $transactionId ?? uniqid('zinipay_'), $amount, 0, 'zinipay'); + $recorded = true; + } elseif (function_exists('invoicePaymentAdd')) { + @invoicePaymentAdd($invoiceId, $transactionId ?? uniqid('zinipay_'), $amount, 0, 'zinipay'); + $recorded = true; } + if ($recorded) zinipay_log('Payment Recorded via Webhook', ['invoice'=>$invoiceId,'transaction'=>$transactionId,'amount'=>$amount]); } +http_response_code(200); +echo 'OK'; +exit; + function zinipay_log($title, $data = []) { $logDir = realpath(__DIR__ . '/../../storage/logs') ?: (__DIR__ . '/../../storage/logs'); if (!is_dir($logDir)) @mkdir($logDir, 0777, true);