From 2f924a635c7d75f92de343ebe49e6b0d5d0ef4cd Mon Sep 17 00:00:00 2001 From: Milad Kian Date: Mon, 13 Jul 2020 17:10:52 +0430 Subject: [PATCH] add retry to get token --- src/Adapter/Parsian.php | 45 ++++++++++++++++++++----------- src/Models/LarapayTransaction.php | 4 +-- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/Adapter/Parsian.php b/src/Adapter/Parsian.php index c653b93..de15944 100755 --- a/src/Adapter/Parsian.php +++ b/src/Adapter/Parsian.php @@ -1,6 +1,6 @@ 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()); } } diff --git a/src/Models/LarapayTransaction.php b/src/Models/LarapayTransaction.php index a076228..1594e5c 100644 --- a/src/Models/LarapayTransaction.php +++ b/src/Models/LarapayTransaction.php @@ -1,5 +1,5 @@ gate_name . ' #' . $e->getCode() . '-' . $e->getMessage()); - return ''; + throw $e; } }