You are here

function commerce_braintree_hostedfields_commerce_cardonfile_payment_terminal_form_alter in Commerce Braintree 7.3

Same name and namespace in other branches
  1. 7.2 modules/commerce_braintree_hostedfields/commerce_braintree_hostedfields.module \commerce_braintree_hostedfields_commerce_cardonfile_payment_terminal_form_alter()

Implements hook_commerce_cardonfile_payment_terminal_form_alter().

File

modules/commerce_braintree_hostedfields/commerce_braintree_hostedfields.module, line 134
Provides integration with Braintree Hosted Fields.

Code

function commerce_braintree_hostedfields_commerce_cardonfile_payment_terminal_form_alter(&$form, &$form_state) {
  if (!empty($form['payment_terminal']) && !empty($form_state['payment_method']['method_id']) && $form_state['payment_method']['method_id'] == 'braintree_hostedfields') {

    // Remove the hosted fields on the payment terminal when
    // card on file is the default option.
    if ($form_state['triggering_element']['#name'] == 'op' && !empty($form['payment_terminal']['payment_details']['cardonfile']['#default_value']) && $form['payment_terminal']['payment_details']['cardonfile']['#default_value'] != 'new') {
      commerce_braintree_hosted_fields_remove_hosted_fields_form($form['payment_terminal']['payment_details'], $form_state);
    }

    // Remove the hosted fields on the payment terminal when
    // a card on file payment method is selected.
    if (!empty($form_state['values']['payment_details']['cardonfile']) && $form_state['values']['payment_details']['cardonfile'] != 'new') {
      commerce_braintree_hosted_fields_remove_hosted_fields_form($form['payment_terminal']['payment_details'], $form_state);
    }
  }
}