You are here

function commerce_authnet_cim_shipto_array in Commerce Authorize.Net 7

Generates a shipTo array for CIM API requests.

Parameters

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

Return value

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

3 calls to commerce_authnet_cim_shipto_array()
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_create_customer_profile_request in ./commerce_authnet.module
Submits a createCustomerProfileRequest XML CIM API request to Authorize.Net.

File

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

Code

function commerce_authnet_cim_shipto_array($order) {

  // Prepare the shipping address for use in the request.
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $shipping_address = $order_wrapper->commerce_customer_shipping->commerce_customer_address
    ->value();

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

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