function commerce_braintree_void_form_submit in Commerce Braintree 7.3
Same name and namespace in other branches
- 7.2 includes/commerce_braintree.admin.inc \commerce_braintree_void_form_submit()
Submit handler: process the void request.
File
- includes/
commerce_braintree.admin.inc, line 136 - Provides admin forms for commerce_braintree.
Code
function commerce_braintree_void_form_submit($form, &$form_state) {
$transaction = $form_state['transaction'];
$payment_method = commerce_payment_method_instance_load($transaction->instance_id);
commerce_braintree_initialize($payment_method);
// Attempt to invoke the Braintree API and process a void transaction on the payment.
try {
$result = Braintree_Transaction::void($transaction->remote_id);
} catch (Exception $ex) {
$result = NULL;
}
// Inform the user if there were any issues processing the void.
if (empty($result) || empty($result->success)) {
$message = !empty($result->message) ? $result->message : t('No error provided from Braintree');
drupal_set_message(t('The payment transaction cannot be voided. @message', array(
'@message' => $message,
)), 'error');
}
// Inform the user of a successful void and update the payment transaction.
if (!empty($result) && !empty($result->success)) {
drupal_set_message(t('Void completed successfully.'));
// Update the payment transaction values to show the void.
$transaction->status = COMMERCE_PAYMENT_STATUS_FAILURE;
$transaction->remote_status = 'voided';
$transaction->message .= '<br />' . t('Voided: @date', array(
'@date' => format_date(REQUEST_TIME, 'short'),
));
commerce_payment_transaction_save($transaction);
}
$form_state['redirect'] = 'admin/commerce/orders/' . $form_state['order']->order_id . '/payment';
}