You are here

function _payment_method_adjustment in Ubercart Payment Method Adjustments 6

Same name and namespace in other branches
  1. 7 uc_pma.module \_payment_method_adjustment()
2 calls to _payment_method_adjustment()
uc_pma_method_items in ./uc_pma.module
uc_pma_order in ./uc_pma.module
Implementation of hook_order().

File

./uc_pma.module, line 167
This module hooks into a few different parts of Ubercart to allow store administrators to associate a fee or discount with payment methods.

Code

function _payment_method_adjustment($order) {
  $adjustment_data = array(
    'name' => _payment_method_data($order->payment_method, 'name'),
    'adjustment' => variable_get('uc_payment_method_' . $order->payment_method . '_adjustment', ''),
  );
  $subtotal = 0;
  foreach ($order->products as $item) {
    $item_total = $item->qty ? $item->qty * $item->price : $item->price;
    $subtotal += $item_total;
  }
  $discount = FALSE;
  $percent = FALSE;
  $adjustment = array();
  $adjustment = ereg_replace('[^-0-9' . variable_get('uc_currency_dec', '.') . '%]+', '', $adjustment_data['adjustment']);
  $ret['value'] = $adjustment;
  $ret['description'] = t('@name fee', array(
    '@name' => $adjustment_data['name'],
  ));
  if (strstr($adjustment, '-')) {
    $discount = TRUE;
  }
  if (strstr($adjustment, '%')) {
    $percent = TRUE;
    $adjustment = str_replace('%', '', $adjustment);
    $adjustment /= 100;
  }
  if ($percent) {
    $ret['value'] = $adjustment * $subtotal;
  }
  if ($discount) {
    $ret['description'] = t('@name discount', array(
      '@name' => $adjustment_data['name'],
    ));
  }
  $ret['value'] = number_format(str_replace(variable_get('uc_currency_dec', '.'), ".", $ret['value']), 2);
  return $ret;
}