diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 816c38ceeb15..82ff65e19668 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -218,13 +218,23 @@ public function preProcess() { if (!empty($this->_membershipBlock)) { $this->_params['selectMembership'] = $this->get('selectMembership'); } - if (!empty($this->_paymentProcessor) && $this->_paymentProcessor['object']->supports('preApproval')) { - $preApprovalParams = $this->_paymentProcessor['object']->getPreApprovalDetails($this->get('pre_approval_parameters')); - $this->_params = array_merge($this->_params, $preApprovalParams); + if (!empty($this->_paymentProcessor)) { + if($this->_paymentProcessor['object']->supports('preApproval')) { + $preApprovalParams = $this->_paymentProcessor['object']->getPreApprovalDetails($this->get('pre_approval_parameters')); + $this->_params = array_merge($this->_params, $preApprovalParams); - // We may have fetched some billing details from the getPreApprovalDetails function so we - // want to ensure we set this after that function has been called. - CRM_Core_Payment_Form::mapParams($this->_bltID, $preApprovalParams, $this->_params, FALSE); + // We may have fetched some billing details from the getPreApprovalDetails function so we + // want to ensure we set this after that function has been called. + CRM_Core_Payment_Form::mapParams($this->_bltID, $preApprovalParams, $this->_params, FALSE); + } + + // Set text version of state & country if present. + if (!empty($this->_params["billing_state_province_id-{$this->_bltID}"])) { + $this->_params["state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]); + } + if (!empty($this->_params["billing_country_id-{$this->_bltID}"])) { + $this->_params["country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]); + } } $this->_params['is_pay_later'] = $this->get('is_pay_later'); diff --git a/CRM/Core/Payment/Form.php b/CRM/Core/Payment/Form.php index 905e4a68a3f4..1a018fa3e62b 100644 --- a/CRM/Core/Payment/Form.php +++ b/CRM/Core/Payment/Form.php @@ -360,13 +360,6 @@ public static function validateCreditCard($values, &$errors, $processorID = NULL * @param bool $reverse */ public static function mapParams($id, $src, &$dst, $reverse = FALSE) { - // Set text version of state & country if present. - if (isset($src["billing_state_province_id-{$id}"])) { - $src["billing_state_province-{$id}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($src["billing_state_province_id-{$id}"]); - } - if (isset($src["billing_country_id-{$id}"])) { - $src["billing_country-{$id}"] = CRM_Core_PseudoConstant::countryIsoCode($src["billing_country_id-{$id}"]);; - }; $map = array( 'first_name' => 'billing_first_name', 'middle_name' => 'billing_middle_name', diff --git a/CRM/Utils/Address.php b/CRM/Utils/Address.php index b4ba87c538f2..73210a3df35d 100644 --- a/CRM/Utils/Address.php +++ b/CRM/Utils/Address.php @@ -348,6 +348,10 @@ public static function getFormattedBillingAddressFieldsFromParameters($params, $ $addressFields = array(); foreach ($addressParts as $name => $field) { $addressFields[$name] = CRM_Utils_Array::value($field, $params); + //Include values which prepend 'billing_' to country and state_province. + if (empty($params[$field])) { + $addressFields[$name] = CRM_Utils_Array::value('billing_' . $field, $params); + } } return CRM_Utils_Address::format($addressFields); } diff --git a/tests/phpunit/WebTest/Contribute/OnlineContributionTest.php b/tests/phpunit/WebTest/Contribute/OnlineContributionTest.php index fcd510d771ca..0a07433bfaf3 100644 --- a/tests/phpunit/WebTest/Contribute/OnlineContributionTest.php +++ b/tests/phpunit/WebTest/Contribute/OnlineContributionTest.php @@ -135,6 +135,13 @@ public function testOnlineContributionAdd() { $this->assertElementContainsText("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_name-section']", $firstName . "billing"); $this->assertElementContainsText("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_name-section']", $lastName . "billing"); + $stateText = CRM_Core_PseudoConstant::stateProvinceAbbreviation(1004); + $countryText = CRM_Core_PseudoConstant::countryIsoCode(1228); + $billingDetails = array('15 Main St.', 'San Jose', '94129', $stateText, $countryText); + foreach ($billingDetails as $field) { + $this->assertElementContainsText("xpath=//div[@class='crm-group billing_name_address-group']//div[@class='crm-section no-label billing_address-section']", $field); + } + $this->click("_qf_Confirm_next-bottom"); $this->waitForPageToLoad($this->getTimeoutMsec());