PHP code example of trisnawan / multi-payment-service

1. Go to this page and download the library: Download trisnawan/multi-payment-service 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/ */

    

trisnawan / multi-payment-service example snippets


use Trisnawan\MultiPaymentService\RequestPayment;
use Trisnawan\MultiPaymentService\PaymentBuyer;
use Trisnawan\MultiPaymentService\PaymentCategory;
use Trisnawan\MultiPaymentService\PaymentDirect;
use Trisnawan\MultiPaymentService\PaymentInvoice;

$payment = new RequestPayment();
$buyer = new PaymentBuyer('buyer-001', 'Pembeli', '[email protected]', '081234567890');
$category = new PaymentCategory('orders', 'Orders', 'Pembelian produk');

// Direct: pembeli membayar memakai instruksi VA, QR, atau URL provider.
$transaction = $payment->createDirect(new PaymentDirect(
    $buyer, $category, 'method-id', 'order-001',
    'Pesanan', 'Pembelian produk', 10000, 'https://example.com/payment/return'
));

// Payment link: pembeli memilih metode pada halaman checkout.
$invoice = new PaymentInvoice(
    $buyer, $category, 'order-002',
    'Pesanan', 'Pembelian produk', 10000, 'https://example.com/payment/return'
);
// Opsional; tanpa nilai ini backend memakai kedaluwarsa default.
$invoice->expired_at = date('Y-m-d H:i:s', time() + 3600);
$link = $payment->createLink($invoice);
echo $link->link;

$capabilities = $payment->getCapabilities();
if ($capabilities['simulation']) {
    $result = $payment->simulateTransaction($transaction->id, 'paid');
    $latest = $payment->getTransaction($transaction->id);
}

$report = $payment->findReport([
    'limit' => 20, 'offset' => 0, 'status' => 'paid',
    'start' => '2026-01-01', 'end' => '2026-12-31', 'cat_ref' => 'orders',
]);

use Trisnawan\MultiPaymentService\Webhook;

$webhook = new Webhook();
try {
    $transaction = $webhook->verifyData();
    // Deduplikasi berdasarkan $transaction->id + $transaction->status.
    // Gunakan client_code untuk menghubungkan transaksi ke order aplikasi.
    http_response_code(200);
} catch (\Exception $error) {
    http_response_code($webhook->responseCode);
}