CRM-13475 Fix credit-card error messages
[civicrm-core.git] / CRM / Core / Payment / Form.php
index 9f61ac2276d0db6106e6beb5a319f38f3a047384..f193753892eec2a6cd9adccebf3f10871b953902 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -182,7 +182,7 @@ class CRM_Core_Payment_Form {
       'title' => ts('Card Type'),
       'cc_field' => TRUE,
       'attributes' => $creditCardType,
-      'is_required' => TRUE,
+      'is_required' => FALSE,
     );
   }
 
@@ -237,7 +237,7 @@ class CRM_Core_Payment_Form {
   /**
    * Function to add all the credit card fields
    *
-   * @return None
+   * @return void
    * @access public
    */
   static function buildCreditCard(&$form, $useRequired = FALSE) {
@@ -272,24 +272,6 @@ class CRM_Core_Payment_Form {
           'state_province' => "billing_state_province_id-{$form->_bltID}",
         ));
       CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
-
-      // Add JS to show icons for the accepted credit cards
-      // the credit card pseudo constant results only the CC label, not the key ID
-      // so we normalize the name to use it as a CSS class.
-      $creditCardTypes = array();
-      foreach (CRM_Contribute_PseudoConstant::creditCard() as $key => $name) {
-        // Replace anything not css-friendly by an underscore
-        // Non-latin names will not like this, but so many things are wrong with
-        // the credit-card type configurations already.
-        $key = str_replace(' ', '', $key);
-        $key = preg_replace('/[^a-zA-Z0-9]/', '_', $key);
-        $key = strtolower($key);
-        $creditCardTypes[$key] = $name;
-      }
-
-      CRM_Core_Resources::singleton()
-        ->addSetting(array('config' => array('creditCardTypes' => $creditCardTypes)))
-        ->addScriptFile('civicrm', 'templates/CRM/Core/BillingBlock.js', 10, 'billing-block');
     }
 
     if ($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
@@ -303,6 +285,24 @@ class CRM_Core_Payment_Form {
     }
   }
 
+  /**
+   * The credit card pseudo constant results only the CC label, not the key ID
+   * So we normalize the name to use it as a CSS class.
+   */
+  static function getCreditCardCSSNames() {
+    $creditCardTypes = array();
+    foreach (CRM_Contribute_PseudoConstant::creditCard() as $key => $name) {
+      // Replace anything not css-friendly by an underscore
+      // Non-latin names will not like this, but so many things are wrong with
+      // the credit-card type configurations already.
+      $key = str_replace(' ', '', $key);
+      $key = preg_replace('/[^a-zA-Z0-9]/', '_', $key);
+      $key = strtolower($key);
+      $creditCardTypes[$key] = $name;
+    }
+    return $creditCardTypes;
+  }
+
   /**
    * Function to add all the direct debit fields
    *
@@ -363,6 +363,9 @@ class CRM_Core_Payment_Form {
         $errors['cvv2'] = ts('Please enter a valid Credit Card Verification Number');
       }
     }
+    elseif (!empty($values['credit_card_number'])) {
+      $errors['credit_card_number'] = ts('Please enter a valid Credit Card Number and Type');
+    }
   }
 
   /**