faysal0x1 / lara-payment
A Laravel Package that makes implementation of multiple payment Gateways endpoints and webhooks seamless
Requires
- php: ^8.0|^8.1|^8.2|^8.3
- guzzlehttp/guzzle: ^7.5
- illuminate/contracts: ^8.50|^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^8.50|^9.0|^10.0|^11.0|^12.0
- spatie/laravel-package-tools: ^1.11
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^5.3|^6.0|^v7.10|^8.1.1
- nunomaduro/larastan: ^1.0.4|^2.2
- orchestra/testbench: ^6.0|^7.0|^8.0|^9.0
- pestphp/pest: ^1.21|^2.34
- pestphp/pest-plugin-laravel: ^1.1|^v2.3.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5|^10.4
This package is not auto-updated.
Last update: 2025-06-04 18:52:56 UTC
README
The lara-payment
package provides a convenient way to handle payments through multiple payment gateways in a Laravel 8, 9 and 10 application.
The package currently supports multiple gateways such as Paystack, Flutterwave and Stripe.
The package offers an easy to use interface that abstracts the complexities of integrating with these payment gateways.
It also provides a way to handle webhooks from the payment gateways.
Documentation
A comprehensive documentation is available to help you get started with the package here
Testing
php artisan test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel SSLCommerz Payment Gateway Integration
A Laravel package for integrating SSLCommerz payment gateway into your Laravel application. This package provides a simple and flexible way to handle payments through SSLCommerz in your Laravel projects.
Features
- Easy checkout and hosted checkout options
- AJAX payment support
- IPN (Instant Payment Notification) handling
- Success, fail, and cancel URL handling
- Order validation
- Sandbox mode support
- Multiple payment methods support
- EMI payment support
- Customizable payment forms
- Comprehensive error handling
Requirements
- PHP >= 7.4
- Laravel >= 8.0
- SSLCommerz merchant account
Installation
- Install the package via Composer:
composer require faysal0x1/lara-payment
- Publish the configuration file:
php artisan vendor:publish --provider="Faysal0x1\LaraPayment\SslcommerzLaravelServiceProvider" --tag="config"
- Publish the controller:
php artisan vendor:publish --provider="Faysal0x1\LaraPayment\SslcommerzLaravelServiceProvider" --tag="controllers"
- Publish the views:
php artisan vendor:publish --provider="Faysal0x1\LaraPayment\SslcommerzLaravelServiceProvider" --tag="views"
- Publish the migrations:
php artisan vendor:publish --provider="Faysal0x1\LaraPayment\SslcommerzLaravelServiceProvider" --tag="migrations"
- Run the migrations:
php artisan migrate
Configuration
Add the following environment variables to your .env
file:
SSLCOMMERZ_SANDBOX=true SSLCOMMERZ_STORE_ID=your_store_id SSLCOMMERZ__STORE_PASSWORD=your_store_password
The configuration file (config/sslcommerz.php
) contains the following options:
return [ 'sandbox' => env("SSLCOMMERZ_SANDBOX", false), 'middleware' => 'web', 'store_id' => env("SSLCOMMERZ_STORE_ID"), 'store_password' => env("SSLCOMMERZ__STORE_PASSWORD"), 'success_url' => '/sslcommerz/success', 'failed_url' => '/sslcommerz/fail', 'cancel_url' => '/sslcommerz/cancel', 'ipn_url' => '/sslcommerz/ipn', 'return_response' => 'html', // html or json ];
Usage
Basic Payment Integration
- Using the Facade:
use Faysal0x1\LaraPayment\Facade\SSLCommerzPayment; // Make payment $data = [ 'total_amount' => 100, 'currency' => 'BDT', 'tran_id' => uniqid(), 'product_category' => 'Test Category' ]; $customer = [ 'name' => 'John Doe', 'email' => 'john@example.com', 'address_1' => 'Dhaka', 'phone' => '8801XXXXXXXXX', 'country' => 'Bangladesh' ]; $shipment = [ 'shipping_method' => 'Yes', 'ship_name' => 'John Doe', 'ship_add1' => 'Dhaka', 'ship_city' => 'Dhaka', 'ship_country' => 'Bangladesh' ]; $response = SSLCommerzPayment::makePayment($data) ->setCustomerInfo($customer) ->setShipmentInfo($shipment);
- Using the Controller:
Visit /example1
for AJAX payment or /example2
for hosted payment.
Available Routes
Route::get('/example1', [SslCommerzPaymentController::class, 'exampleEasyCheckout']); Route::get('/example2', [SslCommerzPaymentController::class, 'exampleHostedCheckout']); Route::post('/pay', [SslCommerzPaymentController::class, 'index']); Route::post('/pay-via-ajax', [SslCommerzPaymentController::class, 'payViaAjax']); Route::post('/success', [SslCommerzPaymentController::class, 'success']); Route::post('/fail', [SslCommerzPaymentController::class, 'fail']); Route::post('/cancel', [SslCommerzPaymentController::class, 'cancel']); Route::post('/ipn', [SslCommerzPaymentController::class, 'ipn']);
Advanced Features
- EMI Payment Support:
$sslc = new SslCommerzNotification(); $sslc->enableEMI(3, 12, false); // 3 months installment, max 12 months, not restricted to EMI only
- Airline Ticket Profile:
$airlineInfo = [ 'hours_till_departure' => '24', 'flight_type' => 'domestic', 'pnr' => 'ABC123', 'journey_from_to' => 'Dhaka to Chittagong' ]; $sslc->setAirlineTicketProfile($airlineInfo);
- Travel Vertical Profile:
$travelInfo = [ 'hotel_name' => 'Grand Hotel', 'length_of_stay' => 3, 'check_in_time' => '14:00', 'hotel_city' => 'Dhaka' ]; $sslc->setTravelVerticalProfile($travelInfo);
- Telecom Vertical Profile:
$telecomInfo = [ 'product_type' => 'prepaid', 'topup_number' => '8801XXXXXXXXX', 'country_topup' => 'Bangladesh' ]; $sslc->setTelecomVerticleProfile($telecomInfo);
Response Handling
- Success Response:
return SSLCommerzPayment::returnSuccess($transId, "Transaction is successfully Completed", '/');
- Failure Response:
return SSLCommerzPayment::returnFail($transId, "Transaction is Failed", '/');
Database Structure
The package creates an orders
table with the following structure:
Schema::create('orders', function (Blueprint $table) { $table->id(); $table->string('name', 191)->nullable(); $table->string('email', 191)->nullable(); $table->string('phone', 60)->nullable(); $table->double('amount')->default(0); $table->text('address')->nullable(); $table->string('status', 20)->default('Pending'); $table->string('transaction_id', 191); $table->string('currency', 20)->nullable()->default('BDT'); $table->timestamps(); });
Security Considerations
- Always use environment variables for sensitive data
- Enable SSL on your production environment
- Validate all incoming data
- Use proper error handling
- Keep your store credentials secure
Testing
- Set
SSLCOMMERZ_SANDBOX=true
in your.env
file for testing - Use test credentials provided by SSLCommerz
- Test all payment scenarios (success, fail, cancel)
- Verify IPN handling
- Test with different currencies and amounts
Support
For any issues or questions, please create an issue in the GitHub repository.
License
This package is open-sourced software licensed under the MIT license.