Download the PHP package sabitahmad/laravel-bkash without Composer
On this page you can find all versions of the php package sabitahmad/laravel-bkash. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sabitahmad/laravel-bkash
More information about sabitahmad/laravel-bkash
Files in sabitahmad/laravel-bkash
Package laravel-bkash
Short Description Unofficial Bkash Package for Laravel providing seamless integration with Bkash payment gateway.
License MIT
Homepage https://github.com/sabitahmad/laravel-bkash
Informations about the package laravel-bkash
Laravel bKash Payment Gateway Integration
A comprehensive solution for integrating bKash payments into Laravel applications.
Table of Contents
- Features
- Requirements
- Installation
- Configuration
- Response Handling
- License
Features
- Complete bKash API v1.2.0 Integration: Full support for all bKash APIs
- Tokenized Checkout: Agreement management for faster payments
- Regular Checkout: Traditional payment flow
- Sandbox & Production Modes: Easy environment switching
- Advanced Token Management: Auto-refresh with retry mechanisms
- Comprehensive Payment Operations: Create, Execute, Query, Refund, Search
- Agreement Management: Create, Execute, Query, Cancel agreements
- Enhanced Exception Handling: Detailed error reporting and handling
- Transaction Logging: Database logging with enhanced tracking
- Network Resilience: Automatic retries and timeout handling
- Parameter Validation: Strict validation with configurable options
- Helper Utilities: Common operations and utilities
- Event-driven Architecture: Laravel events integration
- Customizable Configuration: Flexible configuration options
Requirements
- PHP 8.0+ (PHP 8.3+ required for Laravel 13)
- Laravel 8.x, 9.x, 10.x, 11.x, 12.x, or 13.x
- Composer
- bKash Merchant Account
Installation
You can install the package via composer:
You can publish and run the migrations with:
You can publish the config file with:
This is the contents of the published config file:
Optionally, you can publish the views using
[//]: # ()
Configuration
Add the following environment variables to your .env file:
Usage
Agreement Management (Tokenized Checkout)
Create Agreement
Execute Agreement
Payment Operations
Create Payment (Regular)
Create Payment (Tokenized with Agreement)
Execute Payment
Handle Callback
Additional Operations
Refund Payment
Query Payment Status
Search Transaction
Refund Status Check
Agreement Operations
Using the Helper Class
Response Methods
BaseResponse Methods (Available in All Response Classes)
| Method | Returns | Description |
|---|---|---|
isSuccess() |
bool |
Whether operation succeeded |
hasError() |
bool |
Whether operation has error |
getErrorMessage() |
?string |
Error message if failed |
getStatusCode() |
?string |
bKash status code |
getStatusMessage() |
?string |
bKash status message |
getErrorCode() |
?string |
bKash error code |
getRawData() |
array |
Complete API response |
toArray() |
array |
Response as array |
PaymentResponse Methods
| Method | Returns | Description |
|---|---|---|
getPaymentId() |
?string |
Payment ID |
getPaymentUrl() |
?string |
Redirect URL for payment |
getTrxId() |
?string |
bKash transaction ID |
getAmount() |
?float |
Transaction amount |
getCustomerMsisdn() |
?string |
Customer phone number |
getTransactionStatus() |
?string |
"Completed"/"Failed" etc |
getInvoiceNumber() |
?string |
Merchant invoice number |
getPayerReference() |
?string |
Payer reference |
getCurrency() |
?string |
Transaction currency |
getIntent() |
?string |
Payment intent |
getMode() |
?string |
Payment mode |
getPaymentExecuteTime() |
?Carbon |
Execution timestamp |
getCreateTime() |
?Carbon |
Creation timestamp |
getUpdateTime() |
?Carbon |
Last update timestamp |
isCompleted() |
bool |
Whether payment completed |
isCancelled() |
bool |
Whether payment cancelled |
isFailed() |
bool |
Whether payment failed |
AgreementResponse Methods
| Method | Returns | Description |
|---|---|---|
getAgreementId() |
?string |
Agreement ID |
getAgreementUrl() |
?string |
Redirect URL for agreement |
getAgreementStatus() |
?string |
Agreement status |
getPayerReference() |
?string |
Payer reference |
getCustomerMsisdn() |
?string |
Customer phone number |
getAgreementExecuteTime() |
?Carbon |
Agreement execution time |
RefundResponse Methods
| Method | Returns | Description |
|---|---|---|
getRefundId() |
?string |
Refund transaction ID |
getOriginalPaymentId() |
?string |
Original payment ID |
getRefundAmount() |
?float |
Refunded amount |
getTransactionStatus() |
?string |
Refund status |
getRefundTime() |
?Carbon |
Refund timestamp |
getCharge() |
?float |
Refund charge |
getTrxId() |
?string |
Transaction ID |
getPaymentId() |
?string |
Payment ID |
getCurrency() |
?string |
Currency |
getReason() |
?string |
Refund reason |
QueryResponse Methods
| Method | Returns | Description |
|---|---|---|
getPaymentId() |
?string |
Payment ID |
getTrxId() |
?string |
Transaction ID |
getTransactionStatus() |
?string |
Current payment status |
getAmount() |
?float |
Transaction amount |
getCustomerMsisdn() |
?string |
Customer phone number |
getMerchantInvoiceNumber() |
?string |
Invoice number |
getCurrency() |
?string |
Transaction currency |
getIntent() |
?string |
Payment intent |
getInitiationTime() |
?Carbon |
Transaction initiation time |
getCompletedTime() |
?Carbon |
Transaction completion time |
isCompleted() |
bool |
Whether transaction completed |
isCancelled() |
bool |
Whether transaction cancelled |
isFailed() |
bool |
Whether transaction failed |
SearchResponse Methods
| Method | Returns | Description |
|---|---|---|
getTransactions() |
array |
Array of transactions |
getTransactionCount() |
int |
Number of transactions |
getFirstTransaction() |
?array |
First transaction |
getTransactionByTrxId() |
?array |
Find transaction by trx ID |
getTransactionByPaymentId() |
?array |
Find transaction by payment ID |
Controller Example
See examples/BkashController.php for a complete implementation example showing:
- Agreement creation and handling
- Payment processing (both regular and tokenized)
- Callback handling
- Refund processing
- Transaction querying and searching
- Error handling
Events
The package dispatches the following events:
SabitAhmad\Bkash\Events\PaymentCompleted- When a payment is successfully completedSabitAhmad\Bkash\Events\PaymentFailed- When a payment failsSabitAhmad\Bkash\Events\AgreementCreated- When an agreement is successfully created
You can listen to these events in your EventServiceProvider:
Configuration Options
The package supports extensive configuration options:
- Timeout Settings: Configure API request timeouts and retry attempts
- Validation: Strict parameter validation with configurable limits
- Caching: Token caching with configurable TTL
- Logging: Enhanced transaction logging with detailed information
- Error Handling: Comprehensive error handling with retry mechanisms
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Upgrading from 2.0 to 2.1
If you are upgrading from v2.0.x, please note the following changes:
- Config File Updates: The
urlsconfiguration array has been simplified. If you previously published the config file, you may want to republish it or update your config to use the newbase_urlandendpointsformat. The package maintains backward compatibility for existing configurations. - Database Migrations: The
bkash_paymentstable has two new columns:payer_referenceandinvoice_number. Please publish the updated migration and runphp artisan migrate. - Status Constants: We recommend replacing hardcoded magic strings (e.g.,
'Completed') with the newSabitAhmad\Bkash\Enums\TransactionStatusclass constants. - Interface Injection: You can now type-hint
SabitAhmad\Bkash\Contracts\BkashInterfaceinstead of the concreteBkashclass.
Recent Improvements
Version 2.2.0
- ✅ Laravel 13 Support - Complete compatibility with Laravel 13.x and PHP 8.3/8.4.
- ✅ bKash API Alignment - Added mandatory
X-App-Keyheader and aligned agreement endpoints (/create,/execute). - ✅ Token Refresh Flow - Implemented automatic token refresh via
POST /token/refreshto prevent account rate-limiting blocks. - ✅ Webhook / IPN Support - Added
handleWebhook()for automated AWS SNS IPN processing and subscription confirmations. - ✅ Agreement Event Lifecycle - Added
AgreementCancelledevent. - ✅ Full Error Codes & Refund Params - Added official error code mappings and
trxId/skurefund support.
Version 2.1.0
- ✅ Simplified Configuration - Replaced individual endpoint URLs with concise base URLs.
- ✅ Architectural Refactor - Extracted
BkashInterfacefor easier mocking and testing. - ✅ Database Enhancements - Upgraded the migration with
payer_referenceandinvoice_numberfor faster queries, eliminating dependency on JSON columns. - ✅ Status Enums - Introduced
TransactionStatusconstants for cleaner code. - ✅ Extended Compatibility - Backwards compatibility restored for PHP 8.0+ and Laravel 8.0+.
- ✅ Diagnostics Command - Added
php artisan bkash:statusto quickly verify configurations.
Version 2.0.0
- ✅ Complete Tokenized Checkout Support - Agreement management APIs
- ✅ Enhanced Response Classes - More methods and better data access
- ✅ Advanced Error Handling - Retry mechanisms and detailed exceptions
- ✅ Network Resilience - Automatic retries and timeout handling
- ✅ Search Transaction API - Find transactions by various criteria
- ✅ Refund Status API - Track refund progress
- ✅ Helper Utilities - Common operations and utilities
- ✅ Event System - Laravel events for payment lifecycle
- ✅ Enhanced Database Logging - Better transaction tracking
- ✅ Improved Configuration - More flexible settings
- ✅ Parameter Validation - Strict validation with configurable options
- ✅ Code Optimization - Removed duplicates and improved performance
- ✅ Updated API URLs - Latest bKash endpoint configurations
- ✅ Better Token Management - Enhanced caching and refresh logic
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-bkash with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0