当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Payment_Gateway::validate_fields方法代码示例

本文整理汇总了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;
 }
开发者ID:adrianjonmiller,项目名称:vadsupplies,代码行数:63,代码来源:class-wc-gateway-elavon-vm.php


注:本文中的WC_Payment_Gateway::validate_fields方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。