From 69975a61417132af4d9241018335ea0136f18e18 Mon Sep 17 00:00:00 2001 From: Noel Light-Hilary Date: Fri, 25 Feb 2022 13:41:37 +0000 Subject: [PATCH 1/4] CLA-17 - fix duplicate ID keys when making multiple claims on one `GiftAid` instance --- src/GiftAid.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/GiftAid.php b/src/GiftAid.php index 27fa42c..3bb95e0 100644 --- a/src/GiftAid.php +++ b/src/GiftAid.php @@ -668,7 +668,7 @@ public function giftAidSubmit($donor_data) $this->setMessageTransformation('XML'); $this->addTargetOrganisation($cOrganisation); - $this->addMessageKey($this->getCharIdKey(), $this->getCharIdValue()); + $this->setSoleMessageKey($this->getCharIdKey(), $this->getCharIdValue()); $this->setChannelRoute( $this->getProductUri(), @@ -826,7 +826,10 @@ public function requestClaimData() $this->addTargetOrganisation('IR'); - $this->addMessageKey($this->getCharIdKey(), $this->getClaimingOrganisation()->getHmrcRef()); + $this->setSoleMessageKey( + $this->getCharIdKey(), + $this->getClaimingOrganisation()->getHmrcRef(), + ); $this->setChannelRoute( $this->getProductUri(), @@ -1170,6 +1173,23 @@ public function getResponseErrors() return $govTalkErrors; } + /** + * Removes *all* existing keys and writes a new one with the given type + * and value. This allows for e.g. an agent number to be provided to a `GiftAid` instance + * several times in the same process without worrying about whether header data was already + * set. It should also make it safe to mix and match agent and direct claims while using + * the same instance of `GiftAid`. + * + * @param string $type 'AGENTCHARID' or 'CHARID'. + * @param string $value Identifier for who is claiming. + * @return bool True if the key is valid and added; false if we left `GovTalkDetails` free of keys. + */ + protected function setSoleMessageKey(string $type, string $value): bool + { + $this->resetMessageKeys(); + return $this->addMessageKey($type, $value); + } + /** * @param array[] $businessErrors each possibly including a 'donation_id' key. * @return string[] Donation IDs From cfb0817ec622d38ca1b0f86dd272407981a6435d Mon Sep 17 00:00:00 2001 From: Noel Light-Hilary Date: Fri, 25 Feb 2022 13:43:42 +0000 Subject: [PATCH 2/4] Fix deprecation warning in envelope init --- src/GiftAid.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GiftAid.php b/src/GiftAid.php index 3bb95e0..b6447c8 100644 --- a/src/GiftAid.php +++ b/src/GiftAid.php @@ -664,7 +664,7 @@ public function giftAidSubmit($donor_data) $this->setMessageClass($this->getMessageClass()); $this->setMessageQualifier('request'); $this->setMessageFunction('submit'); - $this->setMessageCorrelationId(null); + $this->setMessageCorrelationId(''); $this->setMessageTransformation('XML'); $this->addTargetOrganisation($cOrganisation); From 22ca5518feab67048b676a14f7b10a2732b3e27a Mon Sep 17 00:00:00 2001 From: Noel Light-Hilary Date: Fri, 25 Feb 2022 13:43:51 +0000 Subject: [PATCH 3/4] Use only stable dependencies --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 5d3f5ad..4486f84 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "description": "A library for charities and CASCs to claim Gift Aid (including Small Donations) from HMRC", "homepage": "https://github.com/thebiggive/hmrc-gift-aid", "license": "GPL-3.0-or-later", - "minimum-stability": "dev", + "minimum-stability": "stable", "prefer-stable": true, "authors": [ { @@ -42,7 +42,7 @@ "ext-simplexml": "*", "ext-xmlwriter": "*", "ext-zlib": "*", - "thebiggive/php-govtalk": "^1.0.0-beta4" + "thebiggive/php-govtalk": "^1.0.0" }, "require-dev": { "phpspec/prophecy-phpunit": "^2.0", From b21f38bb2162f64f80aa5d899f53c0f4f39707f5 Mon Sep 17 00:00:00 2001 From: Noel Light-Hilary Date: Fri, 25 Feb 2022 13:48:26 +0000 Subject: [PATCH 4/4] Fix multiple org claims as per https://github.com/thebiggive/hmrc-gift-aid/pull/9/commits/1019e4dc6b3d521790a09d095f7ea4a2504971ea --- src/GiftAid.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GiftAid.php b/src/GiftAid.php index b6447c8..08c69e6 100644 --- a/src/GiftAid.php +++ b/src/GiftAid.php @@ -572,6 +572,7 @@ private function buildClaimXml(array $donations): string $claimOpen = true; $claimNumber++; $gadNumber = 0; + $currentClaimOrgRef = $d['org_hmrc_ref']; } if (isset($d['donation_date'])) {