You are here

function payment_rules_action_payment_line_item_add in Payment 7

Implements Rules action callback: add a line item.

Parameters

Payment $payment:

string $name: The line item's unique machine name.

string $description:

float $tax_rate: The tax rate that applies to the amount. Should be a float between 0 and 1.

integer $quantity:

integer|string $amount: The amount of money, either as an integer or string that contains placeholders or a Ctools math expression.

File

./payment.rules.inc, line 392
Rules integration.

Code

function payment_rules_action_payment_line_item_add(Payment $payment, $name, $description, $tax_rate, $quantity, $amount) {
  if (!is_numeric($amount)) {

    // Replace placeholders.
    $amount = token_replace($amount, array(
      'payment' => $payment,
    ));

    // Evaluate Ctools math expression.
    if (module_exists('ctools')) {
      $math = new ctools_math_expr();
      $amount = $math
        ->evaluate($amount);
    }
  }
  if (is_numeric($amount)) {
    $payment
      ->setLineItem(new PaymentLineItem(array(
      'name' => $name,
      'amount' => $amount,
      'description' => $description,
      'tax_rate' => $tax_rate,
      'quantity' => $quantity,
    )));
  }
}