Skip to content

Commit

Permalink
Revert "Add retry mechanism via request header"
Browse files Browse the repository at this point in the history
  • Loading branch information
sprain authored Jul 24, 2024
1 parent 625af7c commit 9b5e5fa
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 147 deletions.
67 changes: 0 additions & 67 deletions example/Transaction/example-authorize-retry.php

This file was deleted.

8 changes: 2 additions & 6 deletions lib/SaferpayJson/Request/Container/RequestHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Ticketpark\SaferpayJson\Request\Container;

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

final class RequestHeader
{
Expand Down Expand Up @@ -34,11 +33,8 @@ final class RequestHeader
*/
private ?ClientInfo $clientInfo = null;

public function __construct(
string $customerId,
string $requestId = null,
int $retryIndicator = RequestConfig::MIN_RETRY_INDICATOR
) {
public function __construct(string $customerId, string $requestId = null, int $retryIndicator = 0)
{
$this->customerId = $customerId;
$this->requestId = $requestId;
$this->retryIndicator = $retryIndicator;
Expand Down
4 changes: 1 addition & 3 deletions lib/SaferpayJson/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ public function __construct(RequestConfig $requestConfig)
public function getRequestHeader(): RequestHeader
{
return new RequestHeader(
$this->requestConfig->getCustomerId(),
$this->requestConfig->getRequestId(),
$this->requestConfig->getRetryIndicator()
$this->requestConfig->getCustomerId()
);
}

Expand Down
38 changes: 2 additions & 36 deletions lib/SaferpayJson/Request/RequestConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,21 @@
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;
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,
?string $requestId = null,
int $retryIndicator = 0
) {
public function __construct(string $apiKey, string $apiSecret, string $customerId, bool $test = false)
{
$this->apiKey = $apiKey;
$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;
}

public function getApiKey(): string
Expand Down Expand Up @@ -81,14 +57,4 @@ public function getClient(): Client

return $this->client;
}

public function getRequestId(): ?string
{
return $this->requestId;
}

public function getRetryIndicator(): int
{
return $this->retryIndicator;
}
}
36 changes: 1 addition & 35 deletions tests/SaferpayJson/Tests/Request/CommonRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response as GuzzleResponse;
use GuzzleHttp\Psr7\Utils as GuzzleUtils;
use InvalidArgumentException;
use JMS\Serializer\SerializerBuilder;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand All @@ -31,39 +30,6 @@ public function testErrorResponse(): void
$this->executeRequest();
}

public function getRequestConfigValidationParams(): array
{
return [
'first try' => [null, RequestConfig::MIN_RETRY_INDICATOR],
'second try' => [uniqid(), RequestConfig::MIN_RETRY_INDICATOR + 1],
'last try' => [uniqid(), RequestConfig::MAX_RETRY_INDICATOR],
'try after all retries exceeded' => [uniqid(), RequestConfig::MAX_RETRY_INDICATOR + 1, InvalidArgumentException::class],
'retry without previous request id' => [null, RequestConfig::MAX_RETRY_INDICATOR, InvalidArgumentException::class],
];
}

/**
* @dataProvider getRequestConfigValidationParams
*/
public function testRequestConfigValidation(
?string $requestId,
int $retryIndicator,
?string $expectedException = null): void
{
if ($expectedException !== null) {
$this->expectException($expectedException, $requestId, $retryIndicator);
}

new RequestConfig(
'apiKey',
'apiSecret',
'customerId',
false,
$requestId,
$retryIndicator
);
}

public function doTestSuccessfulResponse(string $responseClass): void
{
$this->successful = true;
Expand Down Expand Up @@ -121,7 +87,7 @@ private function getResponseMock(): MockObject

$response->expects($this->any())
->method('getStatusCode')
->will($this->returnValue($this->successful ? 200 : 404));
->will($this->returnValue($this->successful ? 200: 404));

if ($this->successful) {
$content = $this->getFakedApiResponse($this->successfulResponseClass);
Expand Down

0 comments on commit 9b5e5fa

Please sign in to comment.