You are here

function uc_recurring_authorizenet_cim_update_form_submit in UC Recurring Payments and Subscriptions 7.2

Same name and namespace in other branches
  1. 6.2 includes/uc_recurring.uc_authorizenet.inc \uc_recurring_authorizenet_cim_update_form_submit()

Implements update form submit for the authorizenet CIM gateway.

File

includes/uc_recurring.uc_authorizenet.inc, line 224
Uc recurring implementation for the test gateway module.

Code

function uc_recurring_authorizenet_cim_update_form_submit(&$form, &$form_state) {
  $fee = uc_recurring_fee_user_load($form_state['values']['rfid']);
  $order = uc_order_load($fee->order_id);
  $last4old = substr($order->payment_details['cc_number'], -4);
  $order->payment_details = $form_state['values']['cc_data'];
  $log = array();

  // Process billing address form changes
  if (($bill_changes = uc_order_pane_bill_to('edit-process', $order, $form, $form_state)) != NULL) {
    foreach ($bill_changes as $key => $value) {
      if ($order->{$key} != $value) {
        if (!is_array($value)) {
          $log[$key] = array(
            'old' => $order->{$key},
            'new' => $value,
          );
        }
        $order->{$key} = $value;
      }
    }
  }
  $refs = array_keys($order->data['cc_txns']['references']);
  $profile_id = end($refs);
  if ($message = _uc_recurring_uc_authorizenet_cim_update_paymentprofile($order, $profile_id)) {
    drupal_set_message(t('Account update failed: @error', array(
      '@error' => $message,
    )), 'error');
    $form_state['redirect'] = FALSE;
  }
  else {
    drupal_set_message(t('Account updated'));
    uc_order_save($order);
    $last4new = substr($order->payment_details['cc_number'], -4);
    if ($last4new != $last4old) {
      $log[t('Credit card')] = array(
        'old' => $last4old,
        'new' => $last4new,
      );
    }
    if ($log) {
      uc_order_log_changes($order->order_id, $log);
    }
  }
}