rootwritter/tripay-payment-gateway

PHP Payment Gateway Tripay Library

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

This package is un-official, already compatible with Composer, for more details please visit Documentation. This package is made to make it easier for php users

IMPORTANT: Make sure you read the documentation and understand what these methods are used for!

need PHP 7 and above to use this package

Instalation

composer require rootwritter/tripay-payment-gateway

Configuration

before starting further, you must define or import a tripay for further configuration

use Tripay\Main;

then after that configure 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
);

For mode by default it will be in production mode, to change it to sandbox mode, you can add a 'sandbox' after the merchant code

Contents available

content method available so far

Request available

request can return the available content, the list of available methods is as follows

Channel Pembayaran

This API is used to get a list of all available payment channels along with complete information including transaction fees for each channel

$main->initChannelPembayaran()

the next method can be seen in the request method or can be seen in examples

Instruksi Pembayaran

This API is used to retrieve payment instructions from each channel

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

the next method can be seen in the request method or can be seen in examples

Merchant Channel Pembayaran

This API is used to obtain a list of payment channels available in your Merchant account along with complete information including transaction fees for each channel

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

the next method can be seen in the request method or can be seen in examples

Kalkulator Biaya

This API is used to obtain detailed transaction fee calculations for each channel based on a specified nominal

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

the next method can be seen in the request method or can be seen in examples

Transaction

Before proceeding to the next step in transactions, please configure your reference merchant

$merchantRef = 'your-merchant-ref';//your merchant reference
$init = $main->initTransaction($merchantRef);

Before making a signature, please set the amount for close transactions and for open transactions, please set the payment method

$init->setAmount(1000); // for close payment
$init->setMethod('BRIVAOP'); // for open payment

Note: if you use an open payment do not define the amount and vice versa if you use a close payment do not define the amount

Create Signature

$signature = $init->createSignature();

Close Transaction

To define close transaction, use the closeTransaction () method

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

After you define a close transaction, please set the payload with the setPayload (array $ data) method

**examples:**

$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

for get the payload u can use getPayload() method,

after set transaction u can sent the request and get data directly with the getData () method or for more method u can seen in the request method or can be see in examples

Get Close Detail Transaction

To see further transaction data, you can see it in transaction details, for close transactions, see below where to get reference code? please go to the simulator menu and get it in the transaction menu, there is a reference code that can be matched here

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

the next method can be seen in the request method or can be seen in examples

Open Transaction

To define close transaction, use the openTransaction () method

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

After you define a open transaction, please set the payload with the setPayload (array $ data) method

**examples:**

$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

for get the payload u can use getPayload() method,

after set transaction u can sent the request and get data directly with the getData () method or for more method u can seen in the request method or can be see in examples

Get Open Detail Transaction

To see further transaction data, you can see it in transaction details, for close transactions, see below where can i get uuid? please open the transaction menu then select open payment then there is a uuid code there

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

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

the next method can be seen in the request method or can be seen in examples

Get Daftar Pembayaran Transaction

To see a list of payments made in open transactions you can use this method you can get the uuid in your account.

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

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

the next method can be seen in the request method or can be seen in examples

Callback

Callback is a method of sending transaction notifications from the TriPay server to the user's server. When the payment from the customer is completed, the TriPay system will provide a notification containing transaction data which can then be further managed by the user's system.

please define the method below before starting

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

Receive JSON

to get the json that was sent by tripay you can use the method below

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

Decode JSON

rather than wasting time on json_decode, this package provides that

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

Get The Signature

take signature from tripay using the method below

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

Callback Signature

tripay also sends a callback signature to validate customer data

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

Call Event

for re-validation, tripay sends an event in the form of payment_status this package also captures that

php $init->callEvent(); // callback event, return `payment_status`

Validate Signature

To shorten the code, we prepared signature validation as well.

$init->validateSignature(); // return `true` is valid signature, `false` invalid signature

Validate Event

To shorten the code too, we also set up validate events to go a step further

$init->validateEvent(); // return `true` is PAID, `false` meaning UNPAID,REFUND,etc OR call event undefined

Testing

This package is tested using PHPunit, but mostly direct testing

Contribute

Project ini saya buat karena sebelumnya saya menggunakan tripay sebagai payment gateway, daripada kode saya nganggur jadi ada baiknya saya share. so, silahkan berkontribusi baik dari dokumentasi atau membenahi script dari package ini ;)