Skip to content

Commit

Permalink
Merge pull request #11 from thebiggive/CLA-19-polling-etc
Browse files Browse the repository at this point in the history
CLA-19 – improve polling support + other tweaks
  • Loading branch information
Noel Light-Hilary authored Apr 2, 2022
2 parents 56c3072 + fde3c2b commit 3f934b3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
33 changes: 33 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: 2.1

jobs:
test: # Also lints first
docker:
- image: circleci/php:8.0
auth:
username: $DOCKER_HUB_USERNAME
password: $DOCKER_HUB_ACCESS_TOKEN

steps:
- checkout

- restore_cache:
keys:
- composer-v1-{{ checksum "composer.lock" }}

- run: composer install --no-interaction

- save_cache:
paths:
- vendor
key: composer-v1-{{ checksum "composer.lock" }}

- run: composer run lint:check
- run: composer run test

workflows:
build:
jobs:
- test:
context:
- docker-hub-creds
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
"ext-simplexml": "*",
"ext-xmlwriter": "*",
"ext-zlib": "*",
"thebiggive/php-govtalk": "^1.0.0"
"thebiggive/php-govtalk": "^1.0.1"
},
"require-dev": {
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.5.7",
"roave/security-advisories": "dev-master",
"roave/security-advisories": "dev-latest",
"squizlabs/php_codesniffer": "^3.6.0"
},
"scripts": {
Expand Down
16 changes: 11 additions & 5 deletions src/GiftAid.php
Original file line number Diff line number Diff line change
Expand Up @@ -858,8 +858,8 @@ public function requestClaimData()
}

/**
* Polls the Gateway for a submission response / error following a VAT
* declaration request. By default the correlation ID from the last response
* Polls the Gateway for a submission response / error following a request.
* By default the correlation ID from the last response
* is used for the polling, but this can be over-ridden by supplying a
* correlation ID. The correlation ID can be skipped by passing a null value.
*
Expand Down Expand Up @@ -925,10 +925,14 @@ public function declarationResponsePoll($correlationId = null, $pollUrl = null)
}
} else {
if ($this->responseHasErrors()) {
return [
$returnable = [
'errors' => $this->getResponseErrors(),
'fullResponseString' => $this->fullResponseString
];
$returnable['donation_ids_with_errors'] = $this->getDistinctErroringDonations(
$returnable['errors']['business']
);
return $returnable;
}

return false;
Expand Down Expand Up @@ -1157,8 +1161,10 @@ public function getResponseErrors()
$pattern = '!^/hd:GovTalkMessage\[1]/hd:Body\[1]/r68:IRenvelope\[1]/r68:R68\[1]/' .
'r68:Claim\[(\d+)]/r68:Repayment\[1]/r68:GAD\[(\d+)].+$!';
if (isset($gaError->Location) && preg_match($pattern, $gaError->Location, $matches) === 1) {
if (isset($this->donationIdMap[$matches[1]][$matches[2]])) {
$donationId = $this->donationIdMap[$matches[1]][$matches[2]];
$claimIndex = (int) $matches[1];
$gadIndex = (int) $matches[2];
if (isset($this->donationIdMap[$claimIndex][$gadIndex])) {
$donationId = $this->donationIdMap[$claimIndex][$gadIndex];
}
}

Expand Down
6 changes: 4 additions & 2 deletions tests/GovTalk/GiftAid/GiftAidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,16 +556,18 @@ public function testMultiClaimSubmissionWithMultipleDonationErrors(): void
// `...r68:Claim[2]...`. So the UUID for error index 1 matches our 2nd (index 1)
// donation while that for error index 5 matches our index 0 donation.

// We expect both donations to be in the same claim because they share an HMRC org ref.

$this->assertEquals('some-uuid-1234', $response['errors']['business'][1]['donation_id']);
$this->assertEquals('/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[2]/r68:Repayment[1]/r68:GAD[1]/r68:Donor[1]/r68:Sur[1]', $response['errors']['business'][1]['location']);
$this->assertEquals('/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[1]/r68:Repayment[1]/r68:GAD[2]/r68:Donor[1]/r68:Sur[1]', $response['errors']['business'][1]['location']);

$this->assertEquals('/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[1]/r68:Repayment[1]/r68:GAD[1]/r68:Donor[1]/r68:Sur[1]', $response['errors']['business'][5]['location']);
$this->assertEquals('some-uuid-5678', $response['errors']['business'][5]['donation_id']);

$this->assertEquals(['some-uuid-1234', 'some-uuid-5678'], $response['donation_ids_with_errors']);
}

public function testDeclarationResponsePoll()
public function testDeclarationResponsePoll(): void
{
$this->setMockHttpResponse('DeclarationResponsePoll.xml');
$this->gaService = $this->setUpService(); // Use client w/ mock queue.
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0" encoding="UTF-8"?> <GovTalkMessage xmlns="http://www.govtalk.gov.uk/CM/envelope"> <EnvelopeVersion>2.0</EnvelopeVersion> <Header> <MessageDetails> <Class>HMRC-CHAR-CLM-MULTI</Class> <Qualifier>error</Qualifier> <Function>submit</Function> <CorrelationID>6359058085579170979</CorrelationID> <ResponseEndPoint>http://localhost:5665/LTS/LTSServlet</ResponseEndPoint> <Transformation>XML</Transformation> <GatewayTimestamp>2021-10-12T18:09:03.009</GatewayTimestamp> </MessageDetails> <SenderDetails /> </Header> <GovTalkDetails> <Keys /> <GovTalkErrors> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>3001</Number> <Type>business</Type> <Text>Your submission failed due to business validation errors. Please see below for details.</Text> </Error> </GovTalkErrors> </GovTalkDetails> <Body> <ErrorResponse xmlns="http://www.govtalk.gov.uk/CM/errorresponse" SchemaVersion="2.0"> <Application> <MessageCount>8</MessageCount> </Application> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4065</Number> <Type>schema</Type> <Text>Invalid content found at element 'Sur'</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[2]/r68:Repayment[1]/r68:GAD[1]/r68:Donor[1]/r68:Sur[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-type.3.1.3: The value '' of element 'Sur' is not valid.</DeveloperMessage> </Messages> </Application> </Error> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4082</Number> <Type>schema</Type> <Text>Value '' has an incorrect length</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[2]/r68:Repayment[1]/r68:GAD[1]/r68:Donor[1]/r68:Sur[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type '#AnonType_SurDonorGADRepaymentClaimR68'.</DeveloperMessage> </Messages> </Application> </Error> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4065</Number> <Type>schema</Type> <Text>Invalid content found at element 'Fore'</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[2]/r68:Repayment[1]/r68:GAD[1]/r68:Donor[1]/r68:Fore[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-type.3.1.3: The value '' of element 'Fore' is not valid.</DeveloperMessage> </Messages> </Application> </Error> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4082</Number> <Type>schema</Type> <Text>Value '' has an incorrect length</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[2]/r68:Repayment[1]/r68:GAD[1]/r68:Donor[1]/r68:Fore[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type '#AnonType_ForeDonorGADRepaymentClaimR68'.</DeveloperMessage> </Messages> </Application> </Error> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4065</Number> <Type>schema</Type> <Text>Invalid content found at element 'Sur'</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[1]/r68:Repayment[1]/r68:GAD[1]/r68:Donor[1]/r68:Sur[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-type.3.1.3: The value '' of element 'Sur' is not valid.</DeveloperMessage> </Messages> </Application> </Error> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4082</Number> <Type>schema</Type> <Text>Value '' has an incorrect length</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[1]/r68:Repayment[1]/r68:GAD[1]/r68:Donor[1]/r68:Sur[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type '#AnonType_SurDonorGADRepaymentClaimR68'.</DeveloperMessage> </Messages> </Application> </Error> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4065</Number> <Type>schema</Type> <Text>Invalid content found at element 'Fore'</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[1]/r68:Repayment[1]/r68:GAD[1]/r68:Donor[1]/r68:Fore[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-type.3.1.3: The value '' of element 'Fore' is not valid.</DeveloperMessage> </Messages> </Application> </Error> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4082</Number> <Type>schema</Type> <Text>Value '' has an incorrect length</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[1]/r68:Repayment[1]/r68:GAD[1]/r68:Donor[1]/r68:Fore[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type '#AnonType_ForeDonorGADRepaymentClaimR68'.</DeveloperMessage> </Messages> </Application> </Error> </ErrorResponse> </Body> </GovTalkMessage>
<?xml version="1.0" encoding="UTF-8"?> <GovTalkMessage xmlns="http://www.govtalk.gov.uk/CM/envelope"> <EnvelopeVersion>2.0</EnvelopeVersion> <Header> <MessageDetails> <Class>HMRC-CHAR-CLM-MULTI</Class> <Qualifier>error</Qualifier> <Function>submit</Function> <CorrelationID>6359058085579170979</CorrelationID> <ResponseEndPoint>http://localhost:5665/LTS/LTSServlet</ResponseEndPoint> <Transformation>XML</Transformation> <GatewayTimestamp>2021-10-12T18:09:03.009</GatewayTimestamp> </MessageDetails> <SenderDetails /> </Header> <GovTalkDetails> <Keys /> <GovTalkErrors> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>3001</Number> <Type>business</Type> <Text>Your submission failed due to business validation errors. Please see below for details.</Text> </Error> </GovTalkErrors> </GovTalkDetails> <Body> <ErrorResponse xmlns="http://www.govtalk.gov.uk/CM/errorresponse" SchemaVersion="2.0"> <Application> <MessageCount>8</MessageCount> </Application> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4065</Number> <Type>schema</Type> <Text>Invalid content found at element 'Sur'</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[1]/r68:Repayment[1]/r68:GAD[2]/r68:Donor[1]/r68:Sur[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-type.3.1.3: The value '' of element 'Sur' is not valid.</DeveloperMessage> </Messages> </Application> </Error> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4082</Number> <Type>schema</Type> <Text>Value '' has an incorrect length</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[1]/r68:Repayment[1]/r68:GAD[2]/r68:Donor[1]/r68:Sur[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type '#AnonType_SurDonorGADRepaymentClaimR68'.</DeveloperMessage> </Messages> </Application> </Error> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4065</Number> <Type>schema</Type> <Text>Invalid content found at element 'Fore'</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[1]/r68:Repayment[1]/r68:GAD[2]/r68:Donor[1]/r68:Fore[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-type.3.1.3: The value '' of element 'Fore' is not valid.</DeveloperMessage> </Messages> </Application> </Error> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4082</Number> <Type>schema</Type> <Text>Value '' has an incorrect length</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[1]/r68:Repayment[1]/r68:GAD[2]/r68:Donor[1]/r68:Fore[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type '#AnonType_ForeDonorGADRepaymentClaimR68'.</DeveloperMessage> </Messages> </Application> </Error> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4065</Number> <Type>schema</Type> <Text>Invalid content found at element 'Sur'</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[1]/r68:Repayment[1]/r68:GAD[1]/r68:Donor[1]/r68:Sur[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-type.3.1.3: The value '' of element 'Sur' is not valid.</DeveloperMessage> </Messages> </Application> </Error> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4082</Number> <Type>schema</Type> <Text>Value '' has an incorrect length</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[1]/r68:Repayment[1]/r68:GAD[1]/r68:Donor[1]/r68:Sur[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type '#AnonType_SurDonorGADRepaymentClaimR68'.</DeveloperMessage> </Messages> </Application> </Error> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4065</Number> <Type>schema</Type> <Text>Invalid content found at element 'Fore'</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[1]/r68:Repayment[1]/r68:GAD[1]/r68:Donor[1]/r68:Fore[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-type.3.1.3: The value '' of element 'Fore' is not valid.</DeveloperMessage> </Messages> </Application> </Error> <Error> <RaisedBy>ChRIS</RaisedBy> <Number>4082</Number> <Type>schema</Type> <Text>Value '' has an incorrect length</Text> <Location>/hd:GovTalkMessage[1]/hd:Body[1]/r68:IRenvelope[1]/r68:R68[1]/r68:Claim[1]/r68:Repayment[1]/r68:GAD[1]/r68:Donor[1]/r68:Fore[1]</Location> <Application> <Messages> <DeveloperMessage>cvc-minLength-valid: Value '' with length = '0' is not facet-valid with respect to minLength '1' for type '#AnonType_ForeDonorGADRepaymentClaimR68'.</DeveloperMessage> </Messages> </Application> </Error> </ErrorResponse> </Body> </GovTalkMessage>

0 comments on commit 3f934b3

Please sign in to comment.