supermalang / paytech-client
PayTech在线支付网关的PHP客户端或SDK。 - Forked from papihack/paytech-php-client
dev-master
2023-08-29 16:11 UTC
Requires
- php: >=7.3
- rmccue/requests: >=1.7
Requires (Dev)
- pestphp/pest: >=0.2.3
- phpunit/phpunit: >=9.0
This package is auto-updated.
Last update: 2024-09-29 18:20:27 UTC
README
Forked from papihack/paytech-php-client
这是一个简单的SDK客户端
或API客户端
,用于PayTech在线支付网关
。
查看PayTech SN网站。
如何使用
首先,通过composer安装此包或库
composer require supermalang/paytech-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
来按需处理响应。