papihack / paytech-php-client
PayTech 在线支付网关的 PHP 客户端或 SDK。
v1.0.7
2020-09-02 14:37 UTC
Requires
- php: ^7.3
- rmccue/requests: ^1.7
Requires (Dev)
- pestphp/pest: ^0.2.3
- phpunit/phpunit: ^9.0
README
这是一个简单的 SDK 客户端 或 API 客户端,用于 PayTech 在线支付网关。
如何使用
首先,通过 composer 安装此包或库
composer require papihack/paytech-php-client
然后,使用您的参数设置 API 配置,如下所示
\PayTech\Config::setApiKey('your_api_key'); \PayTech\Config::setApiSecret('your_api_secret'); /* * you can set one of this two environment TEST or PROD * you can just set the env mode via \PayTech\Enums\Env::TEST or \PayTech\Enums\Env::PROD * Like the following example * !!! By default env is PROD !!! * You can also directly set test or prod as a string if you want * Like \PayTech\Config::setEnv('test') or \PayTech\Config::setEnv('prod') */ \PayTech\Config::setEnv(\PayTech\Enums\Env::PROD); /* * The PayTech\Enums\Currency class defined authorized currencies * You can change XOF (in the following example) by USD, CAD or another currency * All allowed currencies are in \PayTech\Enums\Currency class * !!! Notice that XOF is the default currency !!! */ \PayTech\Config::setCurrency(\PayTech\Enums\Currency::XOF); /* !!! Note that if you decide to set the ipn_url, it must be in https !!! */ \PayTech\Config::setIpnUrl('your_ipn_url'); \PayTech\Config::setSuccessUrl('your_success_url'); \PayTech\Config::setCanceUrl('your_cancel_url'); /* * if you want the mobile success or cancel page, you can set * the following parameter */ \PayTech\Config::setIsMobile(true);
然后,您可以继续操作
$article_price = 15000; $article = new \PayTech\Invoice\InvoiceItem('article_name', $article_price, 'command_name', 'ref_command'); /* You can also add custom data or fields like this */ \PayTech\CustomField::set('your_field_name', 'your_field_value'); /* Make the payment request demand to the API */ \PayTech\PayTech::send($article); /* Get the API Response */ $response = [ 'success' => \PayTech\ApiResponse::getSuccess(), 'errors' => \PayTech\ApiResponse::getErrors(), 'token' => \PayTech\ApiResponse::getToken(), 'redirect_url' => \PayTech\ApiResponse::getRedirectUrl(), ];
之后,如果您收到成功的响应,可以将用户重定向到 $response['redirect_url'],以便他可以进行支付。
您可以通过直接操作 \PayTech\ApiResponse 来按您的意愿处理响应。
待办事项
- tests: 覆盖所有用例 ✅
- 联系 paytech.sn 的支持团队以澄清某些问题
贡献
请随意提交 PR 或报告问题 😃
关于测试,我使用优雅的 PHP 测试框架 Pest 😎
哦,还有一件事,请记住在提交 PR 时添加描述 🙂