You are here

function commerce_braintree_cof_process_transaction in Commerce Braintree 7

Process the payment transaction with the info received.

Parameters

object $order: The loaded order that is being processed

array $payment_method: The payment method settings

string $feedback: The parameters received from Braintree regarding the payment

bool $redirect: Specifies whether to call redirect functions or not

2 calls to commerce_braintree_cof_process_transaction()
CommerceBraintreeCofTest::testCommerceBraintreeCofRequest in tests/commerce_braintree_cof.test
Test a card on File request. Be sure we store the credit card.
commerce_braintree_cof_redirect_form_validate in ./commerce_braintree.commerce_braintree_cof.inc
Implements hook_redirect_form_validate().

File

./commerce_braintree.commerce_braintree_cof.inc, line 129
Include payment method settings callback, redirect form callbacks...

Code

function commerce_braintree_cof_process_transaction($order, $payment_method, $feedback, $redirect = TRUE) {
  _commerce_braintree_init_credentials($payment_method);
  $result = Braintree_TransparentRedirect::confirm($feedback);
  $context = commerce_braintree_payment_session_load($order->order_id);
  if (($context === NULL || $context == 'new') && $result->success) {

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

    // 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->_attributes['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->_attributes['creditCard']['cardType'];

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

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

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

    // card_exp_year: the four digit expiration year.
    $new_card_data['card_exp_year'] = $result->transaction->_attributes['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_data_save($new_card_data);
    watchdog('commerce_braintree', 'COF, with remote ID @profile_id, added for user @uid.', array(
      '@profile_id' => $new_card_data['remote_id'],
      '@uid' => $order->uid,
    ));
  }
  commerce_braintree_payement_session_delete($order->order_id);
  _commerce_braintree_default_process_transaction($result, $order, $payment_method, $redirect);
}