/** * create all fields needed for a credit card transaction * * @return void * @access public */ function setCreditCardFields(&$form) { CRM_Core_Payment_Form::_setPaymentFields($form); $form->_paymentFields['credit_card_number'] = array('htmlType' => 'text', 'name' => 'credit_card_number', 'title' => ts('Card Number'), 'cc_field' => TRUE, 'attributes' => array('size' => 20, 'maxlength' => 20, 'autocomplete' => 'off'), 'is_required' => TRUE); $form->_paymentFields['cvv2'] = array('htmlType' => 'text', 'name' => 'cvv2', 'title' => ts('Security Code'), 'cc_field' => TRUE, 'attributes' => array('size' => 5, 'maxlength' => 10, 'autocomplete' => 'off'), 'is_required' => CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'cvv_backoffice_required', CRM_Core_Component::getComponentID('CiviContribute'), 1)); $form->_paymentFields['credit_card_exp_date'] = array('htmlType' => 'date', 'name' => 'credit_card_exp_date', 'title' => ts('Expiration Date'), 'cc_field' => TRUE, 'attributes' => CRM_Core_SelectValues::date('creditCard'), 'is_required' => TRUE); $creditCardType = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::creditCard(); $form->_paymentFields['credit_card_type'] = array('htmlType' => 'select', 'name' => 'credit_card_type', 'title' => ts('Card Type'), 'cc_field' => TRUE, 'attributes' => $creditCardType, 'is_required' => TRUE); }
/** * create all fields needed for a credit card transaction * * @return void * @access public */ function setCreditCardFields(&$form) { CRM_Core_Payment_Form::_setPaymentFields($form); $form->_fields['credit_card_number'] = array('htmlType' => 'text', 'name' => 'credit_card_number', 'title' => ts('Card Number'), 'cc_field' => true, 'attributes' => array('size' => 20, 'maxlength' => 20, 'autocomplete' => 'off'), 'is_required' => true); $form->_fields['cvv2'] = array('htmlType' => 'text', 'name' => 'cvv2', 'title' => ts('Security Code'), 'cc_field' => true, 'attributes' => array('size' => 5, 'maxlength' => 10, 'autocomplete' => 'off'), 'is_required' => true); $form->_fields['credit_card_exp_date'] = array('htmlType' => 'date', 'name' => 'credit_card_exp_date', 'title' => ts('Expiration Date'), 'cc_field' => true, 'attributes' => CRM_Core_SelectValues::date('creditCard'), 'is_required' => true); require_once 'CRM/Contribute/PseudoConstant.php'; $creditCardType = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::creditCard(); $form->_fields['credit_card_type'] = array('htmlType' => 'select', 'name' => 'credit_card_type', 'title' => ts('Card Type'), 'cc_field' => true, 'attributes' => $creditCardType, 'is_required' => true); }
/** * 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. */ public 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; }
/** * Save a payment processor. * * @param array $values * @param int $domainID * @param bool $test */ public function updatePaymentProcessor(&$values, $domainID, $test) { if ($test) { foreach (array('user_name', 'password', 'signature', 'url_site', 'url_recur', 'url_api', 'url_button', 'subject') as $field) { $values[$field] = empty($values["test_{$field}"]) ? CRM_Utils_Array::value($field, $values) : $values["test_{$field}"]; } } 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, 'is_test' => $test, 'is_active' => 0, 'is_default' => 0, 'is_recur' => $this->_ppDAO->is_recur, 'billing_mode' => $this->_ppDAO->billing_mode, 'class_name' => $this->_ppDAO->class_name, 'payment_type' => $this->_ppDAO->payment_type, 'payment_instrument_id' => $this->_ppDAO->payment_instrument_id, 'financial_account_id' => $values['financial_account_id'], 'accepted_credit_cards' => $creditCards), $values); civicrm_api3('PaymentProcessor', 'create', $params); }
/** * Return an array of all the details about the fields potentially required for payment fields. * * Only those determined by getPaymentFormFields will actually be assigned to the form * * @return array * field metadata */ public function getPaymentFormFieldsMetadata() { //@todo convert credit card type into an option value $creditCardType = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::creditCard(); return array('credit_card_number' => array('htmlType' => 'text', 'name' => 'credit_card_number', 'title' => ts('Card Number'), 'cc_field' => TRUE, 'attributes' => array('size' => 20, 'maxlength' => 20, 'autocomplete' => 'off', 'class' => 'creditcard'), 'is_required' => TRUE), 'cvv2' => array('htmlType' => 'text', 'name' => 'cvv2', 'title' => ts('Security Code'), 'cc_field' => TRUE, 'attributes' => array('size' => 5, 'maxlength' => 10, 'autocomplete' => 'off'), 'is_required' => CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'cvv_backoffice_required', NULL, 1), 'rules' => array(array('rule_message' => ts('Please enter a valid value for your card security code. This is usually the last 3-4 digits on the card\'s signature panel.'), 'rule_name' => 'integer', 'rule_parameters' => NULL))), 'credit_card_exp_date' => array('htmlType' => 'date', 'name' => 'credit_card_exp_date', 'title' => ts('Expiration Date'), 'cc_field' => TRUE, 'attributes' => CRM_Core_SelectValues::date('creditCard'), 'is_required' => TRUE, 'rules' => array(array('rule_message' => ts('Card expiration date cannot be a past date.'), 'rule_name' => 'currentDate', 'rule_parameters' => TRUE))), 'credit_card_type' => array('htmlType' => 'select', 'name' => 'credit_card_type', 'title' => ts('Card Type'), 'cc_field' => TRUE, 'attributes' => $creditCardType, 'is_required' => FALSE), 'account_holder' => array('htmlType' => 'text', 'name' => 'account_holder', 'title' => ts('Account Holder'), 'cc_field' => TRUE, 'attributes' => array('size' => 20, 'maxlength' => 34, 'autocomplete' => 'on'), 'is_required' => TRUE), 'bank_account_number' => array('htmlType' => 'text', 'name' => 'bank_account_number', 'title' => ts('Bank Account Number'), 'cc_field' => TRUE, 'attributes' => array('size' => 20, 'maxlength' => 34, 'autocomplete' => 'off'), 'rules' => array(array('rule_message' => ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'), 'rule_name' => 'nopunctuation', 'rule_parameters' => NULL)), 'is_required' => TRUE), 'bank_identification_number' => array('htmlType' => 'text', 'name' => 'bank_identification_number', 'title' => ts('Bank Identification Number'), 'cc_field' => TRUE, 'attributes' => array('size' => 20, 'maxlength' => 11, 'autocomplete' => 'off'), 'is_required' => TRUE, 'rules' => array(array('rule_message' => ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'), 'rule_name' => 'nopunctuation', 'rule_parameters' => NULL))), 'bank_name' => array('htmlType' => 'text', 'name' => 'bank_name', 'title' => ts('Bank Name'), 'cc_field' => TRUE, 'attributes' => array('size' => 20, 'maxlength' => 64, 'autocomplete' => 'off'), 'is_required' => TRUE)); }
/** * Get core CiviCRM payment fields. * * @return array */ private function getCorePaymentFields() { $creditCardType = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::creditCard(); return array('credit_card_number' => array('htmlType' => 'text', 'name' => 'credit_card_number', 'title' => ts('Card Number'), 'cc_field' => TRUE, 'attributes' => array('size' => 20, 'maxlength' => 20, 'autocomplete' => 'off'), 'is_required' => TRUE), 'cvv2' => array('htmlType' => 'text', 'name' => 'cvv2', 'title' => ts('Security Code'), 'cc_field' => TRUE, 'attributes' => array('size' => 5, 'maxlength' => 10, 'autocomplete' => 'off'), 'is_required' => TRUE), 'credit_card_exp_date' => array('htmlType' => 'date', 'name' => 'credit_card_exp_date', 'title' => ts('Expiration Date'), 'cc_field' => TRUE, 'attributes' => CRM_Core_SelectValues::date('creditCard'), 'is_required' => TRUE), 'credit_card_type' => array('htmlType' => 'select', 'name' => 'credit_card_type', 'title' => ts('Card Type'), 'cc_field' => TRUE, 'attributes' => $creditCardType, 'is_required' => FALSE)); }
/** * create all fields needed for a credit card transaction * * @return void * @access public */ function setCreditCardFields() { $this->_fields['first_name'] = array('htmlType' => 'text', 'name' => 'first_name', 'title' => ts('First Name'), 'attributes' => array('size' => 30, 'maxlength' => 60), 'is_required' => true); $this->_fields['middle_name'] = array('htmlType' => 'text', 'name' => 'middle_name', 'title' => ts('Middle Name'), 'attributes' => array('size' => 30, 'maxlength' => 60), 'is_required' => false); $this->_fields['last_name'] = array('htmlType' => 'text', 'name' => 'last_name', 'title' => ts('Last Name'), 'attributes' => array('size' => 30, 'maxlength' => 60), 'is_required' => true); $this->_fields['street_address'] = array('htmlType' => 'text', 'name' => 'street_address', 'title' => ts('Street Address'), 'attributes' => array('size' => 30, 'maxlength' => 60), 'is_required' => true); $this->_fields['city'] = array('htmlType' => 'text', 'name' => 'city', 'title' => ts('City'), 'attributes' => array('size' => 30, 'maxlength' => 60), 'is_required' => true); $this->_fields['state_province_id'] = array('htmlType' => 'select', 'name' => 'state_province_id', 'title' => ts('State / Province'), 'attributes' => array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), 'is_required' => true); $this->_fields['postal_code'] = array('htmlType' => 'text', 'name' => 'postal_code', 'title' => ts('Postal Code'), 'attributes' => array('size' => 30, 'maxlength' => 60), 'is_required' => true); $this->_fields['country_id'] = array('htmlType' => 'select', 'name' => 'country_id', 'title' => ts('Country'), 'attributes' => array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), 'is_required' => true); $this->_fields['credit_card_number'] = array('htmlType' => 'text', 'name' => 'credit_card_number', 'title' => ts('Card Number'), 'attributes' => array('size' => 20, 'maxlength' => 20), 'is_required' => true); $this->_fields['cvv2'] = array('htmlType' => 'text', 'name' => 'cvv2', 'title' => ts('Security Code'), 'attributes' => array('size' => 5, 'maxlength' => 10), 'is_required' => true); $this->_fields['credit_card_exp_date'] = array('htmlType' => 'date', 'name' => 'credit_card_exp_date', 'title' => ts('Expiration Date'), 'attributes' => CRM_Core_SelectValues::date('creditCard'), 'is_required' => true); require_once 'CRM/Contribute/PseudoConstant.php'; $creditCardType = array('' => '- select -') + CRM_Contribute_PseudoConstant::creditCard(); $this->_fields['credit_card_type'] = array('htmlType' => 'select', 'name' => 'credit_card_type', 'title' => ts('Card Type'), 'attributes' => $creditCardType, 'is_required' => true); }