PHP code example of karim007 / laravel-bkash

1. Go to this page and download the library: Download karim007/laravel-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/ */

    

karim007 / laravel-bkash example snippets

bash
php artisan vendor:publish --provider="Karim007\LaravelBkash\BkashServiceProvider"

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');

});

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 refund(Request $request)
{
    $this->validate($request, [
        'payment_id' => ',
        'reason' => 'trxID' => $request->trx_id,
        'sku' => $request->sku,
        'reason' => $request->reason,
    ];
    return BkashRefund::refund($post_fields);
}