Fix AVS for address/zip not starting with a number
authorRuben Rodriguez <ruben@fsf.org>
Thu, 25 Jul 2019 15:41:36 +0000 (11:41 -0400)
committerRuben Rodriguez <ruben@fsf.org>
Thu, 25 Jul 2019 15:41:36 +0000 (11:41 -0400)
CRM/Core/Payment/TrustCommerce.php

index 24502c8ac96ffd88b9a74b5cbc87d83cc5292d54..ea573eb6eb03f730ea5fc6f804d7f69ff5f9cb76 100644 (file)
@@ -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