Skip to content

Commit

Permalink
Merge pull request #10 from thebiggive/CLA-17-auth-key-tweak
Browse files Browse the repository at this point in the history
CLA-17 - fix duplicate ID keys when making multiple claims on one `GiftAid` instance
  • Loading branch information
alihejazi authored Feb 25, 2022
2 parents bab6c9e + b21f38b commit 56c3072
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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",
Expand Down
27 changes: 24 additions & 3 deletions src/GiftAid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down Expand Up @@ -664,11 +665,11 @@ 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);

$this->addMessageKey($this->getCharIdKey(), $this->getCharIdValue());
$this->setSoleMessageKey($this->getCharIdKey(), $this->getCharIdValue());

$this->setChannelRoute(
$this->getProductUri(),
Expand Down Expand Up @@ -826,7 +827,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(),
Expand Down Expand Up @@ -1170,6 +1174,23 @@ public function getResponseErrors()
return $govTalkErrors;
}

/**
* Removes *all* existing <GovTalkDetails /> 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
Expand Down

0 comments on commit 56c3072

Please sign in to comment.