PageSourceSearch

https://villageofhoperomania.org/wp-content/plugins/checkout-plugi…/assets/js/stripe-elements.js?ver=1.11.2

js villageofhoperomania.org collected 2026-10-10 01:20:00 UTC 42,211 bytes, 1,248 lines download raw bytes

1( function( $ ) {
2	const pubKey = cpsw_global_settings.public_key;
3	const inlineCC = cpsw_global_settings.inline_cc;
4	const mode = cpsw_global_settings.mode;
5	const ajaxUrl = cpsw_global_settings.ajax_url;
6	const jsNonce = cpsw_global_settings.js_nonce;
7	const allowedCards = cpsw_global_settings.allowed_cards;
8	const notAllowedString = cpsw_global_settings.not_allowed_string;
9	const defaultCards = cpsw_global_settings.default_cards;
10	const homeURL = cpsw_global_settings.get_home_url;
11	const stripeLocalized = cpsw_global_settings.stripe_localized;
12	const isUserLoggedIn = cpsw_global_settings.is_user_logged_in;
13
14	if ( '' === pubKey || ( 'live' === mode && ! cpsw_global_settings.is_ssl ) ) {
15		return;
16	}
17
18	const stripe = Stripe( pubKey );
19	const elements = stripe.elements();
20	let savedCard = false;
21	let savedPaymentElementMethod = false;
22	let card = null;
23	let cardNumber = null;
24	let cardExpiry = null;
25	let cardCvc = null;
26	let paymentForm = null;
27	let paymentMethod = '';
28	let paymentMethodSepa = '';
29	let paymentElementMethod = '';
30	let paymentType = '';
31	let isAllowedCard = '';
32	let selectedGatewayId = '';
33	let selectedIdealBank = '';
34	let selectedP24Bank = '';
35	let selectedPaymentElementType = '';
36	let sepaIBAN = false;
37	let emptySepaIBANMessage = cpsw_global_settings.empty_sepa_iban_message;
38	const currentUserBilling = cpsw_global_settings.current_user_billing;
39
40	const style = {
41		base: {
42			color: '#32325d',
43		},
44	};
45
46	// Register stripe app info
47	stripe.registerAppInfo( {
48		name: 'Checkout Plugins - Stripe Woo',
49		partner_id: 'pp_partner_KOjySVEy3ClX6G',
50		version: cpsw_global_settings.cpsw_version,
51		url: 'https://wordpress.org/plugins/checkout-plugins-stripe-woo/',
52	} );
53
54	// Create an instance of the iban Element
55	const sepaOptions = Object.keys( cpsw_global_settings.sepa_options ).length ? cpsw_global_settings.sepa_options : {};
56	const sepa = elements.create( 'iban', sepaOptions );
57
58	/**
59	 * display error messages for sepa
60	 */
61	sepa.on( 'change', ( { error } ) => {
62		if ( isSepaSaveCardChosen() ) {
63			return true;
64		}
65
66		if ( error ) {
67			sepaIBAN = false;
68			emptySepaIBANMessage = error.message;
69			$( '.cpsw_stripe_sepa_error' ).html( error.message );
70		} else {
71			sepaIBAN = true;
72			$( '.cpsw_stripe_sepa_error' ).html( '' );
73		}
74	} );
75
76	if ( 'yes' === inlineCC ) {
77		card = elements.create( 'card', {
78			style,
79			hidePostalCode: true,
80			iconStyle: 'solid',
81		} );
82
83		/**
84		 * display error messages
85		 */
86		card.on( 'change', ( { brand, error } ) => {
87			if ( brand ) {
88				isAllowedBrand( brand );
89				if ( ! isAllowedCard ) {
90					if ( 'unknown' === brand ) {
91						$( '.cpsw-stripe-error' ).html( '' );
92					} else {
93						$( '.cpsw-stripe-error' ).html( defaultCards[ brand ] + ' ' + notAllowedString );
94						return;
95					}
96				} else {
97					$( '.cpsw-stripe-error' ).html( '' );
98				}
99			}
100			if ( error ) {
101				$( '.cpsw-stripe-error' ).html( getStripeLocalizedMessage( error.code, error.message ) );
102			} else {
103				$( '.cpsw-stripe-error' ).html( '' );
104			}
105		} );
106	}
107
108	if ( 'no' === inlineCC ) {
109		cardNumber = elements.create( 'cardNumber', {
110			style,
111			iconStyle: 'solid',
112		} );
113
114		cardExpiry = elements.create( 'cardExpiry', {
115			style,
116		} );
117
118		cardCvc = elements.create( 'cardCvc', {
119			style,
120		} );
121		/**
122		 * display error messages
123		 */
124		cardNumber.on( 'change', ( { brand, error } ) => {
125			if ( brand ) {
126				isAllowedBrand( brand );
127				if ( ! isAllowedCard ) {
128					if ( 'unknown' === brand ) {
129						$( '.cpsw-number-error' ).html( '' );
130					} else {
131						$( '.cpsw-number-error' ).html( defaultCards[ brand ] + ' ' + notAllowedString );
132						return;
133					}
134				} else {
135					$( '.cpsw-number-error' ).html( '' );
136				}
137			}
138
139			if ( error ) {
140				$( '.cpsw-number-error' ).html( getStripeLocalizedMessage( error.code, error.message ) );
141			} else {
142				$( '.cpsw-number-error' ).html( '' );
143			}
144		} );
145		cardExpiry.on( 'change', ( { error } ) => {
146			if ( error ) {
147				$( '.cpsw-expiry-error' ).html( getStripeLocalizedMessage( error.code, error.message ) );
148			} else {
149				$( '.cpsw-expiry-error' ).html( '' );
150			}
151		} );
152		cardCvc.on( 'change', ( { error } ) => {
153			if ( error ) {
154				$( '.cpsw-cvc-error' ).html( getStripeLocalizedMessage( error.code, error.message ) );
155			} else {
156				$( '.cpsw-cvc-error' ).html( '' );
157			}
158		} );
159	}
160
161	const options = {
162		style: {
163			base: {
164				padding: '10px 12px',
165				color: '#32325d',
166				fontSize: '16px',
167				'::placeholder': {
168					color: '#aab7c4',
169					backgroundColor: '#fff',
170				},
171			},
172		},
173	};
174
175	const paymentElementSettings = cpsw_global_settings.payment_element_settings;
176	const theme = paymentElementSettings.appearance.theme;
177	switch ( theme ) {
178		case 'minimal':
179			paymentElementSettings.appearance = {
180				theme: 'flat',
181				variables: {
182					fontFamily: ' "Gill Sans", sans-serif',
183					fontLineHeight: '1.5',
184					borderRadius: '10px',
185					colorBackground: '#F6F8FA',
186					accessibleColorOnColorPrimary: '#262626',
187				},
188				rules: {
189					'.Block': {
190						backgroundColor: 'var(--colorBackground)',
191						boxShadow: 'none',
192						padding: '12px',
193					},
194					'.Input': {
195						padding: '12px',
196					},
197					'.Input:disabled, .Input--invalid:disabled': {
198						color: 'lightgray',
199					},
200					'.Tab': {
201						padding: '10px 12px 8px 12px',
202						border: 'none',
203					},
204					'.Tab:hover': {
205						border: 'none',
206						boxShadow: '0px 1px 1px rgba(0, 0, 0, 0.03), 0px 3px 7px rgba(18, 42, 66, 0.04)',
207					},
208					'.Tab--selected, .Tab--selected:focus, .Tab--selected:hover': {
209						border: 'none',
210						backgroundColor: '#fff',
211						boxShadow: '0 0 0 1.5px var(--colorPrimaryText), 0px 1px 1px rgba(0, 0, 0, 0.03), 0px 3px 7px rgba(18, 42, 66, 0.04)',
212					},
213					'.Label': {
214						fontWeight: '500',
215					},
216				},
217			};
218			break;
219		case 'bubblegum':
220			paymentElementSettings.appearance = {
221				theme: 'stripe',
222				variables: {
223					fontWeightNormal: '500',
224					borderRadius: '2px',
225					colorPrimary: '#f360a6',
226					tabIconSelectedColor: '#fff',
227					gridRowSpacing: '16px',
228				},
229				rules: {
230					'.Tab, .Input, .Block, .CheckboxInput, .CodeInput': {
231						boxShadow: '0px 3px 10px rgba(18, 42, 66, 0.08)',
232					},
233					'.Block': {
234						borderColor: 'transparent',
235					},
236					'.BlockDivider': {
237						backgroundColor: '#ebebeb',
238					},
239					'.Tab, .Tab:hover, .Tab:focus': {
240						border: '0',
241					},
242					'.Tab--selected, .Tab--selected:hover': {
243						backgroundColor: '#f360a6',
244						color: '#fff',
245					},
246				},
247			};
248			break;
249		case 'ninety-five':
250			paymentElementSettings.appearance = {
251				theme: 'flat',
252				variables: {
253					fontFamily: 'Verdana',
254					fontLineHeight: '1.5',
255					borderRadius: '0',
256					colorBackground: '#fff',
257					focusBoxShadow: 'none',
258					focusOutline: '-webkit-focus-ring-color auto 1px',
259					tabIconSelectedColor: 'var(--colorText)',
260				},
261				rules: {
262					'.Input, .CheckboxInput, .CodeInput': {
263						transition: 'none',
264						boxShadow: 'inset -1px -1px #ffffff, inset 1px 1px #0a0a0a, inset -2px -2px #dfdfdf, inset 2px 2px #808080',
265					},
266					'.Input': {
267						padding: '12px',
268					},
269					'.Input--invalid': {
270						color: '#DF1B41',
271					},
272					'.Tab, .Block, .PickerItem--selected': {
273						backgroundColor: '#dfdfdf',
274						boxShadow: 'inset -1px -1px #0a0a0a, inset 1px 1px #ffffff, inset -2px -2px #808080, inset 2px 2px #dfdfdf',
275					},
276					'.Tab': {
277						transition: 'none',
278					},
279					'.Tab:hover': {
280						backgroundColor: '#eee',
281					},
282					'.Tab--selected, .Tab--selected:focus, .Tab--selected:hover': {
283						color: 'var(--colorText)',
284						backgroundColor: '#ccc',
285					},
286					'.Tab:focus, .Tab--selected:focus': {
287						boxShadow: 'inset -1px -1px #0a0a0a, inset 1px 1px #ffffff, inset -2px -2px #808080, inset 2px 2px #dfdfdf',
288						outline: 'none',
289					},
290					'.Tab:focus-visible': {
291						outline: 'var(--focusOutline)',
292					},
293					'.PickerItem': {
294						backgroundColor: '#dfdfdf',
295						boxShadow: 'inset -1px -1px #0a0a0a, inset 1px 1px #ffffff, inset -2px -2px #808080, inset 2px 2px #dfdfdf',
296						transition: 'none',
297					},
298					'.PickerItem:hover': {
299						backgroundColor: '#eee',
300					},
301					'.PickerItem--highlight': {
302						outline: '1px solid blue',
303					},
304					'.PickerItem--selected:hover': {
305						backgroundColor: '#dfdfdf',
306					},
307				},
308			};
309			break;
310		case 'dark-blue':
311			paymentElementSettings.appearance = {
312				theme: 'night',
313				variables: {
314					fontFamily: 'Sohne, system-ui, sans-serif',
315					fontWeightNormal: '500',
316					borderRadius: '8px',
317					colorBackground: '#0A2540',
318					colorPrimary: '#EFC078',
319					accessibleColorOnColorPrimary: '#1A1B25',
320					colorText: 'white',
321					colorTextPlaceholder: '#727F96',
322					tabIconColor: 'white',
323					logoColor: 'dark',
324				},
325				rules: {
326					'.Input, .Block': {
327						backgroundColor: '#0A2540',
328						border: '1.5px solid var(--colorPrimary)',
329					},
330					'.Tab': {
331						color: 'white',
332					},
333				},
334			};
335			break;
336		default:
337			paymentElementSettings.appearance = { theme: 'stripe' };
338			break;
339	}
340	const paymentElementOptions = cpsw_global_settings.payment_element_options;
341
342	paymentElementOptions.fields = {
343		billingDetails: {
344			name: getBillingDetails()?.name ? 'never' : 'auto',
345			email: getBillingDetails()?.email ? 'never' : 'auto',
346			phone: getBillingDetails()?.phone ? 'never' : 'auto',
347			address: {
348				country: getBillingDetails()?.address?.country ? 'never' : 'auto',
349				line1: getBillingDetails()?.address?.line1 ? 'never' : 'auto',
350				line2: getBillingDetails()?.address?.line2 ? 'never' : 'auto',
351				city: getBillingDetails()?.address?.city ? 'never' : 'auto',
352				state: getBillingDetails()?.address?.state ? 'never' : 'auto',
353				postalCode: getBillingDetails()?.address?.postal_code ? 'never' : 'auto',
354			},
355		},
356	};
357
358	// Create an instance of the idealBank Element
359	const ideal = elements.create( 'idealBank', options );
360	// Create an instance of the p24 Element
361	const p24 = elements.create( 'p24Bank', options );
362
363	const elementsForPayment = stripe.elements( paymentElementSettings );
364	// Create an instance of the Payment Element
365	const paymentElement = elementsForPayment.create( 'payment', paymentElementOptions );
366	// If Payment element is not loaded, show error message
367	paymentElement.on( 'loaderror', ( event ) => {
368		if ( event.error ) {
369			const errorCode = event.error.code ? event.error.code : event.error?.message_code;
370			$( '.cpsw_stripe_payment_element_error' ).html(
371				getStripeLocalizedMessage( 'payment_element_loaderror', null ) + getStripeLocalizedMessage( errorCode, event?.error?.message ),
372			);
373		}
374	} );
375
376	const saveCardGateways = cpsw_global_settings.savecard_supported_gateways;
377
378	paymentElement.on( 'change', ( event ) => {
379		selectedPaymentElementType = event.value.type;
380		if ( ! saveCardGateways.includes( selectedPaymentElementType ) ) {
381			$( '.cpsw-payment-element-save-method' ).hide();
382			$( 'input[name="wc-cpsw_stripe_element-new-payment-method"]' ).prop( 'checked', false );
383			$( 'input[name="wc-cpsw_stripe_element-new-payment-method"]' ).trigger( 'change' );
384		} else {
385			$( '.cpsw-payment-element-save-method' ).show();
386		}
387	} );
388
389	ideal.on( 'change', function( event ) {
390		selectedIdealBank = event.value;
391		$( '.cpsw_stripe_ideal_error' ).html( '' );
392	} );
393
394	function isSepaSaveCardChosen() {
395		return (
396			$( '#payment_method_cpsw_sepa' ).is( ':checked' ) &&
397			$( 'input[name="wc-cpsw_sepa-payment-token"]' ).is( ':checked' ) &&
398			'new' !== $( 'input[name="wc-cpsw_sepa-payment-token"]:checked' ).val()
399		);
400	}
401
402	p24.on( 'change', function( event ) {
403		selectedP24Bank = event.value;
404		$( '.cpsw_stripe_p24_error' ).html( '' );
405	} );
406
407	function mountCard() {
408		$( '.cpsw-stripe-elements-form' ).show();
409		if ( 0 === $( '.cpsw-stripe-elements-form' ).length ) {
410			return;
411		}
412		if ( 'yes' === inlineCC ) {
413			if ( $( '.cpsw-stripe-elements-form .cpsw-cc' ).html() ) {
414				card.unmount();
415			}
416			card.mount( '.cpsw-stripe-elements-form .cpsw-cc' );
417			$( '.cpsw-stripe-elements-form div' ).css( { backgroundColor: '#fff', padding: '1em' } );
418		} else if ( 'no' === inlineCC ) {
419			cardNumber.mount( '.cpsw-stripe-elements-form .cpsw-number' );
420			cardExpiry.mount( '.cpsw-stripe-elements-form .cpsw-expiry' );
421			cardCvc.mount( '.cpsw-stripe-elements-form .cpsw-cvc' );
422			$( '.cpsw-stripe-elements-form div' ).css( { backgroundColor: '#fff', padding: '1em', marginTop: '0.5em' } );
423		}
424	}
425
426	function mountSepa() {
427		if ( 0 === $( '.payment_method_cpsw_sepa' ).length ) {
428			return false;
429		}
430
431		sepa.mount( '.cpsw_stripe_sepa_iban_element_field' );
432		$( '.cpsw_stripe_sepa_payment_form .cpsw_stripe_sepa_iban_element_field' ).css( { backgroundColor: '#fff', borderRadius: '3px' } );
433	}
434
435	function mountIdeal() {
436		$( '.cpsw_stripe_ideal_form' ).show();
437		if ( 0 === $( '.cpsw_stripe_ideal_form' ).length ) {
438			return;
439		}
440
441		ideal.mount( '.cpsw_stripe_ideal_form .cpsw_stripe_ideal_select' );
442		$( '.cpsw_stripe_ideal_form .cpsw_stripe_ideal_select' ).css( { backgroundColor: '#fff' } );
443	}
444
445	function mountP24() {
446		$( '.cpsw_stripe_p24_form' ).show();
447		if ( 0 === $( '.cpsw_stripe_p24_form' ).length ) {
448			return;
449		}
450
451		p24.mount( '.cpsw_stripe_p24_form .cpsw_stripe_p24_select' );
452		$( '.cpsw_stripe_p24_form .cpsw_stripe_p24_select' ).css( { backgroundColor: '#fff' } );
453	}
454
455	function mountPaymentElement() {
456		if ( 0 === $( '.cpsw_stripe_element_payment_form' ).length ) {
457			return false;
458		}
459
460		paymentElement?.mount( '#cpsw_stripe_payment_element' );
461	}
462
463	function mountGateways() {
464		mountCard();
465		mountIdeal();
466		mountP24();
467		mountSepa();
468		mountPaymentElement();
469	}
470
471	function createStripePaymentMethod() {
472		let paymentObject = {};
473		switch ( selectedGatewayId ) {
474			case 'cpsw_stripe':
475				if ( 'no' === inlineCC ) {
476					card = cardNumber;
477				}
478				paymentObject = {
479					type: 'card',
480					card,
481				};
482				stripe.createPaymentMethod( paymentObject )
483					.then( function( result ) {
484						// Handle result.error or result.paymentMethod
485						if ( result.paymentMethod ) {
486							paymentMethod = result.paymentMethod.id;
487							const brand = result.paymentMethod.card.brand;
488							$( '.cpsw_payment_method' ).remove();
489							$( '.cpsw_card_brand' ).remove();
490							paymentForm.append(
491								"<input type='hidden' class='cpsw_payment_method' name='payment_method_created' value='" +
492								paymentMethod +
493								"'/><input type='hidden' class='cpsw_card_brand' name='card_brand' value='" +
494								brand +
495								"'/>",
496							);
497							if ( $( 'form#order_review' ).length && cpsw_global_settings.changing_payment_method ) {
498								confirmCardSetup( paymentMethod );
499							} else if ( $( 'form#add_payment_method' ).length ) {
500								confirmCardSetup( paymentMethod );
501							} else {
502								paymentForm.trigger( 'submit' );
503							}
504						} else if ( result.error ) {
505							$( '.woocommerce-error' ).remove();
506							$( 'form.woocommerce-checkout' ).unblock();
507							$( 'form#order_review' ).unblock();
508							$( 'form#add_payment_method' ).unblock();
509							logError( result.error );
510							$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + getStripeLocalizedMessage( result.error.code, result.error.message ) + '</div>' ).show();
511							window.scrollTo( { top: 0, behavior: 'smooth' } );
512							return false;
513						}
514					} );
515				break;
516			case 'cpsw_sepa':
517				if ( $( 'form.woocommerce-checkout' ).length && 'no' === cpsw_global_settings.is_cart_amount_zero ) {
518					return true;
519				}
520
521				$( '.woocommerce-error' ).remove();
522				stripe.createPaymentMethod( {
523					type: 'sepa_debit',
524					sepa_debit: sepa,
525					billing_details: $( 'form.woocommerce-checkout' ).length ? getBillingDetails() : currentUserBilling,
526				} ).then( function( result ) {
527					$( 'input.cpsw_payment_method' ).remove();
528					// Handle result.error or result.paymentMethod
529					if ( result.paymentMethod ) {
530						paymentMethodSepa = result.paymentMethod.id;
531						paymentForm.append(
532							"<input type='hidden' class='cpsw_payment_method' name='payment_method_created' value='" +
533							paymentMethodSepa +
534							"'/>",
535						);
536						paymentForm.trigger( 'submit' );
537					} else if ( result.error ) {
538						$( 'form.woocommerce-checkout' ).unblock();
539						logError( result.error );
540						$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + getStripeLocalizedMessage( result.error.code, result.error.message ) + '</div>' ).show();
541						window.scrollTo( { top: 0, behavior: 'smooth' } );
542						$( 'form#order_review' ).unblock();
543						$( 'form#add_payment_method' ).unblock();
544						return false;
545					}
546				} );
547				break;
548			case 'cpsw_stripe_element':
549				if ( selectedPaymentElementType === 'cashapp' && getBillingDetails().address?.country?.toLowerCase() !== 'us' ) {
550					$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + getStripeLocalizedMessage( 'cashapp_country_error', null ) + '</div>' ).show();
551					window.scrollTo( { top: 0, behavior: 'smooth' } );
552					return false;
553				}
554				let billingDetails = getBillingDetails();
555
556				// Check if the URL contains 'pay_for_order'
557				if ( window.location.href.includes( 'pay_for_order' ) ) {
558					const orderpayBillingCountry = cpsw_global_settings.order_pay_country;
559
560					// Initialize billingDetails if it's null
561					if ( ! billingDetails ) {
562						billingDetails = {
563							address: {},
564						};
565					}
566
567					// Ensure the address object exists
568					if ( ! billingDetails.address ) {
569						billingDetails.address = {};
570					}
571
572					// Assign the country
573					billingDetails.address.country = orderpayBillingCountry;
574				}
575
576				elements.submit();
577				stripe.createPaymentMethod( {
578					elements: elementsForPayment,
579					params: {
580						billing_details: $( 'form.woocommerce-checkout' ).length || window.location.href.includes( 'pay_for_order' ) ? billingDetails : currentUserBilling,
581					},
582				} ).then( function( result ) {
583					$( '.woocommerce-error' ).remove();
584					if ( result.paymentMethod ) {
585						paymentElementMethod = result.paymentMethod.id;
586						paymentType = result.paymentMethod.type;
587						$( '.cpsw_payment_method' ).remove();
588						paymentForm.append(
589							"<input type='hidden' class='cpsw_payment_method' name='payment_method_created' value='" +
590							paymentElementMethod +
591							"'/><input type='hidden' class='cpsw_payment_type' name='selected_payment_type' value='" +
592							paymentType +
593							"'/>",
594						);
595						paymentForm.trigger( 'submit' );
596					} else if ( result.error ) {
597						$( 'form.woocommerce-checkout' ).unblock();
598						$( 'form#order_review' ).unblock();
599						$( 'form#add_payment_method' ).unblock();
600						logError( result.error );
601						$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + getStripeLocalizedMessage( result.error.code, result.error.message ) + '</div>' ).show();
602						window.scrollTo( { top: 0, behavior: 'smooth' } );
603						return false;
604					}
605				} );
606				break;
607			default:
608				break;
609		}
610		return true;
611	}
612
613	function confirmStripePayment( clientSecret, redirectURL, authenticationAlready = false ) {
614		const wcCheckoutForm = $( 'form.woocommerce-checkout' );
615
616		switch ( selectedGatewayId ) {
617			case 'cpsw_stripe':
618				stripe.confirmCardPayment( clientSecret, {} ).then( function( result ) {
619					if ( result.error ) {
620						// Show error to your customer (e.g., insufficient funds)
621						$( '.woocommerce-error' ).remove();
622						wcCheckoutForm.unblock();
623						wcCheckoutForm.removeClass( 'processing' );
624						logError( result.error );
625						let errorCode = result.error.code;
626
627						if ( 'card_declined' === result.error.code ) {
628							errorCode = result.error.decline_code;
629						}
630
631						$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + getStripeLocalizedMessage( errorCode, result.error.message ) + '</div>' ).show();
632						window.scrollTo( { top: 0, behavior: 'smooth' } );
633					} else {
634						// The payment has been processed!
635						if ( result.paymentIntent.status === 'succeeded' || result.paymentIntent.status === 'requires_capture' ) {
636							window.location = redirectURL;
637						}
638					}
639				} );
640				break;
641			case 'cpsw_ideal':
642				stripe.confirmIdealPayment( clientSecret, {
643					payment_method: {
644						ideal,
645						billing_details: getBillingDetails(),
646					},
647					return_url: homeURL + redirectURL,
648				} ).then( function( result ) {
649					if ( result.error ) {
650						// Show error to your customer (e.g., insufficient funds)
651						$( '.woocommerce-error' ).remove();
652						wcCheckoutForm.unblock();
653						logError( result.error );
654						$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + getStripeLocalizedMessage( result.error.code, result.error.message ) + '</div>' ).show();
655						window.scrollTo( { top: 0, behavior: 'smooth' } );
656					}
657				} );
658				break;
659			case 'cpsw_alipay':
660				stripe.confirmAlipayPayment( clientSecret, {
661					payment_method: {
662						billing_details: getBillingDetails(),
663					},
664					return_url: homeURL + redirectURL,
665				} ).then( function( result ) {
666					if ( result.error ) {
667						// Show error to your customer (e.g., insufficient funds)
668						$( '.woocommerce-error' ).remove();
669						wcCheckoutForm.unblock();
670						logError( result.error );
671						$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + getStripeLocalizedMessage( result.error.code, result.error.message ) + '</div>' ).show();
672						window.scrollTo( { top: 0, behavior: 'smooth' } );
673						wcCheckoutForm.removeClass( 'processing' );
674					}
675				} );
676				break;
677			case 'cpsw_klarna':
678				let billingDetails = getBillingDetails();
679
680				// Check if the URL contains 'pay_for_order'
681				if ( window.location.href.includes( 'pay_for_order' ) ) {
682					const orderpayBillingCountry = cpsw_global_settings.order_pay_country;
683
684					// Initialize billingDetails if it's null
685					if ( ! billingDetails ) {
686						billingDetails = {
687							address: {},
688						};
689					}
690
691					// Ensure the address object exists
692					if ( ! billingDetails.address ) {
693						billingDetails.address = {};
694					}
695
696					// Assign the country
697					billingDetails.address.country = orderpayBillingCountry;
698				}
699				const returnURL = homeURL + redirectURL;
700				stripe.confirmKlarnaPayment( clientSecret, {
701					payment_method: {
702						billing_details: billingDetails,
703					},
704					return_url: returnURL,
705				} ).then( function( result ) {
706					if ( result.error ) {
707						let errorMessage = result.error.message;
708						if ( window.location.href.includes( 'pay_for_order' ) ) {
709							if ( result.error.code === 'parameter_missing' && result.error.param === 'billing_details[email]' ) {
710								errorMessage = cpsw_global_settings.klarna_email_missing_message;
711							}
712						}
713
714						// Show error to your customer (e.g., insufficient funds)
715						$( '.woocommerce-error' ).remove();
716						wcCheckoutForm.unblock();
717						logError( result.error );
718						$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + getStripeLocalizedMessage( result.error.code, errorMessage ) + '</div>' ).show();
719						window.scrollTo( { top: 0, behavior: 'smooth' } );
720						wcCheckoutForm.removeClass( 'processing' );
721					}
722				} );
723				break;
724			case 'cpsw_bancontact':
725				stripe.confirmBancontactPayment( clientSecret, {
726					payment_method: {
727						billing_details: getBillingDetails(),
728					},
729					return_url: homeURL + redirectURL,
730				} ).then( function( result ) {
731					if ( result.error ) {
732						// Show error to your customer (e.g., insufficient funds)
733						$( '.woocommerce-error' ).remove();
734						wcCheckoutForm.unblock();
735						logError( result.error );
736						$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + getStripeLocalizedMessage( result.error.code, result.error.message ) + '</div>' ).show();
737						window.scrollTo( { top: 0, behavior: 'smooth' } );
738						wcCheckoutForm.removeClass( 'processing' );
739					}
740				} );
741				break;
742			case 'cpsw_sepa':
743				if ( isSepaSaveCardChosen() || authenticationAlready ) {
744					stripe.confirmSepaDebitPayment( clientSecret, {} ).then( function( result ) {
745						if ( result.error ) {
746							// Show error to your customer (e.g., insufficient funds)
747							$( '.woocommerce-error' ).remove();
748							$( 'form.woocommerce-checkout' ).unblock();
749							logError( result.error );
750							$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + getStripeLocalizedMessage( result.error.code, result.error.message ) + '</div>' ).show();
751							window.scrollTo( { top: 0, behavior: 'smooth' } );
752						} else {
753							// The payment has been processed!
754							if ( result.paymentIntent.status === 'succeeded' || result.paymentIntent.status === 'processing' ) {
755								$( '.woocommerce-error' ).remove();
756								window.location = redirectURL;
757							}
758						}
759					} );
760				} else {
761					stripe.confirmSepaDebitPayment( clientSecret, {
762						payment_method: {
763							sepa_debit: sepa,
764							billing_details: getBillingDetails(),
765						},
766					} ).then( function( result ) {
767						if ( result.error ) {
768							// Show error to your customer (e.g., insufficient funds)
769							$( '.woocommerce-error' ).remove();
770							$( 'form.woocommerce-checkout' ).unblock();
771							logError( result.error );
772							$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + getStripeLocalizedMessage( result.error.code, result.error.message ) + '</div>' ).show();
773							window.scrollTo( { top: 0, behavior: 'smooth' } );
774						} else {
775							// The payment has been processed!
776							if ( result.paymentIntent.status === 'succeeded' || result.paymentIntent.status === 'processing' ) {
777								$( '.woocommerce-error' ).remove();
778								window.location = redirectURL;
779							}
780						}
781					} );
782				}
783
784				break;
785			case 'cpsw_p24':
786				stripe.confirmP24Payment(
787					clientSecret,
788					{
789						payment_method: {
790							billing_details: getBillingDetails(),
791						},
792						return_url: homeURL + redirectURL,
793					},
794				);
795				break;
796			case 'cpsw_wechat':
797				stripe.confirmWechatPayPayment( clientSecret, {
798					payment_method_options: {
799						wechat_pay: {
800							client: 'web',
801						},
802					},
803				} ).then( function( result ) {
804					if ( result.error ) {
805						// Show error to your customer (e.g., insufficient funds)
806						$( '.woocommerce-error' ).remove();
807						wcCheckoutForm.unblock();
808						logError( result.error );
809						$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + getStripeLocalizedMessage( result.error.code, result.error.message ) + '</div>' ).show();
810						window.scrollTo( { top: 0, behavior: 'smooth' } );
811					} else {
812						// The payment has been processed!
813						if ( result.paymentIntent.status === 'succeeded' ) {
814							window.location = redirectURL;
815						} else if ( result.paymentIntent.status === 'requires_payment_method' ) {
816							// Show error when requires payment method or some how failed.
817							$( '.woocommerce-error' ).remove();
818							wcCheckoutForm.unblock();
819							logError( result.paymentIntent.last_payment_error );
820							$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + getStripeLocalizedMessage( result.paymentIntent.last_payment_error.code, result.paymentIntent.last_payment_error.message ) + '</div>' ).show();
821							window.scrollTo( { top: 0, behavior: 'smooth' } );
822							wcCheckoutForm.removeClass( 'processing' );
823						} else {
824							wcCheckoutForm.removeClass( 'processing' );
825							wcCheckoutForm.unblock();
826						}
827					}
828				} );
829				break;
830			case 'cpsw_stripe_element':
831				const redirect = selectedPaymentElementType === 'card' ? 'always' : 'if_required';
832				stripe.confirmPayment( {
833					elements: elementsForPayment,
834					clientSecret,
835					confirmParams: {
836						return_url: homeURL + redirectURL,
837						payment_method_data: {
838							billing_details: getBillingDetails(),
839						},
840						payment_method_options: {
841							wechat_pay: {
842								client: 'web',
843							},
844							card: {
845								setup_future_usage: 'off_session',
846							},
847						},
848					},
849					redirect,
850				} ).then( function( result ) {
851					if ( result.error ) {
852						// Show error to your customer (e.g., insufficient funds)
853						$( '.woocommerce-error' ).remove();
854						wcCheckoutForm.unblock();
855						logError( result.error );
856						let errorMessage = result.error?.message;
857						let errorCode = result.error?.code;
858
859						if ( 'card_declined' === errorCode ) {
860							errorCode = result.error?.decline_code;
861						}
862
863						errorMessage = errorMessage?.replace( new RegExp( '`billing_details\\[address\\]\\[country\\]`', 'g' ), 'Billing country' );
864
865						$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + getStripeLocalizedMessage( errorCode, errorMessage ) + '</div>' ).show();
866						window.scrollTo( { top: 0, behavior: 'smooth' } );
867						wcCheckoutForm.removeClass( 'processing' );
868					}
869					wcCheckoutForm.removeClass( 'processing' );
870					wcCheckoutForm.unblock();
871					paymentElementMethod = '';
872				} );
873				break;
874			default:
875				break;
876		}
877	}
878
879	function getStripeLocalizedMessage( type, message ) {
880		return ( null !== stripeLocalized[ type ] && undefined !== stripeLocalized[ type ] ) ? stripeLocalized[ type ] : message;
881	}
882
883	function getBillingDetails() {
884		if ( ! $( 'form.woocommerce-checkout' ).length ) {
885			return currentUserBilling;
886		}
887
888		const billingFirstName = document.getElementById( 'billing_first_name' );
889		const billingLastName = document.getElementById( 'billing_last_name' );
890		const billingEmail = document.getElementById( 'billing_email' );
891		const billingPhone = document.getElementById( 'billing_phone' );
892		const billingCountry = document.getElementById( 'billing_country' );
893		const billingPostcode = document.getElementById( 'billing_postcode' );
894		const billingCity = document.getElementById( 'billing_city' );
895		const billingState = document.getElementById( 'billing_state' );
896		const billingAddress1 = document.getElementById( 'billing_address_1' );
897		const billingAddress2 = document.getElementById( 'billing_address_2' );
898		const firstName = null !== billingFirstName ? billingFirstName.value : '';
899		const lastName = null !== billingLastName ? billingLastName.value : '';
900
901		const billingDetails = {
902			name: firstName + ' ' + lastName,
903			email: null !== billingEmail ? billingEmail.value : '',
904			phone: null !== billingPhone ? billingPhone.value : '',
905			address: {
906				country: null !== billingCountry ? billingCountry.value : '',
907				city: null !== billingCity ? billingCity.value : '',
908				postal_code: null !== billingPostcode ? billingPostcode.value : '',
909				state: null !== billingState ? billingState.value : '',
910				line1: null !== billingAddress1 ? billingAddress1.value : '',
911				line2: null !== billingAddress2 ? billingAddress2.value : '',
912			},
913		};
914
915		return billingDetails;
916	}
917
918	function confirmCardSetup() {
919		$.ajax( {
920			type: 'POST',
921			dataType: 'json',
922			url: ajaxUrl,
923			data: { action: 'create_setup_intent', _security: jsNonce, paymentMethod },
924			beforeSend: () => {
925				$( 'body' ).css( 'cursor', 'progress' );
926			},
927			success( response ) {
928				if ( response.success === true ) {
929					const clientSecret = response.data.client_secret;
930					stripe.confirmCardSetup( clientSecret, { payment_method: paymentMethod } ).then( function() {
931						paymentForm.trigger( 'submit' );
932					} );
933				} else if ( response.success === false ) {
934					return false;
935				}
936				$( 'body' ).css( 'cursor', 'default' );
937			},
938			error() {
939				$( 'body' ).css( 'cursor', 'default' );
940				alert( 'Something went wrong!' );
941			},
942		} );
943	}
944
945	function selectedGateway() {
946		const allPaymentMethods = [ 'cpsw_stripe', 'cpsw_alipay', 'cpsw_ideal', 'cpsw_klarna', 'cpsw_p24', 'cpsw_bancontact', 'cpsw_wechat', 'cpsw_sepa', 'cpsw_stripe_element' ];
947
948		if ( 0 < $( '.wc_payment_method' ).length ) {
949			const selectedPaymentMethod = $( '.wc_payment_method input[name="payment_method"]:checked' ).val();
950			if ( -1 === $.inArray( selectedPaymentMethod, allPaymentMethods ) ) {
951				return false;
952			}
953			return selectedGatewayId = selectedPaymentMethod;
954		} else if ( 0 < $( '#payment_method_cpsw_stripe' ).length && $( '#payment_method_cpsw_stripe' ).is( ':checked' ) && 'cpsw_stripe' === $( '#payment_method_cpsw_stripe' ).val() ) {
955			const selectedPaymentMethod = $( '.payment_methods input[name="payment_method"]:checked' ).val();
956			if ( -1 === $.inArray( selectedPaymentMethod, allPaymentMethods ) ) {
957				return false;
958			}
959			return selectedGatewayId = selectedPaymentMethod;
960		} else if ( 0 < $( '#payment_method_cpsw_sepa' ).length && $( '#payment_method_cpsw_sepa' ).is( ':checked' ) && 'cpsw_sepa' === $( '#payment_method_cpsw_sepa' ).val() ) {
961			const selectedPaymentMethod = $( '.payment_methods input[name="payment_method"]:checked' ).val();
962			if ( -1 === $.inArray( selectedPaymentMethod, allPaymentMethods ) ) {
963				return false;
964			}
965			return selectedGatewayId = selectedPaymentMethod;
966		}
967		return false;
968	}
969
970	function isAllowedBrand( brand ) {
971		if ( 0 === allowedCards.length ) {
972			isAllowedCard = true;
973			return;
974		}
975
976		isAllowedCard = ( -1 === $.inArray( brand, allowedCards ) ) ? false : true;
977	}
978
979	function hideShowCard() {
980		const isSavedCard = ( 'new' === $( "input[name='wc-cpsw-payment-token']:checked" ).val() ) ? false : true;
981		if ( ! isSavedCard ) {
982			$( '.cpsw-stripe-elements-form' ).fadeIn();
983		} else {
984			$( '.cpsw-stripe-elements-form' ).fadeOut();
985		}
986	}
987
988	function hideShowSepaIBAN() {
989		if ( $( "input[name='wc-cpsw_sepa-payment-token']" ).length > 0 ) {
990			const isSavedSepaIBAN = ( 'new' === $( "input[name='wc-cpsw_sepa-payment-token']:checked" ).val() ) ? false : true;
991			if ( ! isSavedSepaIBAN ) {
992				$( '.cpsw_stripe_sepa_payment_form' ).fadeIn();
993			} else {
994				$( '.cpsw_stripe_sepa_payment_form' ).fadeOut();
995			}
996		}
997	}
998
999	function hideShowPaymentElement() {
1000		const isSavedPaymentElement = ( 'new' === $( "input[name='wc-cpsw_stripe_element-payment-token']:checked" ).val() );
1001		if ( isSavedPaymentElement ) {
1002			$( '.cpsw_stripe_element_payment_form' ).show();
1003			savedPaymentElementMethod = false;
1004		} else {
1005			$( '.cpsw_stripe_element_payment_form' ).hide();
1006			savedPaymentElementMethod = true;
1007		}
1008	}
1009
1010	function onHashChange() {
1011		if ( ! selectedGateway() ) {
1012			return;
1013		}
1014		const partials = window.location.hash.match(
1015			/^#?confirm-(pi|si)-([^:]+):(.+):(.+)$/,
1016		);
1017
1018		if ( ! partials || 4 > partials.length ) {
1019			return;
1020		}
1021
1022		const intentClientSecret = partials[ 2 ];
1023		const redirectURL = decodeURIComponent( partials[ 3 ] );
1024
1025		// Cleanup the URL
1026		history.pushState( {}, '', window.location.pathname );
1027		confirmStripePayment( intentClientSecret, redirectURL );
1028	}
1029
1030	function showSavedCards() {
1031		if ( $( '.payment_method_cpsw_stripe .wc-saved-payment-methods' ).length ) {
1032			$( '.payment_method_cpsw_stripe .wc-saved-payment-methods' ).show();
1033		}
1034	}
1035
1036	function hideShowElements() {
1037		if ( 'new' === $( 'input[type=radio][name="wc-cpsw_stripe-payment-token"]:checked' ).val() ) {
1038			$( '.cpsw-stripe-elements-form' ).show();
1039			savedCard = false;
1040		} else {
1041			$( '.cpsw-stripe-elements-form' ).hide();
1042			savedCard = true;
1043		}
1044	}
1045
1046	function logError( error ) {
1047		$.ajax( {
1048			type: 'POST',
1049			dataType: 'json',
1050			url: ajaxUrl,
1051			data: { action: 'cpsw_js_errors', _security: jsNonce, error },
1052			beforeSend: () => {
1053				$( 'body' ).css( 'cursor', 'progress' );
1054			},
1055			success( response ) {
1056				if ( response.success === true ) {
1057				} else if ( response.success === false ) {
1058					return response.message;
1059				}
1060				$( 'body' ).css( 'cursor', 'default' );
1061			},
1062			error() {
1063				$( 'body' ).css( 'cursor', 'default' );
1064				alert( 'Something went wrong!' );
1065			},
1066		} );
1067	}
1068
1069	const processingSubmit = function( e ) {
1070		const wcCheckoutForm = $( 'form.woocommerce-checkout' );
1071		// Check if the selected gateway is Klarna, it's a pay for order page, user is not logged in, and order pay email is set
1072		if ( selectedGateway() === 'cpsw_klarna' &&
1073			window.location.href.includes( 'pay_for_order' ) &&
1074			isUserLoggedIn !== '1' &&
1075			cpsw_global_settings.order_pay_email ) {
1076			e.preventDefault();
1077			$( '.woocommerce-error' ).remove();
1078			$( 'form.woocommerce-checkout' ).unblock();
1079			$( '.woocommerce-notices-wrapper:first-child' )
1080				.html( '<div class="woocommerce-error cpsw-errors">' + cpsw_global_settings.klarna_login_message + '</div>' )
1081				.show();
1082			window.scrollTo( { top: 0, behavior: 'smooth' } );
1083			wcCheckoutForm.removeClass( 'processing' );
1084			return false;
1085		}
1086
1087		if ( ( 'yes' === cpsw_global_settings.is_cart_amount_zero || $( 'form#order_review' ).length || $( 'form#add_payment_method' ).length ) && 'cpsw_sepa' === selectedGateway() && ! isSepaSaveCardChosen() && '' === paymentMethodSepa ) {
1088			e.preventDefault();
1089			createStripePaymentMethod();
1090
1091			return false;
1092		}
1093
1094		if ( 'cpsw_stripe' === selectedGateway() && ! savedCard && '' === paymentMethod ) {
1095			if ( false === isAllowedCard ) {
1096				return false;
1097			}
1098
1099			e.preventDefault();
1100			createStripePaymentMethod();
1101
1102			return false;
1103		}
1104
1105		if ( 'cpsw_stripe_element' === selectedGateway() && ! savedPaymentElementMethod && '' === paymentElementMethod ) {
1106			e.preventDefault();
1107			createStripePaymentMethod();
1108
1109			return false;
1110		}
1111
1112		return true;
1113	};
1114
1115	if ( $( 'form.woocommerce-checkout' ).length ) {
1116		paymentForm = $( 'form.woocommerce-checkout' );
1117	}
1118
1119	$( 'form.woocommerce-checkout' ).on( 'submit checkout_place_order_cpsw_ideal', function() {
1120		// check for iDEAL.
1121		if ( 'cpsw_ideal' === selectedGateway() ) {
1122			if ( '' === selectedIdealBank ) {
1123				$( '.cpsw_stripe_ideal_error' ).html( cpsw_global_settings.empty_bank_message );
1124				$( '.woocommerce-error' ).remove();
1125				$( 'form.woocommerce-checkout' ).unblock();
1126				$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + cpsw_global_settings.empty_bank_message + '</div>' ).show();
1127				window.scrollTo( { top: 0, behavior: 'smooth' } );
1128				return false;
1129			}
1130			$( '.cpsw_stripe_ideal_error' ).html( '' );
1131		}
1132	} );
1133
1134	$( 'form.woocommerce-checkout' ).on( 'submit checkout_place_order_cpsw_sepa', function() {
1135		if ( isSepaSaveCardChosen() ) {
1136			$( '.cpsw_stripe_sepa_error' ).html( '' );
1137			return true;
1138		}
1139
1140		// check for SEPA.
1141		if ( ! sepaIBAN && 'cpsw_sepa' === selectedGateway() ) {
1142			$( '.woocommerce-error' ).remove();
1143			$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + emptySepaIBANMessage + '</div>' ).show();
1144			window.scrollTo( { top: 0, behavior: 'smooth' } );
1145			$( '.cpsw_stripe_sepa_error' ).html( emptySepaIBANMessage );
1146			return false;
1147		}
1148		$( '.cpsw_stripe_sepa_error' ).html( '' );
1149	} );
1150
1151	$( 'form.woocommerce-checkout' ).on( 'submit checkout_place_order_cpsw_p24', function() {
1152		// check for P24.
1153		if ( 'cpsw_p24' === selectedGateway() ) {
1154			if ( '' === selectedP24Bank ) {
1155				$( '.cpsw_stripe_p24_error' ).html( cpsw_global_settings.empty_bank_message );
1156				$( '.woocommerce-error' ).remove();
1157				$( 'form.woocommerce-checkout' ).unblock();
1158				$( '.woocommerce-notices-wrapper:first-child' ).html( '<div class="woocommerce-error cpsw-errors">' + cpsw_global_settings.empty_bank_message + '</div>' ).show();
1159				window.scrollTo( { top: 0, behavior: 'smooth' } );
1160				return false;
1161			}
1162			$( '.cpsw_stripe_p24_error' ).html( '' );
1163		}
1164	} );
1165
1166	$( 'form.woocommerce-checkout' ).on( 'submit checkout_place_order_cpsw_stripe checkout_place_order_cpsw_sepa checkout_place_order_cpsw_stripe_element', processingSubmit );
1167
1168	if ( $( 'form#order_review' ).length ) {
1169		showSavedCards();
1170		paymentForm = $( 'form#order_review' );
1171	}
1172
1173	if ( $( 'form#add_payment_method' ).length ) {
1174		isAllowedCard = true;
1175		paymentForm = $( 'form#add_payment_method' );
1176	}
1177
1178	$( 'form#order_review, form#add_payment_method' ).on( 'submit', processingSubmit );
1179
1180	/**
1181	 * mount card element after woocommerce ajax call
1182	 */
1183	$( document.body ).on( 'updated_checkout', function() {
1184		showSavedCards();
1185		$( 'input[type=radio][name="wc-cpsw_stripe-payment-token"]' ).change( function() {
1186			hideShowElements();
1187		} );
1188		$( 'input[type=radio][name="wc-cpsw_stripe_element-payment-token"]' ).change( function() {
1189			hideShowPaymentElement();
1190		} );
1191		mountGateways();
1192		$( "input[name='wc-cpsw-payment-token']" ).click( function() {
1193			hideShowCard();
1194		} );
1195	} );
1196
1197	$( "input[name='wc-cpsw_sepa-payment-token']" ).click( function() {
1198		hideShowSepaIBAN();
1199	} );
1200
1201	$( "input[type=radio][name='wc-cpsw_stripe_element-payment-token']" ).change( function() {
1202		hideShowPaymentElement();
1203	} );
1204
1205	$( 'input[type=radio][name="wc-cpsw_stripe-payment-token"]' ).change( function() {
1206		hideShowElements();
1207	} );
1208	$( '.cpsw-stripe-elements-form' ).hide();
1209
1210	if ( $( 'form#order_review' ).length && window.location.hash && typeof window.location.hash === 'string' ) {
1211		const partials = window.location.hash.match(
1212			/^#?confirm-(pi|si)-([^:]+):(.+):(.+)$/,
1213		);
1214
1215		if ( partials ) {
1216			try {
1217				if ( ! partials || 4 > partials.length ) {
1218					return;
1219				}
1220
1221				selectedGatewayId = partials[ 4 ];
1222				const intentClientSecret = partials[ 2 ];
1223				const redirectURL = decodeURIComponent( partials[ 3 ] );
1224
1225				// Cleanup the URL
1226				history.pushState( {}, '', window.location.pathname + window.location.search );
1227				confirmStripePayment( intentClientSecret, redirectURL, true );
1228			} catch ( err ) {
1229
1230			}
1231		}
1232	}
1233
1234	// Check if the payment method is available on the checkout page
1235	if ( $( '.cpsw_stripe_element_payment_form' ).length ) {
1236		// Adding custom class to the body tag
1237		$( 'body' ).addClass( 'cpsw_stripe_option_enabled' );
1238	}
1239
1240	window.addEventListener( 'hashchange', onHashChange );
1241	mountGateways();
1242	if ( $( 'form#order_review' ).length ) {
1243		hideShowCard();
1244		hideShowSepaIBAN();
1245		hideShowElements();
1246		hideShowPaymentElement();
1247	}
1248}( jQuery ) );

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.