rootwritter / tripay-payment-gateway

PHP 付款网关 Tripay 库

1.0.0 2023-05-13 17:35 UTC

This package is auto-updated.

Last update: 2024-09-13 20:37:57 UTC


README

Latest Stable Version Total Downloads License

此包为非官方包,已兼容 Composer,更多详情请访问文档此包旨在使 php 用户更容易使用

重要:请务必阅读文档并理解这些方法的使用目的!

使用此包需要 PHP 7 及以上版本

安装

composer require rootwritter/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'

内容可用

目前可用的 content 方法

请求可用

请求可以返回可用的内容,以下为可用的方法列表

支付渠道

此 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

下一个方法可以在请求方法中查看,或者在示例中查看

获取支付交易列表

要查看在开放交易中完成的支付列表,您可以使用此方法来获取账户中的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的形式发送事件,此包也捕获了它

php $init->callEvent(); // 回调事件,返回 `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作为支付网关,我的代码闲置着,所以最好分享一下。所以,请为这个项目的文档或完善此包的脚本做出贡献吧;)