PHPackages                             wmsn-web/bkash-php-client - 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. wmsn-web/bkash-php-client

ActiveLibrary[Payment Processing](/categories/payments)

wmsn-web/bkash-php-client
=========================

This Package will help to integrate the Bkash Payment Gateway more easy way.

v1.1.5(9mo ago)011MITPHP

Since Jun 27Pushed 9mo agoCompare

[ Source](https://github.com/wmsn-web/BkashPhpClient)[ Packagist](https://packagist.org/packages/wmsn-web/bkash-php-client)[ RSS](/packages/wmsn-web-bkash-php-client/feed)WikiDiscussions main Synced today

READMEChangelog (6)Dependencies (5)Versions (7)Used By (0)

PHP bKash Payment Gateway
=========================

[](#php-bkash-payment-gateway)

[![Packagist Version](https://camo.githubusercontent.com/e3dfb82a3a03f3f2702c512fd9680d0ff4301eb4d1baa92960f4ac71603ab9fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776d736e2d7765622f626b6173682d7068702d636c69656e742e737667)](https://packagist.org/packages/wmsn-web/bkash-php-client) [![License](https://camo.githubusercontent.com/9f694b4a029d9e5ff74823e9fcc8e45dead2d13ac1e7e9154f5b9115fd1cfdd0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f776d736e2d7765622f626b6173682d7068702d636c69656e742e737667)](LICENSE)

A simple, lightweight PHP library for integrating the bKash REST payment gateway in your PHP projects.

---

Features
--------

[](#features)

- Create Token
- Refresh Token
- Create &amp; execute payments
- Handle payment callbacks
- Issue refunds
- Query transaction status
- Sandbox &amp; production modes

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

[](#requirements)

- PHP 7.4+
- cURL extension enabled
- Composer

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

[](#installation)

Install via Composer:

```
composer require wmsn-web/BkashPhpClient
```

Then in your PHP code, initialize the client:

```
use WmsnWeb\BkashPhpClient\BkashPhpClient;

$bkash = new BkashPhpClient([
    "base_url" => "https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized",
    "username" => "YOU_BKASH_USERNAME",
    "password" => "BKASH_PASSWORD",
    "app_key" => "BKASH_APP_KEY",
    "app_secret" => "BKASH_APP_SECRET_KEY",
    "type"      =>"sandbox" // or 'prod'
]);
```

OR

```
$credentials = array(
    "base_url" => "https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized",
    "username" => "YOU_BKASH_USERNAME",
    "password" => "BKASH_PASSWORD",
    "app_key" => "BKASH_APP_KEY",
    "app_secret" => "BKASH_APP_SECRET_KEY",
    "type"      =>"sandbox" // or 'prod'
);

$bkash = new BkashPhpClient($credentials);
```

Usage Examples
--------------

[](#usage-examples)

### 1. Grant Token

[](#1-grant-token)

Grant Token API provides an access token as a response. This token can be used to access other bKash APIs as authorization parameter. Once the token gets expired, new token can be generated through Refresh Token API.

```
$response = $bkash->GrantToken();
```

Sample Response

```
[
  "token_type"=> "Bearer",
  "id_token"=> "test_id_token_value",
  "expires_in"=> 3600,
  "refresh_token"=> "test_refresh_token_value"
]
```

Save the `id_token` into the database for reuse without generate a new token. Once it get expire (3600 seconds) Refresh a new token using `refresh_token`.

### 2. Refresh Token

[](#2-refresh-token)

This API provides a new access token against the existing token. This new token can be used in subsequent bKash API calls.

```
$response = $bkash->refreshToken($refresh_token);
```

```
[
  "token_type"=> "Bearer",
  "id_token"=> "test_id_token_value",
  "expires_in"=> 3600,
  "refresh_token"=> "test_refresh_token_value"
]

```

### 3. Create a Payment

[](#3-create-a-payment)

Through this API, a tokenized payment creation request is received by bKash. Upon validation of customer's wallet information, the create payment request will be confirmed by the Execute Payment request.

Get `$token` from your database.

```
$postArray = [
    'mode'                  => '0011',
    'amount'                => 100,
    'payerReference'        =>"11",
    'callbackURL'           => Your callback URL
    'currency'              => 'BDT',
    'intent'                => 'sale',
    'merchantInvoiceNumber' => INVOICE NUMBER
];
$response = $bkash->createPayment($token, $postArray);
```

Sample response

```
[
    "statusCode"                => "0000",
    "statusMessage"             => "Successful",
    "paymentID"                 => "TR0001VK1565072365492", //Timespan 24 hours
    "bkashURL"                  =>"URL TO CHECKOUT THE PAYMENT",
    "callbackURL"               => "https://yourdomain.com/callback?version=v1.2.0-beta&product=tokenized-checkout",
    "successCallbackURL"        => "https://yourdomain.com/callback?version=v1.2.0-beta&product=tokenized-checkout&paymentID=TR0011dQPHnuY1720518383420&status=success&signature=cm8HBfl65A",
    "failureCallbackURL"        => "https://yourdomain.com/callback?version=v1.2.0-beta&product=tokenized-checkout&paymentID=TR0011dQPHnuY1720518383420&status=failure&signature=cm8HBfl65A",
    "cancelledCallbackURL"      => "https://yourdomain.com/callback?version=v1.2.0-beta&product=tokenized-checkout&paymentID=TR0011dQPHnuY1720518383420&status=cancel&signature=cm8HBfl65A",
    "amount"                    => "500",
    "intent"                    => "sale",
    "currency"                  => "BDT",
    "agreementID"               => "TokenizedMerchant01L3IKB6H1565072174986",
    "paymentCreateTime"         => "2019-08-06T12:19:25:593 GMT+0600",
    "transactionStatus"         => "Initiated",
    "merchantInvoiceNumber"     => "Inv0124"
]
```

### 4. Execute the Payment

[](#4-execute-the-payment)

Using this API, a tokenized payment request created using the Create Payment API can be finalized. Thus, a payment can be successful or can be failure. The final result of the payment request can be found through this API.

Basically in callback URL Execute payment API should be call to confirm the payment.

Get `$token` from your database.

```
$response = $bkash->executePayment($token, $response['paymentID']);
```

Sample Response

```
[
    "statusCode"                => "0000",
    "statusMessage"             => "Successful",
    "paymentID"                 => "TR0001VK1565072365492",
    "agreementID"               => "TokenizedMerchant01L3IKB6H1565072174986",
    "payerReference"            => "01770618575",
    "customerMsisdn"            => "01770618575",
    "trxID"                     => "6H6201QDIY",
    "amount"                    => "12",
    "transactionStatus"         => "Completed",
    "paymentExecuteTime"        => "2019-08-06T12:22:41:428 GMT+0600",
    "currency"                  => "BDT",
    "intent"                    => "sale",
    "merchantInvoiceNumber"     => "TestForOnmobile"
]
```

### 5. Query Transaction Status

[](#5-query-transaction-status)

```
$paymentID = 'PAYMENT_ID_FROM_CREATE';
$token = 'from your database'.
$response = $bkash->paymentStatus($token, $paymentID);
```

Configuration Options
---------------------

[](#configuration-options)

OptionTypeDefaultDescription`app_key`string`null`Your bKash API App Key`app_secret`string`null`Your bKash API App Secret`username`string`null`API username`password`string`null`API password`base_url`stringSandbox URLBase URL for bKash endpoints`mode`string`sandbox``sandbox` or `production``timeout`int`30`HTTP request timeout in secondsRunning Tests
-------------

[](#running-tests)

This library uses PHPUnit. To run tests:

```
composer install
./vendor/bin/phpunit --configuration phpunit.xml
```

> **Tip:** Copy `phpunit.xml.dist` to `phpunit.xml` and update with your sandbox credentials.

Examples Directory
------------------

[](#examples-directory)

See the `examples/` directory for full scripts:

- `grant_token.php`
- `refresh_token.php`
- `create_payment.php`
- `execute_payment.php`
- `refund_payment.php`
- `query_status.php`

Please follow PSR-12 coding standards and ensure all tests pass.

Troubleshooting
---------------

[](#troubleshooting)

- **Authentication errors**: Double-check your `app_key`, `app_secret`, `username`, and `password`.
- **Timeouts**: Increase the `timeout` option if requests hang.
- **Sandbox vs Production**: Ensure `base_url` matches the environment.

📚 Official Documentation Reference
----------------------------------

[](#-official-documentation-reference)

This library is built on top of the official [Bkash API documentation](https://developer.bka.sh/docs/product-overview).
Please refer to it for detailed API behavior, limitations, and authentication guidelines.

Credit goes to the Bkash Developer Team for providing well-structured documentation.

License
-------

[](#license)

This library is released under the [MIT License](LICENSE).

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance58

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~20 days

Total

6

Last Release

273d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/58039952?v=4)[Sanjay Natta](/maintainers/wmsn-web)[@wmsn-web](https://github.com/wmsn-web)

---

Top Contributors

[![wmsn-web](https://avatars.githubusercontent.com/u/58039952?v=4)](https://github.com/wmsn-web "wmsn-web (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wmsn-web-bkash-php-client/health.svg)

```
[![Health](https://phpackages.com/badges/wmsn-web-bkash-php-client/health.svg)](https://phpackages.com/packages/wmsn-web-bkash-php-client)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k39](/packages/neuron-core-neuron-ai)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M739](/packages/sylius-sylius)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)

PHPackages © 2026

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