Fix error found by Jitendra and add form validation on the credit card type checking...
authorSeamus Lee <seamuslee001@gmail.com>
Mon, 26 Sep 2016 21:00:34 +0000 (07:00 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Tue, 27 Sep 2016 07:49:05 +0000 (17:49 +1000)
CRM/Admin/Form/PaymentProcessor.php
CRM/Contribute/Form/AbstractEditPayment.php
CRM/Core/Payment.php
CRM/Core/Payment/Form.php
CRM/Core/Payment/PayPalImpl.php
CRM/Utils/Rule.php
templates/CRM/Core/BillingBlock.js

index a3bc30ae4fda22f9e6570309844a125eb45f9b04..c29daa5b71b5bb919a6ba30dbd3ab8c840b47474 100644 (file)
@@ -334,8 +334,10 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form {
           'accepted_credit_cards'
         ), TRUE);
     $acceptedCards = array();
-    foreach ($cards as $card => $val) {
-      $acceptedCards[$card] = 1;
+    if (!empty($cards)) {
+      foreach ($cards as $card => $val) {
+        $acceptedCards[$card] = 1;
+      }
     }
     $defaults['accept_credit_cards'] = $acceptedCards;
     unset($defaults['accepted_credit_cards']);
index c5f8855dc0ac232fb44df913f5df4d8b7b59684d..cacb2db922d212a8956e4e2ea0e7333a6bd44de5 100644 (file)
@@ -350,7 +350,7 @@ WHERE  contribution_id = {$id}
           }
         }
       }
-      CRM_Financial_Form_Payment::addCreditCardJs();
+      CRM_Financial_Form_Payment::addCreditCardJs($id);
     }
     $this->assign('recurringPaymentProcessorIds',
       empty($this->_recurPaymentProcessors) ? '' : implode(',', array_keys($this->_recurPaymentProcessors))
index 745bf1131e130f8896c66f03b2fdc8485a7a5180..bb4e62a90653bc3ce0e81e8a658b3fad3a20f100 100644 (file)
@@ -393,7 +393,7 @@ abstract class CRM_Core_Payment {
   public function validatePaymentInstrument($values, &$errors) {
     CRM_Core_Form::validateMandatoryFields($this->getMandatoryFields(), $values, $errors);
     if ($this->_paymentProcessor['payment_type'] == 1) {
-      CRM_Core_Payment_Form::validateCreditCard($values, $errors);
+      CRM_Core_Payment_Form::validateCreditCard($this->_paymentProcessor['id'], $values, $errors);
     }
   }
 
index 213418656893fe297ab3d1dd4d0fc80eb6bfa3ae..8101efd0bae58d4c0e338a6cc6f094c648cdc8f4 100644 (file)
@@ -326,11 +326,18 @@ class CRM_Core_Payment_Form {
    * Make sure that credit card number and cvv are valid.
    * Called within the scope of a QF formRule function
    *
+   * @param int $processorID
    * @param array $values
    * @param array $errors
    */
-  public static function validateCreditCard($values, &$errors) {
+  public static function validateCreditCard($processorID = NULL, $values, &$errors) {
     if (!empty($values['credit_card_type']) || !empty($values['credit_card_number'])) {
+      if (!empty($values['credit_card_type'])) {
+        $processorCards = CRM_Financial_BAO_PaymentProcessor::getCreditCards($processorID);
+        if (!empty($processorCards) && !in_array($values['credit_card_type'], $processorCards)) {
+          $errors['credit_card_type'] = ts('This procesor does not support credit card type ' . $values['credit_card_type']);
+        }
+      }
       if (!empty($values['credit_card_number']) &&
         !CRM_Utils_Rule::creditCardNumber($values['credit_card_number'], $values['credit_card_type'])
       ) {
index d71e9613d520d7c174a588c4a98e1bc675c2b488..1634c93f1ab308ab9355f1a2f160b60f2bd74b6c 100644 (file)
@@ -176,7 +176,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment {
    */
   public function validatePaymentInstrument($values, &$errors) {
     if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal' && !$this->isPaypalExpress($values)) {
-      CRM_Core_Payment_Form::validateCreditCard($values, $errors);
+      CRM_Core_Payment_Form::validateCreditCard($this->_paymentProcessor['id'], $values, $errors);
       CRM_Core_Form::validateMandatoryFields($this->getMandatoryFields(), $values, $errors);
     }
   }
index 0ea7c32e3cc337c65f8620859dd4e83ff5227646..88310ddd4a6e2c1eb4869b554de696d134a49249 100644 (file)
@@ -725,7 +725,6 @@ class CRM_Utils_Rule {
    * @return bool
    */
   public static function creditCardNumber($value, $type) {
-    require_once 'Validate/Finance/CreditCard.php';
     return Validate_Finance_CreditCard::number($value, $type);
   }
 
@@ -736,8 +735,6 @@ class CRM_Utils_Rule {
    * @return bool
    */
   public static function cvv($value, $type) {
-    require_once 'Validate/Finance/CreditCard.php';
-
     return Validate_Finance_CreditCard::cvv($value, $type);
   }
 
index 1802fb973b27ba3e3427f4c81740ea2f30beb0bb..4d75202f6eace2bd4af6bcfa75c20a0aabd789b8 100644 (file)
     $.each(card_types, function(key, pattern) {
       if (ccnumber.match('^' + pattern + '$')) {
         var value = card_values[key];
-        $('.crm-container .credit_card_type-section .crm-credit_card_type-icon-' + key).css('opacity', 1);
-        $('select#credit_card_type').val(value);
-        return false;
+        //$.each(CRM.config.creditCardTypes, function(key2, val) {
+        //  if (value == val) { 
+            $('.crm-container .credit_card_type-section .crm-credit_card_type-icon-' + key).css('opacity', 1);
+            $('select#credit_card_type').val(value);
+            return false;
+        //  }
+        //  else {
+        //    $
+       // });
       }
     });
   }