You are here

function commerce_braintree_js_process_transaction in Commerce Braintree 7.3

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

Save a commerce_payment_transaction object from the Braintree API response.

2 calls to commerce_braintree_js_process_transaction()
commerce_braintree_cardonfile_charge in ./commerce_braintree.module
Commerce Card on File charge callback.
commerce_braintree_js_form_submit in ./commerce_braintree.module
Submit callback for the Braintree JS based payment methods.

File

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

Code

function commerce_braintree_js_process_transaction($order, $payment_method, $charge, $response) {
  $transaction = commerce_payment_transaction_new('braintree_dropin', $order->order_id);
  $transaction->instance_id = $payment_method['instance_id'];
  $transaction->remote_id = !empty($response->transaction->id) ? $response->transaction->id : NULL;
  $transaction->payload[REQUEST_TIME] = $response;
  if ($response instanceof \Braintree\Result\Error) {
    $currency_code = $charge['currency_code'];
    $amount_converted = $charge['amount'];
  }
  else {

    // Determine the charge amount from the response object.
    $amount = $response->transaction->amount;
    $currency_code = $response->transaction->currencyIsoCode;
    $amount_converted = commerce_currency_decimal_to_amount($amount, $currency_code);
  }

  // Determine the payment transaction internal status from the response status.
  $remote_status = !empty($response->transaction->status) ? $response->transaction->status : NULL;
  $transaction->amount = $amount_converted;
  $transaction->currency_code = $currency_code;
  $transaction->status = commerce_braintree_transaction_status($remote_status);
  $transaction->remote_status = $remote_status;
  $transaction->message = commerce_braintree_build_payment_transaction_message($response);
  commerce_payment_transaction_save($transaction);
  return $transaction;
}