zenopay / zenopay-php
ZenoPay支付处理的PHP包。
v1.0.0
2024-07-24 16:06 UTC
This package is not auto-updated.
Last update: 2024-09-19 16:15:16 UTC
README
此仓库包含与ZenoPay API交互的PHP脚本。这些脚本演示了如何创建订单和检查订单状态。
目录
订单创建脚本
概述
此脚本通过向ZenoPay API端点发送POST请求来创建订单。它包含一个基本的错误日志功能,以捕获请求期间出现的任何问题。
脚本组件
API端点
-
URL:
https://api.zeno.africa
这是创建订单的端点。
订单数据
以下数据包含在POST请求中
$url = "https://api.zeno.africa"; // Data to send for creating the order $orderData = [ 'create_order' => 1, 'buyer_email' => 'CUSTOMER_EMAIL', 'buyer_name' => 'CUSTOMER_NAME', 'buyer_phone' => 'CUSTOMER_PHONE_NUMBER', 'amount' => 10000, // AMOUNT_TO_BE_PAID 'account_id' => 'YOUR_ACCOUNT_ID', 'api_key' => 'YOUR_API_KEY', 'secret_key' => 'YOUR_SECRET_KEY' ];
create_order
(整数):设置为1
以启动订单创建。buyer_email
(字符串):客户的电子邮件地址。buyer_name
(字符串):客户的完整姓名。buyer_phone
(字符串):客户的电话号码。amount
(整数):要支付的数量(以最小货币单位计,例如,分)。account_id
(字符串):您用于身份验证的唯一账户ID。api_key
(字符串):您用于身份验证的API密钥。secret_key
(字符串):您用于身份验证的秘密密钥。
cURL配置
脚本使用cURL进行POST请求
$options = [ 'http' => [ 'method' => 'POST', 'header' => "Content-Type: application/x-www-form-urlencoded\r\n", 'content' => $queryString, ], ];
错误日志功能
将错误记录到文件中
function logError($message) { file_put_contents('error_log.txt', $message . "\n", FILE_APPEND); }
错误处理
为了增强错误处理
-
检查cURL错误:
if ($response === false) { logError('cURL Error: ' . curl_error($ch)); }
-
检查HTTP状态码:
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($httpCode != 200) { logError('HTTP Error: ' . $httpCode); }
示例用法
- 更新订单数据:将占位符值替换为实际信息。
- 保存脚本:将文件保存为
create_order.php
或其他首选文件名。 - 运行脚本:通过命令行或Web服务器执行。
备注
- 确保脚本可以写入
error_log.txt
。 - 安全处理敏感信息,如API密钥和秘密密钥。
订单状态检查脚本
概述
此脚本通过向ZenoPay API端点发送POST请求来检查订单状态。
脚本组件
API端点
-
URL:
https://api.zeno.africa/order-status
这是检查订单状态的端点。
请求数据
以下数据包含在POST请求中
$endpointUrl = "https://api.zeno.africa/order-status"; // Order ID that you want to check the status for $order_id = "66d5e374ccaab"; // Data to be sent in the POST request $postData = [ 'check_status' => 1, 'order_id' => $order_id, 'api_key' => 'YOUR_API_KEY', 'secret_key' => 'YOUR_SECRET_KEY' ];
check_status
(整数):设置为1
以请求状态。order_id
(字符串):您要检查状态的订单ID。api_key
(字符串):您用于身份验证的API密钥。secret_key
(字符串):您用于身份验证的秘密密钥。
cURL配置
脚本使用cURL执行POST请求
$options = [ 'http' => [ 'method' => 'POST', 'header' => "Content-Type: application/x-www-form-urlencoded\r\n", 'content' => $queryString, ], ]; if (curl_errno($ch)) { echo json_encode([ "status" => "error", "message" => 'cURL error: ' . curl_error($ch) ]); } else { $responseData = json_decode($response, true); if ($responseData['status'] === 'success') { echo json_encode([ "status" => "success", "order_id" => $responseData['order_id'], "message" => $responseData['message'], "payment_status" => $responseData['payment_status'] ]); } else { echo json_encode([ "status" => "error", "message" => $responseData['message'] ]); } } curl_close($ch);
错误处理
-
检查cURL错误:
if (curl_errno($ch)) { echo json_encode([ "status" => "error", "message" => 'cURL error: ' . curl_error($ch) ]); }
-
处理响应:根据状态解码和格式化JSON响应
if ($responseData['status'] === 'success') { echo json_encode([ "status" => "success", "order_id" => $responseData['order_id'], "message" => $responseData['message'], "payment_status" => $responseData['payment_status'] ]); } else { echo json_encode([ "status" => "error", "message" => $responseData['message'] ]); }
示例用法
- 更新请求数据:将占位符值替换为实际数据。
- 保存脚本:将文件保存为
check_order_status.php
或其他首选文件名。 - 运行脚本:通过命令行或Web服务器执行。
备注
- 如果您使用错误日志,请确保
error_log.txt
可写。 - 安全处理敏感信息,如API密钥和秘密密钥。
请根据具体需求自由修改或扩展此README。