You are here

function commerce_authnet_acceptjs_cardonfile_create_submit in Commerce Authorize.Net 7

1 string reference to 'commerce_authnet_acceptjs_cardonfile_create_submit'
commerce_authnet_form_commerce_cardonfile_card_form_alter in ./commerce_authnet.module
Implements hook_form_FORM_ID_alter().

File

./commerce_authnet.module, line 896
Implements Authorize.Net payment services for use in Drupal Commerce.

Code

function commerce_authnet_acceptjs_cardonfile_create_submit($form, &$form_state) {
  $op = $form_state['op'];
  $card = $form_state['card'];

  // Invoke the payment method's card create/update callback.
  $payment_method = commerce_payment_method_instance_load($card->instance_id);
  $callback = $payment_method['cardonfile'][$op . ' callback'];
  $success = FALSE;
  if (function_exists($callback)) {
    $callback_return = $callback($form, $form_state, $payment_method, $card);
    if ($callback_return) {
      if ($op == 'create') {
        $card_save = $callback_return;
        $confirm_message = t('A new card has been added.');
      }
      else {
        $card_save = $card;
        $confirm_message = t('The card has been updated.');
      }
      commerce_cardonfile_save($card_save);
      drupal_set_message($confirm_message);
      $success = TRUE;
    }
  }
  if (!$success) {
    if ($op == 'create') {
      drupal_set_message(t('We encountered an error attempting to save your card data. Please try again and contact us if this error persists.'), 'error');
    }
    else {
      drupal_set_message(t('We encountered an error attempting to update your card data. Please try again and contact us if this error persists.'), 'error');
    }
  }
  $form_state['redirect'] = 'user/' . $card->uid . '/cards';
}