X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=Civi%2FPayment%2FPropertyBag.php;h=24987057ef23e95069a66eb1f8a4c2d5ce9124eb;hb=91afc6f13e41f2c0bcb201fd1f107de1c8b8427b;hp=25e4a1d3698f6fb00cc85f690b0821a173c976ec;hpb=7e79b144634138de29b978c8eb67bd6d570219c9;p=civicrm-core.git diff --git a/Civi/Payment/PropertyBag.php b/Civi/Payment/PropertyBag.php index 25e4a1d369..24987057ef 100644 --- a/Civi/Payment/PropertyBag.php +++ b/Civi/Payment/PropertyBag.php @@ -26,13 +26,23 @@ class PropertyBag implements \ArrayAccess { protected static $propMap = [ 'amount' => TRUE, + 'total_amount' => 'amount', 'billingStreetAddress' => TRUE, + 'billing_street_address' => 'billingStreetAddress', + 'street_address' => 'billingStreetAddress', 'billingSupplementalAddress1' => TRUE, 'billingSupplementalAddress2' => TRUE, 'billingSupplementalAddress3' => TRUE, 'billingCity' => TRUE, + 'billing_city' => 'billingCity', + 'city' => 'billingCity', 'billingPostalCode' => TRUE, + 'billing_postal_code' => 'billingPostalCode', + 'postal_code' => 'billingPostalCode', 'billingCounty' => TRUE, + 'billingStateProvince' => TRUE, + 'billing_state_province' => 'billingStateProvince', + 'state_province' => 'billingStateProvince', 'billingCountry' => TRUE, 'contactID' => TRUE, 'contact_id' => 'contactID', @@ -258,13 +268,18 @@ class PropertyBag implements \ArrayAccess { if ($newName === NULL && substr($prop, -2) === '-' . \CRM_Core_BAO_LocationType::getBilling() && isset(static::$propMap[substr($prop, 0, -2)]) ) { - $newName = substr($prop, 0, -2); + $billingAddressProp = substr($prop, 0, -2); + $newName = static::$propMap[$billingAddressProp] ?? NULL; + if ($newName === TRUE) { + // Good, modern name. + return $billingAddressProp; + } } if ($newName === NULL) { if ($silent) { // Only for use by offsetExists - return; + return NULL; } throw new \InvalidArgumentException("Unknown property '$prop'."); } @@ -300,7 +315,7 @@ class PropertyBag implements \ArrayAccess { * * @return PropertyBag $this object so you can chain set setters. */ - protected function set($prop, $label, $value) { + protected function set($prop, $label = 'default', $value) { $this->props[$label][$prop] = $value; return $this; } @@ -591,6 +606,27 @@ class PropertyBag implements \ArrayAccess { return $this->set('billingCounty', $label, (string) $input); } + /** + * BillingStateProvince getter. + * + * @return string + */ + public function getBillingStateProvince($label = 'default') { + return $this->get('billingStateProvince', $label); + } + + /** + * BillingStateProvince setter. + * + * Nb. we can't validate this unless we have the country ID too, so we don't. + * + * @param string $input + * @param string $label e.g. 'default' + */ + public function setBillingStateProvince($input, $label = 'default') { + return $this->set('billingStateProvince', $label, (string) $input); + } + /** * BillingCountry getter. * @@ -1037,7 +1073,10 @@ class PropertyBag implements \ArrayAccess { */ public function setRecurInstallments($recurInstallments, $label = 'default') { // Counts zero as positive which is ok - means no installments - if (!\CRM_Utils_Type::validate($recurInstallments, 'Positive')) { + try { + \CRM_Utils_Type::validate($recurInstallments, 'Positive'); + } + catch (\CRM_Core_Exception $e) { throw new InvalidArgumentException('recurInstallments must be 0 or a positive integer'); }