hosannahighertech / gateway-php
Hosanna 电子支付网关 API PHP 库
This package is auto-updated.
Last update: 2024-09-17 19:13:50 UTC
README
需求
PHP 5.4.0 及以上版本。
Composer
您可以通过 Composer 安装此库。运行以下命令
composer require hosannahighertech/gateway-php
要使用此库,请使用 Composer 的 自动加载
require_once('vendor/autoload.php');
依赖
此库依赖于 Requests Http Library
。库已包含,因此您无需安装任何其他内容。
入门
1. 创建网关对象。
要创建网关对象,您需要首先定义配置。您的配置对象必须实现 hosannahighertech\gateway\interfaces\ConfigurationInterface
接口。这使您可以使用文件、会话或数据库来存储配置。它也不限制获取访问令牌的方式,尽管您可以为此使用捆绑的库。请参阅 src/samples
中的示例。假设您的配置类是 SampleConfiguration
,那么创建网关对象可以像这样简单:
use hosannahighertech\gateway\Gateway; use hosannahighertech\gateway\samples\SampleConfigurations; //Your configuration file $gateway = new Gateway(new SampleConfigurations());
然后,可以使用网关对象创建支付请求和确认收据。
2. 发送支付请求
要创建支付请求,只需创建 PaymentRequest
类的对象,然后使用网关的 sendRequest
方法发送它。该方法返回包含成功时的对象 RequestReceipt
或失败时的 null
。使用网关对象的 getError
方法获取实际的错误消息。
use hosannahighertech\Gateway\PaymentRequest; $request = new PaymentRequest(); $request = $request->setCard('1234565432789054') ->setDescription('Buying some soda') ->setAmount(1500) ->setCurrency("TZS") ->setCompany(1) ->setTransferTo(1234567890987654); $reqReceipt = $gateway->sendRequest($request); if($reqReceipt === null) { echo $gateway->getError()); } else { //succesfully. Do something with Request Receipt }
3. 确认支付
确认支付将执行实际的扣款/转账。为此,只需将前一个请求中从 RequestReceipt
对象中获取的支付 ID 传递给网关对象的 confirmPayment
方法。在失败的情况下,结果将是 null
,在成功的情况下,将是一个 PaymentReceipt
类的对象。使用网关对象的 getError
方法获取实际的错误消息。
$paymentReceipt = $gateway->confirmPayment($reqReceipt->getReceipt()); if($paymentReceipt === null) { echo $gateway->getError()); } else { //succesfully. Do something with Payment Receipt }
请参阅文档以获取更多详细信息。
文档
即将推出!
4. 记录日志
待定
5. 测试
待定