function commerce_payment_commerce_payment_totals_row_info in Commerce Core 7
Implements hook_commerce_payment_totals_row_info().
File
- modules/
payment/ commerce_payment.module, line 376 - Defines the payment system and checkout integration.
Code
function commerce_payment_commerce_payment_totals_row_info($totals, $order) {
$rows = array();
if (count($totals) == 0) {
// Add a row for the remaining balance on the order.
if ($order) {
$balance = commerce_payment_order_balance($order, $totals);
$rows[] = array(
'data' => array(
array(
'data' => t('Order balance'),
'class' => array(
'label',
),
),
array(
'data' => commerce_currency_format($balance['amount'], $balance['currency_code']),
'class' => array(
'balance',
),
),
),
'class' => array(
'order-balance',
),
'weight' => 10,
);
}
}
elseif (count($totals) == 1) {
// Otherwise if there's only a single currency total...
$currency_code = key($totals);
// Add a row for the total amount paid.
$rows[] = array(
'data' => array(
array(
'data' => t('Total paid'),
'class' => array(
'label',
),
),
array(
'data' => commerce_currency_format($totals[$currency_code], $currency_code),
'class' => array(
'total',
),
),
),
'class' => array(
'total-paid',
),
'weight' => 0,
);
// Add a row for the remaining balance on the order.
if ($order) {
$balance = commerce_payment_order_balance($order, $totals);
// Fix false balances.
if (empty($balance)) {
$formatted_amount = commerce_currency_format(0, NULL);
}
else {
$formatted_amount = commerce_currency_format($balance['amount'], $balance['currency_code']);
}
$rows[] = array(
'data' => array(
array(
'data' => t('Order balance'),
'class' => array(
'label',
),
),
array(
'data' => $formatted_amount,
'class' => array(
'balance',
),
),
),
'class' => array(
'order-balance',
),
'weight' => 10,
);
}
}
else {
$weight = 0;
foreach ($totals as $currency_code => $amount) {
$rows[] = array(
'data' => array(
array(
'data' => t('Total paid (@currency_code)', array(
'@currency_code' => $currency_code,
)),
'class' => array(
'label',
),
),
array(
'data' => commerce_currency_format($amount, $currency_code),
'class' => array(
'total',
),
),
),
'class' => array(
'total-paid',
'total-' . $currency_code,
),
'weight' => $weight++,
);
}
}
return $rows;
}