function _commerce_braintree_default_process_transaction in Commerce Braintree 7
Same name and namespace in other branches
- 7.3 commerce_braintree.module \_commerce_braintree_default_process_transaction()
- 7.2 commerce_braintree.module \_commerce_braintree_default_process_transaction()
Process the actual Braintree transaction.
Parameters
$result:
$order:
array $payment_method:
$redirect:
2 calls to _commerce_braintree_default_process_transaction()
- commerce_braintree_cof_process_transaction in ./
commerce_braintree.commerce_braintree_cof.inc - Process the payment transaction with the info received.
- commerce_braintree_process_transaction in ./
commerce_braintree.commerce_braintree.inc - Process the payment transaction with the info received.
File
- ./
commerce_braintree.module, line 510 - Implementations of the Braintree payment gateway (http://braintreepayments.com) for drupal commerce.
Code
function _commerce_braintree_default_process_transaction($result, $order, $payment_method, $redirect) {
// Get the braintree transaction object.
$transaction = $result->transaction;
// Check if we already have this transaction stores in Commerce.
$transaction_id = isset($transaction->id) ? commerce_braintree_get_payment_transaction($transaction->id) : NULL;
if (!$transaction_id) {
$commerce_transaction = commerce_payment_transaction_new('braintree', $order->order_id);
}
else {
$commerce_transaction = commerce_payment_transaction_load($transaction_id);
}
$message = NULL;
if ($result->success) {
$processorResponseCode = $result->transaction->processorResponseCode;
$processorResponseText = $result->transaction->processorResponseText;
$message .= $processorResponseText;
}
else {
$message = $result->message;
drupal_set_message(t('There was an error: %error.', array(
'%error' => $result->message,
)), 'error');
}
// Prepare the data to be recorded in Commerce.
$commerce_transaction->instance_id = $payment_method['instance_id'];
$commerce_transaction->message = $message;
if ($redirect) {
if (!$result->success) {
$commerce_transaction->status = COMMERCE_PAYMENT_STATUS_FAILURE;
commerce_payment_transaction_save($commerce_transaction);
// There was an error, go back to the previous pane.
commerce_payment_redirect_pane_previous_page($order);
}
else {
$commerce_transaction->remote_id = $transaction->id;
$commerce_transaction->remote_status = $transaction->status;
// Commerce don't store amount in decimal, convert it.
$commerce_transaction->amount = commerce_currency_decimal_to_amount($transaction->amount, $transaction->currencyIsoCode);
$commerce_transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
commerce_payment_transaction_save($commerce_transaction);
// Transaction succeded. Go to next pane.
commerce_payment_redirect_pane_next_page($order);
}
}
}