pils36 / rexpay
帮助使用 PHP 进行 Rexpay API 调用。
Requires (Dev)
- guzzlehttp/guzzle: ^6.2
- phpunit/phpunit: ~5.3
- scrutinizer/ocular: ^1.1
- squizlabs/php_codesniffer: ^2.3
- vlucas/phpdotenv: ^2.2
README
为 Rexpay 提供的 PHP API 包装器。
要求
- Curl 7.34.0 或更高版本(除非使用 Guzzle)
- PHP 5.4.0 或更高版本
安装
通过 Composer
$ composer require pils36/rexpay
通过下载
从 发布页面 下载一个版本。解压缩后
require 'path/to/src/autoload.php';
使用方法
将重定向到从 /transaction 端点调用接收到的授权 URL。此 URL 仅限一次使用,因此请确保每个交易生成一个新 URL。
当支付成功时,我们将调用您的回调 URL(在您的仪表板中设置或在初始化交易时设置),并将第一步中发送的引用作为查询参数返回。
如果您使用测试密钥,我们将调用您的测试回调 URL,否则,我们将调用您的实时回调 URL。
0. 前提条件
确认您的服务器可以与 Rexpay 服务器建立 TLSv1.2 连接。大多数最新软件都具备此功能。如果您有任何 SSL 错误,请联系您的服务提供商以获得指导。不要禁用 SSL 伙伴验证!
1. 准备您的参数
email
、userId
、amount
、description
、reference
和 authToken
是最常见的强制参数。
2. 初始化交易
通过调用我们的 API 来初始化交易。
注意:$authtoken 是基本身份验证令牌
您的用户名:密码以 base64 编码。您可以参考生成基本身份验证令牌的链接
点击生成基本认证头
require_once('./vendor/autoload.php'); $rexpay = new \Pils36\Rexpay; try { $tranx = $rexpay->transaction->initialize([ 'reference'=>"sm23oyr1122", // string 'amount'=>200, // integer 'currency'=>"NGN", // string 'userId'=>"awoyeyetimilehin@gmail.com", // string 'callbackUrl'=>"google.com", // string 'metadata'=> ['email' => "awoyeyetimilehin@gmail.com", 'customerName' => "Victor Musa"], // string 'authToken'=> $authtoken, // string - (Basic Authentication Token) 'mode' => 'test' // test or production ]); } catch(\Pils36\Rexpay\Exception\ApiException $e){ print_r($e->getResponseObject()); die($e->getMessage()); } // store transaction reference so we can query in case user never comes back // perhaps due to network issue saveLastTransactionId($tranx);
当用户输入其卡详细信息时,Rexpay 将验证并扣费。它将执行以下所有操作
返回到初始化交易或您的仪表板中设置的回调 URL。客户看到“交易成功”的消息。
在您向客户付款之前,请先通过我们的验证端点进行服务器端调用以确认交易的状态和属性。
3. 验证交易
在我们重定向到您的回调 URL 后,请在付款之前进行交易验证。
// initiate the Library's Rexpay Object $rexpay = new Pils36\Rexpay; try { // verify using the library $tranx = $rexpay->transaction->verify([ 'transactionReference'=>$reference, // unique to transactions 'authToken'=> $authtoken, // string - (Basic Authentication Token) 'mode' => 'test' // test or production ]); } catch(\Pils36\Rexpay\Exception\ApiException $e){ print_r($e->getResponseObject()); die($e->getMessage()); } ($tranx->responseCode === "00") => "success"; ($tranx->responseCode === "01") => "failed"; ($tranx->responseCode === "02") => "pending"; if ($tranx->responseCode === "00") { // transaction was successful... Please check other things like whether you already gave value for this transactions // if the email matches the customer who owns the product etc // Save your transaction information here }
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG。
测试
$ composer test
贡献
请参阅 CONTRIBUTING 和 CONDUCT 以获取详细信息。查看我们的 待办事项列表 以了解已计划的功能。
安全性
如果您发现任何安全相关的问题,请通过电子邮件 adenugaadebambo41@gmail.com 反馈,而不是使用问题跟踪器。