Skip to content

Commit dc0fb24

Browse files
committed
normalized parameters name - all to lowercase
1 parent 10e14e7 commit dc0fb24

File tree

8 files changed

+62
-35
lines changed

8 files changed

+62
-35
lines changed

src/Adapter/AdapterAbstract.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function init() { }
8080
*/
8181
public function __set($key, $val)
8282
{
83+
$key = strtolower($key);
8384
$this->parameters[$key] = trim($val);
8485
}
8586

@@ -90,6 +91,7 @@ public function __set($key, $val)
9091
*/
9192
public function __get($key)
9293
{
94+
$key = strtolower($key);
9395
return isset($this->parameters[$key]) ? trim($this->parameters[$key]) : null;
9496
}
9597

@@ -110,6 +112,7 @@ public function getTransaction(): TransactionInterface
110112
public function setParameters(array $parameters = []): AdapterInterface
111113
{
112114
foreach ($parameters as $key => $value) {
115+
$key = strtolower($key);
113116
$this->parameters[$key] = trim($value);
114117
}
115118

@@ -123,6 +126,7 @@ public function setParameters(array $parameters = []): AdapterInterface
123126
*/
124127
public function getParameter($key)
125128
{
129+
$key = strtolower($key);
126130
return isset($this->parameters[$key]) ? trim($this->parameters[$key]) : null;
127131
}
128132

@@ -177,6 +181,8 @@ public function reverse(): bool
177181
*/
178182
protected function checkRequiredParameters(array $parameters)
179183
{
184+
$parameters = array_change_key_case($parameters,CASE_LOWER);
185+
180186
foreach ($parameters as $parameter) {
181187
if (!array_key_exists($parameter, $this->parameters) || trim($this->parameters[$parameter]) == "") {
182188
throw new Exception("Parameters array must have a not null value for key: '$parameter'");
@@ -187,7 +193,7 @@ protected function checkRequiredParameters(array $parameters)
187193
/**
188194
* @return string
189195
*/
190-
protected function getWSDL()
196+
protected function getWSDL(): string
191197
{
192198
if (config('larapay.mode') == 'production') {
193199
return $this->WSDL;
@@ -199,7 +205,7 @@ protected function getWSDL()
199205
/**
200206
* @return string
201207
*/
202-
protected function getEndPoint()
208+
protected function getEndPoint(): string
203209
{
204210
if (config('larapay.mode') == 'production') {
205211
return $this->endPoint;
@@ -228,7 +234,7 @@ public function setSoapOptions(array $options = [])
228234
/**
229235
* @return array
230236
*/
231-
protected function getSoapOptions()
237+
protected function getSoapOptions(): array
232238
{
233239
return $this->soapOptions;
234240
}
@@ -255,7 +261,7 @@ public function getGatewayReferenceId(): string
255261
/**
256262
* @return bool
257263
*/
258-
public function reverseSupport()
264+
public function reverseSupport(): bool
259265
{
260266
return $this->reverseSupport;
261267
}
@@ -273,7 +279,7 @@ public function canContinueWithCallbackParameters(): bool
273279
*
274280
* @return array
275281
*/
276-
protected function obj2array($obj)
282+
protected function obj2array($obj): array
277283
{
278284
$out = [];
279285
foreach ($obj as $key => $val) {

src/Adapter/Mellat.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ protected function verifyTransaction()
116116
'SaleOrderId',
117117
'SaleReferenceId',
118118
'CardHolderInfo',
119+
'CardHolderPan',
119120
]);
120121

121122
$sendParams = [
@@ -282,7 +283,7 @@ protected function settleTransaction()
282283
* @throws Exception
283284
* @throws \Tartan\Larapay\Adapter\Exception
284285
*/
285-
protected function reverseTransaction()
286+
protected function reverseTransaction(): bool
286287
{
287288
if ($this->reverseSupport == false || $this->getTransaction()->checkForReverse() == false) {
288289
throw new Exception('larapay::larapay.could_not_reverse_payment');

src/Adapter/Parsian.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected function requestToken()
9595
* @throws Exception
9696
* @throws \Tartan\Larapay\Adapter\Exception
9797
*/
98-
protected function generateForm()
98+
protected function generateForm(): string
9999
{
100100
$authority = $this->requestToken();
101101

@@ -112,7 +112,7 @@ protected function generateForm()
112112
* @throws Exception
113113
* @throws \Tartan\Larapay\Adapter\Exception
114114
*/
115-
protected function verifyTransaction()
115+
protected function verifyTransaction(): bool
116116
{
117117
if ($this->getTransaction()->checkForVerify() == false) {
118118
throw new Exception('larapay::larapay.could_not_verify_payment');
@@ -166,7 +166,7 @@ protected function verifyTransaction()
166166
* @throws Exception
167167
* @throws \Tartan\Larapay\Adapter\Exception
168168
*/
169-
protected function reverseTransaction()
169+
protected function reverseTransaction(): bool
170170
{
171171
if ($this->reverseSupport == false || $this->getTransaction()->checkForReverse() == false) {
172172
throw new Exception('larapay::larapay.could_not_reverse_payment');
@@ -218,7 +218,7 @@ public function getGatewayReferenceId(): string
218218
}
219219

220220

221-
protected function getWSDL()
221+
protected function getWSDL(): string
222222
{
223223

224224
$type = $this->requestType;

src/Adapter/Pasargad.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function generateForm(): string
7676
* @return bool
7777
* @throws Exception
7878
*/
79-
protected function verifyTransaction()
79+
protected function verifyTransaction(): bool
8080
{
8181
$this->checkRequiredParameters([
8282
'iN',
@@ -136,7 +136,7 @@ protected function verifyTransaction()
136136
* @return bool
137137
* @throws Exception
138138
*/
139-
protected function reverseTransaction()
139+
protected function reverseTransaction(): bool
140140
{
141141
$this->checkRequiredParameters([
142142
'iN',

src/Adapter/Payir.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class Payir extends AdapterAbstract implements AdapterInterface
1919
public $reverseSupport = false;
2020

2121
/**
22-
* @return array
22+
* @return string
2323
* @throws Exception
2424
* @throws \Tartan\Larapay\Adapter\Exception
2525
*/
26-
protected function requestToken()
26+
protected function requestToken(): string
2727
{
2828
if ($this->getTransaction()->checkForRequestToken() == false) {
2929
throw new Exception('larapay::larapay.could_not_request_payment');
@@ -46,8 +46,6 @@ protected function requestToken()
4646
];
4747

4848
try {
49-
50-
5149
Log::debug('PaymentRequest call', $sendParams);
5250
$result = Helper::post2https($sendParams, $this->endPoint);
5351

@@ -79,7 +77,7 @@ protected function requestToken()
7977
* @throws Exception
8078
* @throws \Tartan\Larapay\Adapter\Exception
8179
*/
82-
protected function generateForm()
80+
protected function generateForm(): string
8381
{
8482
$authority = $this->requestToken();
8583

@@ -95,7 +93,7 @@ protected function generateForm()
9593
* @throws Exception
9694
* @throws \Tartan\Larapay\Adapter\Exception
9795
*/
98-
protected function verifyTransaction()
96+
protected function verifyTransaction(): bool
9997
{
10098
if ($this->getTransaction()->checkForVerify() == false) {
10199
throw new Exception('larapay::larapay.could_not_verify_payment');

src/Adapter/Saman.php

+34-12
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class Saman extends AdapterAbstract implements AdapterInterface
2424
protected $reverseSupport = true;
2525

2626
/**
27-
* @return array
28-
* @throws Exception
27+
* @return string
28+
* @throws \Tartan\Larapay\Adapter\Exception
2929
*/
30-
protected function requestToken()
30+
protected function requestToken(): string
3131
{
3232
Log::debug(__METHOD__);
3333

@@ -74,7 +74,7 @@ protected function requestToken()
7474
}
7575
}
7676

77-
public function generateForm()
77+
public function generateForm(): string
7878
{
7979
Log::debug(__METHOD__);
8080

@@ -85,7 +85,7 @@ public function generateForm()
8585
}
8686
}
8787

88-
protected function generateFormWithoutToken()
88+
protected function generateFormWithoutToken(): string
8989
{
9090
Log::debug(__METHOD__, $this->getParameters());
9191

@@ -107,7 +107,7 @@ protected function generateFormWithoutToken()
107107
]);
108108
}
109109

110-
protected function generateFormWithToken()
110+
protected function generateFormWithToken(): string
111111
{
112112
Log::debug(__METHOD__, $this->getParameters());
113113
$this->checkRequiredParameters([
@@ -133,7 +133,12 @@ protected function generateFormWithToken()
133133
]);
134134
}
135135

136-
protected function verifyTransaction()
136+
/**
137+
* @return bool
138+
* @throws Exception
139+
* @throws \Tartan\Larapay\Adapter\Exception
140+
*/
141+
protected function verifyTransaction(): bool
137142
{
138143
if ($this->getTransaction()->checkForVerify() == false) {
139144
throw new Exception('larapay::larapay.could_not_verify_payment');
@@ -144,7 +149,8 @@ protected function verifyTransaction()
144149
'RefNum',
145150
'ResNum',
146151
'merchant_id',
147-
'TRACENO',
152+
'TraceNo',
153+
'SecurePan'
148154
]);
149155

150156
if ($this->State != 'OK') {
@@ -160,8 +166,10 @@ protected function verifyTransaction()
160166
if (isset($response)) {
161167
Log::info('VerifyTransaction response', ['response' => $response]);
162168

163-
if ($response == $this->getTransaction()->getPayableAmount()) { // check by transaction amount
164-
$this->getTransaction()->setVerified();
169+
if ($response == $this->getTransaction()->getPayableAmount()) {
170+
// double check the amount by transaction amount
171+
$this->getTransaction()->setCardNumber($this->SecurePan, false); // no save()
172+
$this->getTransaction()->setVerified(); // with save()
165173

166174
return true;
167175
} else {
@@ -176,7 +184,12 @@ protected function verifyTransaction()
176184
}
177185
}
178186

179-
protected function reverseTransaction()
187+
/**
188+
* @return bool
189+
* @throws Exception
190+
* @throws \Tartan\Larapay\Adapter\Exception
191+
*/
192+
protected function reverseTransaction(): bool
180193
{
181194
if ($this->reverseSupport == false || $this->getTransaction()->checkForReverse() == false) {
182195
throw new Exception('larapay::larapay.could_not_reverse_payment');
@@ -240,6 +253,10 @@ public function canContinueWithCallbackParameters(): bool
240253
return false;
241254
}
242255

256+
/**
257+
* @return string
258+
* @throws \Tartan\Larapay\Adapter\Exception
259+
*/
243260
public function getGatewayReferenceId(): string
244261
{
245262
$this->checkRequiredParameters([
@@ -249,7 +266,12 @@ public function getGatewayReferenceId(): string
249266
return $this->RefNum;
250267
}
251268

252-
protected function getWSDL($type = null)
269+
/**
270+
* @param string $type
271+
*
272+
* @return string
273+
*/
274+
protected function getWSDL($type = null): string
253275
{
254276
if (config('larapay.mode') == 'production') {
255277
switch (strtoupper($type)) {

src/Adapter/Zarinpal.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class Zarinpal extends AdapterAbstract implements AdapterInterface
2525
public $reverseSupport = false;
2626

2727
/**
28-
* @return array
28+
* @return string
2929
* @throws Exception
3030
* @throws \Tartan\Larapay\Adapter\Exception
3131
*/
32-
protected function requestToken()
32+
protected function requestToken(): string
3333
{
3434
if ($this->getTransaction()->checkForRequestToken() == false) {
3535
throw new Exception('larapay::larapay.could_not_request_payment');
@@ -83,7 +83,7 @@ protected function requestToken()
8383
* @throws Exception
8484
* @throws \Tartan\Larapay\Adapter\Exception
8585
*/
86-
protected function generateForm()
86+
protected function generateForm(): string
8787
{
8888
$authority = $this->requestToken();
8989

@@ -99,7 +99,7 @@ protected function generateForm()
9999
* @throws Exception
100100
* @throws \Tartan\Larapay\Adapter\Exception
101101
*/
102-
protected function verifyTransaction()
102+
protected function verifyTransaction(): bool
103103
{
104104
if ($this->getTransaction()->checkForVerify() == false) {
105105
throw new Exception('larapay::larapay.could_not_verify_payment');

src/Factory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function __call ($name, $arguments)
8686
try {
8787
return call_user_func_array([$this->gateway, $name], $arguments); // call desire method
8888
} catch (\Exception $e) {
89-
Log::error($e->getMessage() .' #'.$e->getCode(). ' File:'.$e->getFile().':'.$e->getLine());
89+
Log::error($e->getMessage() .' Code:'.$e->getCode(). ' File:'.$e->getFile().':'.$e->getLine());
9090
throw $e;
9191
}
9292
}

0 commit comments

Comments
 (0)