PHP code example of mahedi250 / bkash
1. Go to this page and download the library: Download mahedi250/bkash 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/ */
mahedi250 / bkash example snippets bash
php artisan vendor:publish --provider="Mahedi250\Bkash\bkashServiceProvider"
bash
php artisan make:controller Payment/BkashPaymentController
$response = CheckoutUrl::Create(1000,['payerReference'=>"01877722345",'merchantInvoiceNumber'=>"Inv_123"]);
return redirect($response->bkashURL);
public function callback(Request $request)
{
$status = $request->input('status');
$paymentId = $request->input('paymentID');
if ($status === 'success')
{
$response = CheckoutUrl::MakePayment($paymentId);
if ($response->statusCode !== '0000')
{
return CheckoutUrl::Failed($response->statusMessage);
}
if (isset($response->transactionStatus)&&($response->transactionStatus=='Completed'||$response->transactionStatus=='Authorized'))
{
//Database Insert Operation
return CheckoutUrl::Success($response->trxID."({$response->transactionStatus})");
}
else if($response->transactionStatus=='Initiated')
{
return CheckoutUrl::Failed("Try Again");
}
}
else
{
return CheckoutUrl::Failed($status);
}
}
Route::group(['middleware' => ['web']], function () {
Route::post("bkash/pay",[BkashPaymentController::class,'pay'])->name('bkash.pay');
Route::get("bkash/callback",[BkashPaymentController::class,'Callback']);
});
<form action="{{ route('bkash.pay') }}" method="POST">
@csrf
<button type="submit">Pay with bkash</button>
</form>
public function refund(Request $request)
{
return CheckoutUrl::Refund(paymentID,$trxID,$amountToRefund);
}
$amount = 200;
$response = CheckoutUrl::Create($amount,['intent'=>'authorization']);
return redirect($response['bkashURL']);