You are here

function _commerce_braintree_get_transaction_informations in Commerce Braintree 7.3

Same name and namespace in other branches
  1. 7 commerce_braintree.module \_commerce_braintree_get_transaction_informations()
  2. 7.2 commerce_braintree.module \_commerce_braintree_get_transaction_informations()

Prepare data that will be sent during a Braintree transaction.

Parameters

$order:

Return value

array

2 calls to _commerce_braintree_get_transaction_informations()
commerce_braintree_js_form_submit in ./commerce_braintree.module
Submit callback for the Braintree JS based payment methods.
commerce_braintree_tr_redirect_form in ./commerce_braintree.module
Payment method callback: Braintree Transparent Redirect form.

File

./commerce_braintree.module, line 771
Integrates Braintree Transparent Redirect with Drupal Commerce.

Code

function _commerce_braintree_get_transaction_informations($order) {
  $wrapper = entity_metadata_wrapper('commerce_order', $order);

  // Get financial info.
  $currency_code = $wrapper->commerce_order_total->currency_code
    ->value();
  $amount = $wrapper->commerce_order_total->amount
    ->value();

  // Attempt to parse the first and last name if the name_line field is used.
  $customer_name = $wrapper->commerce_customer_billing->commerce_customer_address->name_line
    ->value();
  if (!empty($customer_name)) {
    $name_parts = explode(' ', $customer_name);
    $first_name = array_shift($name_parts);
    $last_name = implode(' ', $name_parts);
  }
  else {

    // Else grab each value separately.
    $first_name = $wrapper->commerce_customer_billing->commerce_customer_address->first_name
      ->value();
    $last_name = $wrapper->commerce_customer_billing->commerce_customer_address->last_name
      ->value();
    $customer_name = $first_name . ' ' . $last_name;
  }
  $country = $wrapper->commerce_customer_billing->commerce_customer_address->country
    ->value();
  $thoroughfare = $wrapper->commerce_customer_billing->commerce_customer_address->thoroughfare
    ->value();
  $locality = $wrapper->commerce_customer_billing->commerce_customer_address->locality
    ->value();
  $postal_code = $wrapper->commerce_customer_billing->commerce_customer_address->postal_code
    ->value();
  $administrative_area = $wrapper->commerce_customer_billing->commerce_customer_address->administrative_area
    ->value();
  $customer_mail = $wrapper->mail
    ->value();
  return array(
    $amount,
    $customer_name,
    $first_name,
    $last_name,
    $country,
    $thoroughfare,
    $locality,
    $postal_code,
    $administrative_area,
    $customer_mail,
  );
}