PHP code example of binderbyte / binderpay-php
1. Go to this page and download the library: Download binderbyte/binderpay-php 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/ */
binderbyte / binderpay-php example snippets
use BinderPay\BinderPay;
$client = new BinderPay([
'partnerId' => '170041', // X-PARTNER-ID
'privateKey' => file_get_contents('private.pem'), // RSA private key (PEM)
'channelId' => 'BCA', // CHANNEL-ID
'isProduction' => false, // default sandbox; true = production
]);
// Create VA (Service 27)
$client->virtualAccount->create([
'customerNo' => '000003212',
'virtualAccountName' => 'Chus Pandi',
'trxId' => 'INV-000000023212',
'totalAmount' => ['value' => '25000.00', 'currency' => 'IDR'],
'virtualAccountTrxType' => 'C', // C | O | R
'expiredDate' => '2023-09-05T19:30:14+07:00',
'additionalInfo' => ['channel' => 'CIMB'],
]);
// Inquiry active VA (Service 30)
$client->virtualAccount->inquiry([
'trxId' => 'INV-000000023212',
'additionalInfo' => ['contractId' => 'ci302a21c9'],
]);
// VA payment status (Service 26)
$client->virtualAccount->status([
'virtualAccountNo' => '2269141693898987',
'trxId' => 'INV-000000023212',
'additionalInfo' => ['contractId' => 'ci302a21c9', 'channel' => 'BCA'],
]);
// Delete VA (Service 31)
$client->virtualAccount->delete([
'trxId' => 'INV-000000023212',
'virtualAccountNo' => '2269141693898987',
'additionalInfo' => ['channel' => 'BCA', 'contractId' => 'ci302a21c9'],
]);
// Generate QRIS (Service 47)
$client->qris->generate([
'partnerReferenceNo' => 'INV-000000023212',
'amount' => ['value' => '45000.00', 'currency' => 'IDR'],
'validityPeriod' => '2024-01-11T17:00:00+07:00', // Id' => 'ci302a21c9'],
]);
// Cancel (Service 77)
$client->qris->cancel([
'originalPartnerReferenceNo' => 'INV-000000023212',
'reason' => 'cancel order',
'additionalInfo' => ['contractId' => 'ci302a21c9'],
]);
use BinderPay\Webhook;
// Laravel example
Route::post('/api/binderpay/callback', function (Request $request) {
$rawBody = $request->getContent(); // exactly as received; do not re-serialize
// Load BinderPay public key (PEM format) from file or environment variable
$binderpayPublicKey = file_get_contents(storage_path('keys/binderpay-public.pem'));
$valid = Webhook::verifyCallbackSignature(
$request->headers->all(),
$rawBody,
$binderpayPublicKey,
);
if (! $valid) {
return response()->json(['message' => 'Cannot verify signature'], 401);
}
$callback = Webhook::parseCallback($request->all()); // auto-detects VA or QRIS
// ... process payment idempotently ...
// Return the matching SNAP success code for the detected callback type.
return response()->json(Webhook::successResponse($callback['type']));
});
use BinderPay\Exceptions\BinderPayException;
use BinderPay\Exceptions\ValidationException;
try {
$client->virtualAccount->create([...]);
} catch (ValidationException $e) {
// invalid input on the SDK side
} catch (BinderPayException $e) {
if ($e->responseCode === '4002701') {
// field format mismatch
}
// $e->status (HTTP status), $e->responseBody (raw body)
}
bash
composer