Skip to content

Commit 88fc481

Browse files
author
Aboozar Ghaffari
authored
Merge pull request #28 from miladkian/master
Add retry to get token
2 parents c8dbd11 + 2f924a6 commit 88fc481

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

src/Adapter/Parsian.php

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
namespace Tartan\Larapay\Adapter;
66

@@ -90,29 +90,42 @@ protected function requestToken()
9090
*/
9191
private function requestTokenWithoutSharing($sendParams)
9292
{
93-
try {
94-
$this->requestType = 'request';
95-
$soapClient = $this->getSoapClient();
93+
for ($i = 1; $i <= 3; $i++) {
94+
try {
95+
96+
$this->requestType = 'request';
97+
$soapClient = $this->getSoapClient();
9698

97-
XLog::debug('SalePaymentRequest call', $sendParams);
99+
XLog::debug('SalePaymentRequest call', $sendParams);
98100

99-
$response = $soapClient->SalePaymentRequest(array("requestData" => $sendParams));
101+
$response = $soapClient->SalePaymentRequest(array("requestData" => $sendParams));
100102

101-
XLog::debug('SalePaymentRequest response', $this->obj2array($response));
103+
XLog::debug('SalePaymentRequest response', $this->obj2array($response));
102104

103-
if (isset($response->SalePaymentRequestResult->Status, $response->SalePaymentRequestResult->Token)) {
104-
if ($response->SalePaymentRequestResult->Status == 0) {
105-
$this->getTransaction()->setGatewayToken(strval($response->SalePaymentRequestResult->Token)); // update transaction reference id
105+
if (isset($response->SalePaymentRequestResult->Status, $response->SalePaymentRequestResult->Token)) {
106+
if ($response->SalePaymentRequestResult->Status == 0) {
107+
$this->getTransaction()->setGatewayToken(strval($response->SalePaymentRequestResult->Token)); // update transaction reference id
106108

107-
return $response->SalePaymentRequestResult->Token;
109+
return $response->SalePaymentRequestResult->Token;
110+
} else {
111+
if ($i == 3) {
112+
throw new Exception($response->SalePaymentRequestResult->Status);
113+
}
114+
usleep(500);
115+
}
108116
} else {
109-
throw new Exception($response->SalePaymentRequestResult->Status);
117+
if ($i == 3) {
118+
throw new Exception('larapay::parsian.errors.invalid_response');
119+
}
120+
usleep(500);
110121
}
111-
} else {
112-
throw new Exception('larapay::parsian.errors.invalid_response');
122+
123+
} catch (SoapFault $e) {
124+
if ($i == 3) {
125+
throw new Exception('SoapFault: ' . $e->getMessage() . ' #' . $e->getCode(), $e->getCode());
126+
}
127+
usleep(500);
113128
}
114-
} catch (SoapFault $e) {
115-
throw new Exception('SoapFault: ' . $e->getMessage() . ' #' . $e->getCode(), $e->getCode());
116129
}
117130
}
118131

src/Models/LarapayTransaction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
declare(strict_types = 1);
2+
declare(strict_types=1);
33

44
namespace Tartan\Larapay\Models;
55

@@ -126,7 +126,7 @@ public function generateForm($autoSubmit = false, $callback = null, $adapterConf
126126
} catch (Exception $e) {
127127
XLog::emergency($this->gate_name . ' #' . $e->getCode() . '-' . $e->getMessage());
128128

129-
return '';
129+
throw $e;
130130
}
131131
}
132132

0 commit comments

Comments
 (0)