You are here

function commerce_stripe_cardonfile_create in Commerce Stripe 7.3

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

Card on file callback: create

1 call to commerce_stripe_cardonfile_create()
commerce_stripe_cardonfile_create_form_submit in ./commerce_stripe.module
1 string reference to 'commerce_stripe_cardonfile_create'
commerce_stripe_commerce_payment_method_info_alter in ./commerce_stripe.module
Implements hook_commerce_payment_method_info_alter().

File

./commerce_stripe.module, line 1436
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_create($form, &$form_state, $payment_method, $card_data) {
  $account = $form_state['values']['user'];
  $card = _commerce_stripe_create_card($form_state['values']['stripe_token'], $account, $payment_method);
  if (!$card) {
    return;
  }

  // Associate a billing profile if we have one.
  $profile = NULL;
  if (isset($form_state['values']['commerce_customer_profile'])) {
    $profile = $form_state['values']['commerce_customer_profile'];
    $profile->status = TRUE;

    // Set the profile's uid if it's being created at this time.
    if (empty($profile->profile_id)) {
      $profile->uid = $account->uid;
    }

    // Notify field widgets.
    field_attach_submit('commerce_customer_profile', $profile, $form, $form_state);

    // Save the profile to pass to the form validators.
    commerce_customer_profile_save($profile);
  }
  $saved = _commerce_stripe_save_cardonfile($card, $card_data->uid, $payment_method, $form_state['values']['credit_card']['cardonfile_instance_default'], $profile);
}