tecksolke-tpay / app-api
此包包含所有 t-pay/api,即向 t-pay 支付网关发送请求的任何应用的 API。
v2.2.2
2020-04-25 20:16 UTC
Requires
- ext-json: *
- guzzlehttp/guzzle: ^6.5
README
简介
T-Pay API 是一个 REST-API,它使得向 T-Pay 支付网关发送请求变得简单易行。
- API 简单且易于安装。
- 为您的应用提供 B2C 和 C2B API。
- 此 API 只能由拥有应用的 T-Pay 支付网关用户使用。
- 该 API 基于 PHP Laravel 框架。但您可以根据您的 PHP 开发平台尝试安装和自定义它。
帮助和文档
安装
推荐通过 Composer 安装 tpay-app-api。
# Install package via composer
composer require tecksolke-tpay/app-api
接下来,运行 Composer 命令以安装最新稳定版本的 tpay/app-api
# Update package via composer
composer update tecksolke-tpay/app-api --lock
安装后,该包将被自动发现。但如果需要,您可能需要运行
# run for auto discovery <-- If the package is not detected automatically -->
composer dump-autoload
然后运行此命令,以获取 api 配置的 config/tpay.php
# run this to get the configuartion file at config/tpay.php <-- read through it --> php artisan vendor:publish --provider="TPay\API\TPayServiceProvider"
您需要将此提供到 .env 中进行 api 配置
# https://sandbox.tpay.co.ke or https://production.tpay.co.ke T_PAY_END_POINT_URL= # TP4*****82F <-- keep this key secret --> T_PAY_APP_KEY= # <-- keep this code secret --> T_PAY_APP_SECRET_CODE= # 60 <-- The access token session lifetime is in minutes i.e 60 minutes --> ->default(58 minutes); T_PAY_TOKEN_SESSION= # 120 <-- Response timeout 120 seconds --> # This is not a must you may choose to use the dafault value defined in the config/tpay.php; T_PAY_RESPONSE_TIMEOUT= # 60 <-- Connection timeout 60 seconds --> # This is not a must you may choose to use the dafault value defined in the config/tpay.php; T_PAY_CONNECTION_TIMEOUT=
用法
按照以下步骤使用 API
如何使用 API
此 API 将通过此包进行访问...
/** * --------------------------------- * Requesting app balance [ GET Request ] * --------------------------------- * @throws Exception */ use TPay\API\API\AppBalances; public function appBalance() { try { //Set request options as shown here $options = [ 'secretCode' => '',//This has to be your app T_PAY_APP_SECRET_CODE ]; //make request here $response = (new AppBalances())->appBalances($options); //continue with what you what to do with the $response here } catch (Exception $exception) { //TODO If an exception occurs } } /** * ------------------ * Express Payment [ POST Request ] * ----------------- * This is used to directly get payment from * a client account to your application */ use TPay\API\API\ExpressPayment; public function expressPayment() { try { $options = [ 'referenceCode' => '',//Unique referenceCode i.e TPXXXXX 'redirectURL' => '',//This is the URL that the user will be redirect after payment 'resultURL' => '',//This is the url that will receive the response data after successful payment. Note that this has to be a post callback so remember to use post in your callback. 'amount' => 1,//amount to be paid ]; //make the request here $response = (new ExpressPayment())->expressPayment($options); //proceed with the response } catch (Exception $exception) { //TODO If an exception occurs } } /** * ------------------------------------ * Making app stk push request for c2b [ POS Request ] * ------------------------------------ */ use TPay\API\API\AppC2BSTKPush; public function appC2BSTKPush() { try { //Set request options as shown here $options = [ 'secretCode' => '',//This has to be your app T_PAY_APP_SECRET_CODE 'phoneNumber' => '',//The phone number has to be 2547xxxxxxx 'referenceCode' => '',//The secret code should be unique in every request you send and must start with TPXXXX 'amount' => 1,//Amount has to be an integer and less than or equal to KES 70000 'resultURL' => '',//This has to be your callback i.e https://mydomain/callback or http://mydomain/callback. Also note that this has to be a post callback so remember to use post in your callback. ]; //make the c2b stk push here $response = (new AppC2BSTKPush())->appC2BSTKPush($options); //continue with what you what to do with the $response here } catch (\Exception $exception) { //TODO If an exception occurs } } /** * ------------------------------------ * Making app withdraw request for b2c [ POST Request ] * ------------------------------------ */ use TPay\API\API\AppB2C; public function appB2C() { try { //Set request options as shown here $options = [ 'secretCode' => '',//This has to be your app T_PAY_APP_SECRET_CODE 'phoneNumber' => '',//The phone number has to be 2547xxxxxxx 'referenceCode' => '',//The secret code should be unique in every request you send and must start with TPXXXX 'amount' => 1,//Amount has to be an integer and has to be greater than KES 10 'resultURL' => '',//This has to be your callback i.e https://mydomain/callback or http://mydomain/callback. Also note that this has to be a post callback so remember to use post in your callback. ]; //make the b2c withdraw here $response = (new AppB2C())->appB2C($options); //continue with what you what to do with the $response here } catch (\Exception $exception) { //TODO If an exception occurs } }
API 响应
这是即时支付成功的情况 -- 如果客户端付款,则只会发送即时支付回调 --
{
"success":true,
"data":{
"amount":1,//This will be the amount paid to your application
"referenceCode":"TP0******6F7"//This the reference code you used to make your request
}
}
这是 B2C 成功的情况 -- 提现已收到 --
{
"success":true,
"data":{
"appName":"",//Your App Name
"referenceCode":"",//This will be your reference Code that you used to make the request
"receiver":"",//The number that receives the payment
"transactionID":"",//Unique transaction ID
"amount"://The amount withdrawn
}
}
这是 B2C 失败的情况 -- 提现未收到 --
{
"success":false,
"data":{
"appName":"",//Your App Name
"referenceCode":"",//This will be your reference Code that you used to make the request
}
}
这是 C2B 成功的情况 -- 已支付 --
{
"success":true,
"data":{
"appName":"",//Your App Name
"referenceCode":"",//This will be your reference Code that you used to make the request
"phoneNumber":"",//The number that makes the payment
"transactionID":"",//Unique transaction ID
"amount"://The amount deposited/Paid
}
}
这是 C2B 失败的情况 -- 未支付 --
{
"success":false,
"data":{
"appName":"",//Your App Name
"referenceCode":"",//This will be your reference Code that you used to make the request
}
}
版本说明
安全漏洞
对于任何安全漏洞,请发送电子邮件至 TecksolKE。
许可
此包是开源 API,受 MIT 许可 许可。