function commerce_stripe_capture_form_validate in Commerce Stripe 7.3
Validate handler: ensure a valid amount is given.
File
- includes/
commerce_stripe.admin.inc, line 246 - Provides admin forms and functions for commerce_stripe.
Code
function commerce_stripe_capture_form_validate($form, &$form_state) {
$transaction = $form_state['transaction'];
$amount = $form_state['values']['amount'];
// Verify this transaction is authorization only (AUTH_ONLY).
if ($transaction->remote_status != 'AUTH_ONLY') {
drupal_set_message(t('This operation can only be done on authorization only transactions.'), 'error');
drupal_goto('admin/commerce/orders/' . $form_state['order']->order_id . '/payment');
}
// Verify 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 capture.'));
}
// Verify the amount is less than or equal to the authorization amount.
if ($amount > commerce_currency_amount_to_decimal($transaction->amount, $transaction->currency_code)) {
form_set_error('amount', t('You cannot capture more than you authorized through Commerce Stripe.'));
}
// If the authorization has expired, display an error message and redirect.
if (time() - $transaction->created > 86400 * 7) {
drupal_set_message(t('This authorization has passed its 7 day limit and cannot be captured.'), 'error');
drupal_goto('admin/commerce/orders/' . $form_state['order']->order_id . '/payment');
}
}