You are here

function commerce_braintree_tr_process_transaction in Commerce Braintree 7.3

Same name and namespace in other branches
  1. 7.2 commerce_braintree.module \commerce_braintree_tr_process_transaction()

Processes a Transparent Redirect transaction after the customer has returned.

Parameters

$order: The loaded order that is being processed

$payment_method: The payment method settings

$feedback: The parameters received from Braintree regarding the payment

$redirect: Boolean indicating whether or not to call redirect functions.

1 call to commerce_braintree_tr_process_transaction()
commerce_braintree_tr_redirect_form_validate in ./commerce_braintree.module
Payment method callback: Braintree Transparent Redirect form validation.

File

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

Code

function commerce_braintree_tr_process_transaction($order, $payment_method, $feedback, $redirect = TRUE) {

  // Initialize the Braintree client.
  commerce_braintree_initialize($payment_method);
  $result = Braintree_TransparentRedirect::confirm($feedback);
  $context = commerce_braintree_payment_session_load($order->order_id);
  if (module_exists('commerce_cardonfile') && !empty($payment_method['settings']['cardonfile']) && ($context === NULL || $context == 'new') && $result->success) {

    // Card on file parameters.
    $new_card_data = array();
    $new_card_data = commerce_cardonfile_new();

    // uid: the user ID of the account the card data is being stored for.
    $new_card_data->uid = $order->uid;

    // payment_method: the name of the payment method the card was used for.
    $new_card_data->payment_method = $payment_method['method_id'];

    // instance_id: the payment method instance ID containing the credentials
    // that will be used to reuse the card on file.
    $new_card_data->instance_id = $payment_method['instance_id'];

    // remote_id: the remote ID to the full card data at the payment gateway.
    $new_card_data->remote_id = $result->transaction->creditCard['token'];

    // card_type: short name of the credit card type if determined, based on the
    // keys returned by commerce_payment_credit_card_types().
    $new_card_data->card_type = $result->transaction->creditCard['cardType'];

    // card_name: the name of the cardholder.
    $new_card_data->card_name = $result->transaction->creditCard['cardholderName'];

    // card_number: the last 4 digits of the credit card number.
    $new_card_data->card_number = $result->transaction->creditCard['last4'];

    // card_exp_month: the numeric representation of the expiration month.
    $new_card_data->card_exp_month = $result->transaction->creditCard['expirationMonth'];

    // card_exp_year: the four digit expiration year.
    $new_card_data->card_exp_year = $result->transaction->creditCard['expirationYear'];

    // status: integer status of the card data: inactive (0), active (1), or
    // active and not deletable (2).
    $new_card_data->status = 1;

    // Save and log the creation of the new card on file.
    $save = commerce_cardonfile_save($new_card_data);
    watchdog('commerce_braintree', '@type ending in @number added for user @uid with token @token.', array(
      '@type' => $new_card_data->card_type,
      '@number' => $new_card_data->card_number,
      '@uid' => $order->uid,
      '@token' => $new_card_data->remote_id,
    ));
  }
  commerce_braintree_payement_session_delete($order->order_id);
  _commerce_braintree_default_process_transaction($result, $order, $payment_method, $redirect);
}