function commerce_square_refund_form_validate in Commerce Square Connect 7
Validate handler: check the credit amount before attempting credit request.
File
- includes/
commerce_square.admin.inc, line 167 - Provides admin menu callbacks for Commerce Square.
Code
function commerce_square_refund_form_validate($form, &$form_state) {
$transaction = $form_state['transaction'];
$amount = $form_state['values']['amount'];
// Ensure a positive numeric amount has been entered for credit.
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 credit more than you captured through Square.'));
}
if (time() - $transaction->created > 86400 * 120) {
drupal_set_message(t('This capture has passed its 120 day limit for issuing refunds.'), 'error');
drupal_goto('admin/commerce/orders/' . $form_state['order']->order_id . '/payment');
}
}