You are here

function commerce_braintree_update_card in Commerce Braintree 7

Same name and namespace in other branches
  1. 7.3 commerce_braintree.module \commerce_braintree_update_card()
  2. 7.2 commerce_braintree.module \commerce_braintree_update_card()

Menu callback. Get the query from Braintree when updating a credit card.

1 string reference to 'commerce_braintree_update_card'
commerce_braintree_menu in ./commerce_braintree.module
Implements hook_menu().

File

./commerce_braintree.module, line 63
Implementations of the Braintree payment gateway (http://braintreepayments.com) for drupal commerce.

Code

function commerce_braintree_update_card() {
  global $user;
  $feedback = commerce_braintree_get_feedback();
  if ($feedback) {
    $payment_method = commerce_payment_method_instance_load('braintree_cof|commerce_payment_braintree_cof');
    _commerce_braintree_init_credentials($payment_method);
    $result = Braintree_TransparentRedirect::confirm($feedback);
    $token = $result->creditCard->_attributes['token'];
    $cardholderName = $result->creditCard->_attributes['cardholderName'];
    $expirationMonth = $result->creditCard->_attributes['expirationMonth'];
    $expirationYear = $result->creditCard->_attributes['expirationYear'];
    $last4 = $result->creditCard->_attributes['last4'];
    $card_stored = db_select('commerce_card_data', 'ccd')
      ->fields('ccd')
      ->condition('ccd.remote_id', $token)
      ->execute()
      ->fetchAssoc();
    $card_stored['card_name'] = $cardholderName;
    $card_stored['card_exp_month'] = $expirationMonth;
    $card_stored['card_exp_year'] = $expirationYear;
    $card_stored['card_number'] = $last4;
    commerce_cardonfile_data_save($card_stored);
  }
  drupal_goto('user/' . $user->uid . '/stored-payment-methods');
}