Download the PHP package theihasan/laravel-bkash without Composer
On this page you can find all versions of the php package theihasan/laravel-bkash. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download theihasan/laravel-bkash
More information about theihasan/laravel-bkash
Files in theihasan/laravel-bkash
Package laravel-bkash
Short Description This is my package laravel-bkash
License MIT
Homepage https://github.com/theihasan/laravel-bkash
Informations about the package laravel-bkash
Laravel bKash
A simple Laravel package for integrating the bKash Tokenized Payment Gateway into your application. With built-in payment flow and full control via manual methods, this package supports payment creation, execution, status queries, refunds, and token management.
Table of Contents
- Overview
- Requirements
- Installation
- Configuration
- Usage
- Initiating a Payment
- Handling the Callback
- Querying Payment Status
- Processing a Refund
- Managing Tokens
- Built-in Payment Flow
- Error Handling
- Customization
- Test Credentials
- Testing
- Contributing
- Credits and License
Overview
The Laravel bKash package simplifies integrating bKash’s tokenized payment gateway into your Laravel projects. It provides:
- Quick installation and configuration.
- Built-in controllers, routes, and views for out-of-the-box payment flow.
- Manual methods for complete control.
- Detailed error handling through custom exceptions.
Requirements
- PHP: 8.0 or higher
- Laravel: 8.x or later
- cURL Extension: Enabled
Installation
Install the package via Composer:
Publish the migrations
Migrate the database
Then, run the setup command to test the connection and publish assets:
Alternatively, publish individual assets as needed:
- Configuration:
Configuration
After publishing, update the config/bkash.php
file with your bKash credentials and settings:
Also, add the necessary variables to your .env file:
Usage
You can use the package with its built-in payment flow or build a custom process.
Initiating a Payment
Use the provided createPayment
method to start a payment:
Multi-tenant Support
Starting from version 1.3.0, the package supports multi-tenant applications. This is useful when you have multiple tenants (organizations, businesses, etc.) using the same application but with different bKash credentials.
Handling the Callback
After payment, bKash will redirect to your callback URL:
Check a payment’s status using:
Multi-tenant Support
Processing a Refund
Initiate a refund (partial or full) with:
Multi-tenant Support
Managing Tokens
For manual token operations:
Multi-tenant Support
Token Management
Tokens are tenant-specific, so you can manage them for each tenant:
Built-in Payment Flow
By default, the package registers these routes:
- GET /bkash/callback – Payment callback handling.
- GET /bkash/success – Payment success page.
- GET /bkash/failed – Payment failure page.
To define your own routes, simply disable the built-in ones in config/bkash.php
by setting:
Error Handling
The package provides clear exception classes to help you handle errors:
- TokenGenerationException: When token generation fails.
- RefreshTokenException: When token refresh fails.
- PaymentCreationException: When payment creation fails.
- PaymentExecutionException: When executing payment fails.
- PaymentQueryException: When payment status query fails.
- RefundException: When refund processing fails.
Handle exceptions as shown in the usage examples above.
Customization
Customize the built-in views and controllers to match your needs:
-
Views:
Files will be copied to
resources/views/vendor/bkash/
. -
Controllers:
Controllers will appear in
app/Http/Controllers/Vendor/Bkash/
. Adjust namespaces as needed.
Database Configuration
Starting from version 1.1.0, you can customize the database table prefix used by the package. This is useful when you want to avoid table name conflicts or organize your database schema.
Setting a Custom Table Prefix
By default, all tables created by this package use the bkash_
prefix. You can change this by updating your .env
file:
Or by directly modifying the config/bkash.php
file:
For Existing Installations
If you're updating from a previous version and want to use a custom table prefix:
-
Publish the new migration file:
-
Set your desired prefix in the
.env
file or config file. - Run the migration to create new tables with your prefix and migrate existing data:
Note: The migration will automatically copy your existing data to the new tables with your custom prefix. Your original tables will remain untouched, so you can verify the data before removing the old tables if needed.
Important Considerations
- Changing the table prefix after you've already been using the package will create new tables with the new prefix.
- The package will automatically use the tables with the configured prefix.
- If you're using direct database queries in your application that reference these tables, make sure to update those queries to use the new table names.
Events
Starting from version 1.1.0, the package can fire Laravel events when certain actions occur. You can listen for these events to perform additional actions in your application.
Available Events
Payment Successful Event
This event is fired when a payment is successfully executed:
The event contains:
$payment
- The BkashPayment model instance$paymentData
- The raw payment data from bKash
Configuring Events
By default, all events are enabled. You can disable specific events in your .env
file:
Or in your config/bkash.php
file:
Listening for Events
You can listen for these events in your EventServiceProvider
:
Or if you are using Laravel 11 or higher Laravel will automatically register the listener. Just run this command for listener
Example listener:
Test Credentials
For sandbox testing, you may use these credentials (or update your .env accordingly):
- Testing Numbers:
- 01929918378
- 01619777283
- 01619777282
- 01823074817
- OTP: 123456
- PIN: 12121
Testing
Run package tests with:
Ensure your testing environment is set up as required by your Laravel configuration.
Contributing
Contributions are welcome. When submitting a pull request:
- Follow PSR-4 coding standards.
- Include tests for new features or bug fixes.
- Update the documentation as needed.
Credits and License
Credits:
- Developed by Abul Hassan
- Special thanks to:
- Ahmed Shamim Hassan Shaon for his invaluable guidance in package development.
- Anis Uddin Ahmed for his valuable insights and support.
License:
Licensed under the MIT License.
All versions of laravel-bkash with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0||^11.0||^12.0