Skip to content

Commit 92ca4d9

Browse files
committed
refactoring for v1.0
1 parent 9bc95ac commit 92ca4d9

File tree

2 files changed

+86
-22
lines changed

2 files changed

+86
-22
lines changed

src/Sslcommerz.php

Lines changed: 81 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,36 @@
44

55
use GuzzleHttp\Client;
66

7-
class Sslcommerz{
7+
/**
8+
* Sslcommerz class
9+
* @author code4mk <[email protected]>
10+
* @version 1.0.0
11+
*/
12+
13+
class Sslcommerz
14+
{
815

916
private $amount;
1017
private $tnx;
11-
private $airTicket = [];
12-
private $emi = false;
1318
private $sslHost;
1419

1520
private $customerData = [
1621
'cus_name' => 'kamal',
1722
'cus_email' => '[email protected]',
18-
'cus_phone' => '01000000000',
23+
'cus_phone' => '00000000000',
1924
'cus_add1' => 'dhaka',
2025
'cus_city' => 'Dhaka',
2126
'cus_postcode' => '1210',
2227
'cus_country' => 'Bangladesh',
2328
];
2429

30+
private $emi = [
31+
'emi_option' => 0,
32+
'emi_max_inst_option' => 3,
33+
'emi_selected_inst' => 2,
34+
'emi_allow_only' => 0,
35+
];
36+
2537
public function __construct()
2638
{
2739
if (config('sslcommerz.sandbox_mode') === 'sandbox') {
@@ -32,33 +44,68 @@ public function __construct()
3244

3345
}
3446

47+
/**
48+
* Set transaction id.
49+
*
50+
* @param int|string $id
51+
* @author code4mk <[email protected]>
52+
* @since v1.0.0
53+
* @version 1.0.0
54+
*/
3555
public function tnx($id)
3656
{
3757
$this->tnx = $id;
3858
return $this;
3959
}
4060

61+
/**
62+
* Set amount.
63+
*
64+
* @param int|float $amount
65+
* @author code4mk <[email protected]>
66+
* @since v1.0.0
67+
* @version 1.0.0
68+
*/
4169
public function amount($amount)
4270
{
4371
$this->amount = $amount;
4472
return $this;
4573
}
4674

47-
public function airlineTickets($data)
48-
{
49-
array_push($this->airTicket,$data);
50-
return $this;
51-
52-
}
5375

54-
public function emi($month,$selectedMonth)
76+
/**
77+
* Set emi option.
78+
*
79+
* @param int $max_inst emi_max_inst_option
80+
* @param int $selected_inst emi_selected_inst
81+
* @param int $allow_only emi_allow_only(0,1)*
82+
* @author code4mk <[email protected]>
83+
* @since v1.0.0
84+
* @version 1.0.0
85+
*/
86+
public function emi($max_inst = '',$selected_inst = '',$allow_only = '')
5587
{
56-
$this->emi = true;
57-
$this->month = $month;
58-
$this->selectedMonth = $selectedMonth;
88+
$this->emi['emi_option'] = 1;
89+
$this->emi['emi_max_inst_option'] = $max_inst == '' ? 3 : $max_inst;
90+
$this->emi['emi_selected_inst'] = $selected_inst == '' ? 3 : $selected_inst;
91+
$this->emi['emi_allow_only'] = $allow_only == '' ? 0 : $allow_only;
5992
return $this;
6093
}
6194

95+
/**
96+
* Set customer information.
97+
*
98+
* @param string $name
99+
* @param string $email
100+
* @param string $phone
101+
* @param string $add1
102+
* @param string $city
103+
* @param string $post_code
104+
* @param string $country
105+
* @author code4mk <[email protected]>
106+
* @since v1.0.0
107+
* @version 1.0.0
108+
*/
62109
public function customer($name = '', $email = '', $phone = '', $add1 = '', $city = '', $post_code = '', $country = ''){
63110
$this->customerData['cus_name'] = $name == '' ? $this->customerData['cus_name'] : $name;
64111
$this->customerData['cus_email'] = $email == '' ? $this->customerData['cus_email'] : $email;
@@ -70,6 +117,14 @@ public function customer($name = '', $email = '', $phone = '', $add1 = '', $city
70117
return $this;
71118
}
72119

120+
/**
121+
* Get response where you can get GatewayPageURL
122+
*
123+
* @return object
124+
* @author code4mk <[email protected]>
125+
* @since v1.0.0
126+
* @version 1.0.0
127+
*/
73128
public function getRedirectUrl()
74129
{
75130
$data = [
@@ -94,18 +149,16 @@ public function getRedirectUrl()
94149
'product_profile' => 'general',
95150
'shipping_method' => 'NO',
96151
'multi_card_name'=>'mastercard,visacard,amexcard',
152+
'emi_option' => $this->emi['emi_option'],
153+
'emi_selected_inst' => $this->emi['emi_selected_inst'],
154+
'emi_max_inst_option' => $this->emi['emi_max_inst_option'] ,
155+
'emi_allow_only' => $this->emi['emi_allow_only'],
97156
'value_a'=>'ref001_A',
98157
'value_b'=>'ref002_B',
99158
'value_c'=>'ref003_C',
100159
'value_d'=>'ref004_D',
101160
];
102161

103-
if($this->emi){
104-
$data['emi'] = 1;
105-
$data['emi_max_inst_option'] = (int) $this->month;
106-
$data['emi_selected_inst'] = (int) $this->selectedMonth;
107-
}
108-
109162
$http = new Client([
110163
'base_uri' => $this->sslHost,
111164
]);
@@ -117,9 +170,16 @@ public function getRedirectUrl()
117170
$body = json_decode($response->getBody());
118171
// return $body->redirectGatewayURL;
119172
return $body;
120-
121173
}
122174

175+
/**
176+
* Verify the transaction.
177+
*
178+
* @return object
179+
* @author code4mk <[email protected]>
180+
* @since v1.0.0
181+
* @version 1.0.0
182+
*/
123183
public function verify($request)
124184
{
125185
$http = new Client([

src/SslcommerzServiceProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
namespace Code4mk\Sslcommerz;
44

5-
65
use Illuminate\Support\ServiceProvider;
76
use Illuminate\Foundation\AliasLoader;
87

8+
/**
9+
* Service Provider class
10+
* @author code4mk <[email protected]>
11+
*/
12+
913
class SslcommerzServiceProvider extends ServiceProvider
1014
{
1115
/**

0 commit comments

Comments
 (0)