From 300013d9e87065df4c23b36b0234085a0ad2ff97 Mon Sep 17 00:00:00 2001 From: David Funke Date: Mon, 22 Jul 2024 14:31:09 +0200 Subject: [PATCH] Added retry fields in RequestConfig.php --- .../Request/Container/RequestHeader.php | 16 +++++++++++++- lib/SaferpayJson/Request/Request.php | 4 +++- lib/SaferpayJson/Request/RequestConfig.php | 22 ++++++++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/SaferpayJson/Request/Container/RequestHeader.php b/lib/SaferpayJson/Request/Container/RequestHeader.php index ec40baf..5071c2c 100644 --- a/lib/SaferpayJson/Request/Container/RequestHeader.php +++ b/lib/SaferpayJson/Request/Container/RequestHeader.php @@ -4,10 +4,14 @@ namespace Ticketpark\SaferpayJson\Request\Container; +use InvalidArgumentException; use JMS\Serializer\Annotation\SerializedName; final class RequestHeader { + private const MIN_RETRY_INDICATOR = 0; + private const MAX_RETRY_INDICATOR = 9; + /** * @SerializedName("SpecVersion") */ @@ -33,9 +37,19 @@ final class RequestHeader */ private ?ClientInfo $clientInfo = null; - public function __construct(string $customerId, string $requestId = null, int $retryIndicator = 0) + public function __construct(string $customerId, string $requestId = null, int $retryIndicator = self::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; diff --git a/lib/SaferpayJson/Request/Request.php b/lib/SaferpayJson/Request/Request.php index d336945..b0a9064 100644 --- a/lib/SaferpayJson/Request/Request.php +++ b/lib/SaferpayJson/Request/Request.php @@ -50,7 +50,9 @@ public function __construct(RequestConfig $requestConfig) public function getRequestHeader(): RequestHeader { return new RequestHeader( - $this->requestConfig->getCustomerId() + $this->requestConfig->getCustomerId(), + $this->requestConfig->getRequestId(), + $this->requestConfig->getRetryIndicator() ); } diff --git a/lib/SaferpayJson/Request/RequestConfig.php b/lib/SaferpayJson/Request/RequestConfig.php index e482ee5..8ba2e0c 100644 --- a/lib/SaferpayJson/Request/RequestConfig.php +++ b/lib/SaferpayJson/Request/RequestConfig.php @@ -13,13 +13,23 @@ final class RequestConfig private string $customerId; private bool $test; private ?Client $client = null; + private ?string $requestId; + private int $retryIndicator; - public function __construct(string $apiKey, string $apiSecret, string $customerId, bool $test = false) + public function __construct( + string $apiKey, + string $apiSecret, + string $customerId, + bool $test = false, + ?string $requestId = null, + int $retryIndicator = 0) { $this->apiKey = $apiKey; $this->apiSecret = $apiSecret; $this->customerId = $customerId; $this->test = $test; + $this->requestId = $requestId; + $this->retryIndicator = $retryIndicator; } public function getApiKey(): string @@ -57,4 +67,14 @@ public function getClient(): Client return $this->client; } + + public function getRequestId(): ?string + { + return $this->requestId; + } + + public function getRetryIndicator(): int + { + return $this->retryIndicator; + } }