PHPackages                             sadiq-bd/bkash-payment-gateway - 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. [API Development](/categories/api)
4. /
5. sadiq-bd/bkash-payment-gateway

ActiveLibrary[API Development](/categories/api)

sadiq-bd/bkash-payment-gateway
==============================

Bkash Payment Gateway for PHP

2.0.1(1y ago)442MITPHPPHP &gt;=8.0

Since Jun 3Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/sadiq-bd/bkash-payment-gateway)[ Packagist](https://packagist.org/packages/sadiq-bd/bkash-payment-gateway)[ RSS](/packages/sadiq-bd-bkash-payment-gateway/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)DependenciesVersions (4)Used By (0)

 [![View Counter](https://camo.githubusercontent.com/48f18817fcbe5e642df9d1c557c85f06d06e00bf5ab036ed6fb45d7f53cd1920/68747470733a2f2f6170692e73616469712e776f726b6572732e6465762f6170702f6769746875622f7265706f2f626b6173682d7061796d656e742d676174657761792f7669657773)](https://camo.githubusercontent.com/48f18817fcbe5e642df9d1c557c85f06d06e00bf5ab036ed6fb45d7f53cd1920/68747470733a2f2f6170692e73616469712e776f726b6572732e6465762f6170702f6769746875622f7265706f2f626b6173682d7061796d656e742d676174657761792f7669657773)

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

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

A well-structured and secure PHP library to integrate bKash payment processing into your application. Provides robust API handling for bKash Merchant operations.

---

Features
--------

[](#features)

- Easy integration with bKash Merchant API
- Handles payment creation, execution, query, refund, and more
- Structured request and response handling
- Exception handling for API errors
- Sandbox and production mode switch
- Example scripts included

---

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

[](#installation)

```
composer require sadiq-bd/bkash-payment-gateway
```

---

Configuration
-------------

[](#configuration)

Set up your credentials and environment using the provided static setter methods. You can use the sample `example.config.php` file as a template.

```
use Sadiq\BkashMerchantAPI\BkashMerchantAPI;

// Set callback URL (for execute payment)
BkashMerchantAPI::setCallBackUrl('https://yourdomain.com/executepayment.php');

// Set your bKash credentials
BkashMerchantAPI::setAppKey('your_app_key');
BkashMerchantAPI::setAppSecret('your_app_secret');
BkashMerchantAPI::setUsername('your_username');
BkashMerchantAPI::setPassword('your_password');

// Enable sandbox mode (set to false for production)
BkashMerchantAPI::sandBoxMode(true);
```

---

Usage
-----

[](#usage)

### Token Generation

[](#token-generation)

Before creating a payment, you need to generate a grant token. See `token.php` and `example.config.php` for sample token generation logic.

### Creating a Payment

[](#creating-a-payment)

Below is an example based on the actual `createpayment.php` flow:

```
use Sadiq\BkashMerchantAPI\BkashMerchantAPI;
use Sadiq\BkashMerchantAPI\Exception\BkashMerchantAPIException;

// Assume configuration and token generation (see example.config.php and token.php)
session_start();
$token = $_SESSION['token'];

$amount = 100; // BDT
$invoice = strtoupper(uniqid());
$reference = "CustomerReference";

try {
    $bkash = new BkashMerchantAPI;
    $bkash->setGrantToken($token);
    if ($resp = $bkash->createPayment($amount, $invoice, $reference)) {
        // Optional: log response
        // prependFileLog(log_file, "\n\n- Create Payment\n{$resp->getResponse()}\n\n");
        $bkash->redirectToPayment($resp);
    }
} catch (BkashMerchantAPIException $e) {
    die($e->getMessage());
}
```

- The user will be redirected to bKash for payment approval.

### Executing a Payment

[](#executing-a-payment)

After user approval, bKash will redirect back to your callback URL (e.g. `executepayment.php`). That file will handle execution.

---

Example Directory Structure
---------------------------

[](#example-directory-structure)

- `src/BkashMerchantAPI/` — Core library classes
- `public/` — Example entry points / demo scripts (`createpayment.php`, `executepayment.php`, `index.php`, etc.)
- `example.config.php` — Example configuration file
- `token.php` — Example for grant token management
- `README.md` — Documentation
- `composer.json` — Package definition

---

Exception Handling
------------------

[](#exception-handling)

All API errors throw `BkashMerchantAPIException` for robust error management.

---

Logging
-------

[](#logging)

To enable logging, create a file named `gateway.log.txt` in your project root. Logging is supported via the `prependFileLog` function (see `example.config.php`).

---

Security
--------

[](#security)

- Never expose your credentials in public repositories.
- Always use HTTPS.
- Rotate credentials regularly.

---

License
-------

[](#license)

[MIT](LICENSE)

---

Support
-------

[](#support)

For issues and feature requests, please use the [GitHub Issues](https://github.com/sadiq-bd/bkash-payment-gateway/issues) page.

---

More Information
----------------

[](#more-information)

- [bKash Official API Documentation](https://developer.bka.sh/)
- [Packagist Package](https://packagist.org/packages/sadiq-bd/bkash-payment-gateway)
- [Browse All Files in This Repo](https://github.com/sadiq-bd/bkash-payment-gateway/search)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance48

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

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 ~79 days

Total

3

Last Release

549d ago

Major Versions

1.1.0 → 2.02024-11-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/0491977a6415c27fea1d821fccaac0e6cf9429a446078ef6f5ab86f119d48c0f?d=identicon)[sadiq-bd](/maintainers/sadiq-bd)

---

Top Contributors

[![sadiq-bd](https://avatars.githubusercontent.com/u/72698818?v=4)](https://github.com/sadiq-bd "sadiq-bd (15 commits)")

---

Tags

apibkash-paymentbkash-payment-gatewaybkash-pgwphp

### Embed Badge

![Health badge](/badges/sadiq-bd-bkash-payment-gateway/health.svg)

```
[![Health](https://phpackages.com/badges/sadiq-bd-bkash-payment-gateway/health.svg)](https://phpackages.com/packages/sadiq-bd-bkash-payment-gateway)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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