You are here

function commerce_payment_rules_compare_balance in Commerce Core 7

Condition callback: checks the unpaid balance of an order.

1 string reference to 'commerce_payment_rules_compare_balance'
commerce_payment_rules_condition_info in modules/payment/commerce_payment.rules.inc
Implements hook_rules_condition_info().

File

modules/payment/commerce_payment.rules.inc, line 106
Rules integration for payments.

Code

function commerce_payment_rules_compare_balance($order, $operator, $value) {

  // Check the balance of the order.
  $balance = commerce_payment_order_balance($order);

  // If the balance was incalculable, set the balance to the order total.
  if ($balance === FALSE) {
    $balance = entity_metadata_wrapper('commerce_order', $order)->commerce_order_total
      ->value();
  }

  // Make a quantity comparison based on the operator.
  switch ($operator) {
    case '<':
      return $balance['amount'] < $value;
    case '<=':
      return $balance['amount'] <= $value;
    case '=':
      return $balance['amount'] == $value;
    case '>=':
      return $balance['amount'] >= $value;
    case '>':
      return $balance['amount'] > $value;
  }
  return FALSE;
}