PHP code example of risekucom / laravel-tripay

1. Go to this page and download the library: Download risekucom/laravel-tripay 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/ */

    

risekucom / laravel-tripay example snippets


// 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'),
];

use Risekucom\LaravelTripay\Facades\Tripay;

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

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

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

// 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)
);

// 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');

$transactionData = [
    'method'         => 'BRIVA',
    'customer_name'  => 'Nama Pelanggan',
    'customer_email' => '[email protected]',
    '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);

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

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

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

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

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

// 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
]);

// 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);
    }
}

$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';
    });
}

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

$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
bash
php artisan vendor:publish --provider="Risekucom\LaravelTripay\TripayServiceProvider"