function commerce_braintree_refund_form_validate in Commerce Braintree 7.3
Same name and namespace in other branches
- 7.2 includes/commerce_braintree.admin.inc \commerce_braintree_refund_form_validate()
Validate handler: check the refund amount before attempting refund request.
File
- includes/
commerce_braintree.admin.inc, line 211 - Provides admin forms for commerce_braintree.
Code
function commerce_braintree_refund_form_validate($form, &$form_state) {
$transaction = $form_state['transaction'];
$amount = $form_state['values']['amount'];
// Ensure a positive numeric amount has been entered for refund.
if (!is_numeric($amount) || $amount <= 0) {
form_set_error('amount', t('You must specify a positive numeric amount to refund.'));
}
// Ensure the amount is less than or equal to the captured amount.
if ($amount > commerce_currency_amount_to_decimal($transaction->amount, $transaction->currency_code)) {
form_set_error('amount', t('You cannot refund more than the original transaction amount.'));
}
}