You are here

function commerce_payment_enable_method in Commerce Core 7

Generic execution callback for the payment method.

1 string reference to 'commerce_payment_enable_method'
commerce_payment_rules_action_info in modules/payment/commerce_payment.rules.inc
Implements hook_rules_action_info().

File

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

Code

function commerce_payment_enable_method($order, $payment_method, $action_settings, $rule_state, $action, $callback_type) {

  // Find the Rule that contains this action.
  $rule = $action
    ->parentElement();
  while (!$rule instanceof RulesActionContainer) {
    if ($rule
      ->parentElement()) {
      $rule = $rule
        ->parentElement();
    }
    else {
      return;
    }
  }

  // Initialize variables for the payment method ID and settings.
  if (is_array($payment_method)) {
    $method_id = $payment_method['method_id'];
    $settings = !empty($payment_method['settings']) ? $payment_method['settings'] : array();
  }
  else {
    $method_id = $payment_method;
    $settings = array();
  }

  // Create a unique key for the instance of the payment method represented by
  // this action.
  $instance_id = commerce_payment_method_instance_id($method_id, $rule);

  // Set the payment method to the order along with its settings and context.
  $order->payment_methods[$instance_id] = array(
    'method_id' => $method_id,
    'settings' => $settings,
    'rule_name' => $rule->name,
    'weight' => $rule->weight,
  );
}