PHP code example of bdpay / laravel-bdpay

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

    

bdpay / laravel-bdpay example snippets


use BDPay\LaravelBDPay\Facades\BDPay;

// Create a Virtual Account
$vaData = BDPay::fundAcceptance()->createVA([
    'amount' => 100000, // Amount in IDR (100,000 IDR)
    'order_id' => 'ORDER-' . time(),
    'customer_name' => 'John Doe',
    'customer_email' => '[email protected]',
    'customer_phone' => '081234567890',
    'description' => 'Payment for order #123',
    'expired_at' => now()->addDays(1),
    'bank_code' => 'BCA', // Optional
]);

// Create a Payment Link
$paymentLinkData = BDPay::fundAcceptance()->createPaymentLink([
    'amount' => 100000,
    'order_id' => 'ORDER-' . time(),
    'customer_name' => 'John Doe',
    'customer_email' => '[email protected]',
    'customer_phone' => '081234567890',
    'description' => 'Payment for order #123',
    'payment_method' => 'all', // or specific payment method
    'redirect_url' => 'https://yourdomain.com/payment/success',
    'callback_url' => 'https://yourdomain.com/bdpay/webhook/payment',
]);

// Create a Static Virtual Account
$staticVAData = BDPay::fundAcceptance()->createStaticVA([
    'customer_name' => 'John Doe',
    'customer_email' => '[email protected]',
    'customer_phone' => '081234567890',
    'description' => 'Static VA for customer',
    'bank_code' => 'BCA',
]);

// Check Payment Status
$status = BDPay::fundAcceptance()->getPaymentStatus('ORDER-123456');

// Create Disbursement
$disbursementData = BDPay::fundDisbursement()->createDisbursement([
    'amount' => 50000,
    'order_id' => 'DISBURSEMENT-' . time(),
    'recipient_name' => 'Jane Doe',
    'recipient_account' => '1234567890',
    'bank_code' => 'BCA',
    'description' => 'Refund for order #123',
    'callback_url' => 'https://yourdomain.com/bdpay/webhook/disbursement',
]);

// Check Disbursement Status
$status = BDPay::fundDisbursement()->getDisbursementStatus('DISBURSEMENT-123456');

// Get Account Balance
$balance = BDPay::fundDisbursement()->getBalance();

use BDPay\LaravelBDPay\Models\BDPayTransaction;

// Get all successful payments
$successfulPayments = BDPayTransaction::payments()->successful()->get();

// Get pending disbursements
$pendingDisbursements = BDPayTransaction::disbursements()->pending()->get();

// Get transaction by order ID
$transaction = BDPayTransaction::where('order_id', 'ORDER-123')->first();

// Format amount for BDPay API (multiply by 100 for IDR)
$formattedAmount = BDPay::fundAcceptance()->formatAmount(1000.00, 'IDR'); // Returns 100000

// Parse amount from BDPay response
$parsedAmount = BDPay::fundAcceptance()->parseAmount(100000, 'IDR'); // Returns 1000.00

// Or use disbursement service for disbursement amounts
$disbursementAmount = BDPay::fundDisbursement()->formatAmount(500.00, 'IDR'); // Returns 50000

// Note: Bank code validation is handled by BDPay API
// Use any bank code supported by BDPay (BCA, BNI, BRI, MANDIRI, etc.)

// Generate signature for webhook verification
$signature = BDPay::generateSignature($data);

// Verify webhook signature
$isValid = BDPay::verifySignature($signature, $data);

use BDPay\LaravelBDPay\Exceptions\BDPayException;
use BDPay\LaravelBDPay\Exceptions\InvalidConfigurationException;
use BDPay\LaravelBDPay\Exceptions\InvalidSignatureException;

try {
    $result = BDPay::fundAcceptance()->createVA($data);
} catch (BDPayException $e) {
    // Handle BDPay API errors
    echo $e->getMessage();
    echo $e->getErrorCode();
    echo $e->getErrorDetailsAsJson();
} catch (InvalidConfigurationException $e) {
    // Handle configuration errors
    echo $e->getMessage();
} catch (InvalidSignatureException $e) {
    // Handle webhook signature verification errors
    echo $e->getMessage();
}
bash
php artisan vendor:publish --provider="BDPay\LaravelBDPay\BDPayServiceProvider" --tag="bdpay-config"
bash
php artisan vendor:publish --provider="BDPay\LaravelBDPay\BDPayServiceProvider" --tag="bdpay-migrations"
bash
php artisan migrate
bash
php artisan vendor:publish --provider="BDPay\LaravelBDPay\BDPayServiceProvider" --tag="bdpay-routes"