Skip to content

Commit

Permalink
Moved retry fields validation in RequestConfig.php
Browse files Browse the repository at this point in the history
  • Loading branch information
DF-Dave committed Jul 22, 2024
1 parent 300013d commit 514bb0c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
20 changes: 5 additions & 15 deletions lib/SaferpayJson/Request/Container/RequestHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

namespace Ticketpark\SaferpayJson\Request\Container;

use InvalidArgumentException;
use JMS\Serializer\Annotation\SerializedName;
use Ticketpark\SaferpayJson\Request\RequestConfig;

final class RequestHeader
{
private const MIN_RETRY_INDICATOR = 0;
private const MAX_RETRY_INDICATOR = 9;

/**
* @SerializedName("SpecVersion")
*/
Expand All @@ -37,19 +34,12 @@ final class RequestHeader
*/
private ?ClientInfo $clientInfo = null;

public function __construct(string $customerId, string $requestId = null, int $retryIndicator = self::MIN_RETRY_INDICATOR)
public function __construct(
string $customerId,
string $requestId = null,
int $retryIndicator = RequestConfig::MIN_RETRY_INDICATOR)
{
$this->customerId = $customerId;

if ($retryIndicator < self::MIN_RETRY_INDICATOR || $retryIndicator > self::MAX_RETRY_INDICATOR) {
throw new InvalidArgumentException('Retry indicator range: inclusive between '
. self::MIN_RETRY_INDICATOR . ' and ' . self::MAX_RETRY_INDICATOR);
}

if ($retryIndicator > self::MIN_RETRY_INDICATOR && $requestId === null) {
throw new InvalidArgumentException('Request id must be set if retry indicator is greater than 0');
}

$this->requestId = $requestId;
$this->retryIndicator = $retryIndicator;

Expand Down
14 changes: 14 additions & 0 deletions lib/SaferpayJson/Request/RequestConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
namespace Ticketpark\SaferpayJson\Request;

use GuzzleHttp\Client;
use InvalidArgumentException;

final class RequestConfig
{
public const MIN_RETRY_INDICATOR = 0;
public const MAX_RETRY_INDICATOR = 9;

private string $apiKey;
private string $apiSecret;
private string $customerId;
Expand All @@ -28,6 +32,16 @@ public function __construct(
$this->apiSecret = $apiSecret;
$this->customerId = $customerId;
$this->test = $test;

if ($retryIndicator < self::MIN_RETRY_INDICATOR || $retryIndicator > self::MAX_RETRY_INDICATOR) {
throw new InvalidArgumentException('Retry indicator range: inclusive between '
. self::MIN_RETRY_INDICATOR . ' and ' . self::MAX_RETRY_INDICATOR);
}

if ($retryIndicator > self::MIN_RETRY_INDICATOR && $requestId === null) {
throw new InvalidArgumentException('Request id must be set if retry indicator is greater than 0');
}

$this->requestId = $requestId;
$this->retryIndicator = $retryIndicator;
}
Expand Down

0 comments on commit 514bb0c

Please sign in to comment.