PHP code example of mainul12501 / bkash-payment-b2c
1. Go to this page and download the library: Download mainul12501/bkash-payment-b2c 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/ */
mainul12501 / bkash-payment-b2c example snippets
use Mainul12501\Bkash\Facades\Bkash;
$checkout = Bkash::checkout();
$tokenized = Bkash::tokenized();
$payouts = Bkash::payouts();
$response = Bkash::checkout()->createPayment([
'amount' => '150.00',
'currency' => 'BDT',
'intent' => 'sale',
'merchantInvoiceNumber' => 'INV-1001',
'merchantAssociationInfo' => 'order:1001',
]);
$payment = $response->toArray();
Bkash::checkout()->executePayment($paymentId);
Bkash::checkout()->capturePayment($paymentId);
Bkash::checkout()->queryPayment($paymentId);
Bkash::checkout()->voidPayment($paymentId);
$response = Bkash::checkout()->searchTransaction($trxId);
$response = Bkash::checkout()->refund([
'paymentID' => $paymentId,
'amount' => '150.00',
'trxID' => $trxId,
'sku' => 'SKU-1001',
'reason' => 'Customer requested cancellation',
]);
$agreement = Bkash::tokenized()->createAgreement([
'mode' => '0000',
'callbackURL' => route('bkash.callback'),
'payerReference' => 'customer-1001',
]);
$executedAgreement = Bkash::tokenized()->executeAgreement([
'paymentID' => $agreement->json('paymentID'),
]);
$payment = Bkash::tokenized()->createPayment([
'mode' => '0011',
'callbackURL' => route('bkash.callback'),
'agreementID' => 'AGREEMENT_ID',
'payerReference' => 'customer-1001',
'amount' => '100.00',
'currency' => 'BDT',
'intent' => 'sale',
'merchantInvoiceNumber' => 'INV-2001',
]);
$executedPayment = Bkash::tokenized()->executePayment([
'paymentID' => $payment->json('paymentID'),
]);
Bkash::tokenized()->queryAgreement('AGREEMENT_ID');
Bkash::tokenized()->cancelAgreement('AGREEMENT_ID');
Bkash::tokenized()->confirmPayment('capture', [
'paymentID' => $paymentId,
]);
Bkash::tokenized()->queryPayment([
'paymentID' => $paymentId,
]);
Bkash::tokenized()->searchTransaction($trxId);
Bkash::tokenized()->refund([
'paymentID' => $paymentId,
'amount' => '10.00',
'trxID' => $trxId,
'sku' => 'SKU-2001',
'reason' => 'Partial refund',
]);
Bkash::tokenized()->refundStatus([
'paymentId' => $paymentId,
'trxId' => $trxId,
]);
Bkash::tokenized()->refundStatus($payload, '/v2/tokenized-checkout/refund/payment/transaction');
$response = Bkash::checkout()->b2cPayment([
'amount' => '500.00',
'currency' => 'BDT',
'merchantInvoiceNumber' => 'B2C-1001',
'receiverMSISDN' => '017XXXXXXXX',
]);
$response = Bkash::checkout()->organizationBalance();
$response = Bkash::checkout()->intraAccountTransfer([
'amount' => '1000.00',
'currency' => 'BDT',
'transferType' => 'Collection2Disbursement',
]);
$initiate = Bkash::payouts()->initiate([
'type' => 'B2B',
'reference' => 'REF-1001',
]);
$payoutId = $initiate->json('payoutID');
$transfer = Bkash::payouts()->b2b([
'payoutID' => $payoutId,
'amount' => '100.00',
'currency' => 'BDT',
'merchantInvoiceNumber' => 'B2B-1001',
'receiverMSISDN' => '01XXXXXXXXX',
]);
$response = Bkash::raw(
service: 'tokenized',
method: 'POST',
path: '/tokenized/checkout/payment/status',
payload: ['paymentID' => $paymentId]
);
$response = Bkash::raw(
service: 'tokenized',
method: 'POST',
path: '/v2/tokenized-checkout/refund/payment/status',
payload: ['paymentId' => $paymentId, 'trxId' => $trxId],
absolutePath: true
);
use Illuminate\Http\Request;
use Mainul12501\Bkash\Facades\Bkash;
Route::post('/bkash/webhook', function (Request $request) {
Bkash::webhooks()->assertMatchingSecret($request);
$payload = Bkash::webhooks()->fromRequest($request);
// Process webhook payload here.
return response()->json(['received' => true]);
});
$response->status();
$response->successful();
$response->json();
$response->json('paymentID');
$response->toArray();
$response->headers();
$response->body();
$response->collect();
$response->collect('items');
$response->raw(); // underlying Illuminate HTTP response
use Mainul12501\Bkash\Exceptions\BkashRequestException;
try {
$response = Bkash::checkout()->createPayment($payload);
} catch (BkashRequestException $exception) {
$status = $exception->status();
$response = $exception->response();
}