Skip to content

Commit dd31edc

Browse files
author
Mostafa Kamal
committed
sslcommerz
sslcommerz
1 parent 887fdec commit dd31edc

File tree

6 files changed

+257
-2
lines changed

6 files changed

+257
-2
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1-
# lara-sslcommerz
2-
Laravel sslcommerz payment
1+
# Laravel sslcommerz payment .
2+
3+
# Installation
4+
5+
```bash
6+
composer require code4mk/lara-sslcommerz
7+
```
8+
9+
10+
#
11+
12+
```bash
13+
php artisan vendor:publish --provider="Code4mk\SslCommerz\SslCommerzServiceProvider" --tag=config
14+
```

composer.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "code4mk/lara-sslcommerz",
3+
"description": "Laravel sslcommerz payment package",
4+
"keywords": [
5+
"sslcommerz",
6+
"sslcommerz-payment",
7+
"code4mk",
8+
],
9+
"homepage": "https://github.com/code4mk/lara-sslcommerz",
10+
"support": {
11+
"issues": "https://github.com/code4mk/lara-sslcommerz/issues",
12+
"source": "https://github.com/code4mk/lara-sslcommerz"
13+
},
14+
"license": "MIT",
15+
"authors": [
16+
{
17+
"name": "code4mk",
18+
"email": "[email protected]",
19+
"website": "https://code4mk.org"
20+
}
21+
],
22+
"autoload": {
23+
"psr-4": {
24+
"Code4mk\\Sslcommerz\\": "src/"
25+
}
26+
},
27+
"extra": {
28+
"laravel": {
29+
"providers": [
30+
"Code4mk\\Sslcommerz\\SslcommerzServiceProvider"
31+
]
32+
}
33+
},
34+
"prefer-stable": true,
35+
"minimum-stability": "dev"
36+
}

config/sslcommerz.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
return [
4+
'store_id' => env('SSLCOMMERZ_STORE_ID', 'store_id'),
5+
'store_password' => env('SSLCOMMERZ_STORE_PASSWORD', 'password'),
6+
'currency' => env('SSLCOMMERZ_CURRENCY', 'BDT'),
7+
'success_url' => env('SSLCOMMERZ_SUCCESS_URL', 'http://example.com/success.php'),
8+
'fail_url' => env('SSLCOMMERZ_FAIL_URL', 'http://example.com/fail.php'),
9+
'cancel_url' => env('SSLCOMMERZ_CANCEL_URL', 'http://example.com/cancel.php'),
10+
'ipn_url' => env('SSLCOMMERZ_IPN_URL', 'http://example.com/ipn.php'),
11+
'sandbox_mode' => env('SSLCOMMERZ_MODE', 'sandbox')
12+
];

src/Facades/SslCommerz.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Code4mk\Sslcommerz\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
class SslCommerz extends Facade
8+
{
9+
/**
10+
* Get the registered name of the component.
11+
*
12+
* @return string
13+
*/
14+
protected static function getFacadeAccessor()
15+
{
16+
return 'sslCommerz';
17+
}
18+
}

src/Sslcommerz.php

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
3+
namespace Code4mk\Sslcommerz;
4+
5+
use GuzzleHttp\Client;
6+
7+
class Sslcommerz{
8+
9+
private $amount;
10+
private $tnx;
11+
private $airTicket = [];
12+
private $emi = false;
13+
14+
public function __construct()
15+
{
16+
17+
}
18+
19+
public function tnx($id)
20+
{
21+
$this->tnx = $id;
22+
return $this;
23+
}
24+
25+
public function amount($amount)
26+
{
27+
$this->amount = $amount;
28+
return $this;
29+
}
30+
31+
public function airlineTickets($data)
32+
{
33+
array_push($this->airTicket,$data);
34+
return $this;
35+
36+
}
37+
38+
public function emi($month,$selectedMonth)
39+
{
40+
$this->emi = true;
41+
$this->month = $month;
42+
$this->selectedMonth = $selectedMonth;
43+
return $this;
44+
}
45+
46+
public function customer($name,$email,$add1,$city,$post_code,$country,$phone){
47+
$data['cus_name'] = $name;
48+
$data['cus_email'] = $email;
49+
$data['cus_add1'] = $add1;
50+
$data['cus_city'] = $city;
51+
$data['cus_postcode'] = $postcode;
52+
$data['cus_country'] = $country;
53+
$data['cus_phone'] = $phone;
54+
}
55+
56+
57+
public function getSession()
58+
{
59+
$data = [
60+
'store_id'=> config('sslcommerz.store_id'),
61+
'store_passwd'=> config('sslcommerz.store_password'),
62+
'total_amount' => $this->amount,
63+
'currency'=> config('sslcommerz.currency'),
64+
'tran_id'=> $this->tnx,
65+
'success_url'=> config('sslcommerz.success_url'),
66+
'fail_url'=> config('sslcommerz.fail_url'),
67+
'cancel_url'=> config('sslcommerz.cancel_url'),
68+
'ipn_url' => config('sslcommerz.ipn_url'),
69+
'cus_name'=> 'kamal',
70+
'cus_email'=> '[email protected]',
71+
'cus_add1'=> 'dhaka',
72+
'cus_add2'=>'dhaka',
73+
'cus_city'=>'dhaka',
74+
'cus_state'=>'dhaka',
75+
'cus_postcode'=>'302',
76+
'cus_country'=>'Bangladesh',
77+
'cus_phone'=>'01711111111',
78+
'cus_fax'=>'01711111111',
79+
'product_name' => 'kamal',
80+
'product_category' => 'phone',
81+
'product_profile' => 'general',
82+
'shipping_method' => 'NO',
83+
'ship_name'=>'Customer Name',
84+
'ship_add1' =>'Dhaka',
85+
'ship_add2'=>'Dhaka',
86+
'ship_city'=>'Dhaka',
87+
'ship_state'=>'Dhaka',
88+
'ship_postcode'=>'1000',
89+
'ship_country'=>'Bangladesh',
90+
'multi_card_name'=>'mastercard,visacard,amexcard',
91+
'value_a'=>'ref001_A',
92+
'value_b'=>'ref002_B',
93+
'value_c'=>'ref003_C',
94+
'value_d'=>'ref004_D',
95+
];
96+
97+
if($this->emi){
98+
$data['emi'] = 1;
99+
$data['emi_max_inst_option'] = (int) $this->month;
100+
$data['emi_selected_inst'] = (int) $this->selectedMonth;
101+
}
102+
103+
$http = new Client([
104+
'base_uri' => 'https://sandbox.sslcommerz.com/',
105+
]);
106+
107+
$response = $http->post('gwprocess/v4/api.php',[
108+
'form_params' => $data
109+
]);
110+
111+
$body = json_decode($response->getBody());
112+
113+
$response2 = $http->get('validator/api/merchantTransIDvalidationAPI.php',[
114+
'sessionkey' => 'A217BAE3045C599323850C882DD583F4',
115+
'store_id' => config('sslcommerz.store_id'),
116+
'store_passwd' => config('sslcommerz.store_password'),
117+
]);
118+
$body2 = json_decode($response2->getBody());
119+
// return $body->redirectGatewayURL;
120+
return $body;
121+
122+
}
123+
124+
public function validate($request)
125+
{
126+
$http = new Client([
127+
'base_uri' => 'https://sandbox.sslcommerz.com/',
128+
]);
129+
130+
$response = $http->get('validator/api/merchantTransIDvalidationAPI.php',[
131+
'query' => [
132+
'val_id' => $request->val_id,
133+
'store_id' => config('sslcommerz.store_id'),
134+
'store_passwd' => config('sslcommerz.store_password'),
135+
'format' => 'json'
136+
]
137+
]);
138+
139+
return json_decode($response->getBody());
140+
}
141+
}

src/SslcommerzServiceProvider.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Code4mk\Sslcommerz;
4+
5+
6+
use Illuminate\Support\ServiceProvider;
7+
use Illuminate\Foundation\AliasLoader;
8+
9+
class SslcommerzServiceProvider extends ServiceProvider
10+
{
11+
/**
12+
* Bootstrap any application services.
13+
*
14+
* @return void
15+
*/
16+
public function boot()
17+
{
18+
$this->publishes([
19+
__DIR__ . '/../config/sslcommerz.php' => config_path('sslcommerz.php'),
20+
], 'config');
21+
22+
AliasLoader::getInstance()->alias('SslPayment', 'Code4mk\Sslcommerz\Facades\SslCommerz');
23+
}
24+
25+
/**
26+
* Register any application services.
27+
*
28+
* @return void
29+
*/
30+
public function register()
31+
{
32+
$this->app->bind('sslCommerz', function () {
33+
return new Sslcommerz;
34+
});
35+
}
36+
}

0 commit comments

Comments
 (0)