This is a php/laravel wrapper package for Bkash
composer require karim007/laravel-bkash
php artisan vendor:publish --provider="Karim007\LaravelBkash\BkashServiceProvider"
After publish config file setup your credential. you can see this in your config directory bkash.php file
"sandbox" => env("BKASH_SANDBOX", true),
"bkash_app_key" => env("BKASH_APP_KEY", "5nej5keguopj928ekcj3dne8p"),
"bkash_app_secret" => env("BKASH_APP_SECRET", "1honf6u1c56mqcivtc9ffl960slp4v2756jle5925nbooa46ch62"),
"bkash_username" => env("BKASH_USERNAME", "testdemo"),
"bkash_password" => env("BKASH_PASSWORD", "test%#de23@msdao"),
"callbackURL" => env("BKASH_CALLBACK_URL", "http://127.0.0.1:8000"),
'timezone' => 'Asia/Dhaka',
BKASH_SANDBOX=true #for production use false
BKASH_APP_KEY=""
BKASH_APP_SECRET=""
BKASH_USERNAME=""
BKASH_PASSWORD=""
BKASH_CALLBACK_URL=""
php artisan make:controller BkashPaymentController
Route::group(['middleware' => ['auth']], function () {
// Payment Routes for bKash
Route::get('/bkash/payment', [BkashPaymentController::class,'index']);
Route::post('/bkash/get-token', [BkashPaymentController::class,'getToken'])->name('bkash-get-token');
Route::post('/bkash/create-payment', [BkashPaymentController::class,'createPayment'])->name('bkash-create-payment');
Route::post('/bkash/execute-payment', [BkashPaymentController::class,'executePayment'])->name('bkash-execute-payment');
Route::get('/bkash/query-payment', [BkashPaymentController::class,'queryPayment'])->name('bkash-query-payment');
Route::post('/bkash/success', [BkashPaymentController::class,'bkashSuccess'])->name('bkash-success');
// Refund Routes for bKash
Route::get('/bkash/refund', [BkashPaymentController::class,'refundPage'])->name('bkash-refund');
Route::post('/bkash/refund', [BkashPaymentController::class,'refund'])->name('bkash-refund');
});
use Karim007\LaravelBkash\Facade\BkashPayment;
use Karim007\LaravelBkash\Facade\BkashRefund;
public function index()
{
return view('bkash::bkash-payment');
}
public function getToken()
{
session()->put('invoice_amount',100);
return BkashPayment::getToken();
}
public function createPayment(Request $request)
{
$request['intent'] = 'sale';
$request['currency'] = 'BDT';
$request['amount'] = session()->get('invoice_amount') ??100;
$request['merchantInvoiceNumber'] = rand();
$request['callbackURL'] = config("bkash.callbackURL");;
$request_data_json = json_encode($request->all());
return BkashPayment::cPayment($request_data_json);
}
public function executePayment(Request $request)
{
$paymentID = $request->paymentID;
return BkashPayment::executePayment($paymentID);
}
public function queryPayment(Request $request)
{
$paymentID = $request->payment_info['payment_id'];
return BkashPayment::queryPayment($paymentID);
}
public function bkashSuccess(Request $request)
{
$pay_success = $request->payment_info['transactionStatus'];
return BkashPayment::bkashSuccess($pay_success);
}
public function refundPage()
{
return BkashRefund::index();
}
public function refund(Request $request)
{
$this->validate($request, [
'payment_id' => 'required',
'amount' => 'required',
'trx_id' => 'required',
'sku' => 'required|max:255',
'reason' => 'required|max:255'
]);
$post_fields = [
'paymentID' => $request->payment_id,
'amount' => $request->amount,
'trxID' => $request->trx_id,
'sku' => $request->sku,
'reason' => $request->reason,
];
return BkashRefund::refund($post_fields);
}
Contributions to the Bkash Payment Gateway package are welcome. Please note the following guidelines before submitting your pull request.
This repository is licensed under the MIT License.
Copyright 2022 md abdul karim. We are not affiliated with Nagad and don't give any guarantee.