PageSourceSearch

https://www.scie.org.uk/wp-content/plugins/invoice-payment-option-…/include/js/af_ig_front.js?ver=1.0.0

js scie.org.uk collected 2026-10-02 02:53:01 UTC 6,426 bytes, 187 lines download raw bytes

1
2jQuery( document ).on(
3	'click',
4	'li.wc_payment_method',
5	function(){
6		jQuery( document.body ).trigger( "update_checkout" );
7	}
8);
9
10var af_ig_front_nonce=af_ig_php_vars.nonce;
11var getshippingData = '';
12var getpaymentData = '';
13let debounceTimeout;
14
15jQuery(document).ready(function($) {
16
17
18jQuery( document ).on(
19	'click',
20	'.wc-block-checkout__use-address-for-billing',
21	function(){
22        setTimeout(() => {
23        wp.apiFetch({ path: '/wc/store/cart' }).then(posts => {
24            getshippingData = wooSelectedShipping();
25            getpaymentData = wooSelectedPaymentMethod();
26            debouncedAfCspBlockGetCheckoutDetails(posts.shipping_address, posts.billing_address, getshippingData, getpaymentData,posts.payment_methods);
27
28        });
29    }, 1000);
30	}
31);
32    setTimeout(() => {
33
34        wp.apiFetch({ path: '/wc/store/cart' }).then(posts => {
35            getshippingData = wooSelectedShipping();
36            getpaymentData = wooSelectedPaymentMethod();
37            debouncedAfCspBlockGetCheckoutDetails(posts.shipping_address, posts.billing_address, getshippingData, getpaymentData,posts.payment_methods);
38
39        });
40
41    
42        wp.hooks.addAction('experimental__woocommerce_blocks-checkout-set-shipping-address', 'a-cm-cart-block', handleHook);
43        wp.hooks.addAction('experimental__woocommerce_blocks-checkout-set-billing-address', 'a-cm-cart-block', handleHook);
44        wp.hooks.addAction('experimental__woocommerce_blocks-checkout-set-email-address', 'a-cm-cart-block', handleHook);
45        wp.hooks.addAction('experimental__woocommerce_blocks-checkout-set-selected-shipping-rate', 'a-cm-cart-block', handleHook);
46        wp.hooks.addAction('experimental__woocommerce_blocks-checkout-set-active-payment-method', 'a-cm-cart-block', handleHook);
47		
48
49    }, 1000);
50
51});
52
53function handleHook(checkout_form) {
54			
55    getshippingData = wooSelectedShipping();
56    getpaymentData = wooSelectedPaymentMethod();
57    debouncedAfCspBlockGetCheckoutDetails(
58        checkout_form.storeCart.shippingAddress,
59        checkout_form.storeCart.billingAddress,
60        getshippingData,
61        getpaymentData,
62        checkout_form.storeCart.paymentMethods
63    );
64}
65
66
67function wooSelectedShipping() {
68    const selectedOption = jQuery('#shipping-option input[type="radio"]:checked');
69    if (selectedOption.length) {
70        return selectedOption.closest('label').find('.wc-block-components-radio-control__label').text();
71    } else {
72        return 'no_shipping_selected';
73    }
74}
75
76function wooSelectedPaymentMethod() {
77    const selectedPaymentOption = jQuery('#payment-method .wc-block-components-radio-control__input[type="radio"]:checked');
78    if (selectedPaymentOption.length) {
79        const paymentId = selectedPaymentOption.attr('id');
80        return paymentId.split('-').pop();
81    } else {
82        return 'no_payment_selected';
83    }
84}
85
86let lastAjaxRequest;
87
88function sendCheckoutDetails(checkoutDetails,paymentMethods) {
89	jQuery('#radio-control-wc-payment-method-options-invoice').closest('.wc-block-components-radio-control-accordion-option').show();
90				jQuery('.af_ig_block_error').hide();
91    // Abort the previous AJAX request if it's still pending
92    if (lastAjaxRequest && lastAjaxRequest.readyState !== 4) {
93        lastAjaxRequest.abort();
94    }
95
96    // Make the new AJAX request and store it in the variable
97    lastAjaxRequest = jQuery.ajax({
98        url: af_ig_php_vars.admin_url,
99        type: 'POST',
100        data: {
101            action: 'af_ig_block_process_checkout_details',
102            checkoutDetails: checkoutDetails,
103            nonce:af_ig_front_nonce
104
105        },
106        success: function(response) {
107
108            if (response.data.invoicecheck == 'hideinvoice') {
109                jQuery('#radio-control-wc-payment-method-options-invoice').closest('.wc-block-components-radio-control-accordion-option').hide();
110            
111				if (checkPaymentMethods(paymentMethods)) {
112					
113
114					
115					// Check if the error notice already exists
116					if (jQuery('.af_ig_block_error').length === 0) {
117
118						const svgIcon = `
119						<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false">
120							<path d="M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"></path>
121						</svg>`;
122						
123						// Create the HTML with the SVG icon and error message
124						const noticeHTML = `<div class="af_ig_block_error wc-block-components-notice-banner is-error">${svgIcon} ${response.data.invoiceerror}</div>`;
125
126
127						// Insert the notice HTML if it doesn't already exist
128						jQuery('.wc-block-checkout__payment-method .wc-block-components-notices').html(noticeHTML);
129					}
130
131					jQuery('.af_ig_block_error').show();
132
133				}
134
135			} 
136			
137        },
138        error: function(xhr, status, error) {
139            if (status !== 'abort') { // Ignore errors from aborted requests
140             
141            }
142        }
143    });
144}
145
146
147function afcspblockgetcheckoutdetails(Shipping_details, Billing_details, ShippingMethod, getpaymentData,paymentMethods) {
148    var $checkbox = jQuery('.wc-block-checkout__use-address-for-billing #checkbox-control-0');
149    var checkoutDetails;
150
151    if ($checkbox.is(':checked')) {
152        checkoutDetails = {
153            "shipping": Shipping_details,
154            "billing": Shipping_details,
155            "shippingMethod": ShippingMethod,
156            "paymentMethod": getpaymentData
157        };
158    } else {
159        checkoutDetails = {
160            "shipping": Billing_details,
161            "billing": Billing_details,
162            "shippingMethod": ShippingMethod,
163            "paymentMethod": getpaymentData
164        };
165    }
166
167
168sendCheckoutDetails(checkoutDetails,paymentMethods);
169
170
171  
172}
173
174
175function debouncedAfCspBlockGetCheckoutDetails(shippingAddress, billingAddress, shippingMethod, paymentMethod,avaliblePaymentOptions) {
176    clearTimeout(debounceTimeout);
177    debounceTimeout = setTimeout(function() {
178        afcspblockgetcheckoutdetails(shippingAddress, billingAddress, shippingMethod, paymentMethod,avaliblePaymentOptions);
179    }, 100); // Adjust debounce time as needed
180}
181
182function checkPaymentMethods(paymentMethods) {
183	if (Array.isArray(paymentMethods) && paymentMethods.length === 1 && paymentMethods[0] === "invoice") {
184		return true;
185	}
186	return false;
187}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.