Skip to content

Commit

Permalink
Merge pull request #28 from miladkian/master
Browse files Browse the repository at this point in the history
Add retry to get token
  • Loading branch information
Aboozar Ghaffari authored Sep 21, 2020
2 parents c8dbd11 + 2f924a6 commit 88fc481
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
45 changes: 29 additions & 16 deletions src/Adapter/Parsian.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace Tartan\Larapay\Adapter;

Expand Down Expand Up @@ -90,29 +90,42 @@ protected function requestToken()
*/
private function requestTokenWithoutSharing($sendParams)
{
try {
$this->requestType = 'request';
$soapClient = $this->getSoapClient();
for ($i = 1; $i <= 3; $i++) {
try {

$this->requestType = 'request';
$soapClient = $this->getSoapClient();

XLog::debug('SalePaymentRequest call', $sendParams);
XLog::debug('SalePaymentRequest call', $sendParams);

$response = $soapClient->SalePaymentRequest(array("requestData" => $sendParams));
$response = $soapClient->SalePaymentRequest(array("requestData" => $sendParams));

XLog::debug('SalePaymentRequest response', $this->obj2array($response));
XLog::debug('SalePaymentRequest response', $this->obj2array($response));

if (isset($response->SalePaymentRequestResult->Status, $response->SalePaymentRequestResult->Token)) {
if ($response->SalePaymentRequestResult->Status == 0) {
$this->getTransaction()->setGatewayToken(strval($response->SalePaymentRequestResult->Token)); // update transaction reference id
if (isset($response->SalePaymentRequestResult->Status, $response->SalePaymentRequestResult->Token)) {
if ($response->SalePaymentRequestResult->Status == 0) {
$this->getTransaction()->setGatewayToken(strval($response->SalePaymentRequestResult->Token)); // update transaction reference id

return $response->SalePaymentRequestResult->Token;
return $response->SalePaymentRequestResult->Token;
} else {
if ($i == 3) {
throw new Exception($response->SalePaymentRequestResult->Status);
}
usleep(500);
}
} else {
throw new Exception($response->SalePaymentRequestResult->Status);
if ($i == 3) {
throw new Exception('larapay::parsian.errors.invalid_response');
}
usleep(500);
}
} else {
throw new Exception('larapay::parsian.errors.invalid_response');

} catch (SoapFault $e) {
if ($i == 3) {
throw new Exception('SoapFault: ' . $e->getMessage() . ' #' . $e->getCode(), $e->getCode());
}
usleep(500);
}
} catch (SoapFault $e) {
throw new Exception('SoapFault: ' . $e->getMessage() . ' #' . $e->getCode(), $e->getCode());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Models/LarapayTransaction.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
declare(strict_types = 1);
declare(strict_types=1);

namespace Tartan\Larapay\Models;

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

return '';
throw $e;
}
}

Expand Down

0 comments on commit 88fc481

Please sign in to comment.