You are here

function commerce_payflow_link_reference_form_validate in Commerce PayPal 7.2

Validate handler: ensure a valid amount is given.

File

modules/payflow/includes/commerce_payflow.admin.inc, line 210
Administrative forms for the Payflow Link module.

Code

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

  // If the original transaction tender was PayPal, ensure there is a billing
  // agreement ID in place.
  if (!empty($transaction->data['commerce_payflow']['tender']) && $transaction->data['commerce_payflow']['tender'] == 'P' && empty($transaction->data['commerce_payflow']['baid'])) {
    drupal_set_message(t('This transaction was initiated from a PayPal account, but it has no billing agreement ID for use in reference transactions.'), 'error');
    drupal_goto('admin/commerce/orders/' . $form_state['order']->order_id . '/payment');
  }

  // If the transaction has expired, display an error message and redirect.
  if (REQUEST_TIME - $transaction->created > 86400 * 365) {
    drupal_set_message(t('This transaction has passed its 365 day limit and can no longer be used for reference transactions.'), 'error');
    drupal_goto('admin/commerce/orders/' . $form_state['order']->order_id . '/payment');
  }
}