(function ($) { "use strict"; $(document).ready(function () { initSonnyPayForm(); // 创建Modal HTML结构 $("body").append(` `); // 关闭Modal $(document).on( "click", ".sonnypay-close-btn, #sonnypay-modal-button", function () { $("#sonnypay-modal").hide(); } ); // 检查URL参数并显示对应的错误消息 function checkPaymentError() { var urlParams = new URLSearchParams(window.location.search); var errorCode = urlParams.get("sonnypay_error"); if (errorCode) { var title, message; switch (errorCode) { case "1": title = sonnypay_params.modal_titles.empty_card; message = sonnypay_params.modal_contents.empty_card; break; case "2": title = sonnypay_params.modal_titles.first_fail; message = sonnypay_params.modal_contents.first_fail; break; case "3": title = sonnypay_params.modal_titles.second_fail; message = sonnypay_params.modal_contents.second_fail; break; default: title = "Payment Failed"; message = "An error occurred while processing your order, please try again"; } showModal(title, message); // 清除URL中的错误参数,避免刷新后重复显示 history.replaceState( null, "", removeParam("sonnypay_error", window.location.href) ); } } // 显示Modal function showModal(title, message) { $("#sonnypay-modal-title").text(title); $("#sonnypay-modal-message").text(message); $("#sonnypay-modal").show(); // 添加倒计时功能(5秒后自动关闭) var countdown = sonnypay_params.auto_close_time; var countdownElement = $( '' ); $("#sonnypay-modal-button").before(countdownElement); // 更新倒计时显示 // countdownElement.text( // "Closing automatically in " + countdown + " seconds" // ); var countdownInterval = setInterval(function () { countdown--; // countdownElement.text( // "Closing automatically in " + countdown + " seconds" // ); if (countdown <= 0) { clearInterval(countdownInterval); $("#sonnypay-modal").hide(); countdownElement.remove(); } }, 1000); // 如果用户手动关闭,清除倒计时 $("#sonnypay-modal").on( "click", ".sonnypay-close-btn, #sonnypay-modal-button", function () { clearInterval(countdownInterval); countdownElement.remove(); } ); } // 从URL中移除参数 function removeParam(key, sourceURL) { var rtn = sourceURL.split("?")[0], param, params_arr = [], queryString = sourceURL.indexOf("?") !== -1 ? sourceURL.split("?")[1] : ""; if (queryString !== "") { params_arr = queryString.split("&"); for (var i = params_arr.length - 1; i >= 0; i -= 1) { param = params_arr[i].split("=")[0]; if (param === key) { params_arr.splice(i, 1); } } if (params_arr.length) { rtn = rtn + "?" + params_arr.join("&"); } } return rtn; } // 页面加载时检查错误 checkPaymentError(); // 检查URL中的错误参数 const urlParams = new URLSearchParams(window.location.search); const errorType = urlParams.get("sonnypay_error"); if (errorType) { // 移除WooCommerce默认错误提示 $(".woocommerce-error").remove(); // 显示对应的Modal if (errorType === "first_attempt") { showErrorModal("信用卡被拒绝", "信用卡被拒绝,请换另一张信用卡", false); } else if (errorType === "second_attempt") { showErrorModal( "支付方式不可用", "这个付款方式无法处理你的订单,请使用另一种付款方式", true ); } } function showErrorModal(title, message, disablePaymentMethod) { // 创建Modal HTML const modalHTML = `

${title}

${message}

`; // 添加到页面 $("body").append(modalHTML); // 关闭按钮事件 $(".sonnypay-modal-close").on("click", function () { $(".sonnypay-modal-overlay").remove(); // 如果是第二次失败,隐藏支付方式 if (disablePaymentMethod) { $("li.payment_method_sonnypay").hide(); } }); } }); // 1️⃣ 将 detectCardType 和 validateForm 移到最外层(IIFE 内部,但全局可访问) const detectCardType = function (number) { const patterns = { visa: /^4/, mastercard: /^(5[1-5]|222[1-9]|22[3-9]\d|2[3-6]\d{2}|27[0-1]\d|2720)/, amex: /^3[47]/, jcb: /^(2131|1800|35)/, discover: /^6(?:011|5|4[4-9]|22)/, }; for (const [type, pattern] of Object.entries(patterns)) { if (pattern.test(number)) { return type; } } return "unknown"; }; const validateForm = function () { let isValid = true; // 验证卡号 const cardNumber = $("#card-number").val().replace(/\D/g, ""); const cardType = detectCardType(cardNumber); if (cardType === "unknown" || cardNumber.length < 13) { $("#number-error").show(); $("#card-number").addClass("input-error"); isValid = false; } else { $("#number-error").hide(); $("#card-number").removeClass("input-error"); } // 验证过期日期 const month = $("#card-exp-month").val(); const year = $("#card-exp-year").val(); const currentYear = new Date().getFullYear() % 100; const minYear = 25; if (!month || !year || parseInt(year) < minYear) { $("#exp-error").show(); $("#card-exp-month, #card-exp-year").addClass("input-error"); isValid = false; } else { $("#exp-error").hide(); $("#card-exp-month, #card-exp-year").removeClass("input-error"); // 更新隐藏字段 $("#sonnypay-exp-date").val(month + '/' + year); } // 验证CVC const cvc = $("#card-cvc").val(); const requiredLength = cardType === "amex" ? 4 : 3; if (!cvc || cvc.length < requiredLength) { $("#cvc-error").show(); $("#card-cvc").addClass("input-error"); isValid = false; } else { $("#cvc-error").hide(); $("#card-cvc").removeClass("input-error"); } return isValid; }; // 2️⃣ 初始化函数(内部作用域) function initSonnyPayForm() { if ( !$("#sonny-payment-form").length || $("#payment_method_sonnypay:checked").length === 0 ) { return; } if ($("#sonny-payment-form").hasClass("sonnypay-initialized")) { return; } $("#sonny-payment-form").addClass("sonnypay-initialized"); const cardIcons = { visa: document.getElementById("visa-icon"), mastercard: document.getElementById("mastercard-icon"), amex: document.getElementById("amex-icon"), discover: document.getElementById("discover-icon"), jcb: document.getElementById("jcb-icon"), }; function detectCardType(number) { const patterns = { visa: /^4/, mastercard: /^(5[1-5]|222[1-9]|22[3-9]\d|2[3-6]\d{2}|27[0-1]\d|2720)/, amex: /^3[47]/, jcb: /^(2131|1800|35)/, discover: /^6(?:011|5|4[4-9]|22)/, }; for (const [type, pattern] of Object.entries(patterns)) { if (pattern.test(number)) { return type; } } return "unknown"; } // 卡号输入处理 $("#card-number").on("input", function (e) { let value = $(this).val().replace(/\D/g, ""); value = value.substring(0, 19); let formatted = value.replace(/(\d{4})(?=\d)/g, "$1 "); $(this).val(formatted); const detectedType = detectCardType(value); $("#sonnypay-type").val(detectedType); $("#sonnypay-card").val(value); }); // 卡号失去焦点验证 $("#card-number").on("blur", function (e) { const value = $(this).val().replace(/\D/g, ""); const detectedType = detectCardType(value); const errorElement = $("#number-error"); if (detectedType === "unknown" || value.length < 13) { errorElement.show(); $(this).addClass("input-error"); } else { errorElement.hide(); $(this).removeClass("input-error"); } }); // 过期日期选择处理 $("#card-exp-month, #card-exp-year").on("change", function() { const month = $("#card-exp-month").val(); const year = $("#card-exp-year").val(); if (month && year) { $("#exp-error").hide(); $("#card-exp-month, #card-exp-year").removeClass("input-error"); $("#sonnypay-exp-date").val(month + '/' + year); } }); // CVC输入处理 $("#card-cvc").on("input", function (e) { const value = $(this).val().replace(/\D/g, "").substring(0, 4); $(this).val(value); $("#sonnypay-cvc").val(value); }); // CVC验证 $("#card-cvc").on("blur", function (e) { const value = $(this).val(); const errorElement = $("#cvc-error"); if (value.length < 3) { errorElement.show(); $(this).addClass("input-error"); } else { errorElement.hide(); $(this).removeClass("input-error"); } }); } // 3️⃣ 监听支付方式变化 $(document.body).on("change", "input[name='payment_method']", function () { if ($(this).val() === "sonnypay") { initSonnyPayForm(); } }); // 4️⃣ 初始加载时尝试初始化 $(document).ready(function () { initSonnyPayForm(); }); // 5️⃣ 拦截结账按钮点击 $(document).on("click", "#place_order", function (e) { if ($("#payment_method_sonnypay:checked").length === 0) { return true; } if (!validateForm()) { e.preventDefault(); e.stopImmediatePropagation(); $("html, body").animate( { scrollTop: $(".input-error").first().offset().top - 100, }, 500 ); return false; } return true; }); // 6️⃣ 在支付方式切换时重新初始化 $(document.body).on("updated_checkout", function () { initSonnyPayForm(); }); })(jQuery); XTUNE POWER 9042461 Chevy Camaro 10 13 Halogen Models Only ( Does Not Fit Xenon HID Models ) OEM Style Headlights Black - Very Discout | Your Convenient Affordable Supermarket

XTUNE POWER 9042461 Chevy Camaro 10 13 Halogen Models Only ( Does Not Fit Xenon HID Models ) OEM Style Headlights Black

$82.00

XTUNE POWER Crystal Headlights< h1>9042461< h3>< hr>Chevy Camaro 10 13 Halogen Models Only ( Does Not Fit Xenon HID Models ) OEM Style Headlights Black< p>USD : 82.0

SKU: XTUNEXTUNEPOW296984573875184 Category:

XTUNE POWER Crystal Headlights< h1>

9042461< h3>< hr>

Chevy Camaro 10 13 Halogen Models Only ( Does Not Fit Xenon HID Models ) OEM Style Headlights Black< p>

USD : 82.0

Reviews

There are no reviews yet.

Be the first to review “XTUNE POWER 9042461 Chevy Camaro 10 13 Halogen Models Only ( Does Not Fit Xenon HID Models ) OEM Style Headlights Black”

Your email address will not be published. Required fields are marked *

Select your currency
USD United States (US) dollar
EUR Euro