syedmahamudul/sslcommerz-laravel

SSLCommerz Payment Gateway Integration Package for Laravel

Maintainers

Package info

github.com/syedmahamudul/laravel-sslcommerz

pkg:composer/syedmahamudul/sslcommerz-laravel

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-07-01 16:04 UTC

This package is auto-updated.

Last update: 2026-07-01 16:23:56 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads Daily Downloads composer.lock PHP Version

This package is built for SSLCommerz 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

  • โœ… 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

๐Ÿ“ฆ Installation

Requirements

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

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 << 'EOF'
[PASTE THE ENTIRE CONTENT ABOVE HERE]
EOF
Option 2: Save via Notepad
Copy the entire content above

Open Notepad

Paste the content

Click File โ†’ Save As

Save as README.md (make sure to select "All Files" not "Text Files")

Save in /c/laragon/www/sslcommerz-laravel/

Option 3: Quick Download
Since I can't directly create a download link, please copy the content above and save it as README.md in your package root directory.

Summary
This complete README includes:

Section	Content
Badges	8 badges (version, downloads, license, PHP version)
Features	18 comprehensive features
Table of Contents	Complete navigation with 12 main sections
Installation	6 step-by-step sub-sections with commands
Usage	9 usage scenarios with complete code examples
Available Methods	Required, Optional, and Response methods tables
Advanced Usage	10 advanced features with code
Security	7 security practices
Testing	Command and instructions
Troubleshooting	6 common issues and debugging
Changelog	Link to CHANGELOG.md
License	MIT License
Support	Contact and GitHub links
The file is now complete and ready to use! ๐ŸŽ‰