定制 xenon/bkash-php 二次开发

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

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

xenon/bkash-php

最新稳定版本:v1.0.3

Composer 安装命令:

composer require xenon/bkash-php

包简介

This is a php sdk for integrating with your php application easily

README 文档

README

xenon/bkash-php is a Bkash PHP SDK for integrating bkash api in website easily. Follow below steps for better understanding.

Step 1: Installation

composer require xenon/bkash-php

Step 2: Format Configuration

Create your credentials (array) to use along with Xenon\BkashPhp\BkashPhp class

$configuration = [
        'config' => [
            "app_key" => "app key goes here",
            "app_secret" => "app secret goes here",
        ],
        'headers' => [
            "username" => "username goes here",
            "password" => "password goes here",
        ]
    ];

Step 3: Exception

Exception Handling

use Xenon\BkashPhp\Handler\Exception\RenderBkashPHPException

Always call below methods under try block. After any of this method failed or exception occurs then it will throw RenderBkashPHPException

createTokenizedPayment()
executePayment()
searchTransaction()

Create Payment Url

Bkash payment gateway allows you to create payment url based on different parameters. Follow below code sample

use Xenon\BkashPhp\Handler\Exception\RenderBkashPHPException
use Xenon\BkashPhp\BkashPhp;

try{
   $paymentData = [ 
        'mode' => '0011', //fixed
        'payerReference' => '017AAXXYYZZ',
        'callbackURL' => 'http://example.com/callback',
        'merchantAssociationInfo' => 'xxxxxxxxxx',
        'amount' => 10,
        'currency' => 'BDT', //fixed
        'intent' => 'sale', //fixed
        'merchantInvoiceNumber' => "invoice number goes here",
    ];
    $createTokenizedPaymentResponse = $bkash->createTokenizedPayment($paymentData);

}catch(RenderBkashPHPException $e){
    //do whatever you want
}

If everything goes well then it will return below object. After that redirect to bkashURL from below object

stdClass Object
(
    [statusCode] => 0000
    [statusMessage] => Successful
    [paymentID] => TR0011DVJQOkh169400XXX
    [bkashURL] => https://sandbox.payment.bkash.com/redirect/tokenized/?paymentID=TR0011DVJQOkh1694007349990&hash=yaJMHgVb_BW_pJuxErXXXdf8-QFyHHG0bqkwBdUU(NLFwI(-ltH8z36kpnxtxa5Xs5tJxFxW5KoyKN5nWPisXXXXXXXXXXX50209&mode=0011&apiVersion=v1.2.0-beta
    [callbackURL] => http://example.com/callback
    [successCallbackURL] => http://example.com/callback?paymentID=TR0011DVJQOkh169400XXX&status=success
    [failureCallbackURL] => http://example.com/callback?paymentID=TR0011DVJQOkh169400XXX&status=failure
    [cancelledCallbackURL] => http://example.com/callback?paymentID=TR0011DVJQOkh169400XXX&status=cancel
    [amount] => 10
    [intent] => sale
    [currency] => BDT
    [paymentCreateTime] => 2023-09-06T19:35:50:209 GMT+0600
    [transactionStatus] => Initiated
    [merchantInvoiceNumber] => dsf64f8803XXX93
)

Execute Payment

After payment done customer will be redirected to merchant callback url having query string like below
"https://example.com?paymentID=TR0011ZCxlJhC1693137759378&status=success"

Now it's time to call executePayment() method with paymentID

use Xenon\BkashPhp\Handler\Exception\RenderBkashPHPException
use Xenon\BkashPhp\BkashPhp;

try{
    $bkash = new BkashPhp($configuration);
    $executePaymentResponse = $bkash->executePayment($paymentId);

}catch(RenderBkashPHPException $e){
    //do whatever you want
}

stdClass Object
(
    [statusCode] => 0000
    [statusMessage] => Successful
    [paymentID] => TR0011DVJQOkh169400XXX
    [payerReference] => 017AAXXYYZZ
    [customerMsisdn] => 01877722345
    [trxID] => AI620D4DVQ
    [amount] => 10
    [transactionStatus] => Completed
    [paymentExecuteTime] => 2023-09-06T19:11:01:698 GMT+0600
    [currency] => BDT
    [intent] => sale
    [merchantInvoiceNumber] => dsf64f8803XXX93
)

Query Payment

After successful payment execution, it needs to call searchTransaction() method.

use Xenon\BkashPhp\Handler\Exception\RenderBkashPHPException
use Xenon\BkashPhp\BkashPhp;

try{
    $trxID = request()->trxID; //get trxID from executePayment() method
    $bkash = new BkashPhp($configuration);
    $searchPaymentResponse = $bkash->searchTransaction($trxID);
}catch(RenderBkashPHPException $e){
    //do whatever you want
}

This will match trxID with bkash database. After getting response object you will do further according to your web application requirements.
stdClass Object
(
    [trxID] => AI620D4DVQ
    [initiationTime] => 2023-09-06T22:15:34:000 GMT+0600
    [completedTime] => 2023-09-06T22:15:34:000 GMT+0600
    [transactionType] => bKash Tokenized Checkout via API
    [customerMsisdn] => 01877722345
    [transactionStatus] => Completed
    [amount] => 10
    [currency] => BDT
    [organizationShortCode] => 50022
    [statusCode] => 0000
    [statusMessage] => Successful
)

Stargazers

Stargazers repo roster for @arif98741/bkash-php

Forkers

Forkers repo roster for @arif98741/bkash-php

Contributors



This is a start only. This package will be more enriched in future. If you find any issues or bug , please create an issue in this repository. Any technical suggestion or opinion will be highly appreciated

xenon/bkash-php 适用场景与选型建议

xenon/bkash-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 101 次下载、GitHub Stars 达 13, 最近一次更新时间为 2023 年 09 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 xenon/bkash-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 xenon/bkash-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 xenon/bkash-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-06