From bf48856814286751e2f01dd5cc46e847dfbb41db Mon Sep 17 00:00:00 2001 From: Omid Date: Tue, 26 Oct 2021 23:33:55 +0330 Subject: [PATCH] fix: IDPay verification --- src/Drivers/IDPay/IDPay.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Drivers/IDPay/IDPay.php b/src/Drivers/IDPay/IDPay.php index 538e0da..f2a50ef 100644 --- a/src/Drivers/IDPay/IDPay.php +++ b/src/Drivers/IDPay/IDPay.php @@ -5,7 +5,6 @@ use Illuminate\Support\Facades\Http; use Illuminate\Support\Str; use Omalizadeh\MultiPayment\Drivers\Contracts\Driver; -use Omalizadeh\MultiPayment\Exceptions\HttpRequestFailedException; use Omalizadeh\MultiPayment\Exceptions\InvalidConfigurationException; use Omalizadeh\MultiPayment\Exceptions\PaymentAlreadyVerifiedException; use Omalizadeh\MultiPayment\Exceptions\PaymentFailedException; @@ -40,6 +39,17 @@ public function pay(): RedirectionForm public function verify(): Receipt { + $status = (int) request('status'); + + if (!in_array($status, [ + $this->getPendingVerificationStatusCode(), + $this->getPaymentAlreadyVerifiedStatusCode(), + $this->getSuccessResponseStatusCode() + ], true) + ) { + throw new PaymentFailedException($this->getStatusMessage($status), $status); + } + $response = $this->callApi($this->getVerificationUrl(), $this->getVerificationData()); if (isset($response['error_code'])) { @@ -153,6 +163,11 @@ protected function getSuccessResponseStatusCode(): int return 100; } + private function getPendingVerificationStatusCode(): int + { + return 10; + } + private function getPaymentAlreadyVerifiedStatusCode(): int { return 101; @@ -177,11 +192,7 @@ private function callApi(string $url, array $data) { $response = Http::withHeaders($this->getRequestHeaders())->post($url, $data); - if ($response->successful()) { - return $response->json(); - } - - throw new HttpRequestFailedException($response->body(), $response->status()); + return $response->json(); } private function getRequestHeaders(): array