You are here

function uc_authorizenet_arb_cancel in Ubercart 5

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

Cancels an ARB subscription.

Parameters

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

$order_id: Optional. The ID of the order the recurring fee was attached to.

$fee: Optional. The data array for the recurring fee being canceled.

Return value

TRUE or FALSE indicating the success of the cancellation.

2 calls to uc_authorizenet_arb_cancel()
uc_authorizenet_arb_admin_cancel_form_submit in payment/uc_authorizenet/uc_authorizenet.module
uc_authorizenet_arb_user_cancel_form_submit in payment/uc_authorizenet/uc_authorizenet.module

File

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

Code

function uc_authorizenet_arb_cancel($subscription_id, $order_id = NULL, $fee = array()) {
  $server = variable_get('uc_authnet_arb_mode', 'disabled');

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

  // Build the XML string.
  $xml = _uc_authorizenet_xml_api_wrapper('ARBCancelSubscriptionRequest', _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 cancellation 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 cancelled.', array(
    '@subscription_id' => $subscription_id,
  )), 'admin');

  // Let other modules act on the canceled fee.
  if (!empty($fee)) {
    module_invoke_all('uc_arb_cancel', $fee);
  }
  return TRUE;
}