function commerce_payleap_get_billing_info in Commerce Payleap 7
Prepare ExtData XML element.
4 calls to commerce_payleap_get_billing_info()
- CommercePayleapTest::createDummyCreditCardInfo in tests/
commerce_payleap.test - Return an array with credit card info.
- commerce_payleap_cof_submit_form_submit in ./
commerce_payleap.module - Payment method callback: checkout form submission - Card on file.
- commerce_payleap_customer_profile_request in ./
commerce_payleap.module - Submits a ManageCustomer request PayLeap. This function will perform a Add/Update/Delete of a Customer Profile
- commerce_payleap_direct_submit_form_submit in ./
commerce_payleap.module - Payment method callback: checkout form submission - Direct.
File
- ./
commerce_payleap.module, line 504 - Implements PayLeap payment services for use in Drupal Commerce.
Code
function commerce_payleap_get_billing_info($order) {
$billing_data = array(
'ext_data' => '',
'street' => '',
'street2' => '',
'city' => '',
'state' => '',
'zip' => '',
'country' => '',
'name_on_card' => '',
'first_name' => '',
'last_name' => '',
);
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
if ($order_wrapper->commerce_customer_billing
->value()) {
$ext_data = '';
$billing_address = $order_wrapper->commerce_customer_billing->commerce_customer_address
->value();
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);
}
// Build and populate the API request SimpleXML element.
$ext_data .= '<CustomerID>' . substr($order->uid, 0, 20) . '</CustomerID>';
// Customer Billing Address.
$ext_data .= '<Invoice><BillTo>';
$name_on_card = substr($billing_address['first_name'], 0, 50) . ' ' . substr($billing_address['last_name'], 0, 50);
// Use company name as billing name when available.
if (!empty($billing_address['organisation_name'])) {
$ext_data .= '<Name>' . substr($billing_address['organisation_name'], 0, 50) . '</Name>';
}
else {
$ext_data .= '<Name>' . $name_on_card . '</Name>';
}
$ext_data .= '<Email>' . substr($order->mail, 0, 255) . '</Email>';
$ext_data .= '<Address>';
$ext_data .= '<Street>' . substr($billing_address['thoroughfare'], 0, 60) . '</Street>';
$ext_data .= '<City>' . substr($billing_address['locality'], 0, 40) . '</City>';
$ext_data .= '<State>' . substr($billing_address['administrative_area'], 0, 40) . '</State>';
$ext_data .= '<Zip>' . substr($billing_address['postal_code'], 0, 20) . '</Zip>';
$ext_data .= '<Country>' . $billing_address['country'] . '</Country>';
$ext_data .= '</Address>';
$ext_data .= '</BillTo></Invoice>';
$billing_data['ext_data'] = $ext_data;
$billing_data['street'] = substr($billing_address['thoroughfare'], 0, 60);
$billing_data['street2'] = substr($billing_address['premise'], 0, 60);
$billing_data['city'] = substr($billing_address['locality'], 0, 40);
$billing_data['state'] = substr($billing_address['administrative_area'], 0, 40);
$billing_data['zip'] = substr($billing_address['postal_code'], 0, 20);
$billing_data['country'] = $billing_address['country'];
$billing_data['name_on_card'] = $name_on_card;
$billing_data['first_name'] = $billing_address['first_name'];
$billing_data['last_name'] = $billing_address['last_name'];
}
return $billing_data;
}