Skip to content

Commit

Permalink
fix: IDPay verification
Browse files Browse the repository at this point in the history
  • Loading branch information
omalizadeh committed Oct 26, 2021
1 parent 37490e8 commit bf48856
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/Drivers/IDPay/IDPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'])) {
Expand Down Expand Up @@ -153,6 +163,11 @@ protected function getSuccessResponseStatusCode(): int
return 100;
}

private function getPendingVerificationStatusCode(): int
{
return 10;
}

private function getPaymentAlreadyVerifiedStatusCode(): int
{
return 101;
Expand All @@ -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
Expand Down

0 comments on commit bf48856

Please sign in to comment.