You are here

function commerce_avatax_validate_shipping_address_ajax_callback in Drupal Commerce Connector for AvaTax 7.5

Same name and namespace in other branches
  1. 7.4 commerce_avatax.module \commerce_avatax_validate_shipping_address_ajax_callback()

Custom Ajax callback for setting up address validation popup.

1 string reference to 'commerce_avatax_validate_shipping_address_ajax_callback'
commerce_avatax_form_alter in ./commerce_avatax.module
Implements hook_form_alter().

File

./commerce_avatax.module, line 895
AvaTax service integration from Avalara, Inc.

Code

function commerce_avatax_validate_shipping_address_ajax_callback($form, &$form_state) {
  $commands = array();

  // See commerce_avatax_checkout_validate().
  if (isset($form_state['commerce_avatax']) && !empty($form_state['commerce_avatax']['address_validation_failed'])) {
    if (!empty($form_state['commerce_avatax']['address_validation_result'])) {
      $validation_result = $form_state['commerce_avatax']['address_validation_result'];
      $buttons = array();
      if ($validation_result['result'] == 'invalid') {
        $buttons[] = array(
          'code' => 'invalid',
          'text' => t('Let me change the address'),
        );
      }
      elseif ($validation_result['result'] == 'needs_correction') {
        $buttons[] = array(
          'code' => 'recommended',
          'text' => t('Use recommended'),
        );
        $buttons[] = array(
          'code' => 'keep_address',
          'text' => t('Use as entered'),
        );
        $buttons[] = array(
          'code' => 'invalid',
          'text' => t('Let me change the address'),
        );
      }
      $commands[] = array(
        'command' => 'commerce_avatax_address_modal_display',
        'html' => $validation_result['msg'],
        'buttons' => $buttons,
        'selector' => '#commerce-avatax-address-validation-wrapper',
      );
    }
  }
  else {

    // We need to unblock the form submission.
    $commands[] = ajax_command_invoke(NULL, 'commerceAvaTaxUnblockCheckout', array());
  }
  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}