Skip to content

Commit

Permalink
Correctly reset endpoint for new claims
Browse files Browse the repository at this point in the history
Fixes the process breaking after a poll
  • Loading branch information
NoelLH committed Apr 4, 2022
1 parent 77bb0bb commit 7b8671b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
25 changes: 15 additions & 10 deletions src/GiftAid.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ class GiftAid extends GovTalk
*/
private array $donationIdMap = [];

private ?string $customTestEndpoint = null;
private ?bool $testMode = null;

/**
* The class is instantiated with the 'SenderID' and password issued to the
* claiming charity by HMRC. Also we need to know whether messages for
Expand All @@ -177,18 +180,19 @@ public function __construct(
string $route_uri,
string $software_name,
string $software_version,
bool $test = false,
bool $testMode = false,
?Client $httpClient = null,
?string $customTestEndpoint = null
) {
$test = is_bool($test) ? $test : false;
$this->testMode = $testMode;
$this->customTestEndpoint = $customTestEndpoint;

$endpoint = $this->getEndpoint($test, $customTestEndpoint);
$endpoint = $this->getClaimEndpoint();

$this->setProductUri($route_uri);
$this->setProductName($software_name);
$this->setProductVersion($software_version);
$this->setTestFlag($test);
$this->setTestFlag($this->testMode);

parent::__construct(
$endpoint,
Expand Down Expand Up @@ -221,15 +225,13 @@ public function setLogger(LoggerInterface $logger): void
* @link https://www.gov.uk/government/publications/local-test-service-and-lts-update-manager
* @link https://github.com/comicrelief/gail/blob/e80a0793b5dac8b9c8e037e409a398eaf79342d3/Documents/technical_guidance.md
*/
public function getEndpoint($test = false, ?string $customTestEndpoint = null): string
public function getClaimEndpoint(): string
{
$test = is_bool($test) ? $test : false;

if ($test && $customTestEndpoint) {
return $customTestEndpoint;
if ($this->testMode && $this->customTestEndpoint) {
return $this->customTestEndpoint;
}

return $test ? $this->devEndpoint : $this->liveEndpoint;
return $this->testMode ? $this->devEndpoint : $this->liveEndpoint;
}

/**
Expand Down Expand Up @@ -656,6 +658,9 @@ public function giftAidSubmit($donor_data)
return false;
}

// Ensure we are using the correct endpoint even if a poll has just happened.
$this->setGovTalkServer($this->getClaimEndpoint());

$cOrganisation = 'IR';
$sDefaultCurrency = 'GBP'; // currently HMRC only allows GBP
$sIRmark = 'IRmark+Token';
Expand Down
6 changes: 3 additions & 3 deletions tests/GovTalk/GiftAid/GiftAidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ public function testClaimingOrganisation()

public function testEndpoint()
{
$testEndpoint = $this->gaService->getEndpoint(true);
$liveEndpoint = $this->gaService->getEndpoint(false);
$testEndpoint = $this->gaService->getClaimEndpoint();

$this->assertNotSame($liveEndpoint, $testEndpoint);
// No longer possible to override test mode for individual URL requests.
$this->assertEquals('https://test-transaction-engine.tax.service.gov.uk/submission', $testEndpoint);
}

public function testAdjustments()
Expand Down

0 comments on commit 7b8671b

Please sign in to comment.