Skip to content

Commit

Permalink
Added retry fields 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 ca4f76d commit 300013d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
16 changes: 15 additions & 1 deletion lib/SaferpayJson/Request/Container/RequestHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")
*/
Expand All @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion lib/SaferpayJson/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}

Expand Down
22 changes: 21 additions & 1 deletion lib/SaferpayJson/Request/RequestConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 300013d

Please sign in to comment.