From 996ea35a3790e56d010db47fd6ffeea513d7b72f Mon Sep 17 00:00:00 2001 From: Rich Lott / Artful Robot Date: Thu, 7 Nov 2019 17:18:13 +0000 Subject: [PATCH] Payment PropertyBag: allow week as recurFrequencyUnit; accept ZLS for feeAmount for legacy sake --- Civi/Payment/PropertyBag.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Civi/Payment/PropertyBag.php b/Civi/Payment/PropertyBag.php index 51c2864b102f..d102c29ab38f 100644 --- a/Civi/Payment/PropertyBag.php +++ b/Civi/Payment/PropertyBag.php @@ -94,8 +94,8 @@ 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'. @@ -103,6 +103,15 @@ public function offsetSet($offset, $value) { $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); @@ -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); }