CyberSource Flex Microform 的woocommerce plugin在使用的时候,如果未使用checkout页面进行支付调用,会发现无法输入信用卡号和安全码字段。(Fixed the issue where other plug-ins calling API payment did not use the checkout page, causing Flex Microform to not initialize.)
<script defer> /** * WooCommerce CyberSource Flex Microform handler. * 修复其他插件调用API支付未使用checkout页面,导致Flex Microform未初始化的问题。 * Fixed the issue where other plug-ins calling API payment did not use the checkout page, causing Flex Microform to not *initialize. * fix 2winter * url 2winter.com * date 2024/7/10 */ jQuery(document).ready(($) => {
// the base non-flex form handler for eChecks or credit cards with Flex disabled window.WC_Cybersource_Payment_Form_Handler = window.SV_WC_Payment_Form_Handler_v5_12_3;
/** * CyberSource Credit Card Flex Microform Handler class * * Loads CyberSource Flex Microform in an iframe and intercepts the form submission to inject the token returned by CyberSource. * * @since 2.0.0-dev-2 */ window.WC_Cybersource_Flex_Payment_Form_Handler = classWC_Cybersource_Flex_Payment_Form_HandlerextendsSV_WC_Payment_Form_Handler_v5_12_3 {
if (data.payment_form.id !== this.id) { return data.passed_validation; }
// if regular validation passed if (data.passed_validation) {
// if a saved method is selected, we have a token if (this.saved_payment_method_selected || this.get_flex_token()) {
let token_input = this.form.find('input#wc-cybersource-credit-card-payment-token-' + this.saved_payment_method_selected)
// these values are accessed by 3DS handler later on if (token_input.length) { this.card_expiration_month = token_input.data('card-expiration-month').toString(); this.card_expiration_year = token_input.data('card-expiration-year').toString(); }
// avoid calling init_cybersource_microform() again before the request to initialize the microform instance finishes if (this.initializing_microform_instance) { return; }
// bail if the hosted credit card form field is already part of the page if (this.microform_instance && this.microform_instance.iframe && $(`#${this.microform_instance.iframe.id}`).length) { return; }
// bail if the WooCommerce payment form is rendered if (!$('#wc-cybersource-credit-card-account-number-hosted').length > 0) { return }
// handle card type changes numberField.on('change', function (data) {
let $card_number_field = $('#wc-cybersource-credit-card-account-number-hosted');
// clear any previous card type classes $card_number_field.attr('class', (i, c) => { return c.replace(/(^|\s)card-type-\S+/g, ''); });
// set the card type class for display if (data && data.card && data.card[0] && data.card[0].name) { $card_number_field.addClass('card-type-' + data.card[0].name); }
let payload = JSON.parse(atob(token.split('.')[1])); let card = payload.content.paymentInformation.card
// these values are accessed by the 3DS handler later on if (card) { this.card_type = card.number && card.number.detectedCardTypes && card.number.detectedCardTypes.length ? card.number.detectedCardTypes[0] : null this.card_bin = card.number && card.number.bin ? card.number.bin : null this.card_expiration_month = card.expirationMonth ? card.expirationMonth.value : null this.card_expiration_year = card.expirationYear ? card.expirationYear.value : null }
if (payload.jti) { this.jti = payload.jti; }
// at this point the token & key may be added to the form as hidden fields $('[name=wc-cybersource-credit-card-flex-key]').val(this.capture_context); $('[name=wc-cybersource-credit-card-flex-token]').val(token);