An open API service indexing awesome lists of open source software.

https://github.com/smiftakhairul/sslcommerz

SSLCommerz Payment Gateway Package for Laravel 5, 6, 7, 8
https://github.com/smiftakhairul/sslcommerz

payment-gateway sslcommerz sslcommerz-payment sslcommerz-payment-gateway

Last synced: 6 months ago
JSON representation

SSLCommerz Payment Gateway Package for Laravel 5, 6, 7, 8

Awesome Lists containing this project

README

          

# SSLCommerz
[SSLCommerz](https://www.sslcommerz.com/) is the first payment gateway in Bangladesh opening doors for merchants to receive payments on the internet via their online stores.

Official documentation [here](https://developer.sslcommerz.com/).

## Installation
```bash
$ composer require smiftakhairul/sslcommerz
```

## Vendor
```bash
$ php artisan vendor:publish --provider="SSLCZ\SSLCommerz\SSLCommerzServiceProvider"
```
A file `sslcommerz.php` will be added to `config` directory after running above command. We need to setup our configuration to `.env` file as follows:

```bash
STORE_ID="your-store-id"
STORE_PASSWORD="your-store-password"
IS_PRODUCTION=false
```
For deveopment mode we need to set `IS_PRODUCTION=false`, and for production mode `IS_PRODUCTION=true`. Please go through the official [docs](https://developer.sslcommerz.com/) of SSLCommerz for further information.

## Usage
#### *Initiate a payment*
```php
$sslcommerz = new SSLCommerz();
$sslcommerz->setPaymentDisplayType('hosted'); // enum('hosted', 'checkout')
$sslcommerz->setPrimaryInformation([
'total_amount' => 1000,
'currency' => 'BDT',
]);
$sslcommerz->setTranId('your-transaction-id'); // set your transaction id here
$sslcommerz->setSuccessUrl('http://www.example.com/success');
$sslcommerz->setFailUrl('http://www.example.com/fail');
$sslcommerz->setCancelUrl('http://www.example.com/cancel');
$sslcommerz->setCustomerInformation([
'cus_name' => 'John Doe',
'cus_email' => 'john.doe@yahoo.com',
'cus_add1' => 'Dhaka',
'cus_add2' => 'Dhaka',
'cus_city' => 'Dhaka',
'cus_state' => 'Dhaka',
'cus_postcode' => '1000',
'cus_country' => 'Bangladesh',
'cus_phone' => '+880**********',
]);
$sslcommerz->setShipmentInformation([
'ship_name' => 'Store Test',
'ship_add1' => 'Dhaka',
'ship_add2' => 'Dhaka',
'ship_city' => 'Dhaka',
'ship_state' => 'Dhaka',
'ship_postcode' => '1000',
'ship_country' => 'Bangladesh',
'shipping_method' => 'NO',
]);
$sslcommerz->setAdditionalInformation([
'value_a' => 'CPT-112-A',
'value_b' => 'CPT-112-B',
'value_c' => 'CPT-112-C',
'value_d' => 'CPT-112-D',
]);
$sslcommerz->setEmiOption(1); // enum(1, 0)
$sslcommerz->setProductInformation([
'product_name' => 'Computer',
'product_category' => 'Goods',
'product_profile' => 'physical-goods',
]);
$sslcommerz->setCart([
['product' => 'Product X', 'amount' => '2000.00'],
['product' => 'Product Y', 'amount' => '4000.00'],
['product' => 'Product Z', 'amount' => '8000.00'],
]);
$sslcommerz->setProductAmount('1000');
$sslcommerz->setVat('100');
$sslcommerz->setDiscountAmount('0');
$sslcommerz->setConvenienceFee('50');

$response = $sslcommerz->initPayment($sslcommerz);
```
#### *Set store information dynamically*

```php
$sslcommerz = new SSLCommerz([
'store_id' => 'your-store-id',
'store_password' => 'your-store-password',
'is_production' => false
]);
```

#### *Response*
> You will get a response after initiating a payment by which you can deal with. You can see a sample response format in the official documentation.

### Hosted Payment Integration
```php
// Controller
$sslcommerz = new SSLCommerz();
$sslcommerz->setPaymentDisplayType('hosted');
// ---

$response = $sslcommerz->initPayment($sslcommerz);
return redirect($response['GatewayPageURL']); // redirect to gateway page url
```

### Easy Checkout Integration
```javascript
// View(js) - Step 1
(function (window, document) {
var loader = function () {
var script = document.createElement("script"), tag = document.getElementsByTagName("script")[0];
script.src = "{{ 'Sandbox or Live(Production) Script' }}" + Math.random().toString(36).substring(7);
tag.parentNode.insertBefore(script, tag);
};

window.addEventListener ? window.addEventListener("load", loader, false) : window.attachEvent("onload", loader);
})(window, document);

/*
Sandbox Script URL: https://sandbox.sslcommerz.com/embed.min.js?
Live or Production Script URL: https://seamless-epay.sslcommerz.com/embed.min.js?
*/
```

```html

Pay Now

```

```php
// Controller
$sslcommerz = new SSLCommerz();
$sslcommerz->setPaymentDisplayType('checkout');
// ---

$response = $sslcommerz->initPayment($sslcommerz);
echo $sslcommerz->formatCheckoutResponse($response); // show easycheckout pay popup
```

### Disable CSRF Protection
Disable `CSRF` protection for the following URL's.
- `init-payment-via-ajax` url
- `success` url
- `fail` url
- `cancel` url
- `ipn` url

Disable them from `VerifyCsrfToken` middleware.
```php
// VerifyCsrfToken.php
protected $except = [
'/init-payment-via-ajax',
'/success',
'/cancel',
'/fail',
'/ipn'
];
```

### Order Validation
```php
$sslcommerz = new SSLCommerz();
$response = $sslcommerz->orderValidate([
'val_id' => $request->input('val_id'),
'store_id' => 'your-store-id', // Optional: by default `$sslcommerz->getStoreId()`
'store_password' => 'your-store-password', // Optional: by default `$sslcommerz->getStorePassword()`
'v' => '1', // Optional: by default `1`
'format' => 'json' // Optional: by default `json`
]);
```

### Transaction Query
```php
$sslcommerz = new SSLCommerz();

// by Transaction Id
$response = $sslcommerz->transactionQueryById([
'tran_id' => $request->input('tran_id'),
'store_id' => 'your-store-id', // Optional: by default `$sslcommerz->getStoreId()`
'store_password' => 'your-store-password', // Optional: by default `$sslcommerz->getStorePassword()`
]);
// by Session Id
$response = $sslcommerz->transactionQueryBySessionId([
'sessionkey' => 'initiated-session-key',
'store_id' => 'your-store-id', // Optional: by default `$sslcommerz->getStoreId()`
'store_password' => 'your-store-password', // Optional: by default `$sslcommerz->getStorePassword()`
]);
```

### Refund
```php
$sslcommerz = new SSLCommerz();

// Initiate
$response = $sslcommerz->refundPayment([
'bank_tran_id' => $request->input('bank_tran_id'),
'store_id' => 'your-store-id', // Optional: by default `$sslcommerz->getStoreId()`
'store_password' => 'your-store-password', // Optional: by default `$sslcommerz->getStorePassword()`
'refund_amount' => 1000,
'refund_remarks' => 'your-refund-remarks',
'refe_id' => 'your-ref-id', // Optional
'format' => 'json', // Optional: by default `json`
]);
// Status
$response = $sslcommerz->refundStatus([
'refund_ref_id' => 'refund-ref-id',
'store_id' => 'your-store-id', // Optional: by default `$sslcommerz->getStoreId()`
'store_password' => 'your-store-password', // Optional: by default `$sslcommerz->getStorePassword()`
]);
```

## Available Env's & API's
***Environments:*** `getApiEnvironment()`
- **sandbox** (`IS_PRODUCTION` false)
- **production** (`IS_PRODUCTION` true)

***Domains:*** `getApiDomain()`
- **sandbox** (https://sandbox.sslcommerz.com)
- **production** (https://securepay.sslcommerz.com)

***APIs:***
- `getApiUrl()` ([api_domain]/gwprocess/v4/api.php)
- `getOrderValidateApiUrl()` ([api_domain]/validator/api/validationserverAPI.php)
- `getTransactionStatusApiUrl()` ([api_domain]/validator/api/merchantTransIDvalidationAPI.php)
- `getRefundPaymentApiUrl()` ([api_domain]/validator/api/merchantTransIDvalidationAPI.php)
- `getRefundStatusApiUrl()` ([api_domain]/validator/api/merchantTransIDvalidationAPI.php)

## Available Methods
##### Environment & domain related configuration:



Method Name
Param Info
Description




getApiEnvironment()

API environment: sandbox or production.


setApiEnvironment()
string
Set API environment: sandbox or production only.


getApiDomain()

API domain: for example
https://sandbox.sslcommerz.com
or

https://securepay.sslcommerz.com


isProductionMode()

Get production_mode.


setProductionMode()
boolean
Set production_mode. By default, production_mode sets by IS_PRODUCTION value.

##### API url configuration:



Method Name
Param Info
Description




getApiUrl()

Get payment initiate api url.


setApiUrl()
string
Set payment initiate api url. By default, api url sets based on IS_PRODUCTION value. If IS_PRODUCTION = true, live api url will be set and for IS_PRODUCTION = false sandbox api url will be set.


getTransactionStatusApiUrl()

Get transaction status api url.


setTransactionStatusApiUrl()
string
Set transaction status api url.


getOrderValidateApiUrl()

Get order validation api url.


setOrderValidateApiUrl()
string
Set order validation api url.


getRefundPaymentApiUrl()

Get refund payment api url.


setRefundPaymentApiUrl()
string
Set refund payment api url.


getRefundStatusApiUrl()

Get refund status api url.


setRefundStatusApiUrl()
string
Set refund status api url.

#### Set information as a compact:



Method Name
Param Info
Description




getPrimaryInformation()


Get primary information such as:



store_id,
store_passwd,
total_amount,
currency,
tran_id,
success_url,
fail_url,
cancel_url and other optional information.




setPrimaryInformation()
array()

Set primary information.



Required parameter key elements:


  • store_id

  • store_passwd

  • total_amount

  • currency

  • tran_id

  • success_url

  • fail_url

  • cancel_url


Optional parameter key elements:

  • ipn_url

  • multi_card_name

  • allowed_bin





getCustomerInformation()


Get customer information such as:



cus_name,
cus_email,
cus_add1,
cus_add2,
cus_city,
cus_postcode,
cus_country,
cus_phone and other optional information.




setCustomerInformation()
array()

Set customer information.



Required parameter key elements:

  • cus_name

  • cus_email

  • cus_add1

  • cus_add2

  • cus_city

  • cus_postcode

  • cus_country

  • cus_phone


Optional parameter key elements:

  • cus_state

  • cus_fax





getProductInformation()


Get product information such as:



product_name,
product_category,
product_profile and other optional information.




setProductInformation()
array()

Set product information.



Required parameter key elements:

  • product_name

  • product_category

  • product_profile


Optional parameter key elements:

  • cart

  • product_amount

  • vat

  • discount_amount

  • convenience_fee

  • hours_till_departure

  • flight_type

  • pnr

  • journey_from_to

  • third_party_booking

  • hotel_name

  • length_of_stay

  • check_in_time

  • hotel_city

  • product_type

  • topup_number

  • country_topup





getShipmentInformation()


Get shipment information such as:



shipping_method,
num_of_item and other optional information.




setShipmentInformation()
array()

Set shipment information.



Required parameter key elements:

  • shipping_method

  • num_of_item


Optional parameter key elements:

  • ship_name

  • ship_add1

  • ship_add2

  • ship_state

  • ship_city

  • ship_postcode

  • ship_country





getEmiInformation()


Get EMI information such as:



emi_option and other optional information.




setEmiInformation()
array()

Set EMI information.



Required parameter key elements:

  • emi_option


Optional parameter key elements:

  • emi_max_inst_option

  • emi_selected_inst

  • emi_allow_only





getAdditionalInformation()


Get additional information such as:



value_a,
value_b,
value_c,
value_d.




setAdditionalInformation()
array()

Set additional information.



Optional parameter key elements:

  • value_a

  • value_b

  • value_c

  • value_d




##### Other getters and setters:



Method Name
Param Info
Description




getPaymentDisplayType()

Get payment display type.


setPaymentDisplayType()*
enum('hosted', 'checkout')
Set payment display type. Default value is checkout.


getStoreId()

Get SSLCommerz store_id.


setStoreId()*
string
Set SSLCommerz store_id. Default value sets by STORE_ID value.


getStorePassword()

Get SSLCommerz store_passwd.


setStorePassword()*
string
Set SSLCommerz store_passwd. Default value sets by STORE_PASSWORD value.


getTotalAmount()

Get total_amount of transaction.


setTotalAmount()*
decimal
Set total_amount of transaction. The transaction amount must be from 10.00 BDT to 500000.00 BDT


getCurrency()

Get currency type. Example: BDT, USD, EUR, SGD, INR, MYR, etc


setCurrency()*
string
Set currency type.


getTranId()

Get unique tran_id to identify order.


setTranId()*
string
Set tran_id to unify your order.


getSuccessUrl()

Get callback success_url.


setSuccessUrl()*
string
Set callback success_url where user will redirect after successful payment.


getFailUrl()

Get callback fail_url.


setFailUrl()*
string
Set callback fail_url where user will redirect after any failure occurs during payment.


getCancelUrl()

Get callback cancel_url.


setCancelUrl()*
string
Set callback cancel_url where user will redirect if user cancels the transaction.


getIpnUrl()

Get Instant Payment Notification ipn_url.


setIpnUrl()
string
Set ipn_url. Enable instant payment notification option so that SSLCommerz can send the transaction's status to ipn_url.


getMultiCardName()

Get multi_card_name.


setMultiCardName()
string
Set multi_card_name. Use it only if gateway list needs to be customized.


getAllowedBin()

Get allowed_bin.


setAllowedBin()
string
Set allowed_bin. Use it only if transaction needs to be controlled.


getCustomerName()

Get cus_name.


setCustomerName()*
string
Set cus_name.


getCustomerEmail()

Get cus_email.


setCustomerEmail()*
string
Set cus_email.


getCustomerAddress1()

Get cus_add1.


setCustomerAddress1()*
string
Set cus_add1.


getCustomerAddress2()

Get cus_add2.


setCustomerAddress2()
string
Set cus_add2.


getCustomerCity()

Get cus_city.


setCustomerCity()*
string
Set cus_city.


getCustomerState()

Get cus_state.


setCustomerState()
string
Set cus_state.


getCustomerPostCode()

Get cus_postcode.


setCustomerPostCode()*
string
Set cus_postcode.


getCustomerCountry()

Get cus_country.


setCustomerCountry()*
string
Set cus_country.


getCustomerPhone()

Get cus_phone.


setCustomerPhone()*
string
Set cus_phone.


getCustomerFax()

Get cus_fax.


setCustomerFax()
string
Set cus_fax.


getProductName()

Get product_name.


setProductName()*
string
Set product_name.


getProductCategory()

Get product_category.


setProductCategory()*
string
Set product_category.


getProductProfile()

Get product_profile.


setProductProfile()*
string
Set product_profile.


Available keys:


  1. general

  2. physical-goods

  3. non-physical-goods

  4. airline-tickets

  5. travel-vertical

  6. telecom-vertical





getProductHoursTillDeparture()

Get hours_till_departure.


setProductHoursTillDeparture()**
string
Set hours_till_departure. Required if product_profile is airline-tickets.


getProductFlightType()

Get flight_type.


setProductFlightType()**
string
Set flight_type. Required if product_profile is airline-tickets.


getProductPnr()

Get pnr.


setProductPnr()**
string
Set pnr. Required if product_profile is airline-tickets.


getProductJourneyFromTo()

Get journey_from_to.


setProductJourneyFromTo()**
string
Set journey_from_to. Required if product_profile is airline-tickets.


getProductThirdPartyBooking()

Get third_party_booking.


setProductThirdPartyBooking()**
string
Set third_party_booking. Required if product_profile is airline-tickets.


getProductHotelName()

Get hotel_name.


setProductHotelName()**
string
Set hotel_name. Required if product_profile is travel-vertical.


getProductLengthOfStay()

Get length_of_stay.


setProductLengthOfStay()**
string
Set length_of_stay. Required if product_profile is travel-vertical.


getProductCheckInTime()

Get check_in_time.


setProductCheckInTime()**
string
Set check_in_time. Required if product_profile is travel-vertical.


getProductHotelCity()

Get hotel_city.


setProductHotelCity()**
string
Set hotel_city. Required if product_profile is travel-vertical.


getProductType()

Get product_type.


setProductType()**
string
Set product_type. Required if product_profile is telecom-vertical.


getProductTopUpNumber()

Get topup_number.


setProductTopUpNumber()**
string
Set topup_number. Required if product_profile is telecom-vertical.


getProductCountryTopUp()

Get country_topup.


setProductCountryTopUp()**
string
Set country_topup. Required if product_profile is telecom-vertical.


getCart()

Get cart.


setCart()
json
Set cart. JSON data with two elements. product: Max 255 characters, quantity: Quantity in numeric value and amount: Decimal (12,2).

Example:
[{"product":"DHK TO BRS AC A1","quantity":"1","amount":"200.00"},{"product":"DHK TO BRS AC A2","quantity":"1","amount":"200.00"},{"product":"DHK TO BRS AC A3","quantity":"1","amount":"200.00"},{"product":"DHK TO BRS AC A4","quantity":"2","amount":"200.00"}]


getProductAmount()

Get product_amount.


setProductAmount()
decimal
Set product_amount.


getVat()

Get vat.


setVat()
decimal
Set vat.


getDiscountAmount()

Get discount_amount.


setDiscountAmount()
decimal
Set discount_amount.


getConvenienceFee()

Get convenience_fee.


setConvenienceFee()
decimal
Set convenience_fee.


getShippingMethod()

Get shipping_method of the order.


setShippingMethod()*
string
Set shipping_method of the order. Example: YES or NO or Courier.


getShippingItemNumber()

Get num_of_item of product.


setShippingItemNumber()*
integer
Set num_of_item of product will be shipped.


getShippingName()

Get ship_name of address.


setShippingName()**
string
Set ship_name of address. Required if shipping_method is YES.


getShippingAddress1()

Get ship_add1.


setShippingAddress1()**
string
Set ship_add1. Required if shipping_method is YES.


getShippingAddress2()

Get ship_add2.


setShippingAddress2()
string
Set ship_add2.


getShippingCity()

Get ship_city.


setShippingCity()**
string
Set ship_city. Required if shipping_method is YES.


getShippingState()

Get ship_state.


setShippingState()
string
Set ship_state.


getShippingPostCode()

Get ship_postcode.


setShippingPostCode()**
string
Set ship_postcode. Required if shipping_method is YES.


getShippingCountry()

Get ship_country.


setShippingCountry()**
string
Set ship_country. Required if shipping_method is YES.


getEmiOption()

Get emi_option.


setEmiOption()*
integer
Set emi_option. Value must be 1 or 0.


getEmiMaxInstOption()

Get emi_max_inst_option.


setEmiMaxInstOption()
integer
Set emi_max_inst_option.


getEmiSelectedInst()

Get emi_selected_inst.


setEmiSelectedInst()
integer
Set emi_selected_inst.


getEmiAllowOnly()

Get emi_allow_only.


setEmiAllowOnly()
integer
Set emi_allow_only. Value must be 1 or 0. This parameter depends on emi_option and emi_selected_inst


getAdditionalValueA()

Get value_a.


setAdditionalValueA()
string
Set value_a.


getAdditionalValueB()

Get value_b.


setAdditionalValueB()
string
Set value_b.


getAdditionalValueC()

Get value_c.


setAdditionalValueC()
string
Set value_c.


getAdditionalValueD()

Get value_d.


setAdditionalValueD()
string
Set value_d.

`*` = **Required** and `**` = **Dependently Required**.

## License
[MIT](https://choosealicense.com/licenses/mit/)