Skip to content

Commit

Permalink
Merge pull request #1 from AfzalSabbir/build-0
Browse files Browse the repository at this point in the history
It's time to publish
  • Loading branch information
AfzalSabbir authored Sep 11, 2022
2 parents e853793 + bc24d7f commit 58ce809
Show file tree
Hide file tree
Showing 19 changed files with 2,029 additions and 30 deletions.
177 changes: 168 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,183 @@
# SSLaraCommerz
# SSLaraCommerz - Laravel Package

> A package for SSLCommerz Payment Gateway \
<sub><sup>Inspired by [SSLCommerz](https://github.com/sslcommerz/SSLCommerz-Laravel)</sup></sub> \
[SSLCommerz](https://www.sslcommerz.com) Payment gateway library for Laravel framework. Official documentation is [here](https://developer.sslcommerz.com/docs.html).

[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Travis](https://img.shields.io/travis/afzalsabbir/sslaracommerz.svg?style=flat-square)]()
[![Latest Version on Packagist](https://img.shields.io/packagist/v/afzalsabbir/sslaracommerz.svg?style=flat-square)](https://packagist.org/packages/afzalsabbir/sslaracommerz)
[![Build Status](https://img.shields.io/travis/afzalsabbir/sslaracommerz/master.svg?style=flat-square)](https://travis-ci.org/afzalsabbir/sslaracommerz)
[![Quality Score](https://img.shields.io/scrutinizer/g/afzalsabbir/sslaracommerz.svg?style=flat-square)](https://scrutinizer-ci.com/g/afzalsabbir/sslaracommerz)
[![Total Downloads](https://img.shields.io/packagist/dt/afzalsabbir/sslaracommerz.svg?style=flat-square)](https://packagist.org/packages/afzalsabbir/sslaracommerz)

__Tags:__ Payment Gateway, SSLCommerz, IPN, Laravel, SSLaraCommerz

__Requires:__ Laravel >= 5.6 and MySQL

__License:__ MIT License

## Install

```bash
```php
composer require afzalsabbir/sslaracommerz
```

## Migration

```php
php artisan migrate
```

## Instructions

### Vendor Publish - _Required_

<span id="public-assets">

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

</span>

#### **Public Assets**: _To integrate popup checkout, use the below script before the end of body tag._

- For Sandbox

```html
<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](#public-assets) and use the below `sandbox` script

```html
<script src="/assets/js/sandbox.js"></script>
```

- For Live

```html
<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](#public-assets) and use the below `live` script

```html
<script src="/assets/js/live.js"></script>
```

<span id="routes-controller">

```bash
# Routes and Controller
php artisan vendor:publish --provider="AfzalSabbir\SSLaraCommerz\SSLaraCommerzServiceProvider" --tag="routes-controller"
```

</span>

#### **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`
```php
namespace App\Providers;

// ...

class RouteServiceProvider extends ServiceProvider
{
// ...
public function boot()
{
// ...
$this->loadRoutesFrom(base_path('routes/sslcommerz.php'));
}
// ...
}
```

---

### Vendor Publish - _Optional_

<span id="config-views-migrations">

## Usage
```bash
# 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"
```
</span>

> __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/](https://developer.sslcommerz.com/registration/)

* __Step 2:__ Add the below routes into the `$excepts` array of `VerifyCsrfToken` middleware.

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

Write a few lines about the usage of this package.
Now, let's go to the main integration part.

* __Step 3:__ Use the below button where you want to show the **"Pay Now"** button:

```html
<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.php`files. You can update those files according to your need.

## Original Documentation

For more clear concept
read: [SSLCommerz README.md](https://github.com/sslcommerz/SSLCommerz-Laravel/blob/master/README.md)

## Testing

Expand All @@ -25,17 +187,14 @@ Run the tests with:
vendor/bin/phpunit
```


## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) 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](/LICENSE.md) for more information.
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "afzalsabbir/sslaracommerz",
"description": "Your Package Description here",
"description": "A package for SSLCommerz Payment Gateway. Inspired by https://github.com/sslcommerz/SSLCommerz-Laravel",
"type": "library",
"license": "MIT",
"keywords": [
Expand All @@ -16,7 +16,11 @@
],
"minimum-stability": "dev",
"prefer-stable":true,
"require": {},
"require": {
"php": "^7.1.3|^8.0",
"laravel/framework": "^5.6|^6.0|^7.0|^8.0|^9.0",
"guzzlehttp/guzzle": "^6.3|^7.0"
},
"require-dev": {
"symfony/thanks": "^1.0",
"phpunit/phpunit": "^7.4@dev",
Expand Down
5 changes: 0 additions & 5 deletions config/s_s_lara_commerz.php

This file was deleted.

25 changes: 25 additions & 0 deletions config/sslcommerz.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

// SSLCommerz configuration
return [
'projectPath' => env('PROJECT_PATH'),
// For Sandbox, use "https://sandbox.sslcommerz.com"
// For Live, use "https://securepay.sslcommerz.com"
'apiDomain' => env("API_DOMAIN_URL", "https://sandbox.sslcommerz.com"),
'apiCredentials' => [
'store_id' => env("STORE_ID"),
'store_password' => env("STORE_PASSWORD"),
],
'apiUrl' => [
'make_payment' => "/gwprocess/v4/api.php",
'transaction_status' => "/validator/api/merchantTransIDvalidationAPI.php",
'order_validate' => "/validator/api/validationserverAPI.php",
'refund_payment' => "/validator/api/merchantTransIDvalidationAPI.php",
'refund_status' => "/validator/api/merchantTransIDvalidationAPI.php",
],
'connect_from_localhost' => env("IS_LOCALHOST", true), // For Sandbox, use "true", For Live, use "false"
'success_url' => '/success',
'failed_url' => '/fail',
'cancel_url' => '/cancel',
'ipn_url' => '/ipn',
];
50 changes: 50 additions & 0 deletions database/migrations/2022_09_11_134122_create_orders_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* CREATE TABLE `orders` (
* `id` int(11) NOT NULL,
* `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
* `email` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
* `phone` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
* `amount` double DEFAULT NULL,
* `address` text COLLATE utf8_unicode_ci,
* `status` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
* `transaction_id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
* `currency` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
*
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('orders', function (Blueprint $table) {
$table->id();
$table->string('name', 191)->nullable();
$table->string('email', 100)->nullable();
$table->string('phone', 20)->nullable();
$table->double('amount')->nullable();
$table->text('address')->nullable();
$table->string('status', 10)->nullable();
$table->string('transaction_id', 191)->nullable();
$table->string('currency', 20)->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('orders');
}
};
9 changes: 9 additions & 0 deletions public/assets/js/live.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(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);
9 changes: 9 additions & 0 deletions public/assets/js/sandbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(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);
Loading

0 comments on commit 58ce809

Please sign in to comment.