You are here

function commerce_stripe_commerce_payment_method_info_alter in Commerce Stripe 7.3

Same name and namespace in other branches
  1. 7 commerce_stripe.module \commerce_stripe_commerce_payment_method_info_alter()
  2. 7.2 commerce_stripe.module \commerce_stripe_commerce_payment_method_info_alter()

Implements hook_commerce_payment_method_info_alter().

File

./commerce_stripe.module, line 873
This module provides Stripe (http://stripe.com/) payment gateway integration to Commerce. Commerce Stripe offers a PCI-compliant way to process payments straight from you Commerce shop.

Code

function commerce_stripe_commerce_payment_method_info_alter(&$payment_methods) {
  if (isset($payment_methods['commerce_stripe'])) {

    // The payment method info depends on the stripe integration method (stripe.js
    // or Stripe Checkout) the administrator has selected.  We need to load
    // the rules action to determine which integration method is selected.
    // Note that this code is intentionally duplicated to avoid the infinite
    // recursion that would occur if we called _commerce_stripe_load_settings().
    // @todo: Explore using a static variable to avoid that recursion.
    $stripe_integration = COMMERCE_STRIPE_DEFAULT_INTEGRATION;
    $cardonfile = FALSE;
    $payment_method_rule = rules_config_load('commerce_payment_commerce_stripe');
    if ($payment_method_rule && $payment_method_rule->active) {
      foreach ($payment_method_rule
        ->actions() as $action) {

        // Skip any actions that are not simple rules actions. (i.e. loops)
        if (!$action instanceof RulesAction) {
          continue;
        }
        if (!empty($action->settings['payment_method']['method_id']) && $action->settings['payment_method']['method_id'] == 'commerce_stripe') {

          // Default to Stripe.js if no integration_type has been chosen.
          if (!empty($action->settings['payment_method']['settings']['integration_type'])) {
            $stripe_integration = $action->settings['payment_method']['settings']['integration_type'];
          }
          $cardonfile = !empty($action->settings['payment_method']['settings']['cardonfile']) ? TRUE : FALSE;
          break;
        }
      }
    }

    // Set the cardonfile settings. We check that the administrator has enabled
    // cardonfile functionality for commerce_stripe; if not, we do not add the
    // cardonfile callbacks that would otherwise be called.
    if (!empty($cardonfile)) {

      // Allow charging and deleting saved cards for any Stripe integration method.
      $payment_methods['commerce_stripe']['cardonfile'] = array(
        'charge callback' => 'commerce_stripe_cardonfile_charge',
        'delete callback' => 'commerce_stripe_cardonfile_delete',
        'create form callback' => 'commerce_stripe_cardonfile_create_form',
        'create callback' => 'commerce_stripe_cardonfile_create',
        'update form callback' => 'commerce_stripe_cardonfile_update_form',
        'update callback' => 'commerce_stripe_cardonfile_update',
      );
    }
  }
}