PHPackages                             syedmahamudul/sslcommerz-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. syedmahamudul/sslcommerz-laravel

ActiveLibrary[Payment Processing](/categories/payments)

syedmahamudul/sslcommerz-laravel
================================

SSLCommerz Payment Gateway Integration Package for Laravel

00PHP

Pushed todayCompare

[ Source](https://github.com/syedmahamudul/laravel-sslcommerz)[ Packagist](https://packagist.org/packages/syedmahamudul/sslcommerz-laravel)[ RSS](/packages/syedmahamudul-sslcommerz-laravel/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersionsUsed By (0)

SSLCommerz Payment Gateway Package for Laravel
==============================================

[](#sslcommerz-payment-gateway-package-for-laravel)

[![Latest Stable Version](https://camo.githubusercontent.com/1eae9780d6d575ca3375ab3afb73a3015802c2e16fdb32d9a20e6c79463d37da/68747470733a2f2f706f7365722e707567782e6f72672f737965646d6168616d7564756c2f73736c636f6d6d65727a2d6c61726176656c2f762f737461626c65)](https://packagist.org/packages/syedmahamudul/sslcommerz-laravel)[![Total Downloads](https://camo.githubusercontent.com/931ca6f46aab376ccb16373c2b0075cdb147f7255c0ce31266a1d418611fb237/68747470733a2f2f706f7365722e707567782e6f72672f737965646d6168616d7564756c2f73736c636f6d6d65727a2d6c61726176656c2f646f776e6c6f616473)](https://packagist.org/packages/syedmahamudul/sslcommerz-laravel)[![Latest Unstable Version](https://camo.githubusercontent.com/eb75609471e22311c62da5fa6cd415e20e76fc7dd447393705cbc9dd98853bc5/68747470733a2f2f706f7365722e707567782e6f72672f737965646d6168616d7564756c2f73736c636f6d6d65727a2d6c61726176656c2f762f756e737461626c65)](https://packagist.org/packages/syedmahamudul/sslcommerz-laravel)[![License](https://camo.githubusercontent.com/06f0d36aa3263c963b48d95785fb1d2c180f8cebf515d4e39ed3cc021ec0a18d/68747470733a2f2f706f7365722e707567782e6f72672f737965646d6168616d7564756c2f73736c636f6d6d65727a2d6c61726176656c2f6c6963656e7365)](https://packagist.org/packages/syedmahamudul/sslcommerz-laravel)[![Monthly Downloads](https://camo.githubusercontent.com/620a01a78e302c8c4e546c8dc0b839c537e8f9e4cd7b12efe1c68af45e1fd5ca/68747470733a2f2f706f7365722e707567782e6f72672f737965646d6168616d7564756c2f73736c636f6d6d65727a2d6c61726176656c2f642f6d6f6e74686c79)](https://packagist.org/packages/syedmahamudul/sslcommerz-laravel)[![Daily Downloads](https://camo.githubusercontent.com/52ad4cd5488d521f3566db14e000232f9ce93c30826fd3d9a7ada9c34170d79f/68747470733a2f2f706f7365722e707567782e6f72672f737965646d6168616d7564756c2f73736c636f6d6d65727a2d6c61726176656c2f642f6461696c79)](https://packagist.org/packages/syedmahamudul/sslcommerz-laravel)[![composer.lock](https://camo.githubusercontent.com/8d310bb37dcaf6a89c50c86887ce1a5144a6167d8a800f095d7408f29f27431b/68747470733a2f2f706f7365722e707567782e6f72672f737965646d6168616d7564756c2f73736c636f6d6d65727a2d6c61726176656c2f636f6d706f7365726c6f636b)](https://packagist.org/packages/syedmahamudul/sslcommerz-laravel)[![PHP Version](https://camo.githubusercontent.com/bba7beb272b7ea60d78ebffd8c937660ae074516d3b6032b2623cbf834f5fda8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f737965646d6168616d7564756c2f73736c636f6d6d65727a2d6c61726176656c)](https://packagist.org/packages/syedmahamudul/sslcommerz-laravel)

This package is built for [SSLCommerz](https://www.sslcommerz.com) online payment gateway in Bangladesh. It supports **Laravel 5.5+, 6.x, 7.x, 8.x, 9.x, 10.x, and 11.x, 12.x, 13.x** and works with **PHP 7.0 to 8.2+**.

🚀 Features
----------

[](#-features)

- ✅ **Easy Installation** - One command installation
- ✅ **Fluent API** - Chainable methods for building payment requests
- ✅ **Automatic Validation** - Built-in payment validation
- ✅ **IPN Support** - Instant Payment Notification handling
- ✅ **Refund Functionality** - Process refunds easily
- ✅ **Transaction Query** - Check transaction status
- ✅ **Sandbox/Live Mode** - Easy switching between test and production
- ✅ **All Laravel Versions** - Works with Laravel 5.5 to 13.x
- ✅ **PHP 7.0 to 8.2+** - Compatible with all PHP versions
- ✅ **No Version Conflicts** - Works with any Laravel project
- ✅ **Comprehensive Error Handling** - Detailed error messages
- ✅ **Event-driven Architecture** - Events for payment statuses
- ✅ **Comprehensive Logging** - Debug and track payments
- ✅ **EMI Support** - Easy EMI payment integration
- ✅ **Card BIN Restriction** - Restrict payments to specific card BINs
- ✅ **Custom Callback URLs** - Customize success/failure URLs
- ✅ **Multiple Products** - Support for multiple products in one transaction
- ✅ **Checkout Integration** - AJAX/JSON checkout mode support

📋 Table of Contents
-------------------

[](#-table-of-contents)

- [Installation](#installation)
    - [Requirements](#requirements)
    - [Install via Composer](#install-via-composer)
    - [Publish Configuration](#publish-configuration)
    - [Setup Environment](#setup-environment)
    - [Create Routes](#create-routes)
    - [CSRF Exception](#csrf-exception)
    - [Clear Cache](#clear-cache)
- [Usage](#usage)
    - [Basic Payment](#basic-payment)
    - [Payment with Customer Details](#payment-with-customer-details)
    - [Payment with Shipping](#payment-with-shipping)
    - [Multiple Products](#multiple-products)
    - [Validate Payment](#validate-payment)
    - [Payment with Callback Methods](#payment-with-callback-methods)
    - [Refund Process](#refund-process)
    - [Transaction Query](#transaction-query)
    - [IPN Handling](#ipn-handling)
- [Available Methods](#available-methods)
    - [Required Methods](#required-methods)
    - [Optional Methods](#optional-methods)
    - [Response Methods](#response-methods)
- [Advanced Usage](#advanced-usage)
    - [Checkout Integration](#checkout-integration)
    - [Events](#events)
    - [Error Handling](#error-handling)
    - [Custom Callback URLs](#custom-callback-urls)
    - [Custom Currency](#custom-currency)
    - [EMI Payment](#emi-payment)
    - [Card BIN Restriction](#card-bin-restriction)
    - [Airline Ticket Profile](#airline-ticket-profile)
    - [Travel Vertical Profile](#travel-vertical-profile)
    - [Telecom Vertical Profile](#telecom-vertical-profile)
    - [Set Extras](#set-extras)
- [Security](#security)
- [Testing](#testing)
- [Troubleshooting](#troubleshooting)
    - [Common Issues](#common-issues)
    - [Debugging](#debugging)
- [Changelog](#changelog)
- [License](#license)

---

📦 Installation
--------------

[](#-installation)

### Requirements

[](#requirements)

- PHP 7.0 or higher
- Laravel 5.5 or higher
- SSLCommerz Merchant Account (Sandbox or Live)

### Install via Composer

[](#install-via-composer)

```
composer require syedmahamudul/sslcommerz-laravel
Publish Configuration
Run the installer command:

bash
php artisan sslcommerz:install
Or manually publish the configuration:

bash
php artisan vendor:publish --tag=sslcommerz-config
Setup Environment
Update your .env file with SSLCommerz credentials:

Sandbox/Test Mode:

env
SSLC_SANDBOX=true
SSLC_STORE_ID=your_sandbox_store_id
SSLC_STORE_PASSWORD=your_sandbox_store_password
SSLC_CURRENCY=BDT
Live/Production Mode:

env
SSLC_SANDBOX=false
SSLC_STORE_ID=your_live_store_id
SSLC_STORE_PASSWORD=your_live_store_password
SSLC_CURRENCY=BDT
Create Routes
Create four POST routes for SSLCommerz callbacks in routes/web.php:

php
Route::prefix('sslcommerz')->group(function () {
    Route::post('success', [PaymentController::class, 'success'])->name('sslcommerz.success');
    Route::post('failure', [PaymentController::class, 'failure'])->name('sslcommerz.failure');
    Route::post('cancel', [PaymentController::class, 'cancel'])->name('sslcommerz.cancel');
    Route::post('ipn', [PaymentController::class, 'ipn'])->name('sslcommerz.ipn');
});
CSRF Exception
Add these routes to CSRF exception in app/Http/Middleware/VerifyCsrfToken.php:

php
protected $except = [
    'sslcommerz/*',
];
Clear Cache
After configuration:

bash
php artisan config:clear
php artisan cache:clear
💳 Usage
Basic Payment
Create a payment initiation method in your controller:

php
use Syedmahamudul\Sslcommerz\Facades\Sslcommerz;

public function initiatePayment()
{
    $response = Sslcommerz::init([
        'total_amount' => 100,
        'product_name' => 'Demo Product',
    ])
    ->execute();

    if ($response->success()) {
        return redirect($response->gatewayPageURL());
    }

    return back()->with('error', $response->error());
}
Payment with Customer Details
php
$response = Sslcommerz::init([
    'total_amount' => 100,
    'product_name' => 'Demo Product',
])
->setCustomer([
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'phone' => '01700000000',
    'address' => 'Dhaka, Bangladesh',
    'city' => 'Dhaka',
    'country' => 'Bangladesh',
])
->execute();
Payment with Shipping
php
$response = Sslcommerz::init([
    'total_amount' => 100,
    'product_name' => 'Demo Product',
])
->setCustomer([
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'phone' => '01700000000',
])
->setShipping([
    'method' => 'NO',
    'name' => 'John Doe',
    'address' => 'Dhaka, Bangladesh',
    'city' => 'Dhaka',
    'country' => 'Bangladesh',
    'postcode' => '1000',
])
->execute();
Multiple Products
php
$response = Sslcommerz::init([
    'total_amount' => 200,
])
->setCustomer([...])
->addProduct([
    'name' => 'Product 1',
    'amount' => 100,
    'quantity' => 1,
])
->addProduct([
    'name' => 'Product 2',
    'amount' => 100,
    'quantity' => 1,
])
->execute();
Validate Payment
In your success callback:

php
use Syedmahamudul\Sslcommerz\Facades\Sslcommerz;

public function success(Request $request)
{
    $transactionId = $request->input('tran_id');
    $amount = $request->input('amount');

    if (Sslcommerz::validate($request->all(), $transactionId, $amount)) {
        // Payment is valid
        // Update your database
        // Mark order as paid
        $bankID = $request->input('bank_tran_id'); // Keep for refund

        return redirect()->route('home')->with('success', 'Payment successful!');
    }

    return redirect()->route('home')->with('error', 'Payment validation failed!');
}
Payment with Callback Methods
php
public function success(Request $request)
{
    $validate = Sslcommerz::validate($request->all(), $request->input('tran_id'), $request->input('amount'));

    if ($validate) {
        $bankID = $request->input('bank_tran_id'); // Store this for refund

        // Update your database
        // Send confirmation email
        // Redirect to success page
    }
}

public function failure(Request $request)
{
    // Payment failed
    // Update order status
    // Redirect to failure page
}

public function cancel(Request $request)
{
    // Payment cancelled by user
    // Update order status
    // Redirect to cart or home page
}

public function ipn(Request $request)
{
    // Handle IPN (Instant Payment Notification)
    // This is called by SSLCommerz server
    // No response is expected

    $transactionId = $request->input('tran_id');
    $amount = $request->input('amount');

    if (Sslcommerz::validate($request->all(), $transactionId, $amount)) {
        // Process payment in background
        // Update database, send emails, etc.
    }

    return response()->json(['status' => 'SUCCESS']);
}
Refund Process
php
use Syedmahamudul\Sslcommerz\Facades\Sslcommerz;

public function refund($bankID)
{
    $refund = Sslcommerz::refund($bankID, 100, 'Customer request');

    if ($refund['status'] === 'SUCCESS') {
        return back()->with('success', 'Refund processed successfully!');
    }

    return back()->with('error', 'Refund failed!');
}
Transaction Query
php
use Syedmahamudul\Sslcommerz\Facades\Sslcommerz;

public function getTransactionStatus($transactionId)
{
    $transaction = Sslcommerz::query($transactionId);

    if ($transaction['status'] === 'VALID') {
        dd($transaction); // Transaction details
    }

    return back()->with('error', 'Transaction not found!');
}
IPN Handling
php
use Syedmahamudul\Sslcommerz\Facades\Sslcommerz;

public function ipn(Request $request)
{
    $transactionId = $request->input('tran_id');
    $amount = $request->input('amount');

    if (Sslcommerz::validate($request->all(), $transactionId, $amount)) {
        // Process payment in background
        // Update database, send emails, etc.
    }

    return response()->json(['status' => 'SUCCESS']);
}
🔧 Available Methods
Required Methods
Method	Parameters	Description	Usage
init()	array	Initialize payment with amount and product	Sslcommerz::init(['total_amount' => 100, 'product_name' => 'Product'])
setCustomer()	array	Set customer information	->setCustomer(['name' => 'John', 'email' => 'john@example.com', 'phone' => '017...'])
execute()	none	Execute the payment	->execute()
Optional Methods
Method	Parameters	Description	Usage
setShipping()	array	Set shipping details	->setShipping(['method' => 'NO', 'name' => 'John', 'address' => 'Dhaka'])
addProduct()	array	Add multiple products	->addProduct(['name' => 'Product', 'amount' => 100, 'quantity' => 1])
validate()	array, string, float	Validate payment response	Sslcommerz::validate($request->all(), $transactionId, $amount)
refund()	string, float, string	Process refund	Sslcommerz::refund($bankID, $amount, $reason)
query()	string	Query transaction status	Sslcommerz::query($transactionId)
Response Methods
Method	Description	Usage
success()	Check if payment was successful	$response->success()
failed()	Check if payment failed	$response->failed()
gatewayPageURL()	Get SSLCommerz payment page URL	$response->gatewayPageURL()
transactionId()	Get transaction ID	$response->transactionId()
validationId()	Get validation ID	$response->validationId()
error()	Get error message	$response->error()
all()	Get all response data	$response->all()
🚀 Advanced Usage
Checkout Integration
For AJAX/JSON checkout integration:

php
$response = Sslcommerz::init([...])
    ->setCustomer([...])
    ->execute();

if ($response->success()) {
    return response()->json([
        'status' => 'success',
        'redirect_url' => $response->gatewayPageURL()
    ]);
}
Events
The package dispatches events for different payment statuses:

PaymentSuccess

PaymentFailed

PaymentCancelled

PaymentIpnReceived

Listen to these events in your EventServiceProvider:

php
protected $listen = [
    \Syedmahamudul\Sslcommerz\Events\PaymentSuccess::class => [
        \App\Listeners\HandleSuccessfulPayment::class,
    ],
];
Error Handling
php
try {
    $response = Sslcommerz::init([...])->execute();

    if ($response->success()) {
        // Handle success
    } else {
        $error = $response->error();
        Log::error('Payment failed: ' . $error);
    }
} catch (\Exception $e) {
    Log::error('Payment exception: ' . $e->getMessage());
    return back()->with('error', 'Something went wrong!');
}
Custom Callback URLs
Override default callback URLs:

php
$response = Sslcommerz::init([
    'total_amount' => 100,
    'product_name' => 'Demo Product',
    'success_url' => route('custom.success'),
    'fail_url' => route('custom.failure'),
    'cancel_url' => route('custom.cancel'),
    'ipn_url' => route('custom.ipn'),
])
->setCustomer([...])
->execute();
Custom Currency
Set custom currency:

php
$response = Sslcommerz::init([
    'total_amount' => 100,
    'product_name' => 'Demo Product',
    'currency' => 'USD',
])
->setCustomer([...])
->execute();
EMI Payment
Enable EMI payment options:

php
$response = Sslcommerz::init([
    'total_amount' => 100,
    'product_name' => 'Demo Product',
    'emi_option' => 1, // Enable EMI
    'emi_max_inst_option' => 12, // Max installment options
])
->setCustomer([...])
->execute();
Card BIN Restriction
Restrict payment to specific card BINs:

php
$response = Sslcommerz::init([
    'total_amount' => 100,
    'product_name' => 'Demo Product',
    'multi_card_name' => 'mastercard,visacard,amexcard',
    'allowed_bin' => '371598,371599,376947',
])
->setCustomer([...])
->execute();
Airline Ticket Profile
For airline ticket product profile:

php
$response = Sslcommerz::init([
    'total_amount' => 100,
    'product_name' => 'Airline Ticket',
    'product_profile' => 'airline-tickets',
])
->setCustomer([...])
->setAirlineTicketProfile([
    'flight_type' => 'bus',
    'hours_till_departure' => 3,
    'pnr' => 1,
    'journey_from_to' => 'DHK-RAJ',
    'third_party_booking' => null
])
->execute();
Travel Vertical Profile
For travel vertical product profile:

php
$response = Sslcommerz::init([
    'total_amount' => 100,
    'product_name' => 'Hotel Booking',
    'product_profile' => 'travel-vertical',
])
->setCustomer([...])
->setTravelVerticalProfile([
    'hotel_name' => 'Dalas Hotel',
    'length_of_stay' => 3,
    'check_in_time' => '12:00pm',
    'hotel_city' => 'Rajshahi'
])
->execute();
Telecom Vertical Profile
For telecom vertical product profile:

php
$response = Sslcommerz::init([
    'total_amount' => 100,
    'product_name' => 'Mobile Recharge',
    'product_profile' => 'telecom-vertical',
])
->setCustomer([...])
->setTelecomVerticleProfile([
    'product_type' => 'Flexiload',
    'topup_number' => '01700000000',
    'country_topup' => 'BD'
])
->execute();
Set Extras
Pass extra parameters to callback responses:

php
$response = Sslcommerz::init([
    'total_amount' => 100,
    'product_name' => 'Demo Product',
])
->setCustomer([...])
->setExtras([
    'extra1' => 'Order ID: 12345',
    'extra2' => 'User ID: 1001'
])
->execute();
🔒 Security
All callback URLs are automatically excluded from CSRF verification

IPN requests are validated

Amount and transaction ID are verified

No sensitive data is stored in logs by default

Supports sandbox mode for testing

SSL/TLS encryption for all API calls

Validation against SSLCommerz API

🧪 Testing
Test your integration with the built-in command:

bash
php artisan sslcommerz:make-payment 100 --product="Test Product"
This will initiate a test payment and display the payment URL.

❗ Troubleshooting
Common Issues
1. "Could not find a matching version"

Your package is not published on Packagist or version tag is missing

Solution: Create a version tag or use dev-main

2. "CSRF token mismatch"

Callback URLs not added to CSRF exception

Solution: Add sslcommerz/* to $except array

3. "Payment validation failed"

Amount mismatch or invalid transaction

Solution: Verify amount and transaction ID

4. "SSL certificate error"

SSL certificate not trusted

Solution: Disable SSL verification in development

5. "Store ID or Password incorrect"

Wrong credentials in .env file

Solution: Verify your SSLCommerz credentials

6. "Transaction not found"

Invalid transaction ID

Solution: Check if transaction exists in SSLCommerz

Debugging
Enable logging in .env:

env
SSLC_LOGGING=true
SSLC_LOG_CHANNEL=daily
SSLC_LOG_LEVEL=debug
Check logs at storage/logs/laravel.log

📝 Changelog
Please see CHANGELOG for more information on what has changed recently.

🤝 Contributing
Please see CONTRIBUTING for details.

👨‍💻 Author
Syed Mahamudul Hasan - GitHub

Email: syedmahamudulhasan@gmail.com

📄 License
The MIT License (MIT). Please see License File for more information.

⭐ Support
If you like this package, please star it on GitHub! ⭐

🙏 Acknowledgments
SSLCommerz for providing the payment gateway

Laravel for the amazing framework

All contributors who helped improve this package

Made with ❤️ in Bangladesh

text

---

## How to Save This File

### Option 1: Save via Command Line

```bash
cd /c/laragon/www/sslcommerz-laravel
cat > README.md
