You are here

function commerce_payment_method_instance_load in Commerce Core 7

Returns a payment method instance array which includes the settings specific to the context of the instance.

Parameters

$instance_id: A payment method instance ID in the form of a pipe delimited string containing the method_id and the enabling Rule's name.

Return value

The payment method instance object which is identical to the payment method object with the addition of the settings array.

8 calls to commerce_payment_method_instance_load()
CommercePaymentTransactionEntityController::buildContent in modules/payment/includes/commerce_payment_transaction.controller.inc
Builds a structured array representing the entity's content.
commerce_payment_order_transaction_add_form_submit in modules/payment/includes/commerce_payment.forms.inc
Submit callback for commerce_payment_order_transaction_add_form().
commerce_payment_pane_checkout_form in modules/payment/includes/commerce_payment.checkout_pane.inc
Payment pane: form callback.
commerce_payment_pane_checkout_form_submit in modules/payment/includes/commerce_payment.checkout_pane.inc
Payment pane: submit callback.
commerce_payment_pane_checkout_form_validate in modules/payment/includes/commerce_payment.checkout_pane.inc
Payment pane: validation callback.

... See full list

File

modules/payment/commerce_payment.module, line 726
Defines the payment system and checkout integration.

Code

function commerce_payment_method_instance_load($instance_id) {

  // Return FALSE if there is no pipe delimeter in the instance ID.
  if (strpos($instance_id, '|') === FALSE) {
    return FALSE;
  }

  // Explode the method key into its component parts.
  list($method_id, $rule_name) = explode('|', $instance_id);

  // Return FALSE if we didn't receive a proper instance ID.
  if (empty($method_id) || empty($rule_name)) {
    return FALSE;
  }

  // First load the payment method and add the instance ID.
  $payment_method = commerce_payment_method_load($method_id);
  $payment_method['instance_id'] = $instance_id;

  // Then load the Rule configuration that enables the method.
  $rule = rules_config_load($rule_name);

  // Return FALSE if it couldn't be loaded.
  if (empty($rule)) {
    return FALSE;
  }

  // Iterate over its actions to find one with the matching element ID and pull
  // its settings into the payment method object.
  $payment_method['settings'] = array();
  foreach ($rule
    ->actions() as $action) {
    if (is_callable(array(
      $action,
      'getElementName',
    )) && $action
      ->getElementName() == 'commerce_payment_enable_' . $method_id) {
      if (is_array($action->settings['payment_method']) && !empty($action->settings['payment_method']['settings'])) {
        $payment_method['settings'] = $action->settings['payment_method']['settings'];
      }
    }
  }
  return $payment_method;
}