You are here

function commerce_authnet_cim_billto_array in Commerce Authorize.Net 7

Generates a billTo array for CIM API requests.

Parameters

$order: The order object containing the billing information used for the billTo.

$billing_address: Optional. A commerce_customer_address field value array to use when the order object is empty; useful for generating an API request when you do not have an order object.

Return value

An array used to generate the billTo XML in CIM API requests.

7 calls to commerce_authnet_cim_billto_array()
commerce_authnet_acceptjs_cardonfile_create in ./commerce_authnet.module
Commerce Card on File create callback.
commerce_authnet_acceptjs_create_customer_payment_profile_request in includes/commerce_authnet.acceptjs.inc
Submits a createCustomerPaymentProfileRequest XML CIM API request.
commerce_authnet_acceptjs_create_customer_profile_request in includes/commerce_authnet.acceptjs.inc
Submits a createCustomerProfileRequest XML CIM API request to Authorize.Net.
commerce_authnet_acceptjs_submit_form_submit in includes/commerce_authnet.acceptjs.inc
Payment method callback: checkout form submission.
commerce_authnet_cim_cardonfile_create in ./commerce_authnet.module
Commerce Card on File create callback.

... See full list

File

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

Code

function commerce_authnet_cim_billto_array($order, $billing_address = NULL) {

  // If an order was given, prepare the billing address for use in this request.
  if (!empty($order)) {
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
    $billing_address = $order_wrapper->commerce_customer_billing->commerce_customer_address
      ->value();
  }

  // Ensure we have a first and last name in the address.
  if (empty($billing_address['first_name'])) {
    $name_parts = explode(' ', $billing_address['name_line']);
    $billing_address['first_name'] = array_shift($name_parts);
    $billing_address['last_name'] = implode(' ', $name_parts);
  }

  // Ensure we have a state the address.
  if (empty($billing_address['administrative_area'])) {
    $billing_address['administrative_area'] = $billing_address['locality'];
  }

  // Ensure organisation name is keyed.
  if (!isset($billing_address['organisation_name'])) {
    $billing_address['organisation_name'] = '';
  }

  // Return the billTo array.
  return array(
    'firstName' => substr($billing_address['first_name'], 0, 50),
    'lastName' => substr($billing_address['last_name'], 0, 50),
    'company' => substr($billing_address['organisation_name'], 0, 50),
    'address' => substr($billing_address['thoroughfare'], 0, 60),
    'city' => substr($billing_address['locality'], 0, 40),
    'state' => substr($billing_address['administrative_area'], 0, 40),
    'zip' => substr($billing_address['postal_code'], 0, 20),
    'country' => $billing_address['country'],
  );
}