You are here

function commerce_braintree_cardonfile_update_delete in Commerce Braintree 7.2

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

Payment method callback: Braintree Transparent Redirect card on file delete.

3 string references to 'commerce_braintree_cardonfile_update_delete'
commerce_braintree_commerce_payment_method_info in ./commerce_braintree.module
Implements hook_commerce_payment_method_info().
commerce_braintree_dropin_commerce_payment_method_info in modules/commerce_braintree_dropin/commerce_braintree_dropin.module
Implements hook_commerce_payment_method_info().
commerce_braintree_hostedfields_commerce_payment_method_info in modules/commerce_braintree_hostedfields/commerce_braintree_hostedfields.module
Implements hook_commerce_payment_method_info().

File

./commerce_braintree.module, line 508
Integrates Braintree Transparent Redirect with Drupal Commerce.

Code

function commerce_braintree_cardonfile_update_delete($form, &$form_state, $payment_method, $card_data) {
  if (module_exists('commerce_cardonfile') && $form['#id'] == 'commerce-cardonfile-delete-form') {
    commerce_braintree_initialize($payment_method);
    try {
      $result = Braintree_CreditCard::delete($card_data->remote_id);
    } catch (Braintree_Exception_NotFound $e) {

      // If the card is not found in the Braintree vault, delete the local
      // record with no error message. The card data no longer exists or has
      // changed its token in Braintree, so there's no use keeping it locally.
      commerce_cardonfile_delete($card_data->card_id);
    }

    // If the delete request was successful delete the local data.
    if (!empty($result) && $result instanceof Braintree_Result_Successful) {
      commerce_cardonfile_delete($card_data->card_id);
    }
    return TRUE;
  }
}