axeloth090909 / tripay-payment-gateway
PHP支付网关Tripay库
Requires
- guzzlehttp/guzzle: ^7.0
- symfony/http-foundation: ^5.2
Requires (Dev)
- phpunit/phpunit: ^9.2.2
- symfony/var-dumper: ^5.1.4
This package is not auto-updated.
Last update: 2024-09-28 23:25:49 UTC
README
此包是非官方的,已与Composer兼容,更多详情请访问文档。 此包旨在使PHP用户更容易使用
重要:请确保您阅读了文档并理解了这些方法的使用目的!
使用此包需要PHP 7及以上版本
安装
composer require muhammadnan/tripay-payment-gateway
配置
在开始进一步操作之前,您必须定义或导入tripay以进行进一步配置
use Tripay\Main;
然后配置api-key、private-key和merchant-code
$main = new Main( 'your-api-key', 'your-private-key', 'your-merchant-code', 'sandbox' // fill for sandbox mode, leave blank if in production mode );
默认情况下,模式为生产模式,要将其更改为沙盒模式,可以在merchant-code后添加'sandbox'。
内容可用
目前可用的内容方法
请求可用
请求可以返回可用的内容,以下为可用的方法列表
支付渠道
此API用于获取所有可用支付渠道的完整列表,包括每个渠道的交易费等详细信息
$main->initChannelPembayaran()
下一个方法可以在请求方法中查看,或者可以在示例中查看
支付指令
此API用于从每个渠道检索支付指令
$code = 'BRIVA'; //more info code, https://payment.tripay.co.id/developer $init = $main->initInstruksiPembayaran($code)
下一个方法可以在请求方法中查看,或者可以在示例中查看
商户支付渠道
此API用于获取您商户账户中可用的支付渠道列表,包括每个渠道的交易费等详细信息
$code = 'BRIVA'; //more info code, check your account $init = $main->initMerchantChannelPembayaran($code);
下一个方法可以在请求方法中查看,或者可以在示例中查看
费用计算器
此API用于根据指定面额获取每个渠道的详细交易费计算
$code = 'BRIVA'; //more info code, https://payment.tripay.co.id/developer $amount = 1000;//your amount $init = $main->initKalkulatorBiaya($code, $amount);
下一个方法可以在请求方法中查看,或者可以在示例中查看
交易
在进入交易下一步之前,请配置您的参考商户
$merchantRef = 'your-merchant-ref';//your merchant reference $init = $main->initTransaction($merchantRef);
在生成签名之前,请设置关闭交易的金额,对于开放交易,请设置支付方式
$init->setAmount(1000); // for close payment $init->setMethod('BRIVAOP'); // for open payment
注意:如果您使用开放支付,不要定义金额;反之,如果您使用关闭支付,不要定义金额
创建签名
$signature = $init->createSignature();
关闭交易
要定义关闭交易,请使用closeTransaction ()方法
$transaction = $init->closeTransaction(); // define your transaction type, for close transaction use `closeTransaction()`
定义关闭交易后,请使用setPayload (array $ data)方法设置有效载荷
示例
$transaction->setPayload([ 'method' => 'BRIVA', // IMPORTANT, dont fill by `getMethod()`!, for more code method you can check here https://payment.tripay.co.id/developer 'merchant_ref' => $merchantRef, 'amount' => $init->getAmount(), 'customer_name' => 'Nama Pelanggan', 'customer_email' => 'emailpelanggan@domain.com', 'customer_phone' => '081234567890', 'order_items' => [ [ 'sku' => 'PRODUK1', 'name' => 'Nama Produk 1', 'price' => $init->getAmount(), 'quantity' => 1 ] ], 'callback_url' => 'https://domainanda.com/callback', 'return_url' => 'https://domainanda.com/redirect', 'expired_time' => (time()+(24*60*60)), // 24 jam 'signature' => $init->createSignature() ]); // set your payload, with more examples https://payment.tripay.co.id/developer
要获取有效载荷,您可以使用getPayload()方法,
设置交易后,您可以使用getData ()方法直接发送请求并获取数据,或者您可以在请求方法中查看更多方法,或者可以在示例中查看
获取关闭交易详情
要查看更详细的交易数据,您可以在交易详情中查看,对于关闭交易,请看下面的参考代码从哪里获取?请转到模拟器菜单,在交易菜单中获取它,这里有一个可以匹配的参考代码
$referenceCode = 'your-reference-code'; // fill by reference code $detail = $transaction->getDetail($referenceCode); // return get detail your transaction with your reference code
下一个方法可以在请求方法中查看,或者可以在示例中查看
开放交易
要定义关闭交易,请使用openTransaction ()方法
$transaction = $init->openTransaction(); // define your transaction type, for close transaction use `openTransaction()`
定义开放交易后,请使用setPayload (array $ data)方法设置有效载荷
示例
$transaction->setPayload([ 'method' => $this->getMethod(), 'merchant_ref' => $merchantRef, 'customer_name' => 'Nama Pelanggan', 'signature' => $init->createSignature() ]); // set your payload, with more examples https://payment.tripay.co.id/developer
要获取有效载荷,您可以使用getPayload()方法,
设置交易后,您可以使用getData ()方法直接发送请求并获取数据,或者您可以在请求方法中查看更多方法,或者可以在示例中查看
获取开放交易详情
要查看更多交易数据,您可以在交易详情中查看,对于已关闭的交易,请见下文如何在获取uuid?请打开交易菜单,然后选择打开付款,那里就有uuid代码。
$uuidCode = 'your-uuid-code'; // fill by reference code $detail = $transaction->getDetail($uuid); // return get detail your open transaction with your uuid code
下一个方法可以在请求方法中查看,或者可以在示例中查看
获取Daftar Pembayaran交易
要查看在开放交易中已进行的付款列表,您可以使用此方法,您可以在您的账户中获取uuid。
$referenceCode = 'your-reference-code'; // fill by reference code $detail = $transaction->getDetail($referenceCode); // return get detail your transaction with your reference code
下一个方法可以在请求方法中查看,或者可以在示例中查看
回调
回调是从TriPay服务器向用户服务器发送交易通知的方法。当客户完成付款时,TriPay系统将提供包含交易数据的通知,然后用户系统可以进一步管理。
在开始之前请定义以下方法
$init = $main->initCallback(); // return callback
接收JSON
要获取由tripay发送的JSON,您可以使用以下方法
$init->get(); // get all callback
解码JSON
与其浪费时间在json_decode上,此包提供了这一点
$init->getJson(); // get json callback
获取签名
使用以下方法从tripay获取签名
$init->signature(); // callback signature
回调签名
tripay还发送回调签名以验证客户数据
$init->callbackSignature(); // callback signature
调用事件
为了重新验证,tripay以payment_status的形式发送事件,此包也捕获这一点
$init->callEvent(); // callback event, return `payment_status`
验证签名
为了缩短代码,我们还准备了签名验证。
$init->validateSignature(); // return `true` is valid signature, `false` invalid signature
验证事件
为了进一步缩短代码,我们还设置了验证事件
$init->validateEvent(); // return `true` is PAID, `false` meaning UNPAID,REFUND,etc OR call event undefined
测试
此包使用PHPunit进行测试,但主要是直接测试
贡献
我创建这个项目是因为之前我使用了tripay作为支付网关,我的代码闲置,所以最好是分享。因此,请为文档或改进此包的脚本做出贡献 ;)