sadiq-bd/bkash-payment-gateway
Composer 安装命令:
composer require sadiq-bd/bkash-payment-gateway
包简介
Bkash Payment Gateway for PHP
README 文档
README
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
- 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
composer require sadiq-bd/bkash-payment-gateway
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
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
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
After user approval, bKash will redirect back to your callback URL (e.g. executepayment.php). That file will handle execution.
Example Directory Structure
src/BkashMerchantAPI/— Core library classespublic/— Example entry points / demo scripts (createpayment.php,executepayment.php,index.php, etc.)example.config.php— Example configuration filetoken.php— Example for grant token managementREADME.md— Documentationcomposer.json— Package definition
Exception Handling
All API errors throw BkashMerchantAPIException for robust error management.
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
- Never expose your credentials in public repositories.
- Always use HTTPS.
- Rotate credentials regularly.
License
Support
For issues and feature requests, please use the GitHub Issues page.
More Information
sadiq-bd/bkash-payment-gateway 适用场景与选型建议
sadiq-bd/bkash-payment-gateway 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 42 次下载、GitHub Stars 达 4, 最近一次更新时间为 2024 年 02 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 sadiq-bd/bkash-payment-gateway 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sadiq-bd/bkash-payment-gateway 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 42
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-04