本文整理汇总了PHP中WC_Payment_Gateway::validate_fields方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Payment_Gateway::validate_fields方法的具体用法?PHP WC_Payment_Gateway::validate_fields怎么用?PHP WC_Payment_Gateway::validate_fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Payment_Gateway
的用法示例。
在下文中一共展示了WC_Payment_Gateway::validate_fields方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate_fields
/**
* Validate payment form fields
*
* @see WC_Payment_Gateway::validate_fields()
*/
public function validate_fields()
{
$is_valid = parent::validate_fields();
$account_number = $this->get_post('elavon_vm_accountNumber');
$cv_number = $this->get_post('elavon_vm_cvNumber');
$expiration_month = $this->get_post('elavon_vm_expirationMonth');
$expiration_year = $this->get_post('elavon_vm_expirationYear');
// Elavon has stringent length limits for name/address fields
$billing_field_lengths = array('billing_first_name' => 20, 'billing_last_name' => 30, 'billing_company' => 50, 'billing_address_1' => 30, 'billing_address_2' => 30, 'billing_city' => 30, 'billing_state' => 30, 'billing_postcode' => 9, 'billing_country' => 50, 'billing_email' => 100, 'billing_phone' => 20);
// for each of our billing fields with maximum lengths
foreach ($billing_field_lengths as $field_name => $length) {
// if the supplied length exceeds the maximum
if (strlen($this->get_post($field_name)) > $length) {
// is there a checkout field with this name, to grab the label from? Otherwise, just use the upper-cased version of $field_name
if (isset(WC()->checkout()->checkout_fields['billing'][$field_name]['label']) && WC()->checkout()->checkout_fields['billing'][$field_name]['label']) {
$field_label = WC()->checkout()->checkout_fields['billing'][$field_name]['label'];
} else {
$field_label = ucwords(str_replace('_', ' ', $field_name));
}
if (false === stripos($field_label, 'billing')) {
wc_add_notice(sprintf(__('The billing %s is too long, %d characters maximum are allowed. Please fix the %s and try again.', WC_Elavon_VM::TEXT_DOMAIN), $field_label, $length, $field_label), 'error');
$is_valid = false;
} else {
wc_add_notice(sprintf(__('The %s is too long, %d characters maximum are allowed. Please fix the %s and try again.', WC_Elavon_VM::TEXT_DOMAIN), $field_label, $length, $field_label), 'error');
$is_valid = false;
}
}
}
if ($this->cvv_required()) {
// check security code
if (empty($cv_number)) {
wc_add_notice(__('Card security code is missing', WC_Elavon_VM::TEXT_DOMAIN), 'error');
$is_valid = false;
}
if (!ctype_digit($cv_number)) {
wc_add_notice(__('Card security code is invalid (only digits are allowed)', WC_Elavon_VM::TEXT_DOMAIN), 'error');
$is_valid = false;
}
if (strlen($cv_number) < 3 || strlen($cv_number) > 4) {
wc_add_notice(__('Card security code is invalid (wrong length)', WC_Elavon_VM::TEXT_DOMAIN), 'error');
$is_valid = false;
}
}
// check expiration data
$current_year = date('Y');
$current_month = date('n');
if (!ctype_digit($expiration_month) || !ctype_digit($expiration_year) || $expiration_month > 12 || $expiration_month < 1 || $expiration_year < $current_year || $expiration_year == $current_year && $expiration_month < $current_month || $expiration_year > $current_year + 20) {
wc_add_notice(__('Card expiration date is invalid', WC_Elavon_VM::TEXT_DOMAIN), 'error');
$is_valid = false;
}
// check card number
$account_number = str_replace(array(' ', '-'), '', $account_number);
if (empty($account_number) || !ctype_digit($account_number) || !$this->luhn_check($account_number)) {
wc_add_notice(__('Card number is invalid', WC_Elavon_VM::TEXT_DOMAIN), 'error');
$is_valid = false;
}
return $is_valid;
}