You are here

function commerce_stripe_cardonfile_update in Commerce Stripe 7.2

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

Card on file callback: updates the associated customer payment profile.

1 string reference to 'commerce_stripe_cardonfile_update'
commerce_stripe_commerce_payment_method_info in ./commerce_stripe.module
Implements hook_commerce_payment_method_info().

File

./commerce_stripe.module, line 508
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_cardonfile_update($form, &$form_state, $payment_method, $card_data) {
  if (!commerce_stripe_load_library()) {
    return FALSE;
  }

  // Fetch the customer id and card id from $card_data->remote_id
  list($customer_id, $card_id) = explode('|', $card_data->remote_id);
  Stripe::setApiKey($payment_method['settings']['secret_key']);
  try {
    $customer = Stripe_Customer::retrieve($customer_id);
    $card = $customer->cards
      ->retrieve($card_id);
    $card->exp_month = $form_state['values']['credit_card']['exp_month'];
    $card->exp_year = $form_state['values']['credit_card']['exp_year'];
    $card
      ->save();
    return TRUE;
  } catch (Exception $e) {
    drupal_set_message(t('We received the following error processing your card: %error. Please enter your information again or try a different card.', array(
      '%error' => $e
        ->getMessage(),
    )), 'error');
    watchdog('commerce_stripe', 'Following error received when updating card @stripe_error.', array(
      '@stripe_error' => $e
        ->getMessage(),
    ), WATCHDOG_NOTICE);
    return FALSE;
  }
}