You are here

function _commerce_stripe_save_cardonfile in Commerce Stripe 7.2

Same name and namespace in other branches
  1. 7.3 commerce_stripe.module \_commerce_stripe_save_cardonfile()
  2. 7 commerce_stripe.module \_commerce_stripe_save_cardonfile()
2 calls to _commerce_stripe_save_cardonfile()
commerce_stripe_cardonfile_create in ./commerce_stripe.module
Card on file callback: create
commerce_stripe_submit_form_submit in ./commerce_stripe.module
Payment method callback: checkout form submission.

File

./commerce_stripe.module, line 320
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_save_cardonfile($card, $uid, $payment_method, $set_default) {

  // Store the Stripe customer and card ids in the remote id field of {commerce_cardonfile} table
  $remote_id = (string) $card->customer . '|' . (string) $card->id;

  // Populate and save the card
  $card_data = commerce_cardonfile_new();
  $card_data->uid = $uid;
  $card_data->payment_method = $payment_method['method_id'];
  $card_data->instance_id = $payment_method['instance_id'];
  $card_data->remote_id = $remote_id;
  $card_data->card_type = $card->type;
  $card_data->card_name = $card->name;
  $card_data->card_number = $card->last4;
  $card_data->card_exp_month = $card->exp_month;
  $card_data->card_exp_year = $card->exp_year;
  $card_data->status = 1;
  commerce_cardonfile_save($card_data);
  if ($set_default) {
    commerce_cardonfile_set_default_card($card_data->card_id);
  }
  watchdog('commerce_stripe', 'Stripe Customer Profile @profile_id created and saved to user @uid.', array(
    '@profile_id' => (string) $card->customer,
    '@uid' => $uid,
  ));
}