Browse Source

Upload files to ''

master
alamin 6 months ago
parent
commit
6be3ccea1c
  1. 94
      zinipay.php

94
zinipay.php

@ -1,79 +1,29 @@
<?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"]
];
$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;
}
function zinipay_validate_config($params = []) {
// No API key field since it is hardcoded
return [];
if ($recorded) zinipay_log('Payment Recorded via Webhook', ['invoice'=>$invoiceId,'transaction'=>$transactionId,'amount'=>$amount]);
}
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}";
}
}
http_response_code(200);
echo 'OK';
exit;
function zinipay_log($title, $data = []) {
$logDir = realpath(__DIR__ . '/../../storage/logs') ?: (__DIR__ . '/../../storage/logs');

Loading…
Cancel
Save