diff --git a/src/GiftAid.php b/src/GiftAid.php index 48a5638..8039f8e 100644 --- a/src/GiftAid.php +++ b/src/GiftAid.php @@ -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 @@ -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, @@ -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; } /** @@ -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'; diff --git a/tests/GovTalk/GiftAid/GiftAidTest.php b/tests/GovTalk/GiftAid/GiftAidTest.php index 8b603c9..88be061 100644 --- a/tests/GovTalk/GiftAid/GiftAidTest.php +++ b/tests/GovTalk/GiftAid/GiftAidTest.php @@ -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()