You are here

function commerce_authnet_acceptjs_create_customer_profile_request in Commerce Authorize.Net 7

Submits a createCustomerProfileRequest XML CIM API request to Authorize.Net.

This function will attempt to create a CIM Customer Profile and a default Payment Profile for it using the given payment details.

Parameters

$payment_method: The payment method instance array containing the API credentials for a CIM enabled Authorize.Net account.

$order: The order object containing the billing address and e-mail to use for the customer profile.

$payment_details: An array of payment details to use in the default payment profile. See the respective helper array functions for possible keys.

Return value

A SimpleXMLElement containing the API response.

See also

commerce_authnet_cim_credit_card_array()

1 call to commerce_authnet_acceptjs_create_customer_profile_request()
commerce_authnet_acceptjs_submit_new_card_form_submit in includes/commerce_authnet.acceptjs.inc
Handles advanced logic relating to creating AcceptJS orders with new card data.

File

includes/commerce_authnet.acceptjs.inc, line 499
Includes the Accept.js payment method callbacks.

Code

function commerce_authnet_acceptjs_create_customer_profile_request($payment_method, $order, $payment_details = array()) {
  $billto = commerce_authnet_cim_billto_array($order);

  // Build the base profile request data.
  $api_request_data = array(
    'profile' => array(
      'merchantCustomerId' => $order->uid,
      'description' => $billto['firstName'] . ' ' . $billto['lastName'],
      'email' => $order->mail,
    ),
  );
  if (!empty($payment_details)) {
    $api_request_data['profile']['paymentProfiles'] = array(
      'billTo' => $billto,
      'payment' => array(),
    );
  }

  // Add the shipping address if available.
  if (isset($order->commerce_customer_shipping)) {
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
    if ($order_wrapper->commerce_customer_shipping
      ->value()) {
      $api_request_data['profile']['shipToList'] = commerce_authnet_cim_shipto_array($order);
    }
  }

  // If the order is anonymous, unset the merchantCustomerId from the request.
  if (empty($api_request_data['profile']['merchantCustomerId'])) {
    unset($api_request_data['profile']['merchantCustomerId']);
  }
  if (!empty($payment_details['opaqueData'])) {
    $api_request_data['profile']['paymentProfiles']['payment'] = $payment_details;
  }
  return commerce_authnet_cim_request($payment_method, 'createCustomerProfileRequest', $api_request_data);
}