You are here

function uc_authorizenet_arb_update in Ubercart 5

Same name and namespace in other branches
  1. 6.2 payment/uc_authorizenet/uc_authorizenet.module \uc_authorizenet_arb_update()
  2. 7.3 payment/uc_authorizenet/uc_authorizenet.module \uc_authorizenet_arb_update()

Updates an ARB subscription; for simplicity's sake, payment schedule information cannot be updated at this time.

Parameters

$subscription_id: The ID of the subscription at Authorize.Net.

$updates: An array of data to update using key/value pairs from the XML API for ARB; keys should be children of the subscription element in the XML. See the ARB_guide.pdf from Authorize.Net for ARBCreateSubscriptionRequests.

Return value

TRUE or FALSE indicating the success of the cancellation.

2 calls to uc_authorizenet_arb_update()
uc_authorizenet_arb_admin_update_form_submit in payment/uc_authorizenet/uc_authorizenet.module
uc_authorizenet_arb_user_update_form_submit in payment/uc_authorizenet/uc_authorizenet.module

File

payment/uc_authorizenet/uc_authorizenet.module, line 925
Process payments using Authorize.net. Supports AIM and ARB.

Code

function uc_authorizenet_arb_update($subscription_id, $updates, $order_id = NULL) {
  $server = variable_get('uc_authnet_arb_mode', 'disabled');
  unset($update['paymentSchedule']);

  // Build the data array for the request.
  $data = array(
    'refId' => substr($order->order_id . '-' . time(), 0, 20),
    'subscriptionId' => $subscription_id,
    'subscription' => $updates,
  );

  // Build the XML string.
  $xml = _uc_authorizenet_xml_api_wrapper('ARBUpdateSubscriptionRequest', _uc_authorizenet_array_to_xml($data));

  // Send the request off to the server and get the response.
  $response = uc_authorizenet_xml_api($server, $xml);

  // Fail if the response is empty or FALSE.
  if (!$response) {
    return FALSE;
  }

  // Parse the response into a data array.
  $data = _uc_authorizenet_arb_parse_response($response);
  if ($data['resultCode'] == 'Error') {
    if (!empty($order_id)) {
      uc_order_comment_save($order_id, 0, t('Authorize.Net: Subscription @subscription_id updated failed.<br />@error - @text', array(
        '@subscription_id' => $subscription_id,
        '@error' => $data['code'],
        '@text' => $data['text'],
      )), 'admin');
    }
    return FALSE;
  }
  uc_order_comment_save($order_id, 0, t('Authorize.Net: Subscription @subscription_id updated.', array(
    '@subscription_id' => $subscription_id,
  )), 'admin');
  return TRUE;
}