function commerce_sagepay_release_form_validate in Drupal Commerce SagePay Integration 7
Validate handler: ensure a valid amount is given.
File
- includes/
commerce_sagepay_release.inc, line 71
Code
function commerce_sagepay_release_form_validate($form, &$form_state) {
$transaction = $form_state['transaction'];
$amount = $form_state['values']['amount'];
// Ensure a positive numeric amount has been entered for capture.
if (!is_numeric($amount) || $amount <= 0) {
form_set_error('amount', t('You must specify a positive numeric amount to release.'));
}
// Ensure the amount is less than or equal to the transaction amount.
if ($amount > commerce_currency_amount_to_decimal($transaction->amount, $transaction->currency_code)) {
form_set_error('amount', t('You cannot release more than you deferred through SagePay.'));
}
// If the transaction has expired, display an error message and redirect.
if (time() - $transaction->created > 86400 * 30) {
drupal_set_message(t('This authorization has passed its 90 day limit cannot be released.'), 'error');
drupal_goto('admin/commerce/orders/' . $form_state['order']->order_id . '/payment');
}
}