function _commerce_cardonfile_payment_method_instances in Commerce Card on File 7.2
Returns all payment method instances for a given payment method id
Parameters
$method_id: A payment method id
$include_disabled: Return enabled and disabled instances
Return value
An array of all loaded payment method instances keyed by instance_id
4 calls to _commerce_cardonfile_payment_method_instances()
- commerce_cardonfile_add_any_access in ./
commerce_cardonfile.module - Determines if the user can create a card on any payment method.
- commerce_cardonfile_add_page in includes/
commerce_cardonfile.pages.inc - Menu callback: displays the add card page.
- commerce_cardonfile_menu in ./
commerce_cardonfile.module - Implements hook_menu().
- commerce_cardonfile_rules_payment_instance_charge_options_list in ./
commerce_cardonfile.rules.inc - Options list for payment method instances that provide a charge callback
File
- ./
commerce_cardonfile.module, line 1446 - Supports card on file functionality for credit card payment methods by associating card data reference IDs from payment gateways with user accounts.
Code
function _commerce_cardonfile_payment_method_instances($method_id, $include_disabled = FALSE) {
$cached_ids =& drupal_static(__FUNCTION__, array());
$include_disabled = !empty($include_disabled);
if (!array_key_exists($method_id, $cached_ids)) {
$cached_ids[$method_id] = array();
// load all rules ... no easier way
$rules_configs = rules_config_load_multiple(FALSE);
// find all rules with an action to enable this method
foreach ($rules_configs as $rule_name => $rule) {
// Only rules and sub-types have actions.
if (!$rule instanceof Rule) {
continue;
}
// fast skip if rule does not depend on commerce_payment
if (!isset($rule->dependencies) || !in_array('commerce_payment', $rule->dependencies)) {
continue;
}
foreach ($rule
->actions() as $action) {
// skip any actions that are not simple rules actions, ie loops
if (!$action instanceof RulesAction) {
continue;
}
if ($action
->getElementName() == 'commerce_payment_enable_' . $method_id) {
$instance_id = commerce_payment_method_instance_id($method_id, $rule);
$cached_ids[$method_id][$instance_id] = $rule->active;
continue 2;
// skip to next rule
}
}
}
}
// load instances
$instances = array();
if (!empty($cached_ids[$method_id])) {
foreach ($cached_ids[$method_id] as $instance_id => $instance_active) {
if ($instance_active || $include_disabled) {
$instances[$instance_id] = commerce_payment_method_instance_load($instance_id);
}
}
}
return $instances;
}