From d30429aab8943a3865466a873ec397859c0bf3e4 Mon Sep 17 00:00:00 2001 From: Ruben Rodriguez Date: Thu, 25 Jul 2019 11:41:36 -0400 Subject: [PATCH] Fix AVS for address/zip not starting with a number --- CRM/Core/Payment/TrustCommerce.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CRM/Core/Payment/TrustCommerce.php b/CRM/Core/Payment/TrustCommerce.php index 24502c8..ea573eb 100644 --- a/CRM/Core/Payment/TrustCommerce.php +++ b/CRM/Core/Payment/TrustCommerce.php @@ -537,6 +537,17 @@ class CRM_Core_Payment_TrustCommerce extends CRM_Core_Payment { $fields['zip'] = $this->_getParam('postal_code'); $fields['country'] = $this->_getParam('country'); + /** + * Fix AVS problem when a non-US country, has address1 and zip both starting + * with a letter. + */ + if( ($fields['country'] !== '840' && $fields['country'] !== 840) + && (preg_match("/^\D/", $fields['zip']) === 1) + && (preg_match("/^\D/", $fields['address1']) === 1) ) { + // Add a number to the beginning of the address. + $fields['address1'] = preg_replace("/^/", "1 ", $fields['address1']); + } + $fields['name'] = $this->_getParam('billing_first_name') . ' ' . $this->_getParam('billing_last_name'); // This assumes currencies where the . is used as the decimal point, like USD -- 2.25.1