risekucom/laravel-tripay

Unofficial Laravel package for Tripay Payment API.

v1.0.0 2025-02-25 14:11 UTC

This package is auto-updated.

Last update: 2025-07-25 15:38:27 UTC


README

A Laravel package for integrating with the Tripay Payment Gateway API. This package provides a simple and elegant way to interact with Tripay's payment services in your Laravel applications.

Features

  • Simple integration with Tripay payment gateway
  • Support for closed and open payment transactions
  • Payment channel management
  • Transaction fee calculations
  • Callback verification
  • Laravel-friendly response handling

Requirements

  • PHP 8.1 or higher
  • Laravel 10.0 or higher

Installation

You can install the package via composer:

composer require risekucom/laravel-tripay

Configuration

After installation, publish the configuration file:

php artisan vendor:publish --provider="Risekucom\LaravelTripay\TripayServiceProvider"

This will create a config/tripay.php file in your config directory. Edit this file with your Tripay API credentials:

// config/tripay.php
return [
    'tripay_api_production' => env('TRIPAY_API_PRODUCTION', false),
    'tripay_api_key' => env('TRIPAY_API_KEY'),
    'tripay_private_key' => env('TRIPAY_PRIVATE_KEY'),
    'tripay_merchant_code' => env('TRIPAY_MERCHANT_CODE'),
];

Then, add these variables to your .env file:

TRIPAY_API_PRODUCTION=false
TRIPAY_API_KEY=
TRIPAY_PRIVATE_KEY=
TRIPAY_MERCHANT_CODE=

Set TRIPAY_API_PRODUCTION to true when you're ready to process real payments.

Usage

Basic Usage

use Risekucom\LaravelTripay\Facades\Tripay;

// Get available payment channels
$channels = Tripay::getPaymentChannelList();

Available Methods

Get Payment Channel List

Retrieve available payment channels from Tripay:

// Get all payment channels
$channels = Tripay::getPaymentChannelList();

// Get specific payment channel by code
$channel = Tripay::getPaymentChannelList('BRIVA');

Official Documentation: Payment Channel List

Get Payment Instructions

Retrieve payment instructions for a specific payment method:

// Get payment instructions for BRIVA
$instructions = Tripay::getPaymentInstructionList('BRIVA');

// Get payment instructions with additional parameters
$instructions = Tripay::getPaymentInstructionList(
    'BRIVA',
    'PAYMENT123',  // Optional payment code
    50000,         // Optional amount
    1              // Allow HTML in instructions (1 = yes, 0 = no)
);

Official Documentation: Payment Instructions

Calculate Transaction Fee

Get fee details for a specific payment method and amount:

// Calculate fee for a 100,000 IDR transaction using all payments
$feeDetails = Tripay::getTransactionFeeDetails(100000);

// Calculate fee for a 100,000 IDR transaction using BRIVA
$feeDetails = Tripay::getTransactionFeeDetails(100000, 'BRIVA');

Official Documentation: Transaction Fee

Create Closed Transaction

Create a new closed payment transaction:

$transactionData = [
    'method'         => 'BRIVA',
    'customer_name'  => 'Nama Pelanggan',
    'customer_email' => 'emailpelanggan@domain.com',
    'customer_phone' => '081234567890',
    'order_items'    => [
        [
            'sku'         => 'FB-06',
            'name'        => 'Nama Produk 1',
            'price'       => 500000,
            'quantity'    => 1,
            'product_url' => 'https://tokokamu.com/product/nama-produk-1',
            'image_url'   => 'https://tokokamu.com/product/nama-produk-1.jpg',
        ],
        [
            'sku'         => 'FB-07',
            'name'        => 'Nama Produk 2',
            'price'       => 500000,
            'quantity'    => 1,
            'product_url' => 'https://tokokamu.com/product/nama-produk-2',
            'image_url'   => 'https://tokokamu.com/product/nama-produk-2.jpg',
        ]
    ],
    'return_url'   => 'https://domainanda.com/redirect',
    'expired_time' => (time() + (24 * 60 * 60)), // 24 hours
];

$transaction = Tripay::createClosedTransaction($transactionData);

Official Documentation: Create Closed Transaction

Get Closed Transaction Details

Retrieve details of a closed transaction:

$transaction = Tripay::getClosedTransactionDetail('T123456789');

Official Documentation: Transaction Detail

Create Open Transaction

Create a new open payment transaction:

$transactionData = [
    'method' => 'QRIS',
    'merchant_ref' => 'INV-' . time(),
    'customer_name' => 'John Doe',
    'callback_url' => 'https://yourdomain.com/payment/callback',
];

$transaction = Tripay::createOpenTransaction($transactionData);

Official Documentation: Create Open Transaction

Get Open Transaction Details

Retrieve details of an open transaction:

$transaction = Tripay::getOpenTransactionDetail('uuid-string-here');

Official Documentation: Open Transaction Detail

Get Open Transaction List

Retrieve a list of open transactions:

$transactions = Tripay::getOpenTransactionList('uuid-string-here');

Official Documentation: Open Transaction List

Get Merchant Transaction List

Get a list of merchant transactions:

// Get all transactions
$transactions = Tripay::getMerchantTransactionList();

// Get transactions with filters
$transactions = Tripay::getMerchantTransactionList([
    'page' => 1,
    'per_page' => 25,
    'sort' => 'desc',
    'reference' => 'T123456789',  // Optional specific transaction
    'merchant_ref' => 'INV123',   // Optional merchant reference
    'status' => 'PAID',           // Optional status filter
]);

Official Documentation: Merchant Transaction List

Verify Callback Data

Verify the authenticity of callback data from Tripay:

// In your callback controller
public function handleCallback(Request $request)
{
    $callbackData = $request->getContent();
    $callbackSignature = $request->server('HTTP_X_CALLBACK_SIGNATURE');
    $callbackEvent = $request->server('HTTP_X_CALLBACK_EVENT');

    try {
        $result = Tripay::verifyCallbackData(
            $callbackData,
            $callbackSignature,
            $callbackEvent
        );

        if (!$result->get('success')) {
            throw new \Exception($result->get('message'), $result->get('code'));
        }

        // Process the payment based on the callback data
        // $result contains the verified data
        $data = $result->get('data');

        return response()->json(['success' => true]);
    } catch (\Exception $e) {
        return response()->json(['error' => $e->getMessage()], 400);
    }
}

Official Documentation: Callback

Response Handling

All methods return a Laravel Collection instance, which provides a fluent interface for working with the response data:

$channels = Tripay::getPaymentChannelList();

// Check if request was successful
if ($channels->get('success')) {
    // Access the data
    $paymentMethods = $channels->get('data');

    // Filter payment methods
    $bankTransfers = collect($paymentMethods)->filter(function ($method) {
        return $method['group'] === 'Virtual Account';
    });
}

Error Handling

The package returns error responses in this format:

{
    "code": 400,
    "success": false,
    "message": "Payment channel not available or under maintenance"
}

You can handle these errors in your application:

$transaction = Tripay::getClosedTransactionDetail('INVALID-REF');

if (!$transaction->get('success')) {
    // Handle the error
    $errorCode = $transaction->get('code');
    $errorMessage = $transaction->get('message');

    return response()->json([
        'success' => false,
        'message' => $errorMessage
    ], $errorCode);
}

// Continue processing successful response

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

Acknowledgments

This is an unofficial package and is not affiliated with Tripay. Always refer to the official Tripay documentation for the latest API details.