public function testCreditCardCSSName()
 {
     $params = array('name' => 'API_Test_PP_Type', 'title' => 'API Test Payment Processor Type', 'class_name' => 'CRM_Core_Payment_APITest', 'billing_mode' => 'form', 'payment_processor_type_id' => 1, 'is_recur' => 0, 'domain_id' => 1, 'accepted_credit_cards' => json_encode(array('Visa' => 'Visa', 'Mastercard' => 'Mastercard', 'Amex' => 'Amex')));
     $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::create($params);
     $cards = CRM_Financial_BAO_PaymentProcessor::getCreditCards($paymentProcessor->id);
     $CSSCards = CRM_Core_Payment_Form::getCreditCardCSSNames($cards);
     $expectedCSSCards = array('visa' => 'Visa', 'mastercard' => 'Mastercard', 'amex' => 'Amex');
     $this->assertEquals($CSSCards, $expectedCSSCards, 'Verify correct credit card types are returned');
     $CSSCards2 = CRM_Core_Payment_Form::getCreditCardCSSNames(array());
     $allCards = array('visa' => 'Visa', 'mastercard' => 'MasterCard', 'amex' => 'Amex', 'discover' => 'Discover');
     $this->assertEquals($CSSCards2, $allCards, 'Verify correct credit card types are returned');
 }
示例#2
0
 /**
  * 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($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'])) {
             $errors['credit_card_number'] = ts('Please enter a valid Card Number');
         }
         if (!empty($values['cvv2']) && !CRM_Utils_Rule::cvv($values['cvv2'], $values['credit_card_type'])) {
             $errors['cvv2'] = ts('Please enter a valid Card Verification Number');
         }
     }
 }
示例#3
0
 /**
  * Add JS to show icons for the accepted credit cards.
  */
 public static function addCreditCardJs($paymentProcessorID = NULL)
 {
     $creditCards = array();
     $creditCards = CRM_Financial_BAO_PaymentProcessor::getCreditCards($paymentProcessorID);
     $creditCardTypes = CRM_Core_Payment_Form::getCreditCardCSSNames($creditCards);
     CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Core/BillingBlock.js', 10)->addScript('CRM.config.creditCardTypes = ' . json_encode($creditCardTypes) . ';');
 }