PHP code example of itsrafsanjani / laravel-bkash

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

    

itsrafsanjani / laravel-bkash example snippets


return [
    'sandbox' => env('BKASH_SANDBOX', true), // true for testing, false for production

    'app_key' => env('BKASH_APP_KEY', ''),
    'app_secret' => env('BKASH_APP_SECRET', ''),
    'username' => env('BKASH_USERNAME', ''),
    'password' => env('BKASH_PASSWORD', ''),

    // bkash will send data to this url
    'callbackURL' => env('BKASH_CALLBACK_URL', 'http://127.0.0.1:8000/bkash/callback'),
    'timezone' => 'Asia/Dhaka',
];

Route::get('/bkash/callback', [PaymentController::class, 'callback']);

protected $except = [
    'bkash/*',
];

use Illuminate\Http\Request;
use ItsRafsanJani\Bkash\Data\CreatePaymentData;
use ItsRafsanJani\Bkash\Facades\Bkash;

class PaymentController extends Controller
{
    public function pay()
    {
        // ..
        // save payment related data in your database or anything
        // ..

        $invoiceId = uniqid(); // could be any string

        $response = Bkash::createPayment(
            new CreatePaymentData(
                amount: 20.50,
                payerReference: $invoiceId,
            )
        );

        // dd($response);

        return redirect()->away($response->bkashURL);
    }

    public function callback(Request $request)
    {
        // first you need to execute
        $executeResponse = Bkash::executePayment($request->paymentID);

        // then query
        $queryResponse =  Bkash::queryPayment($request->paymentID);
        
        // ..
        // update payment status
        // ..
    }
}

$invoiceId = uniqid(); // could be any string

$response = Bkash::createPayment(
    new CreatePaymentData(
        amount: 20.50,
        payerReference: $invoiceId,
    )
);

return response()->json($response);

$response = Bkash::executePayment($request->paymentID);

return response()->json($response);

$response =  Bkash::queryPayment($request->paymentID);

return response()->json($response);

$searchTransactionResponse = Bkash::searchTransaction($response['trxID']);

return response()->json($searchTransactionResponse);
bash
php artisan vendor:publish --tag="laravel-bkash-config"