You are here

function commerce_cardonfile_data_save in Commerce Card on File 7

Saves an array of card data.

Parameters

$card_data: An array of card data including the following keys:

  • card_id: if present, saves an existing card data array, otherwise inserts the card data in a new record
  • uid: the user ID of the account the card data is being stored for
  • payment_method: the name of the payment method the card was used for
  • instance_id: the payment method instance ID containing the credentials that will be used to reuse the card on file
  • remote_id: the remote ID to the full card data at the payment gateway
  • card_type: short name of the credit card type if determined, based on the keys returned by commerce_payment_credit_card_types()
  • card_name: the name of the cardholder
  • card_number: the last 4 digits of the credit card number
  • card_exp_month: the numeric representation of the expiration month
  • card_exp_year: the four digit expiration year
  • status: integer status of the card data: inactive (0), active (1), or active and not deletable (2).

Return value

The operation performed by drupal_write_record() on save; since the card data array is received by reference, it will contain the serial numeric card_id used to represent the card data locally after an insert.

2 calls to commerce_cardonfile_data_save()
commerce_cardonfile_delete_form_submit in includes/commerce_cardonfile.pages.inc
Form submit handler: delete stored card data.
commerce_cardonfile_update_form_submit in includes/commerce_cardonfile.pages.inc
Form submit handler: update stored card data.

File

./commerce_cardonfile.module, line 422
Supports card on file functionality for credit card payment methods by associating card data reference IDs from payment gateways with user accounts.

Code

function commerce_cardonfile_data_save(&$card_data) {
  if (!empty($card_data['card_id']) && commerce_cardonfile_data_load($card_data['card_id'])) {
    $card_data['changed'] = REQUEST_TIME;
    return drupal_write_record('commerce_card_data', $card_data, 'card_id');
  }
  else {
    $card_data['card_id'] = NULL;
    $card_data['created'] = REQUEST_TIME;
    $card_data['changed'] = REQUEST_TIME;
    return drupal_write_record('commerce_card_data', $card_data);
  }
}