function commerce_stripe_pi_cardonfile_update in Commerce Stripe Payment Intent 7
Card on file callback: updates the associated customer payment profile.
1 call to commerce_stripe_pi_cardonfile_update()
- commerce_stripe_pi_cardonfile_update_form_submit in ./
commerce_stripe_pi.module - Submit the cardonfile update.
1 string reference to 'commerce_stripe_pi_cardonfile_update'
File
- ./
commerce_stripe_pi.module, line 1805 - Payment intent stripe payment integration.
Code
function commerce_stripe_pi_cardonfile_update($form, &$form_state, $payment_method, $card_data) {
if (!commerce_stripe_pi_load_library()) {
return FALSE;
}
// Fetch the customer id and paymenet method id from $card_data->remote_id.
list(, $payment_method_id) = explode('|', $card_data->remote_id);
try {
$data = array(
'card' => array(
'exp_month' => $form_state['values']['credit_card']['exp_month'],
'exp_year' => $form_state['values']['credit_card']['exp_year'],
),
);
$langcode = $form['commerce_customer_address']['#language'];
if (!empty($form_state['values']['commerce_customer_address'][$langcode])) {
$address = reset($form_state['values']['commerce_customer_address'][$langcode]);
$data['billing_details'] = array(
'address' => array(
'city' => $address['locality'],
'country' => $address['country'],
'line1' => $address['thoroughfare'],
'line2' => $address['premise'],
'postal_code' => $address['postal_code'],
'state' => $address['administrative_area'],
),
'name' => $address['name_line'],
);
}
PaymentMethod::update($payment_method_id, $data);
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_pi', 'Following error received when updating card @stripe_pi_error.', array(
'@stripe_pi_error' => $e
->getMessage(),
), WATCHDOG_NOTICE);
return FALSE;
}
}