Skip to content

A package for SSLCommerz Payment Gateway Inspired by SSLCommerz for Laravel framework (PHP).

License

Notifications You must be signed in to change notification settings

AfzalSabbir/SSLaraCommerz

Repository files navigation

SSLaraCommerz - Laravel Package

A package for SSLCommerz Payment Gateway
Inspired by SSLCommerz
SSLCommerz Payment gateway library for Laravel framework. Official documentation is here.

Software License Latest Version on Packagist Build Status Quality Score Commits Since

GitHub contributors GitHub issues GitHub issues

GitHub forks GitHub stars GitHub watchers GitHub followers Twitter Follow

Total Downloads GitHub code size in bytes GitHub repo size in bytes

GitHub last commit GitHub commit activity the past week, 4 weeks, year GitHub commit activity the past week, 4 weeks, year GitHub commit activity the past week, 4 weeks, year

GitHub release GitHub release date

GitHub tag GitHub release GitHub release

Tags: Payment Gateway, SSLCommerz, IPN, Laravel, SSLaraCommerz

Requires: Laravel >= 5.6 and MySQL

License: MIT License

Install

composer require afzalsabbir/sslaracommerz

Migration

php artisan migrate

Instructions

Vendor Publish - Required

# Public Assets
php artisan vendor:publish --provider="AfzalSabbir\SSLaraCommerz\SSLaraCommerzServiceProvider" --tag="public-assets"

Public Assets: To integrate popup checkout, use the below script before the end of body tag.

  • For Sandbox

    <script>
        (function (window, document) {
            var loader = function () {
                var script = document.createElement("script"),
                    tag    = document.getElementsByTagName("script")[0];
                script.src = "https://sandbox.sslcommerz.com/embed.min.js?" + Math.random().toString(36).substring(7);
                tag.parentNode.insertBefore(script, tag);
            };
    
            window.addEventListener ? window.addEventListener("load", loader, false) : window.attachEvent("onload", loader);
        })(window, document);
    </script>

    or, Publish the Public Assets and use the below sandbox script

    <script src="/assets/js/sandbox.js"></script>
  • For Live

    <script>
        (function (window, document) {
            var loader = function () {
                var script = document.createElement("script"),
                    tag    = document.getElementsByTagName("script")[0];
                script.src = "https://seamless-epay.sslcommerz.com/embed.min.js?" + Math.random().toString(36).substring(7);
                tag.parentNode.insertBefore(script, tag);
            };
    
            window.addEventListener ? window.addEventListener("load", loader, false) : window.attachEvent("onload", loader);
        })(window, document);
    </script>

    or, Publish the Public Assets and use the below live script

    <script src="/assets/js/live.js"></script>
# Routes and Controller
php artisan vendor:publish --provider="AfzalSabbir\SSLaraCommerz\SSLaraCommerzServiceProvider" --tag="routes-controller"

Routes and Controller: To customize the routes and controller, use the below command.

  • Add $this->loadRoutesFrom(base_path('routes/sslcommerz.php')); in app/Providers/RouteServiceProvider.php
    namespace App\Providers;
    
    // ...
    
    class RouteServiceProvider extends ServiceProvider
    {
        // ...
        public function boot()
        {
            // ...
            $this->loadRoutesFrom(base_path('routes/sslcommerz.php'));
        }
        // ...
    }

Vendor Publish - Optional

# Config
php artisan vendor:publish --provider="AfzalSabbir\SSLaraCommerz\SSLaraCommerzServiceProvider" --tag="config"

# Views
## Namespace: sslaracommerz
php artisan vendor:publish --provider="AfzalSabbir\SSLaraCommerz\SSLaraCommerzServiceProvider" --tag="views"

# Migrations
php artisan vendor:publish --provider="AfzalSabbir\SSLaraCommerz\SSLaraCommerzServiceProvider" --tag="migrations"

Note: If you later encounter issues with session destroying after redirect, you can set 'same_site' => null, in your config/session.php file.

  • Step 1: Add STORE_ID and STORE_PASSWORD values on your project's .env file. You can register for a store at https://developer.sslcommerz.com/registration/

  • Step 2: Add the below routes into the $excepts array of VerifyCsrfToken middleware.

    protected $except = [
        '/pay-via-ajax', '/success','/cancel','/fail','/ipn'
    ];

Now, let's go to the main integration part.

  • Step 3: Use the below button where you want to show the "Pay Now" button:

    <button class="your-button-class" id="sslczPayBtn"
            token="if you have any token validation"
            postdata="your javascript arrays or objects which requires in backend"
            order="If you already have the transaction generated for current order"
            endpoint="/pay-via-ajax"> Pay Now
    </button>
  • Step 4: For EasyCheckout (Popup) integration, you can update the checkout_ajax.php or use a different file according to your need. We have provided a basic sample page from where you can kickstart the payment gateway integration.

  • Step 5: For Hosted Checkout integration, you can update the checkout_hosted.php or use a different file according to your need. We have provided a basic sample page from where you can kickstart the payment gateway integration.

  • Step 6: For redirecting action from SSLCommerz Payment gateway, we have also provided sample success.php , cancel.php, fail.phpfiles. You can update those files according to your need.

Original Documentation

For more clear concept read: SSLCommerz README.md

Testing

Run the tests with:

vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email afzalbd1@gmail.com instead of using the issue tracker.

License

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