You are here

function commerce_cop_confirm_payment_form_validate in Commerce Custom Offline Payments 7

Validate handler: ensure a valid amount is given.

File

./commerce_cop.module, line 161
Custom offline payment methods for Drupal Commerce.

Code

function commerce_cop_confirm_payment_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 capture.'));
  }

  // 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 confirm more than transaction amount.'));
  }

  // Fieldable payment transactions.
  if (!empty($form_state['field'])) {

    // Notify field widgets to validate their data.
    field_attach_form_validate('commerce_payment_transaction', $transaction, $form, $form_state);
  }
}