定制 arafatkn/laravel-bkash 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

arafatkn/laravel-bkash

最新稳定版本:0.0.2

Composer 安装命令:

composer require arafatkn/laravel-bkash

包简介

bKash Tokenized Payment Gateway Implementation for Laravel

README 文档

README

Laravel package for bKash Tokenized Payment Gateway integration.

Requirements

  • PHP ^8.0
  • Laravel ^8.0

Installation

composer require arafatkn/laravel-bkash

The service provider and facade are registered automatically via Laravel's package auto-discovery.

Configuration

Publish the config file:

php artisan vendor:publish --tag=bkash-config

Add the following variables to your .env file:

BKASH_SANDBOX=true
BKASH_APP_KEY=your_app_key
BKASH_APP_SECRET=your_app_secret
BKASH_USERNAME=your_username
BKASH_PASSWORD=your_password

Config Options

Key Default Description
sandbox true Use sandbox or live environment
debug APP_DEBUG Log all requests and responses
app_key '' bKash app key
app_secret '' bKash app secret
username '' bKash username
password '' bKash password
cache.refresh_token_lifetime 604800 Refresh token cache lifetime in seconds (7 days)
default_currency BDT Default payment currency
default_intent sale Default payment intent

Usage

Use the BkashTokenizedPayment facade or resolve Arafatkn\LaravelBkash\Tokenized\Payment from the container.

Create Payment

Initiates a tokenized payment and returns a bkashURL to redirect the customer to.

use BkashTokenizedPayment;

$response = BkashTokenizedPayment::createPayment([
    'amount'                => '100',
    'merchantInvoiceNumber' => 'INV-001',
    'callbackURL'           => route('bkash.callback'),
    'payerReference'        => 'user_123',   // optional
    'currency'              => 'BDT',         // optional, defaults to config
    'intent'                => 'sale',        // optional, defaults to config
]);

// Redirect customer to payment page
return redirect($response['bkashURL']);

Execute Payment

Called from your callback URL after the customer approves the payment.

$paymentID = $request->query('paymentID');

$response = BkashTokenizedPayment::executePayment($paymentID);

if ($response['statusCode'] === '0000') {
    // Payment successful
    $trxID = $response['trxID'];
}

Query Payment

Check the status of a payment by paymentID.

$response = BkashTokenizedPayment::queryPayment($paymentID);

Search Transaction

Look up a transaction by bKash transaction ID.

$response = BkashTokenizedPayment::searchTransaction($trxID);

Refund Transaction

Initiate a refund for a completed payment.

$response = BkashTokenizedPayment::refundPayment(
    'TR0011xxxxxxxxxxx',
    'ADxxxxxxxx',
    [
        'amount' => '100',                           // optional
        'reason' => 'Customer requested refund',     // optional
        'sku'    => 'product-sku',                   // optional, defaults to 'NA'
    ]
);

Token Management

Token management is handled automatically. The package:

  • Grants a new token on first use
  • Caches the id_token based on the API-reported expires_in (minus 10 seconds as a safety buffer)
  • Caches the refresh_token for 7 days
  • Automatically uses the cached refresh_token to obtain a new id_token when it expires, avoiding a full re-authentication

Debugging

To log all bKash API requests and responses, set in your .env:

BKASH_DEBUG=true

Or it will follow APP_DEBUG by default. Logs are written at the debug level via Laravel's Log facade.

Typical Payment Flow

1. createPayment()  → redirect customer to bkashURL
2. Customer approves on bKash
3. bKash redirects to your callbackURL with paymentID
4. executePayment() → confirm the payment
5. searchTransaction() or queryPayment() → verify if needed

License

MIT

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固