diff --git a/modules/authnet_ui/authnet_ui.module b/modules/authnet_ui/authnet_ui.module index b5c8bb7..2e588eb 100644 --- a/modules/authnet_ui/authnet_ui.module +++ b/modules/authnet_ui/authnet_ui.module @@ -344,12 +344,7 @@ function authnet_ui_payment_profile_form(&$form_state, $customer_profile_id = NU function authnet_ui_bank_account_form(&$form_state, $customer_profile_id, $payment_profile_id, $payment_profile) { // Bank account type. - $bank_types = array( - '' => t(''), - 'checking' => t('Checking account'), - 'savings' => t('Savings account'), - 'businessChecking' => t('Business checking account'), - ); + $bank_types = array('' => t('')) + authnet_ui_bank_account_types(); $form['account_type'] = array( '#type' => 'select', '#title' => t('Bank account type'), @@ -417,17 +412,11 @@ function authnet_ui_bank_account_form(&$form_state, $customer_profile_id, $payme function authnet_ui_credit_card_form(&$form_state, $customer_profile_id, $payment_profile_id, $payment_profile) { // Card type. - $card_types = array( - '', - 'Visa', - 'MasterCard', - 'American Express', - 'Discover', - ); + $card_types = array('') + authnet_ui_credit_card_types(); $form['type'] = array( '#type' => 'select', '#title' => t('Card type'), - '#options' => drupal_map_assoc($card_types), + '#options' => $card_types, ); // Card number. @@ -620,6 +609,29 @@ function authnet_ui_payment_profile_options($customer_profile_id) { } /** + * Returns an array of available credit card types. + */ +function authnet_ui_credit_card_types() { + return array( + 'Visa' => t('Visa'), + 'MasterCard' => t('MasterCard'), + 'American Express' => t('American Express'), + 'Discover' => t('Discover'), + ); +} + +/** + * Returns an array of available bank account types. + */ +function authnet_ui_bank_account_types() { + return array( + 'checking' => t('Checking account'), + 'savings' => t('Savings account'), + 'businessChecking' => t('Business checking account'), + ); +} + +/** * Create a new Authorize.net customer profile during form submit. * * @param $form_id diff --git a/modules/authnet_user/authnet_user.admin.inc b/modules/authnet_user/authnet_user.admin.inc index d57c480..6973b31 100644 --- a/modules/authnet_user/authnet_user.admin.inc +++ b/modules/authnet_user/authnet_user.admin.inc @@ -17,19 +17,53 @@ function authnet_user_settings_form(&$form_state) { '#description' => t('These settings pertain to the UI elements provided by the Authorize.net User module.'), ); + // Define available credit card options. + $form['user_settings']['credit_card'] = array( + '#type' => 'fieldset', + '#title' => t('Credit card settings'), + '#description' => t('Define available credit card options.'), + ); + // Allow users to store credit card information. - $form['user_settings']['authnet_user_allow_credit_card'] = array( + $form['user_settings']['credit_card']['authnet_user_allow_credit_card'] = array( '#type' => 'checkbox', '#title' => t('Allow users to store credit card information.'), '#default_value' => variable_get('authnet_user_allow_credit_card', TRUE), ); + // Allowed credit card types. + $card_types = authnet_ui_credit_card_types(); + $form['user_settings']['credit_card']['authnet_user_allow_credit_card_types'] = array( + '#type' => 'checkboxes', + '#title' => t('Allowed credit card types'), + '#description' => t('Allow users to save these credit card types.'), + '#options' => $card_types, + '#default_value' => variable_get('authnet_user_allow_credit_card_types', array_keys($card_types)), + ); + + // Define available bank account options. + $form['user_settings']['bank_account'] = array( + '#type' => 'fieldset', + '#title' => t('Bank account settings'), + '#description' => t('Define available bank account options.'), + ); + // Allow users to add bank accounts. - $form['user_settings']['authnet_user_allow_bank_account'] = array( + $form['user_settings']['bank_account']['authnet_user_allow_bank_account'] = array( '#type' => 'checkbox', '#title' => t('Allow users to store bank account information.'), '#default_value' => variable_get('authnet_user_allow_bank_account', FALSE), ); + // Allowed bank account types. + $bank_types = authnet_ui_bank_account_types(); + $form['user_settings']['bank_account']['authnet_user_allow_bank_account_types'] = array( + '#type' => 'checkboxes', + '#title' => t('Allowed bank account types'), + '#description' => t('Allow users to save these bank account types.'), + '#options' => $bank_types, + '#default_value' => variable_get('authnet_user_allow_bank_account_types', array_keys($bank_types)), + ); + return system_settings_form($form); } diff --git a/modules/authnet_user/authnet_user.install b/modules/authnet_user/authnet_user.install index 60fd418..6551aba 100644 --- a/modules/authnet_user/authnet_user.install +++ b/modules/authnet_user/authnet_user.install @@ -12,5 +12,7 @@ function authnet_user_uninstall() { // Clean up variables. variable_del('authnet_user_allow_credit_card'); + variable_del('authnet_user_allow_credit_card_types'); variable_del('authnet_user_allow_bank_account'); + variable_del('authnet_user_allow_bank_account_types'); } diff --git a/modules/authnet_user/authnet_user.pages.inc b/modules/authnet_user/authnet_user.pages.inc index fc232c6..615b678 100644 --- a/modules/authnet_user/authnet_user.pages.inc +++ b/modules/authnet_user/authnet_user.pages.inc @@ -170,6 +170,28 @@ function authnet_user_payment_profile_form(&$form_state, $user, $payment_profile } } + // Alter the payment profile form to remove disallowed credit card types. + $credit_card_type_options = &$form['payment']['payment_type']['card']['type']['#options']; + if (!empty($credit_card_type_options)) { + $allowed_types = variable_get('authnet_user_allow_credit_card_types', array()); + foreach ($credit_card_type_options as $key => $option) { + if ($key != '' && !$allowed_types[$key]) { + unset($credit_card_type_options[$key]); + } + } + } + + // Alter the payment profile form to remove disallowed bank account types. + $bank_account_type_options = &$form['payment']['payment_type']['bank']['account_type']['#options']; + if (!empty($bank_account_type_options)) { + $allowed_types = variable_get('authnet_user_allow_bank_account_types', array()); + foreach ($bank_account_type_options as $key => $option) { + if ($key != '' && !$allowed_types[$key]) { + unset($bank_account_type_options[$key]); + } + } + } + // Add a submit function for redirecting. $form['submit']['#submit'][] = 'authnet_user_billing_redirect';