pils36 / wayapay-php
帮助您使用PHP调用Wayapay API。
Requires (Dev)
- guzzlehttp/guzzle: ^6.2
- phpunit/phpunit: ~5.3
- scrutinizer/ocular: ^1.1
- squizlabs/php_codesniffer: ^2.3
- vlucas/phpdotenv: ^2.2
This package is auto-updated.
Last update: 2024-09-17 20:48:15 UTC
README
为Wayapay提供的PHP API包装器。
需求
- Curl 7.34.0或更高版本(除非使用Guzzle)
- PHP 5.4.0或更高版本
安装
通过Composer
$ composer require pils36/wayapay-php
通过下载
从发布页面下载一个版本。解压后
require 'path/to/src/autoload.php';
用法
将重定向到从/transaction端点调用收到的授权URL。此URL仅限一次使用,因此请确保为每笔交易生成新的URL。
当支付成功时,我们将调用您的回调URL(如在仪表板中设置或初始化交易时),并将第一步中发送的参考作为查询参数返回。
如果您使用测试密钥,我们将调用您的测试回调URL;否则,我们将调用您的实时回调URL。
0. 前提条件
确认您的服务器可以与Wayapay服务器建立TLSv1.2连接。大多数最新的软件都有这个功能。如果您遇到SSL错误,请联系您的服务提供商以获取指导。不要禁用SSL对等验证!
1. 准备您的参数
email
,amount
,description
,wayaPublicKey
和merchantId
是最常见的必填参数。
2. 初始化交易
通过调用我们的API来初始化交易。
require_once('./vendor/autoload.php'); $wayapay = new \Pils36\Wayapay; try { $tranx = $wayapay->transaction->initialize([ 'amount'=>"128.00", // string 'description'=>"Order for something", // string 'currency'=>566, // int 'fee'=>1, // int 'customer'=> ['name' => "Like Vincent", 'email' => "wakexow@mailinator.com", 'phoneNumber' => "+11948667447"], // array 'merchantId'=>"MER_qZaVZ1645265780823HOaZW", // string 'wayaPublicKey'=>"WAYAPUBK_TEST_0x3442f06c8fa6454e90c5b1a518758c70", // string 'mode'=>"test" // string: \\test or live ]); } catch(\Pils36\Wayapay\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->data->tranId); // Get Authorization URL to make payment to the Wayapay payment gateway environment $uri = $wayapay->authorizationUrl('test'); // change to live for production // Use the authorization url to $authorization_url = $uri.$tranx->data->tranId;
当用户输入他们的卡详细信息时,Wayapay将验证并扣款。它将执行以下所有操作
返回到在初始化交易时设置的回调URL或在您的仪表板上。客户看到“交易成功”的消息。
在您向客户付款之前,请通过我们的验证端点进行服务器端调用,以确认交易的状态和属性。
3. 验证交易
在我们重定向到您的回调URL后,请在付款之前验证交易。
$transactionId = isset($_GET['_tranId']) ? $_GET['_tranId'] : ''; if(!$transactionId){ die('No transaction id provided'); } // initiate the Library's Wayapay Object $wayapay = new Pils36\Wayapay; try { // verify using the library $tranx = $wayapay->transaction->verify([ '_tranId'=>$transactionId, // unique to transactions 'mode'=>'test', // test or live ]); } catch(\Pils36\Wayapay\Exception\ApiException $e){ print_r($e->getResponseObject()); die($e->getMessage()); } if ($tranx->status === true) { // 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 }
变更日志
有关最近更改的更多信息,请参阅CHANGELOG。
测试
$ composer test
贡献
请参阅CONTRIBUTING和CONDUCT以获取详细信息。查看我们的待办事项列表,了解已计划的功能。
安全
如果您发现任何与安全相关的问题,请通过电子邮件adenugaadebambo41@gmail.com联系,而不是使用问题跟踪器。