if ($this->_ppType) {
$defaults['payment_processor_type_id'] = $this->_ppType;
}
- $defaults['accept_credit_cards'] = json_decode(CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor',
+ $cards = json_decode(CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor',
$this->_id,
'accepted_credit_cards'
), TRUE);
+ $acceptedCards = array();
+ foreach ($cards as $card => $val) {
+ $acceptedCards[$card] = 1;
+ }
+ $defaults['accept_credit_cards'] = $acceptedCards;
unset($defaults['accepted_credit_cards']);
// now get testID
$testDAO = new CRM_Financial_DAO_PaymentProcessor();
$values[$field] = empty($values["test_{$field}"]) ? CRM_Utils_Array::value($field, $values) : $values["test_{$field}"];
}
}
- $creditCards = empty($values['accept_credit_cards']) ? "NULL" : json_encode($values['accept_credit_cards']);
+ if (!empty($values['accept_credit_cards'])) {
+ $creditCards = array();
+ $accptedCards = array_keys($values['accept_credit_cards']);
+ $creditCardTypes = CRM_Contribute_PseudoConstant::creditCard();
+ foreach ($creditCardTypes as $type => $val) {
+ if (in_array($type, $accptedCards)) {
+ $creditCards[$type] = $creditCardTypes[$type];
+ }
+ }
+ $creditCards = json_encode($creditCards);
+ }
+ else {
+ $creditCards = "NULL";
+ }
$params = array_merge(array(
'id' => $test ? $this->_testID : $this->_id,
'domain_id' => $domainID,
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.7 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2016 |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM. |
+ | |
+ | CiviCRM is free software; you can copy, modify, and distribute it |
+ | under the terms of the GNU Affero General Public License |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | |
+ | CiviCRM is distributed in the hope that it will be useful, but |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ | See the GNU Affero General Public License for more details. |
+ | |
+ | You should have received a copy of the GNU Affero General Public |
+ | License and the CiviCRM Licensing Exception along |
+ | with this program; if not, contact CiviCRM LLC |
+ | at info[AT]civicrm[DOT]org. If you have questions about the |
+ | GNU Affero General Public License or the licensing of CiviCRM, |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * Class CRM_Financial_BAO_PaymentProcessorTypeTest
+ * @group headless
+ */
+class CRM_Financial_BAO_PaymentProcessorTypeTest extends CiviUnitTestCase {
+ public function setUp() {
+ parent::setUp();
+ }
+
+ /**
+ * Check method create()
+ */
+ public function testGetCreditCards() {
+ $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);
+ $expectedCards = array(
+ 'Visa' => 'Visa',
+ 'Mastercard' => 'Mastercard',
+ 'Amex' => 'Amex',
+ );
+ $cards = CRM_Financial_BAO_PaymentProcessor::getCreditCards($paymentProcessor->id);
+ $this->assertEquals($cards, $expectedCards, 'Verify correct credit card types are returned');
+ }
+
+ 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');
+ }
+
+}