Skip to content

Commit 60c8703

Browse files
author
Liam Jackson
committed
fix: throw invalid currency exception when invalid currency has been passed.
1 parent ebed7e9 commit 60c8703

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
4+
namespace LJJackson\Volt\Exceptions;
5+
6+
7+
use InvalidArgumentException;
8+
9+
class InvalidCurrencyException extends InvalidArgumentException
10+
{
11+
12+
}

src/Services/PaymentService.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use GuzzleHttp\RequestOptions;
88
use LJJackson\Volt\Entities\AccessToken;
99
use LJJackson\Volt\Entities\PaymentRequest;
10+
use LJJackson\Volt\Exceptions\InvalidCurrencyException;
1011
use LJJackson\Volt\Exceptions\PaymentValidationException;
1112

1213
class PaymentService extends BaseService
@@ -29,9 +30,17 @@ public function requestPayment(AccessToken $token, array $data): PaymentRequest
2930
RequestOptions::JSON => $data,
3031
]);
3132
} catch (RequestException $exception) {
32-
$response = json_decode($exception->getResponse()->getBody()->getContents(), true);
33+
if ($exception->getResponse()->getStatusCode() === 400) {
34+
$response = json_decode($exception->getResponse()->getBody()->getContents(), true);
35+
throw new PaymentValidationException($response['exception']['errorList'], $exception->getResponse()->getStatusCode());
36+
}
37+
38+
if ($exception->getResponse()->getStatusCode() === 422) {
39+
throw new InvalidCurrencyException();
40+
}
41+
42+
throw $exception;
3343

34-
throw new PaymentValidationException($response['exception']['errorList'], $exception->getResponse()->getStatusCode());
3544
}
3645

3746
$request = new PaymentRequest(json_decode($response->getBody()->getContents(), true));

0 commit comments

Comments
 (0)