PHPackages                             karim007/laravel-bkash-tokenize - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. karim007/laravel-bkash-tokenize

ActiveLibrary[Payment Processing](/categories/payments)

karim007/laravel-bkash-tokenize
===============================

This is bKash tokenize payment gateway for laravel

v2.4(5mo ago)2221.1k↑28.8%17MITPHPPHP ^7.4|^8.0|^8.1|^8.2

Since Jan 22Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/karim-007/laravel-bkash-tokenize)[ Packagist](https://packagist.org/packages/karim007/laravel-bkash-tokenize)[ RSS](/packages/karim007-laravel-bkash-tokenize/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)DependenciesVersions (10)Used By (0)

Bkash Payment Gateway for PHP/Laravel Framework
===============================================

[](#bkash-payment-gateway-for-phplaravel-framework)

[![Downloads](https://camo.githubusercontent.com/0e2bf6a26e392df7f1c11c45ebf0530c8545c49e19399576d95d22901224f0cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b6172696d3030372f6c61726176656c2d626b6173682d746f6b656e697a65)](https://packagist.org/packages/karim007/laravel-bkash-tokenize)[![Starts](https://camo.githubusercontent.com/cf8fc75d4aa7d496377498493caf5627fcfe069204713f2eaa9eadbd429fbe4f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f6b6172696d3030372f6c61726176656c2d626b6173682d746f6b656e697a65)](https://packagist.org/packages/karim007/laravel-bkash-tokenize)

Features
--------

[](#features)

This is a php/laravel wrapper package for [Bkash](https://developer.bka.sh/)

Requirements
------------

[](#requirements)

- PHP &gt;=7.4
- Laravel &gt;= 6

Installation
------------

[](#installation)

```
composer require karim007/laravel-bkash-tokenize
```

Examples
--------

[](#examples)

![]()[![bkash tokenize](example/bkash1.png)](example/bkash1.png)![]()[![bkash tokenize payment](example/bkash2.png)](example/bkash2.png)![]()[![bkash](example/bkash3.png)](example/bkash3.png)![]()[![bkash](example/bkash4.png)](example/bkash4.png)![]()[![bkash](example/bkash5.png)](example/bkash5.png)

For video tutorial click the image bellow or

[![laravel bkash tokenize](https://camo.githubusercontent.com/28c975d49fcb5ddf92ffdf5d7f7ba883d596279fa71b22e907a7c3ae53e0cfc2/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f704162723158304a7a36732f687164656661756c742e6a7067)](https://youtu.be/pAbr1X0Jz6s)

### vendor publish (config)

[](#vendor-publish-config)

```
php artisan vendor:publish --provider="Karim007\LaravelBkashTokenize\BkashTokenizeServiceProvider" --tag="config"
```

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", ""),
"bkash_app_secret" => env("BKASH_APP_SECRET", ""),
"bkash_username"      => env("BKASH_USERNAME", ""),
"bkash_password"     => env("BKASH_PASSWORD", ""),

"bkash_app_key_2"     => env("BKASH_APP_KEY_2", ""),
"bkash_app_secret_2" => env("BKASH_APP_SECRET_2", ""),
"bkash_username_2"      => env("BKASH_USERNAME_2", ""),
"bkash_password_2"     => env("BKASH_PASSWORD_2", ""),

//so on ...

"callbackURL"     => env("BKASH_CALLBACK_URL", "http://127.0.0.1:8000/bkash/callback"),
'timezone'        => 'Asia/Dhaka',

```

### Set .env configuration

[](#set-env-configuration)

```
BKASH_SANDBOX=true  #for production use false

BKASH_APP_KEY=""
BKASH_APP_SECRET=""
BKASH_USERNAME=""
BKASH_PASSWORD=""

#for multi account
BKASH_APP_KEY_2=""
BKASH_APP_SECRET_2=""
BKASH_USERNAME_2=""
BKASH_PASSWORD_2=""

#so on just use _number likes _3, _4, _5

BKASH_CALLBACK_URL=""

```

Usage
-----

[](#usage)

### 1. publish a controller

[](#1-publish-a-controller)

```
php artisan vendor:publish --provider="Karim007\LaravelBkashTokenize\BkashTokenizeServiceProvider" --tag="controllers"

```

### 2. you can override the routes

[](#2-you-can-override-the-routes)

```
Route::group(['middleware' => ['web']], function () {
    // Payment Routes for bKash
    Route::get('/bkash/payment', [App\Http\Controllers\BkashTokenizePaymentController::class,'index']);
    Route::get('/bkash/create-payment', [App\Http\Controllers\BkashTokenizePaymentController::class,'createPayment'])->name('bkash-create-payment');
    Route::get('/bkash/callback', [App\Http\Controllers\BkashTokenizePaymentController::class,'callBack'])->name('bkash-callBack');

    //search payment
    Route::get('/bkash/search/{trxID}', [App\Http\Controllers\BkashTokenizePaymentController::class,'searchTnx'])->name('bkash-serach');

    //refund payment routes
    Route::get('/bkash/refund', [App\Http\Controllers\BkashTokenizePaymentController::class,'refund'])->name('bkash-refund');
    Route::get('/bkash/refund/status', [App\Http\Controllers\BkashTokenizePaymentController::class,'refundStatus'])->name('bkash-refund-status');

});
```

### 3. payment page

[](#3-payment-page)

you will find it App\\Http\\Controllers\\BkashTokenizePaymentController

```
public function index()
{
    return view('bkashT::bkash-payment');
}

```

### 4. create payment

[](#4-create-payment)

```
public function createPayment(Request $request)
    {
        $inv = uniqid();
        $request['intent'] = 'sale';
        $request['mode'] = '0011';
        $request['payerReference'] = $inv;
        $request['currency'] = 'BDT';
        $request['amount'] = 100;
        $request['merchantInvoiceNumber'] = $inv;
        $request['callbackURL'] = config("bkash.callbackURL");;

        $request_data_json = json_encode($request->all());

        $response =  BkashPaymentTokenize::cPayment($request_data_json);
        //$response =  BkashPaymentTokenize::cPayment($request_data_json,1); //last parameter is your account number for multi account its like, 1,2,3,4,cont.. default param is 1

        //store paymentID and your account number for matching in callback request
        // dd($response) //if you are using sandbox and not submit info to bkash use it for 1 response

        if (isset($response['bkashURL'])) return redirect()->away($response['bkashURL']);
        else return redirect()->back()->with('error-alert2', $response['statusMessage']);
    }
```

\###create payment response

```
array[
  "statusCode" => "0000"
  "statusMessage" => "Successful"
  "paymentID" => "Your payment id"
  "bkashURL" => "https://sandbox.payment.bkash.com/redirect/tokenized/?paymentID=your_payment_id&hash=your_hash"
  "callbackURL" => "base_url/bkash/callback"
  "successCallbackURL" => "base_url/bkash/callback?paymentID=your_payment_id&status=success"
  "failureCallbackURL" => "base_url/bkash/callback?paymentID=your_payment_id&status=failure"
  "cancelledCallbackURL" => "base_url/bkash/callback?paymentID=your_payment_id&status=cancel"
  "amount" => "100"
  "intent" => "sale"
  "currency" => "BDT"
  "paymentCreateTime" => "2023-01-23T02:16:57:784 GMT+0600"
  "transactionStatus" => "Initiated"
  "merchantInvoiceNumber" => "merchant_invoice_no"
]

```

### 5. callback function

[](#5-callback-function)

```
public function callBack(Request $request)
    {
        //callback request params
        // paymentID=your_payment_id&status=success&apiVersion=1.2.0-beta
        //using paymentID find the account number for sending params

        if ($request->status == 'success'){
            $response = BkashPaymentTokenize::executePayment($request->paymentID);
            //$response = BkashPaymentTokenize::executePayment($request->paymentID, 1); //last parameter is your account number for multi account its like, 1,2,3,4,cont..

            if (!$response){
                $response =  BkashPaymentTokenize::queryPayment($request->paymentID);
                //$response = BkashPaymentTokenize::queryPayment($request->paymentID,1); //last parameter is your account number for multi account its like, 1,2,3,4,cont..

            }
            if (isset($response['statusCode']) && $response['statusCode'] == "0000" && $response['transactionStatus'] == "Completed") {
                /*
                 * for refund need to store
                 * paymentID and trxID
                 * */
                return BkashPaymentTokenize::success('Thank you for your payment', $response['trxID']);
            }
            return BkashPaymentTokenize::failure($response['statusMessage']);
        }else if ($request->status == 'cancel'){
            return BkashPaymentTokenize::cancel('Your payment is canceled');
        }else{
            return BkashPaymentTokenize::failure('Your transaction is failed');
        }
    }
```

### 5. execute payment response

[](#5-execute-payment-response)

```
{
   "statusCode":"0000",
   "statusMessage":"Successful",
   "paymentID":"your_payment_id",
   "payerReference":"your_ref_id",
   "customerMsisdn":"customer_msi",
   "trxID":"your_tnx_id",
   "amount":"100",
   "transactionStatus":"Completed",
   "paymentExecuteTime":"2023-01-23T02:04:05:736 GMT+0600",
   "currency":"BDT",
   "intent":"sale"
}
```

### 6. query payment response

[](#6-query-payment-response)

```
{
    "paymentID":"your_payment_id",
   "mode":"0011",
   "paymentCreateTime":"2023-01-23T02:01:06:713 GMT+0600",
   "paymentExecuteTime":"2023-01-23T02:04:05:736 GMT+0600",
   "amount":"100",
   "currency":"BDT",
   "intent":"sale",
   "merchantInvoice":"merchant_inv_no",
   "trxID":"tnx_no",
   "transactionStatus":"Completed",
   "verificationStatus":"Complete",
   "statusCode":"0000",
   "statusMessage":"Successful",
   "payerReference":"pay_ref"
}
```

### 7. search transaction

[](#7-search-transaction)

```
public function searchTnx($trxID)
{
    //response
    /*{
        "trxID":"tnx_no",
       "initiationTime":"2023-01-23T12:06:05:000 GMT+0600",
       "completedTime":"2023-01-23T12:06:05:000 GMT+0600",
       "transactionType":"bKash Tokenized Checkout via API",
       "customerMsisdn":"customer_msi",
       "transactionStatus":"Completed",
       "amount":"20",
       "currency":"BDT",
       "organizationShortCode":"og_short_code",
       "statusCode":"0000",
       "statusMessage":"Successful"
    }*/
    return BkashPaymentTokenize::searchTransaction($trxID);
    //return BkashPaymentTokenize::searchTransaction($trxID,1); //last parameter is your account number for multi account its like, 1,2,3,4,cont..

}
```

### 8. refund transaction

[](#8-refund-transaction)

```
public function refund(Request $request)
    {
        $paymentID='paymentID';
        $trxID='trxID';
        $amount=5;
        $reason='this is test reason';
        $sku='abc';
        //response
        /*{
            "statusCode":"0000",
           "statusMessage":"Successful",
           "originalTrxID":"or_tnx_no",
           "refundTrxID":"refund_tnx",
           "transactionStatus":"Completed",
           "amount":"5",
           "currency":"BDT",
           "charge":"0.00",
           "completedTime":"2023-01-23T15:53:29:120 GMT+0600"
        }*/
        return BkashRefundTokenize::refund($paymentID,$trxID,$amount,$reason,$sku);
        //return BkashRefundTokenize::refund($paymentID,$trxID,$amount,$reason,$sku, 1); //last parameter is your account number for multi account its like, 1,2,3,4,cont..

    }
```

### 9. refund status check

[](#9-refund-status-check)

```
public function refundStatus(Request $request)
    {
        $paymentID='paymentID';
        $trxID='trxID';
        /*{
            "statusCode":"0000",
           "statusMessage":"Successful",
           "originalTrxID":"ori_tx",
           "refundTrxID":"ref_tx",
           "transactionStatus":"Completed",
           "amount":"5",
           "currency":"BDT",
           "charge":"0.00",
           "completedTime":"2023-01-23T15:53:29:120 GMT+0600"
        }*/
        return BkashRefundTokenize::refundStatus($paymentID,$trxID);
        //return BkashRefundTokenize::refundStatus($paymentID,$trxID, 1); //last parameter is your account number for multi account its like, 1,2,3,4,cont..

    }
```

N.B. If you are using single account dont need to think about account parameter ignore it just simply use as usal

#### Required APIs

[](#required-apis)

1. **Developer Portal** (detail Product, workflow, API information):
2. **Grant Token :**
3. **Create Payment :**
4. **Execute Payment :**
5. **Query Payment :**
6. **Search Transaction Details :**

### Checkout Demo

[](#checkout-demo)

1. Go to
2. **Wallet Number:** 01770618575
3. **OTP:** 123456
4. **Pin:** 12121

Contributions to the Bkash Payment Gateway package are welcome. Please note the following guidelines before submitting your pull request.

- Follow [PSR-4](http://www.php-fig.org/psr/psr-4/) coding standards.
- Read bkash API documentations first. Please contact with bkash for their api documentation and sandbox access.

License
-------

[](#license)

This repository is licensed under the [MIT License](http://opensource.org/licenses/MIT).

Copyright 2022 [md abdul karim](https://github.com/karim-007). We are not affiliated with bkash and don't give any guarantee.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance71

Regular maintenance activity

Popularity40

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 89.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~130 days

Recently: every ~232 days

Total

9

Last Release

166d ago

Major Versions

v1.0.3 → v2.02023-05-19

PHP version history (2 changes)v1.0.0PHP ^7.4|^8.0|^8.1

v1.0.3PHP ^7.4|^8.0|^8.1|^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/1628a1636c45e8e246f880d1f2401497d66af3f657dba80a0f189b102e4b4ce7?d=identicon)[karim.cse007](/maintainers/karim.cse007)

---

Top Contributors

[![karim-007](https://avatars.githubusercontent.com/u/54572884?v=4)](https://github.com/karim-007 "karim-007 (17 commits)")[![jbhasan](https://avatars.githubusercontent.com/u/20739060?v=4)](https://github.com/jbhasan "jbhasan (1 commits)")[![polashmahmud](https://avatars.githubusercontent.com/u/8996190?v=4)](https://github.com/polashmahmud "polashmahmud (1 commits)")

---

Tags

bkashbkash-payment-gatewaybkash-paymentlaravel-bkashlaravel-bkash-paymentlaravel-bkash-payment-tokenize

### Embed Badge

![Health badge](/badges/karim007-laravel-bkash-tokenize/health.svg)

```
[![Health](https://phpackages.com/badges/karim007-laravel-bkash-tokenize/health.svg)](https://phpackages.com/packages/karim007-laravel-bkash-tokenize)
```

###  Alternatives

[tbbc/money-bundle

This is a Symfony bundle that integrates moneyphp/money library (Fowler pattern): https://github.com/moneyphp/money.

1961.9M](/packages/tbbc-money-bundle)[2checkout/2checkout-php

2Checkout PHP Library

83740.3k2](/packages/2checkout-2checkout-php)[smhg/sepa-qr-data

Generate QR code data for SEPA payments

61717.2k5](/packages/smhg-sepa-qr-data)[dnetix/redirection

Library to connect with PlacetoPay Checkout service

17123.3k2](/packages/dnetix-redirection)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
