Skip to content

Commit

Permalink
Payment PropertyBag: allow week as recurFrequencyUnit; accept ZLS for…
Browse files Browse the repository at this point in the history
… feeAmount for legacy sake
  • Loading branch information
Rich Lott / Artful Robot committed Nov 7, 2019
1 parent ca3f7dc commit 996ea35
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Civi/Payment/PropertyBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,24 @@ public function offsetSet($offset, $value) {
$prop = $this->handleLegacyPropNames($offset);
}
catch (InvalidArgumentException $e) {
// We need to make a lot of noise here @todo
// We're being asked to merge in something we can't validate.
// We need to make a lot of noise here, we're being asked to merge in
// something we can't validate because we don't know what this property is.
// This is fine if it's something particular to a payment processor
// (which should be using setCustomProperty) however it could also lead to
// things like 'my_weirly_named_contact_id'.
$this->legacyWarning($e->getMessage() . " We have merged this in for now as a custom property. Please rewrite your code to use PropertyBag->setCustomProperty if it is a genuinely custom property, or a standardised setter like PropertyBag->setContactID for standard properties");
$this->setCustomProperty($offset, $value, 'default');
return;
}

// Coerce legacy values that were in use but shouldn't be in our new way of doing things.
if ($prop === 'feeAmount' && $value === '') {
// At least the following classes pass in ZLS for feeAmount.
// CRM_Core_Payment_AuthorizeNetTest::testCreateSingleNowDated
// CRM_Core_Payment_AuthorizeNetTest::testCreateSinglePostDated
$value = 0;
}

// These lines are here (and not in try block) because the catch must only
// catch the case when the prop is custom.
$setter = 'set' . ucfirst($prop);
Expand Down Expand Up @@ -587,12 +596,12 @@ public function getRecurFrequencyUnit($label = 'default') {
}

/**
* @param string $recurFrequencyUnit month|day|year
* @param string $recurFrequencyUnit month|day|week|year
* @param string $label e.g. 'default'
*/
public function setRecurFrequencyUnit($recurFrequencyUnit, $label = 'default') {
if (!preg_match('/^day|month|year$/', $recurFrequencyUnit)) {
throw new \InvalidArgumentException("recurFrequencyUnit must be month|day|year");
if (!preg_match('/^day|week|month|year$/', $recurFrequencyUnit)) {
throw new \InvalidArgumentException("recurFrequencyUnit must be day|week|month|year");
}
return $this->set('recurFrequencyUnit', $label, $recurFrequencyUnit);
}
Expand Down

0 comments on commit 996ea35

Please sign in to comment.