function commerce_stripe_cardonfile_update in Commerce Stripe 7
Same name and namespace in other branches
- 7.3 commerce_stripe.module \commerce_stripe_cardonfile_update()
- 7.2 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'
File
- ./
commerce_stripe.module, line 1027 - 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);
if (property_exists($customer, 'cards')) {
$card = $customer->cards
->retrieve($card_id);
}
else {
$card = $customer->sources
->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;
}
}