You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.9 KiB
85 lines
2.9 KiB
<?php
|
|
/**
|
|
* ZiniPay Live Payment Gateway for PHPNuxBill
|
|
* Live-only version, fully API-style, with auto-verify on return.
|
|
*/
|
|
|
|
function zinipay_config() {
|
|
return [
|
|
"FriendlyName" => ["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 "<script>window.location.href = '{$data['url']}';</script>";
|
|
} else {
|
|
$msg = $data['message'] ?? 'Failed to create payment request';
|
|
zinipay_log("Payment Creation Failed", ['response'=>$data]);
|
|
return "Payment failed: {$msg}";
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|