function commerce_paypal_wpp_capture_form_validate in Commerce PayPal 7.2
Same name and namespace in other branches
- 7 modules/wpp/includes/commerce_paypal_wpp.admin.inc \commerce_paypal_wpp_capture_form_validate()
Validate handler: ensure a valid amount is given.
File
- modules/
wpp/ includes/ commerce_paypal_wpp.admin.inc, line 67 - Administrative forms for the PayPal WPP module.
Code
function commerce_paypal_wpp_capture_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 within the allowed limit for PayPal authorizations.
$authorization_amount = commerce_currency_amount_to_decimal($transaction->amount, $transaction->currency_code);
$authorization_amount_upper = commerce_currency_amount_to_decimal($transaction->amount, $transaction->currency_code) + 75;
if ($amount > $authorization_amount * 1.15 || $amount > $authorization_amount_upper) {
form_set_error('amount', t('You cannot capture an amount $75 or 115% greater than the authorization amount in PayPal WPP.'));
}
// If the authorization has expired, display an error message and redirect.
if (REQUEST_TIME - $transaction->created > 86400 * 29) {
drupal_set_message(t('This authorization has passed its 29 day limit and cannot be captured.'), 'error');
drupal_goto('admin/commerce/orders/' . $form_state['order']->order_id . '/payment');
}
}