faysal0x1/lara-payment

A Laravel Package that makes implementation of multiple payment Gateways endpoints and webhooks seamless

0.2 2025-05-20 20:06 UTC

This package is not auto-updated.

Last update: 2025-06-04 18:52:56 UTC


README

Latest Version on Packagist PHP from Packagist Laravel Version Test Status Code Style Status Total Downloads

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

  1. Install the package via Composer:
composer require faysal0x1/lara-payment
  1. Publish the configuration file:
php artisan vendor:publish --provider="Faysal0x1\LaraPayment\SslcommerzLaravelServiceProvider" --tag="config"
  1. Publish the controller:
php artisan vendor:publish --provider="Faysal0x1\LaraPayment\SslcommerzLaravelServiceProvider" --tag="controllers"
  1. Publish the views:
php artisan vendor:publish --provider="Faysal0x1\LaraPayment\SslcommerzLaravelServiceProvider" --tag="views"
  1. Publish the migrations:
php artisan vendor:publish --provider="Faysal0x1\LaraPayment\SslcommerzLaravelServiceProvider" --tag="migrations"
  1. 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

  1. 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);
  1. 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

  1. EMI Payment Support:
$sslc = new SslCommerzNotification();
$sslc->enableEMI(3, 12, false); // 3 months installment, max 12 months, not restricted to EMI only
  1. Airline Ticket Profile:
$airlineInfo = [
    'hours_till_departure' => '24',
    'flight_type' => 'domestic',
    'pnr' => 'ABC123',
    'journey_from_to' => 'Dhaka to Chittagong'
];
$sslc->setAirlineTicketProfile($airlineInfo);
  1. Travel Vertical Profile:
$travelInfo = [
    'hotel_name' => 'Grand Hotel',
    'length_of_stay' => 3,
    'check_in_time' => '14:00',
    'hotel_city' => 'Dhaka'
];
$sslc->setTravelVerticalProfile($travelInfo);
  1. Telecom Vertical Profile:
$telecomInfo = [
    'product_type' => 'prepaid',
    'topup_number' => '8801XXXXXXXXX',
    'country_topup' => 'Bangladesh'
];
$sslc->setTelecomVerticleProfile($telecomInfo);

Response Handling

  1. Success Response:
return SSLCommerzPayment::returnSuccess($transId, "Transaction is successfully Completed", '/');
  1. 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

  1. Always use environment variables for sensitive data
  2. Enable SSL on your production environment
  3. Validate all incoming data
  4. Use proper error handling
  5. Keep your store credentials secure

Testing

  1. Set SSLCOMMERZ_SANDBOX=true in your .env file for testing
  2. Use test credentials provided by SSLCommerz
  3. Test all payment scenarios (success, fail, cancel)
  4. Verify IPN handling
  5. 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.