PHP code example of rootwritter / tripay-payment-gateway

1. Go to this page and download the library: Download rootwritter/tripay-payment-gateway library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rootwritter / tripay-payment-gateway example snippets


use Tripay\Main;

$main = new Main(
    'your-api-key',
    'your-private-key',
    'your-merchant-code',
    'sandbox' // fill for sandbox mode, leave blank if in production mode
);

$main->initChannelPembayaran()

$code = 'BRIVA'; //more info code, https://payment.tripay.co.id/developer
$init = $main->initInstruksiPembayaran($code)

$code = 'BRIVA'; //more info code, check your account
$init = $main->initMerchantChannelPembayaran($code);

$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();

$transaction = $init->closeTransaction(); // define your transaction type, for close transaction use `closeTransaction()`

$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'    => '[email protected]',
    '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

$referenceCode = 'your-reference-code'; // fill by reference code
$detail = $transaction->getDetail($referenceCode); // return get detail your transaction with your reference code

$transaction = $init->openTransaction(); // define your transaction type, for close transaction use `openTransaction()`

$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

$uuidCode = 'your-uuid-code'; // fill by reference code

$detail = $transaction->getDetail($uuid); // return get detail your open transaction with your uuid code

$referenceCode = 'your-reference-code'; // fill by reference code

$detail = $transaction->getDetail($referenceCode); // return get detail your transaction with your reference code

$init = $main->initCallback(); // return callback

$init->get(); // get all callback

$init->getJson(); // get json callback

$init->signature(); // callback signature

$init->callbackSignature(); // callback signature

$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