PHP code example of webimpian / bayarcash-php-sdk

1. Go to this page and download the library: Download webimpian/bayarcash-php-sdk 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/ */

    

webimpian / bayarcash-php-sdk example snippets


$bayarcash = new Webimpian\BayarcashSdk\Bayarcash(TOKEN_HERE);
$bayarcash->useSandbox(); // call this method to switch to use sandbox

// set value for BAYARCASH_API_TOKEN and BAYARCASH_API_SECRET_KEY in the .env file
BAYARCASH_API_TOKEN=
BAYARCASH_API_SECRET_KEY=

$bayarcash = app(\Webimpian\BayarcashSdk\Bayarcash::class);
$bayarcash->useSandbox(); // call this method to switch to use sandbox

// Optional: Set API version (default is 'v2')
$bayarcash->setApiVersion('v3');

Bayarcash::FPX                 // FPX Online Banking
Bayarcash::FPX_DIRECT_DEBIT   // FPX Direct Debit
Bayarcash::FPX_LINE_OF_CREDIT // FPX Line of Credit
Bayarcash::DUITNOW_DOBW       // DuitNow Online Banking
Bayarcash::DUITNOW_QR         // DuitNow QR
Bayarcash::SPAYLATER          // ShopeePayLater
Bayarcash::BOOST_PAYFLEX      // Boost PayFlex
Bayarcash::QRISOB            // QRIS Online Banking
Bayarcash::QRISWALLET        // QRIS Wallet
Bayarcash::NETS              // NETS

// Get all available portals
$portals = $bayarcash->getPortals();

// Get available payment channels for a specific portal
$channels = $bayarcash->getChannels('your_portal_key');

// Get list of available FPX banks
$banks = $bayarcash->fpxBanksList();

// Generate checksum for payment intent
$paymentIntentRequestChecksum = $bayarcash->createPaymentIntenChecksumValue(API_SECRET_KEY, REQUEST_DATA); 

// append checksum value to your REQUEST_DATA
$data['checksum'] = $paymentIntentRequestChecksum;

// Send payment request
$response = $bayarcash->createPaymentIntent(REQUEST_DATA);
header("Location: " . $response->url); // redirect payer to Bayarcash checkout page.

// Verify callbacks
// pre-transaction callback
$validPreTransaction = $bayarcash->verifyPreTransactionCallbackData(CALLBACK_DATA, API_SECRET_KEY);

// transaction callback
$validTransaction = $bayarcash->verifyTransactionCallbackData(CALLBACK_DATA, API_SECRET_KEY);

// return URL callback
$validReturnUrl = $bayarcash->verifyReturnUrlCallbackData(CALLBACK_DATA, API_SECRET_KEY);

// Get payment intent details (V3 API only)
$paymentIntent = $bayarcash->getPaymentIntent('payment_intent_id');

// Get single transaction
$transaction = $bayarcash->getTransaction('transaction_id');

// V3 API Features
if ($bayarcash->getApiVersion() === 'v3') {
    // Get all transactions with filters
    $transactions = $bayarcash->getAllTransactions([
        'order_number' => 'ORDER123',
        'status' => '3',
        'payment_channel' => Bayarcash::FPX,
        'exchange_reference_number' => 'REF123',
        'payer_email' => '[email protected]'
    ]);

    // Specialized transaction queries
    $orderTransactions = $bayarcash->getTransactionByOrderNumber('ORDER123');
    $emailTransactions = $bayarcash->getTransactionsByPayerEmail('[email protected]');
    $statusTransactions = $bayarcash->getTransactionsByStatus('3');
    $channelTransactions = $bayarcash->getTransactionsByPaymentChannel(Bayarcash::FPX);
    $refTransaction = $bayarcash->getTransactionByReferenceNumber('REF123');
}

$enrolmentRequestChecksum = $bayarcash->createFpxDirectDebitEnrolmentChecksumValue(API_SECRET_KEY, REQUEST_DATA); 

// append checksum value to your REQUEST_DATA
$data['checksum'] = $enrolmentRequestChecksum;

$response = $bayarcash->createFpxDirectDebitEnrollmentIntent($data);
header("Location: " . $response->url); // redirect payer to Bayarcash Fpx Direct Debit enrolment page.

$maintenanceRequestChecksum = $bayarcash->createFpxDirectDebitMaintenanceChecksumValue(API_SECRET_KEY, REQUEST_DATA); 

// append checksum value to your REQUEST_DATA
$data['checksum'] = $maintenanceRequestChecksum;

$response = $bayarcash->createFpxDirectDebitMaintenanceIntent($data);
header("Location: " . $response->url); // redirect payer to Bayarcash Fpx Direct Debit maintenance page.

$response = $bayarcash->createFpxDirectDebitTerminationIntent($data);
header("Location: " . $response->url); // redirect payer to Bayarcash Fpx Direct Debit termination page.
bash
composer