PageSourceSearch

https://stpaulsr.org/wp-content/plugins/wp-easy-pay-premium/assets…?rand=414508356&ver=7.1.2

js stpaulsr.org collected 2026-10-02 02:05:35 UTC 97,999 bytes, 2,900 lines download raw bytes

1let googlePay = {};
2let afterpay = {};
3let cashAppPay = {};
4let applePay = {};
5const payments   = initializePayments( wpep_local_vars.square_application_id, wpep_local_vars.square_location_id_in_use );
6
7document.addEventListener('DOMContentLoaded', async function () {
8	jQuery('.loader').hide();
9	jQuery('#cash_app_pay_v1_element').bind('click', function(e){
10		e.preventDefault();
11		e.stopImmediatePropagation();
12	});
13	jQuery( '.wizard-section' ).css( 'visibility', 'visible' );
14	jQuery( '.parent-loader' ).remove();
15		
16	var wpep_paymentForm = {};
17
18	
19	if (jQuery( 'form.wpep_payment_form' ).length > 0) {
20		jQuery( 'form.wpep_payment_form' ).each(
21			async function () {
22				var current_form_id = jQuery( this ).data( 'id' );
23				var currency        = jQuery( this ).data( 'currency' );
24				let card;
25
26				calculate( current_form_id, currency );
27
28				jQuery('.qty').keyup(function(){
29					calculate( current_form_id, currency );
30				});
31		
32				if (!window.Square) {
33					throw new Error('Square.js failed to load properly');
34				}
35
36				// Bind an event handler to the custom amount input field
37				jQuery('.other-'+current_form_id).click( function () {
38					let timeoutId;
39					jQuery('.other-'+current_form_id).on('input', function() {
40					  var customAmount = jQuery(this).val();
41					  clearTimeout(timeoutId);
42					  timeoutId = setTimeout(function() {
43						jQuery('.loader').show();
44						jQuery('#wpep-selected-amount-'+ current_form_id ).val(customAmount).trigger('change');
45						jQuery('#wpep-single-form-'+ current_form_id ).click();
46					  }, 500);
47					}); 
48				});
49				if ( wpep_local_vars.applepay == 'on') {
50					
51					    var applePayButtonTarget = '';
52						 jQuery('#wpep-selected-amount-'+current_form_id).val(jQuery('#amount_display_'+current_form_id).html());
53        			     jQuery('#one_unit_cost').val(jQuery('#amount_display_'+current_form_id).html().trim().replace(wpep_local_vars.wpep_currency_symbol, ""));
54            			     	    
55					    applePay[current_form_id] = await displayApplePay( payments, current_form_id, currency ,applePay, applePayButtonTarget);
56					    
57						let timeoutpayId;
58
59            			function handleDOMChanges(app_btn) {
60            			  clearTimeout(timeoutpayId);
61            			  timeoutpayId = setTimeout(async function() {
62            			  
63            			      jQuery('#wpep-selected-amount-'+current_form_id).val(jQuery('#amount_display_'+current_form_id).html());
64            			      jQuery('#one_unit_cost').val(jQuery('#amount_display_'+current_form_id).html().trim().replace(wpep_local_vars.wpep_currency_symbol, ""));
65            			      
66            				try {
67            				    
68            				    jQuery('#applePay-'+current_form_id).remove(); 
69            	                jQuery('#applePayfather-'+current_form_id).append('<div id="applePay-'+current_form_id+'" class="apple-pay-button tab-content-'+current_form_id+'"></div>');
70            	                
71            					var applePayButtonTarget = document.getElementById('applePay-'+current_form_id);
72            					jQuery('#applePayfather-'+current_form_id).css('display', 'none');
73            					applePay[current_form_id] = await displayApplePay( payments, current_form_id, currency ,applePay, applePayButtonTarget);
74            					//jQuery('#testing_apple').html('');
75            					applePayButtonTarget.addEventListener('click', eventHandlerapple);
76            				
77            					setTimeout(function() {
78            					    if(jQuery('#applePayfather-'+current_form_id).hasClass('current')){
79            					        jQuery('#applePayfather-' + current_form_id).css('display', 'block');
80            					    }
81                                }, 1200); // 2000 milliseconds = 2 seconds
82                                
83            					
84            				} catch (e) {
85            				  console.error('Initializing Applepay failed', e);
86            				}
87            			  }, 10); 	 
88            			}
89            			// Use Mutation Observer to detect DOM changes
90            			const observer = new MutationObserver(handleDOMChanges);
91            			// Observe changes in the amount display element
92            			const amountDisplayElement = document.getElementById('amount_display_' + current_form_id);
93            			if (amountDisplayElement) {
94            			  observer.observe(amountDisplayElement, { subtree: true, childList: true });
95            			}
96					applePayButtonTarget = document.getElementById('applePay-'+current_form_id);
97					applePayButtonTarget.addEventListener('click', eventHandlerapple);
98				
99					async function eventHandlerapple(event) {
100					    
101						event.preventDefault();
102						event.stopImmediatePropagation();
103						try {
104						card = '';
105						var res = false;
106						res = paymentButtonClicked(event, card, current_form_id, currency);
107						
108						if(res || wpep_local_vars.wpep_show_wizard == 'on'){
109							/* const divElement = document.getElementById("testing_apple");
110                            
111							// Convert the applePay object to a string
112							const applePayString = JSON.stringify(applePay, null, 2);
113
114							// Create a text node with the string representation of the applePay object
115							const textNode = document.createTextNode(applePayString);
116
117							// Append the text node to the div element
118							divElement.appendChild(textNode); */
119							
120				// 			jQuery('#testing_apple').html(applePay);
121				             
122							const result = await applePay[current_form_id].tokenize();
123							if (result.status === 'OK') {
124								await handlePaymentMethodSubmission(event, applePay, current_form_id, currency,  result.token);
125							}
126						} else {
127							event.preventDefault();
128							event.stopImmediatePropagation();
129						} 
130						} catch (e) {
131						console.error(e);
132						}
133					};
134				}
135				if ( wpep_local_vars.gpay == 'on') {
136				
137					googlePay[current_form_id] = await displayGooglePay( payments, current_form_id, currency ,googlePay);
138					var googlePayButtonTarget = document.getElementById('google-pay-button-'+current_form_id);
139					googlePayButtonTarget.addEventListener('click', eventHandler);
140				
141					async function eventHandler(event) {
142						event.preventDefault();
143						event.stopImmediatePropagation();
144						
145						try {
146						
147						card = '';
148						var res = false;
149						res = paymentButtonClicked(event, card, current_form_id, currency);
150						
151						if(res || wpep_local_vars.wpep_show_wizard == 'on'){
152							const result = await googlePay[current_form_id].tokenize();
153							
154							if (result.status === 'OK') {
155								await handlePaymentMethodSubmission(event, googlePay, current_form_id, currency, result.token);
156							}
157						} else {
158							event.preventDefault();
159							event.stopImmediatePropagation();
160						} 
161						} catch (e) {
162						console.error(e);
163						}
164					};
165				}
166
167				if ( wpep_local_vars.afterpay == 'on') {
168			
169					afterpay = displayAfterPay( payments, current_form_id, currency );
170					
171					if (afterpay !== undefined) {
172						const afterpayButton = document.getElementById('afterpay-button-'+current_form_id);
173						
174						afterpayButton.addEventListener('click', async function (event) {
175						
176						card = '';
177						var res = false;
178						res = paymentButtonClicked(event, card, current_form_id, currency);
179						if(res || wpep_local_vars.wpep_show_wizard == 'on'){
180							await handlePaymentMethodSubmission(event, afterpay, current_form_id, currency, false);
181							} else {
182								event.preventDefault();
183								event.stopImmediatePropagation();
184							}
185						});
186					} 	
187		
188				}
189
190				if ( wpep_local_vars.cashapp == 'on') {
191			
192					cashAppPay = displayCashApp( payments, current_form_id, currency );
193					
194					jQuery('#cash-app-pay-'+current_form_id).on('click', function(ee){
195						card = '';
196						var res = paymentButtonClicked(event, card, current_form_id, currency);
197						
198						if(res || wpep_local_vars.wpep_show_wizard == 'on'){
199							 cashAppPay.addEventListener('ontokenization', function (event) {
200								const { tokenResult, error } = event.detail;
201								if (error) {
202								  // developer handles error
203								} else if (tokenResult.status === 'OK') {
204									if(res || wpep_local_vars.wpep_show_wizard == 'on'){
205										jQuery( "#theForm-" + current_form_id ).append( jQuery( '<div />' ).attr( 'class', 'wpepLoader' ).html( '<div class="initial-load-animation"><div class="payment-image icomoonLib"><span class="icon-pay"></span></div><div class="loading-bar"><div class="blue-bar"></div></div></div>' ) );
206										handlePaymentMethodSubmission(event, cashAppPay, current_form_id, currency, tokenResult.token, 'cashapp');
207									}
208								}
209								
210							  }); 
211						} else {
212							ee.preventDefault();
213							ee.stopImmediatePropagation();
214						}
215						
216					
217					});
218				}
219
220				async function initializeCard(payments, current_form_id) {
221					const card = await payments.card();
222					await card.attach('#card-container-'+current_form_id); 
223					return card; 
224				}
225
226						   
227
228				async function initializeACH(payments) {
229					let redirectURI   = 'https://development-cloud.local/421-2/';
230					let transactionId = 'wpeasypay-01';
231					const ach = await payments.ach({ redirectURI, transactionId });
232					return ach;
233				}		   
234			   
235		
236				 
237				try {
238
239					let ach;
240					jQuery('.loader').show();
241					card = await initializeCard(payments, current_form_id);
242					jQuery('.loader').hide();
243					 jQuery('.wpep-single-form-' + current_form_id).click(async function (event) {
244						event.preventDefault();
245						var current_form_id = jQuery( this ).parents( 'form' ).data( 'id' );
246						paymentButtonClicked(event, card, current_form_id, currency);
247					});
248				
249					jQuery('.wpep-wizard-form-' + current_form_id).click(async function (event) {
250						event.preventDefault();
251						var current_form_id = jQuery( this ).parents( 'form' ).data( 'id' );
252						paymentButtonClicked(event, card, current_form_id, currency);
253					});
254					if ( wpep_local_vars.achDebit == 'on') {
255						ach = await initializeACH(payments);
256						const achButton = document.getElementById('ach-button-'+current_form_id);
257						achButton.addEventListener('click', async function (event) {
258							event.preventDefault();
259
260							card = '';
261							ach.addEventListener(
262								`ontokenization`, function (event) {
263									console.log(event)
264									const { tokenResult, error } = event.detail;
265									if (error) {
266										// add code here to handle errors
267									}
268									else if (tokenResult.status === `OK`) {
269										const paymentForm = document.getElementById('theForm-' + current_form_id);
270										const achOptions = getACHOptions(paymentForm, current_form_id);
271										handlePaymentMethodSubmission(event, ach, current_form_id, currency, tokenResult.token, 'ach', achOptions);
272									}
273								}
274							);
275							var res = paymentButtonClicked(event, card, current_form_id, currency);
276							if(res || wpep_local_vars.wpep_show_wizard == 'on'){
277
278								const paymentForm = document.getElementById('theForm-' + current_form_id);
279								const achOptions = getACHOptions(paymentForm, current_form_id);
280								await handlePaymentMethodSubmission(event, ach, current_form_id, currency, false, 'ach', achOptions);
281								// ACH with the `accountHolderName` as an option.
282							}
283						});
284					}
285					
286
287				} catch (e) {
288
289					console.error('Initializing Card failed', e);
290					return;
291					
292				}	
293				
294				// jQuery('.customPayment.otherPayment.other-'+current_form_id).trigger("change"); 
295			
296			}
297		);
298	}
299
300
301jQuery('#terminialpay-button').on('click', function(e){
302	e.preventDefault();
303	card = '';
304	var current_form_id = jQuery( this ).parents( 'form' ).data( 'id' );
305	var first_name       = jQuery( "#theForm-" + current_form_id + " input[name='wpep-first-name-field']" ).val();
306	var last_name        = jQuery( "#theForm-" + current_form_id + " input[name='wpep-last-name-field']" ).val();
307	var email            = jQuery( "#theForm-" + current_form_id + " input[name='wpep-email-field']" ).val();
308	
309	currency =  jQuery( '.wpep_payment_form' ).data( 'currency' );
310	var res = paymentButtonClicked(event, card, current_form_id, currency);
311	if(res){
312		var amount           = jQuery( '#amount_display_' + current_form_id ).text();
313		amount               = amount.trim();
314		amount 				 = amount.replace(wpep_local_vars.wpep_currency_symbol, "");
315		var adata = {
316				action: 'wpep_pay_pos_terminal',
317				id: current_form_id,
318				first_name: first_name,
319				last_name: last_name,
320				last_name: email,
321				amount: amount,
322			}
323		jQuery.ajax({
324			url: wpep_local_vars.ajax_url,
325			type: "POST",
326			dataType: "json",
327			data: adata,
328			 success: function (response) { 
329			jQuery('#terminialpay-button').prop('disabled', true);
330			jQuery('#terminialpay-button').prop('disabled', true).css('cursor', 'not-allowed');
331			jQuery('.loader').show();
332				var  aj_status = 0;
333				var refreshId = setInterval(function() {
334				aj_status = aj_status+1;
335				var formData = {
336					action: 'wpep_check_pay_terminal',
337					checkout_id: response.checkout.id,
338					t_status: response.checkout.status,
339					id: current_form_id,
340				}
341				jQuery.ajax({
342					url: wpep_local_vars.ajax_url,
343					'type' : 'GET',
344					'data' : formData,
345					'success' : function(response) {
346							var response_json = JSON.parse(response);
347							
348							if(response_json.result_info.checkout.status == 'COMPLETED'){
349								clearInterval(refreshId);
350								
351								jQuery(`#theForm-${current_form_id}`).append(`<input type="hidden" id="wpep-checkout-id-${current_form_id}" name="wpep-checkout-id-${current_form_id}" value="${response_json.result_info.checkout.id}" />`);
352						
353								/*jQuery('form.woocommerce-checkout, form#order_review').append( '<input type="hidden" class="term_checkout_status" name="term_checkout_status" value="' + response_json.result_info.checkout.status + '" />' );
354								jQuery('form.woocommerce-checkout, form#order_review').append( '<input type="hidden" class="term_checkout_app_id" name="term_checkout_app_id" value="' + response_json.result_info.checkout.app_id + '" />' );
355								jQuery('form.woocommerce-checkout, form#order_review').append( '<input type="hidden" class="term_checkout_id" name="term_checkout_id" value="' + response_json.result_info.checkout.id + '" />' );
356								jQuery('form.woocommerce-checkout, form#order_review').append( '<input type="hidden" class="term_customer_id" name="term_customer_id" value="' + response_json.result_info.checkout.customer_id + '" />' );
357								 */
358								 var token = 'cnon:customer-card-id-ok';
359								createPayment(token, current_form_id, currency, false, false);
360								// send_payment_request(adata, current_form_id)
361								
362								// completepym(refreshId);
363							}else{
364								console.error('Card id error: ', response_json.result_info.checkout.status);
365								this.disabled = false;	
366								aj_status = 0;
367							}
368						},
369					})
370				},5000)
371			}
372		});
373	}
374	});
375	function getBillingContact(form, current_form_id) {
376		return {
377		  givenName:  jQuery( "#theForm-" + current_form_id + " input[name='wpep-first-name-field']" ).val(),
378		  familyName: jQuery( "#theForm-" + current_form_id + " input[name='wpep-last-name-field']" ).val(),
379		};
380	  }
381	 
382	  function getACHOptions(form, current_form_id) {
383		  var amount           = jQuery( '#amount_display_' + current_form_id ).text();
384		  if(wpep_local_vars.currencySymbolType == 'code'){
385			  amount               = amount.trim();
386			  amount               = amount.split(' ');
387			  amount               = amount[0];
388			  amount 				 = amount.replace(wpep_local_vars.wpep_square_currency_new+" ", "");
389		  }else{
390			  amount               = amount.trim();
391			  amount               = amount.split(' ');
392			  amount               = amount[0];
393			  amount 				 = amount.replace(wpep_local_vars.wpep_currency_symbol, "");
394		  }
395		  amount = parseFloat(amount.replace(",", ""));
396		  const billingContact = getBillingContact(form, current_form_id);
397		  const accountHolderName = `${billingContact.givenName} ${billingContact.familyName}`;
398		  return { 
399			  accountHolderName,
400			  intent: 'CHARGE',
401			  total: {
402				  amount: amount*100,
403				  currencyCode: wpep_local_vars.wpep_square_currency_new
404			  },
405		  };
406	  }
407	 
408
409	  function send_payment_request(data, current_form_id) {
410		jQuery.post(
411			wpep_local_vars.ajax_url,
412			data,
413			function (response) {
414
415				var json_response = JSON.parse(response);
416				
417					if ('success' == json_response.status) {
418
419						var form_id           = current_form_id;
420						var current           = jQuery( 'form[data-id="' + form_id + '"]' );
421						var next              = jQuery( 'form[data-id="' + form_id + '"]' );
422						var currentActiveStep = current.find( '.form-wizard-steps .active' );
423						next.find( '.wizard-fieldset' ).removeClass( "show", "400" );
424						currentActiveStep.removeClass( 'active' ).addClass( 'activated' ).next().addClass( 'active', "400" );
425						next.find( '.wizard-fieldset.orderCompleted' ).addClass( "show wpep-ptb-150", "400" );
426						next.find( '.wpep-popup' ).addClass( 'completed' );
427						next.find( '.wizard-fieldset.orderCompleted' ).siblings().remove();
428						// remove form desc on thankyou page
429						current.find( '.wpep-form-desc' ).remove();
430						
431						jQuery( 'html, body' ).animate(
432							{
433								scrollTop: jQuery( "#theForm-" + form_id ).offset().top - 50
434							},
435							800,
436							function () {
437								window.location.hash = '#';
438							}
439						);
440						if (current.data( 'redirection' ) == 'http://Yes') {
441							var counter = parseInt( current.data( 'delay' ) );
442
443							current.find( '#counter' ).text( counter );
444
445							if (current.data( 'redirectionurl' ) != '') {
446
447								setInterval(
448									function () {
449										counter--;
450										if (counter >= 0) {
451											span           = document.getElementById( "counter-" + form_id );
452											span.innerHTML = counter;
453										}
454
455										if (counter === 0) {
456											window.location.href = current.data( 'redirectionurl' );
457											clearInterval( counter );
458										}
459
460									},
461									1000
462								);
463
464							} else {
465
466								setInterval(
467									function () {
468										counter--;
469										if (counter >= 0) {
470											span           = document.getElementById( "counter-" + form_id );
471											span.innerHTML = counter;
472										}
473
474										if (counter === 0) {
475											location.reload();
476											clearInterval( counter );
477										}
478
479									},
480									1000
481								);
482							}
483						} else {
484							current.find( 'small.counterText' ).remove();
485						}
486
487					} else {
488
489						var json_response = JSON.parse( response );
490
491						jQuery( "#theForm-" + current_form_id + " .paymentsBlocks-" + current_form_id ).prepend( '<div class="wpep-alert wpep-alert-danger wpep-alert-dismissable"><a href="#" data-dismiss="alert" class="wpep-alert-close">×</a>' + json_response.detail + '</div>' );
492						jQuery( 'html, body' ).animate(
493						{
494							scrollTop: jQuery( "#theForm-" + current_form_id + " .paymentsBlocks-" + current_form_id ).offset().top
495						},
496						800,
497						function () {
498								window.location.hash = '#';
499						}
500						);
501
502					}
503			}
504		).done(
505			function () {
506				jQuery( '.wpepLoader' ).remove();
507			}
508		);
509
510	}
511
512	// Call this function to send a payment token, buyer name, and other details
513	// to the project server code so that a payment can be created with 
514	// Payments API
515	async function createPayment(token, current_form_id, currency, cof, verifyToken = false) {
516		var first_name       = jQuery( "#theForm-" + current_form_id + " input[name='wpep-first-name-field']" ).val();
517		var last_name        = jQuery( "#theForm-" + current_form_id + " input[name='wpep-last-name-field']" ).val();
518		var email            = jQuery( "#theForm-" + current_form_id + " input[name='wpep-email-field']" ).val();
519		var currencies       = ['CAD', 'USD', 'EUR', 'JPY', 'AUD', 'GBP'];
520		var currency_symbols = ['C$', 'A$', '¥', '£', '€', '$'];
521		var amount           = jQuery( '#amount_display_' + current_form_id ).text();
522		if(jQuery.inArray(currency, currencies) !== -1){
523			if(wpep_local_vars.currencySymbolType == 'code'){
524				amount               = amount.trim();
525				amount               = amount.split(' ');
526				amount               = amount[0];
527				amount 				 = amount.replace(currency+" ", "");
528			}else{
529				amount               = amount.trim();
530				amount               = amount.split(' ');
531				amount               = amount[0];
532				amount 				 = amount.replace(wpep_local_vars.wpep_currency_symbol, "");
533			}
534		}
535			
536		var payment_type     = jQuery( '#wpep_payment_form_type_' + current_form_id ).val();
537		var payment_source   = jQuery( '.tab-content-'+ current_form_id+'.current' ).attr('id');
538		var form_values      = [];
539		var selectedCheckbox = [];
540		var checkLabel       = '';
541		
542
543		if (jQuery( '#theForm-' + current_form_id ).find( 'input[type="checkbox"]' ).length > 0) {
544			var checkboxName = jQuery( '#theForm-' + current_form_id + ' input[type="checkbox"]' ).attr( 'name' );
545			if (checkboxName != undefined) {
546				jQuery( 'form[data-id="' + current_form_id + '"] input[name="' + chec
546kboxName + '"]' ).each(
547					function () {
548						checkLabel = jQuery( this ).data( 'main-label' );
549						if (jQuery( this ).is( ':checked' )) {
550							selectedCheckbox.push( jQuery( this ).val() );
551						}
552					}
553				);
554			}
555
556		}
557
558		form_values.push(
559		{
560			label: checkLabel,
561			value: selectedCheckbox.join( ", " )
562		});
563
564		var product_label = [];
565		var product_price = [];
566		var product_qty = [];
567		var product_cost = [];
568		if(jQuery( '.product_label' ).length > 0){
569			jQuery( '.product_label' ).each(
570				function(key, value) {
571					var item_display = jQuery( this ).closest( '.wpItem' ).css( 'display' ) == 'none' ? 'no' : 'yes';
572					if ('yes' == item_display) {
573						product_label.push( jQuery( value ).text() );
574					}
575				}
576			);
577			jQuery( '.price' ).each(
578				function(key, value) {
579
580					var item_display = jQuery( this ).closest( '.wpItem' ).css( 'display' ) == 'none' ? 'no' : 'yes';
581
582					if ('yes' == item_display) {
583						product_price.push( jQuery( value ).val() );
584					}
585				}
586			);
587			jQuery( '.qty' ).each(
588				function(key, value) {
589					var item_display = jQuery( this ).closest( '.wpItem' ).css( 'display' ) == 'none' ? 'no' : 'yes';
590
591					if ('yes' == item_display) {
592						if ('' !== jQuery( value ).val()) {
593							product_qty.push( jQuery( value ).val() );
594						}
595					}
596				}
597			);
598			jQuery( '.price' ).each(
599				function(key, value) {
600					var item_display = jQuery( this ).closest( '.wpItem' ).css( 'display' ) == 'none' ? 'no' : 'yes';
601					if ('yes' == item_display) {
602						product_cost.push( jQuery( value ).val() );
603					}
604				}
605			);
606		}else if(jQuery( '.subscriptionPlan' ).length > 0){
607			if(jQuery( '.radio_amount' ).length > 0){
608				product_label.push( jQuery( 'input[name="radio-name"]:checked' ).attr("data-label") );
609				product_price.push( jQuery( 'input[name="radio-name"]:checked' ).val() );
610				product_cost.push( jQuery( 'input[name="radio-name"]:checked' ).val() );
611				product_qty.push( 1 );
612			}
613		}else if(jQuery( '.paynowDrop' ).length > 0){
614			if(jQuery( '.custom-option' ).length > 0){
615				jQuery( '.custom-option' ).each(
616					function(key, value) {
617						if(jQuery(value).hasClass('selection')){
618							product_label.push( jQuery(value).text() );
619							product_price.push( jQuery(value).attr("data-value") );
620							product_cost.push( jQuery(value).attr("data-value") );
621							product_qty.push( 1 );
622						}
623					}
624				);
625			}
626		}else if(jQuery( '.paymentSelect' ).length > 0){
627			var cc;
628			if(wpep_local_vars.currencySymbolType == 'code'){
629				cc = wpep_local_vars.wpep_square_currency_new;
630			}else{
631				cc = wpep_local_vars.wpep_currency_symbol;
632			}
633			if(jQuery( '.selection' ).length > 0){
634				product_label.push( 'Custom Amount' );
635				var pp = jQuery( '#amount_display_' + current_form_id ).text();
636				var neat_price = pp.replace(/\s/g, '');
637				neat_price = neat_price.replace(cc, '');
638				product_price.push( neat_price );
639				product_cost.push( neat_price );
640				product_qty.push( 1 );
641			}
642		}
643		var products_data = {};
644		jQuery.each(
645			product_label ,
646			function(key, value) {
647
648				var tmp_product_data      = {};
649				tmp_product_data.label    = product_label[key];
650				tmp_product_data.quantity = product_qty[key];
651				tmp_product_data.price    = product_price[key];
652				tmp_product_data.cost     = product_cost[key];
653
654				products_data[key] = tmp_product_data;
655
656			}
657		);
658
659		products_data = JSON.stringify( products_data );
660
661		if (jQuery( '#theForm-' + current_form_id ).find( 'input[type="radio"]' ).length > 0) {
662			var radioName = jQuery( '#theForm-' + current_form_id + ' input[type="radio"]' ).attr( 'name' );
663			if (radioName != undefined) {
664				jQuery( 'form[data-id="' + current_form_id + '"] input[name="' + radioName + '"]' ).each(
665					function () {
666
667						if (jQuery( this ).is( ':checked' )) {
668							form_values.push(
669								{
670									label: jQuery( this ).data( 'main-label' ),
671									value: jQuery( this ).val()
672								}
673							);
674						}
675
676					}
677				);
678			}
679		}
680
681		form_values.push(
682			{
683				label: 'Line Items',
684				value: products_data
685			}
686		);
687
688
689		jQuery('.radio_amount').each(function(){
690			
691			if (jQuery( this ).is( ':checked' )) {
692
693				form_values.push(
694					{
695						label: jQuery(this).data('label'),
696						value: jQuery(this).val()
697					}
698				);
699
700			}
701
702		});
703
704		jQuery( 'form[data-id="' + current_form_id + '"] input[type="date"]' ).each(
705			function () {
706
707				if (jQuery( this ).data( 'label' ) !== '' && typeof jQuery( this ).data( 'label' ) !== 'undefined') {
708					form_values.push(
709						{
710							label: jQuery( this ).data( 'label' ),
711							value: jQuery( this ).val()
712						}
713					);
714				}
715
716			}
717		);
718
719		jQuery( 'form[data-id="' + current_form_id + '"] input[type="number"]' ).each(
720			function () {
721				if (jQuery( this ).data( 'label' ) !== '' && typeof jQuery( this ).data( 'label' ) !== 'undefined') {
722					form_values.push(
723						{
724							label: jQuery( this ).data( 'label' ),
725							value: jQuery( this ).val()
726						}
727					);
728				}
729			}
730		);
731
732		jQuery( 'form[data-id="' + current_form_id + '"] select' ).each(
733			function () {
734
735				var selMulti = jQuery.map(
736					jQuery( 'form[data-id="' + current_form_id + '"] select option:selected' ),
737					function (el, i) {
738						return jQuery( el ).text();
739					}
740				);
741
742				if (jQuery( this ).data( 'label' ) !== '' && typeof jQuery( this ).data( 'label' ) !== 'undefined') {
743					form_values.push(
744						{
745							label: jQuery( this ).data( 'label' ),
746							value: selMulti.join( ", " )
747						}
748					);
749				}
750
751			}
752		);
753
754		jQuery( 'form[data-id="' + current_form_id + '"] input[type="text"]' ).each(
755			function () {
756
757				if (jQuery( this ).data( 'label' ) !== '' && typeof jQuery( this ).data( 'label' ) !== 'undefined') {
758					form_values.push(
759						{
760							label: jQuery( this ).data( 'label' ),
761							value: jQuery( this ).val()
762						}
763					);
764				}
765			}
766		);
767
768		jQuery( 'form[data-id="' + current_form_id + '"] textarea' ).each(
769			function () {
770
771				if (jQuery( this ).data( 'label' ) !== '' && typeof jQuery( this ).data( 'label' ) !== 'undefined') {
772					form_values.push(
773						{
774							label: jQuery( this ).data( 'label' ),
775							value: jQuery( this ).val()
776						}
777					);
778				}
779
780			}
781		);
782
783		jQuery( 'form[data-id="' + current_form_id + '"] input[type="email"]' ).each(
784			function () {
785
786				if (jQuery( this ).data( 'label' ) !== '' && typeof jQuery( this ).data( 'label' ) !== 'undefined') {
787					form_values.push(
788						{
789							label: jQuery( this ).data( 'label' ),
790							value: jQuery( this ).val()
791						}
792					);
793				}
794
795			}
796		);
797
798		jQuery( 'form[data-id="' + current_form_id + '"] input[type="tel"]' ).each(
799			function () {
800				if (jQuery( this ).data( 'label' ) !== '' && typeof jQuery( this ).data( 'label' ) !== 'undefined') {
801						form_values.push(
802						{
803							label: jQuery( this ).data( 'label' ),
804							value: jQuery( this ).val()
805						}
806					);
807				}
808			}
809		);
810
811		jQuery( 'form[data-id="' + current_form_id + '"] input[type="password"]' ).each(
812			function () {
813				if (jQuery( this ).data( 'label' ) !== '' && typeof jQuery( this ).data( 'label' ) !== 'undefined') {
814						form_values.push(
815						{
816							label: jQuery( this ).data( 'label' ),
817							value: jQuery( this ).val()
818						}
819					);
820				}
821			}
822		);
823
824		jQuery( 'form[data-id="' + current_form_id + '"] input[type="color"]' ).each(
825			function () {
826				if (jQuery( this ).data( 'label' ) !== '' && typeof jQuery( this ).data( 'label' ) !== 'undefined') {
827					form_values.push(
828						{
829							label: jQuery( this ).data( 'label' ),
830							value: jQuery( this ).val()
831						}
832					);
833				}
834			}
835		);
836		var amount_display = jQuery( '#amount_display_' + current_form_id ).text(); 
837		var amount_display_neat = amount_display.replace(/\s/g, ''); 
838		form_values.push(
839			{
840				label: 'total_amount',
841				value: amount_display_neat
842			}
843		);
844
845		var quantity_id = '#wpep_quantity_' + current_form_id;
846		form_values.push(
847			{
848				label: 'quantity',
849				value: jQuery( quantity_id ).val()
850			}	
851		);
852		// check if discount applied or not
853		if ( jQuery(`#theForm-${current_form_id} input[name="wpep-discount"]`).length > 0 ) { 
854			var discount = jQuery(`#theForm-${current_form_id} input[name="wpep-discount"]`).val();
855		} else {
856			var discount = 0;
857		}
858		var recaptcha = '';
859		if(wpep_local_vars.enable_recaptcha == 'on' && wpep_local_vars.recaptcha_version == 'v2'){
860			var recaptcha = grecaptcha.getResponse()
861		}
862		else if(wpep_local_vars.enable_recaptcha == 'on' && wpep_local_vars.recaptcha_version == 'v3'){
863			var recaptcha = jQuery('#wpep_recaptcha').val();
864			
865		}
866	
867		var data = {
868			'action': 'wpep_payment_request',
869			'nonce': token,
870			'first_name': first_name,
871			'last_name': last_name,
872			'email': email,
873			'discount': discount,
874			'amount': amount,
875			'save_card': jQuery( '#saveCardLater' ).is( ':checked' ),
876			'save_customer_id': jQuery( '#wpep_square_customer_id' ).val(),
877			'payment_type': payment_type,
878			'payment_source': payment_source,
879			'payment_tcheckoutid': jQuery('#wpep-checkout-id-'+current_form_id).val(),
880			'current_form_id': current_form_id,
881			'form_values': form_values,
882			'currency': currency,
883			'card_on_file': cof,
884			'buyer_verification': verifyToken,
885			'wp_payment_nonce': wpep_local_vars.wp_payment_nonce,
886			'wp_payment_recapcha': recaptcha
887		};
888
889
890		if (undefined !== jQuery('#wpep_file_upload_field')[0]) {
891			var files = jQuery('#wpep_file_upload_field')[0].files[0];
892
893				if (undefined !== files) {
894					var fd = new FormData();
895					fd.append('file', files);
896					fd.append('file_upload', 'true');
897					fd.append('action', 'wpep_file_upload');
898
899				jQuery.ajax({
900					url: wpep_local_vars.ajax_url,
901					type: 'post',
902					data: fd,
903					contentType: false,
904					processData: false,
905					success: function (response) {
906						var parsed_response = JSON.parse(response);
907						if (parsed_response.hasOwnProperty('error')) {
908							jQuery( "#theForm-" + current_form_id + " .paymentsBlocks-" + current_form_id ).prepend( '<div class="wpep-alert wpep-alert-danger wpep-alert-dismissable"><a href="#" data-dismiss="alert" class="wpep-alert-close">×</a>' + parsed_response.error + '</div>' );
909							jQuery( '.wpepLoader' ).remove();
910							
911						} else {
912							 wpep_file_upload_url(parsed_response.uploaded_file_url);
913							saveFileUploadUrlToSession(parsed_response.uploaded_file_url, data, current_form_id);
914						}
915					}
916				});
917			} else {
918				send_payment_request(data, current_form_id);
919			}
920		} else {
921			send_payment_request(data, current_form_id);
922		}
923
924		function saveFileUploadUrlToSession(fileUrl, data, formId) {
925			jQuery.ajax({
926				url: wpep_local_vars.ajax_url,
927				type: 'post',
928				data: {
929					action: 'wpep_save_file_upload_url',
930					file_url: fileUrl,
931					data: data,
932					form_id: formId
933				},
934				success: function (response) {
935					send_payment_request(data, formId);
936				}
937			});
938		}
939		function wpep_file_upload_url(url) {
940			form_values.push(
941				{
942					label: 'Uploaded URL',
943					value: url
944				}
945			);
946		}
947
948		
949	}
950
951
952	
953	
954	// This function tokenizes a payment method. 
955	// The ‘error’ thrown from this async function denotes a failed tokenization,
956	// which is due to buyer error (such as an expired card). It is up to the
957	// developer to handle the error and provide the buyer the chance to fix
958	// their mistakes.
959	async function tokenize(paymentMethod, options = false) {
960
961		console.log(options);
962		const tokenResult = await paymentMethod.tokenize(options);
963
964		if (tokenResult.status === 'OK') {
965			return tokenResult.token;
966		} else {
967		let errorMessage = `Tokenization failed-status: ${tokenResult.status}`;
968		if (tokenResult.errors) {
969			errorMessage += ` and errors: ${JSON.stringify(
970			tokenResult.errors
971			)}`;
972		}
973		jQuery( '.wpepLoader' ).remove();
974		throw new Error(errorMessage);
975		}
976	}
977
978	async function handlePaymentMethodSubmission(event, paymentMethod, current_form_id, currency, token = false, method = null, achOptions = null) {
979	
980		jQuery( "#theForm-" + current_form_id ).append( jQuery( '<div />' ).attr( 'class', 'wpepLoader' ).html( '<div class="initial-load-animation"><div class="payment-image icomoonLib"><span class="icon-pay"></span></div><div class="loading-bar"><div class="blue-bar"></div></div></div>' ) );
981		if ( method === null && method !== 'cashapp') {
982			event.preventDefault();
983		}
984
985
986		try {
987			
988			var amount = jQuery('input[name="wpep-selected-amount"]').val();	
989			
990			if ( isNaN(amount) ){
991				amount 		     = amount.replace("$", "");
992			}
993			
994			var first_name       = jQuery( "#theForm-" + current_form_id + " input[name='wpep-first-name-field']" ).val();
995			var last_name        = jQuery( "#theForm-" + current_form_id + " input[name='wpep-last-name-field']" ).val();
996			var email            = jQuery( "#theForm-" + current_form_id + " input[name='wpep-email-field']" ).val();
997			var payment_type     = jQuery( '#wpep_payment_form_type_' + current_form_id ).val();
998			var save_card_later  = jQuery( '#saveCardLater' ).is( ':checked' );
999
1000			if ( payment_type == 'subscription' || save_card_later == true ) {
1001				var intent           = 'STORE';
1002			} else {
1003				var intent           = 'CHARGE';
1004			}
1005
1006			if ( ! token ) {
1007				if ( method === 'ach' ) {
1008					tokenize(paymentMethod, achOptions).then(token => {
1009						alert('token: '+token);
1010						createPayment(token, current_form_id, currency, false, false);
1011					});
1012				} else {
1013					tokenize(paymentMethod).then(token => {
1014						verifyBuyer(payments, token, amount, currency, intent, first_name, last_name, email).then(verifyToken => {
1015							createPayment(token, current_form_id, currency, false, verifyToken);
1016						});
1017					});
1018				}
1019				
1020				
1021			} else {
1022				verifyBuyer(payments, token, amount, currency, intent, first_name, last_name, email).then(verifyToken => {
1023					createPayment(token, current_form_id, currency, false, verifyToken);
1024				});
1025				
1026			}
1027		
1028	
1029		} catch (e) {
1030			console.log(e)
1031		}
1032		if ( wpep_local_vars.afterpay == 'on') {
1033			if (afterpay) {
1034				const afterpayButton = document.getElementById('afterpay-button');
1035				afterpayButton.addEventListener('click', async function (event) {
1036					await handlePaymentMethodSubmission(event, afterpay, current_form_id, currency, false);
1037				});
1038			}
1039		}
1040	}
1041
1042	async function verifyBuyer(payments, token, amount, currency, intent, first_name, last_name, email) {
1043		
1044		if ( isNaN(amount) ){
1045			amount 		     = amount.replace("$", "");
1046		}
1047		const verificationDetails = {
1048			amount: amount.toString(),
1049			billingContact: {
1050			  familyName: last_name,
1051			  givenName: first_name,
1052			  email: email,
1053			},
1054			currencyCode: currency,
1055			intent: intent
1056		};
1057		
1058		const verificationResults = await payments.verifyBuyer(
1059		  token,
1060		  verificationDetails
1061		);
1062		
1063		return verificationResults.token;
1064
1065	}
1066
1067	function validateEmail(email) {
1068		var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
1069		return re.test( String( email ).toLowerCase() );
1070	}
1071
1072
1073	function paymentButtonClicked(event, card, current_form_id, currency) {
1074		var ewallet = false;
1075		var first_name       = jQuery( "#theForm-" + current_form_id + " input[name='wpep-first-name-field']" ).val();
1076		var last_name        = jQuery( "#theForm-" + current_form_id + " input[name='wpep-last-name-field']" ).val();
1077		var email            = jQuery( "#theForm-" + current_form_id + " input[name='wpep-email-field']" ).val();
1078		 
1079		if (first_name != '' && last_name != '' && email != ''){
1080			jQuery( '.wpep-alert' ).remove();
1081			if (jQuery( "#theForm-" + current_form_id ).find( 'div' ).hasClass( 'wpep-popup' )) {
1082				// jQuery( "#theForm-" + current_form_id ).find( 'div.wpep-content' ).append( jQuery( '<div />' ).attr( 'class', 'wpepLoader' ).html( '<div class="initial-load-animation"><div class="payment-image icomoonLib"><span class="icon-pay"></span></div><div class="loading-bar"><div class="blue-bar"></div></div></div>' ) );
1083			} else {
1084				// jQuery( "#theForm-" + current_form_id ).append( jQuery( '<div />' ).attr( 'class', 'wpepLoader' ).html( '<div class="initial-load-animation"><div class="payment-image icomoonLib"><span class="icon-pay"></span></div><div class="loading-bar"><div class="blue-bar"></div></div></div>' ) );
1085			}
1086		}
1087		var result1 = jQuery( "#theForm-" + current_form_id + " .wizard-fieldset.show .fieldMainWrapper div.wpep-required input" ).filter(
1088			function () {
1089				return jQuery.trim( jQuery( this ).val() ).length == 0
1090			}
1091		).length == 0;
1092		// client side validation
1093		var result2    = false;
1094		var emailCheck = false;
1095		var wpepError  = '';
1096		var termCond   = false;
1097		jQuery( "#theForm-" + current_form_id + " .wizard-fieldset.show .fieldMainWrapper div.wpep-required" ).each(
1098			function(){
1099				
1100				var current = jQuery( this );
1101
1102				wpepError = jQuery( '<span />' ).attr( 'class', 'wpepError' ).html( 'Required Field' );
1103
1104				if (current.find( 'input[type="text"]' ).length > 0) {
1105
1106					if (current.find( 'input[type="text"]' ).val() == '' || current.find( 'input[type="text"]' ).val() == undefined) {
1107						if (current.find( 'input[type="text"] ~ .wpepError' ).length == 0) {
1108							jQuery( wpepError ).insertAfter( current.find( 'input[type="text"]' ) );
1109						}
1110						result2 = false;
1111						// return false;
1112					} else {
1113						wpepError = '';
1114						current.find( '.wpepError' ).remove();
1115						result2 = true;
1116					}
1117				}
1118
1119				if (current.find( 'textarea' ).length > 0) {
1120
1121					if (current.find( 'textarea' ).val() == '' || current.find( 'textarea' ).val() == undefined) {
1122						if (current.find( 'textarea ~ .wpepError' ).length == 0) {
1123							jQuery( wpepError ).insertAfter( current.find( 'textarea' ) );
1124						}
1125						result2 = false;
1126						// return false;
1127					} else {
1128						wpepError = '';
1129						current.find( '.wpepError' ).remove();
1130						result2 = true;
1131					}
1132
1133				}
1134
1135				if (current.find( 'select' ).length > 0) {
1136					if (current.find( 'select' ).val() == '' || current.find( 'select' ).val() == undefined) {
1137						if (current.find( 'select ~ .wpepError' ).length == 0) {
1138							jQuery( wpepError ).insertAfter( current.find( 'select' ) );
1139						}
1140						result2 = false;
1141					} else {
1142						wpepError = '';
1143						current.find( '.wpepError' ).remove();
1144						result2 = true;
1145					}
1146				}
1147
1148				if (current.find('input[type="number"]').length > 0) {
1149				  var numberInput = current.find('input[type="number"]');
1150				  //var inputValue = parseInt(numberInput.val(), 10);
1151				  var inputValue =numberInput.val();
1152				  var maxVal = parseInt(numberInput.attr('max'), 10)
1153				  if (isNaN(inputValue) || inputValue === undefined || inputValue === '') {
1154					if (current.find('input[type="number"] ~ .wpepError').length === 0) {
1155					  jQuery(wpepError).insertAfter(numberInput);
1156					}
1157					result2 = false;
1158				  } else if (inputValue > maxVal) {
1159					if (current.find('input[type="number"] ~ .wpepError').length === 0) {
1160					  jQuery(wpepError).insertAfter(numberInput);
1161					}
1162					jQuery('.wpepError').text('Maximum value exceeded. Max: ' + maxVal);
1163					result2 = false;
1164				  } else {
1165					wpepError = '';
1166					current.find('.wpepError').remove();
1167					result2 = true;
1168				  }
1169				}
1170
1171
1172				if (current.find( 'input[type="password"]' ).length > 0) {
1173
1174					if (current.find( 'input[type="password"]' ).val() == '' || current.find( 'input[type="password"]' ).val() == undefined) {
1175						if (current.find( 'input[type="password"] ~ .wpepError' ).length == 0) {
1176							jQuery( wpepError ).insertAfter( current.find( 'input[type="password"]' ) );
1177						}
1178						result2 = false;
1179						// return false;
1180					} else {
1181						wpepError = '';
1182						current.find( '.wpepError' ).remove();
1183						result2 = true;
1184					}
1185				}
1186
1187				if (current.find( 'input[type="color"]' ).length > 0) {
1188
1189					if (current.find( 'input[type="color"]' ).val() == '' || current.find( 'input[type="color"]' ).val() == undefined) {
1190						if (current.find( 'input[type="color"] ~ .wpepError' ).length == 0) {
1191							jQuery( wpepError ).insertAfter( current.find( 'input[type="color"]' ) );
1192						}
1193						result2 = false;
1194						// return false;
1195					} else {
1196						wpepError = '';
1197						current.find( '.wpepError' ).remove();
1198						result2 = true;
1199					}
1200				}
1201
1202				if (jQuery( '#theForm-' + current_form_id ).find( 'input[type="checkbox"]' ).length > 0) {
1203
1204					// for checkbox input we need name because we can select atleast one at a time in group checkbox.
1205					var checkboxName = current.find( 'input[type="checkbox"]' ).attr( 'name' );
1206
1207					if (checkboxName != undefined) {
1208						if ( ! (jQuery( '#theForm-' + current_form_id ).find( 'input[name="' + checkboxName + '"]' ).is( ':checked' )) ) {
1209							if (jQuery( '#theForm-' + current_form_id ).find( 'input[name="' + checkboxName + '"] ~ .wpepError' ).length == 0) {
1210								jQuery( wpepError ).insertAfter( current.find( 'input[name="' + checkboxName + '"]' ) );
1211							}
1212							result2 = false;
1213							// return false;
1214						} else {
1215							wpepError = '';
1216							jQuery( '#theForm-' + current_form_id ).find( 'input[name="' + checkboxName + '"] ~ .wpepError' ).remove();
1217							result2 = true;
1218						}
1219					}
1220				}
1221
1222				if (jQuery( '#theForm-' + current_form_id ).find( 'input[type="radio"]' ).length > 0) {
1223
1224					// for radio input we need name because we can select only one at a time.
1225					var radioName = current.find( 'input[type="radio"]' ).attr( 'name' );
1226
1227					if (radioName != undefined) {
1228						if ( ! (jQuery( '#theForm-' + current_form_id ).find( 'input[name="' + radioName + '"]' ).is( ':checked' )) ) {
1229							if (jQuery( '#theForm-' + current_form_id ).find( 'input[name="' + radioName + '"] ~ .wpepError' ).length == 0) {
1230								jQuery( wpepError ).insertAfter( current.find( 'input[name="' + radioName + '"]' ) );
1231							}
1232							result2 = false;
1233						} else {
1234							wpepError = '';
1235							jQuery( '#theForm-' + current_form_id ).find( 'input[name="' + radioName + '"] ~ .wpepError' ).remove();
1236							result2 = true;
1237						}
1238					}
1239					
1240				}
1241
1242				if (current.find( 'input[type="email"]' ).length > 0) {
1243
1244
1245
1246					if (current.find( 'input[type="email"]' ).val() == '' || current.find( 'input[type="email"]' ).val() == undefined || validateEmail( current.find( 'input[type="email"]' ).val() ) == false ) {
1247						if (current.find( 'input[type="email"] ~ .wpepError' ).length == 0) {
1248							jQuery( wpepError ).insertAfter( current.find( 'input[type="email"]' ) );
1249						}
1250						emailCheck = false;
1251
1252					} else {
1253						wpepError = '';
1254						current.find( '.wpepError' ).remove();
1255						emailCheck = true;
1256					}
1257				}
1258
1259				if (current.find( 'input[type="date"]' ).length > 0) {
1260
1261					if (current.find( 'input[type="date"]' ).val() == '' || current.find( 'input[type="date"]' ).val() == undefined) {
1262
1263						if (current.find( 'input[type="date"] ~ .wpepError' ).length == 0) {
1264							jQuery( wpepError ).insertAfter( current.find( 'input[type="date"]' ) );
1265						}
1266						result2 = false;
1267
1268					} else {
1269
1270						wpepError = '';
1271						current.find( '.wpepError' ).remove();
1272						result2 = true;
1273					}
1274				}
1275
1276				if (jQuery( '#theForm-' + current_form_id ).find( 'input[type="file"]' ).length) {
1277
1278					if (jQuery( '#theForm-' + current_form_id ).find( 'input[type="file"]' ).val() !== '') {
1279
1280						var file = jQuery( '#theForm-' + current_form_id ).find( 'input[type="file"]' ).val();
1281						var ext  = file.split( '.' ).pop();
1282
1283						if ( 'exe' == ext || 'dll' == ext || 'deb' == ext ) {
1284
1285							if ( jQuery( '#theForm-' + current_form_id ).find( 'input[type="file"] ~ .wpepError' ).length == 0 ) {
1286
1287								result2 = false;
1288
1289							}
1290						}
1291
1292					}
1293
1294				}
1295
1296				if (current.find( 'input[type="url"]' ).length > 0) {
1297
1298					if (current.find( 'input[type="url"]' ).val() == '' || current.find( 'input[type="url"]' ).val() == undefined) {
1299						if (current.find( 'input[type="url"] ~ .wpepError' ).length == 0) {
1300							jQuery( wpepError ).insertAfter( current.find( 'input[type="url"]' ) );
1301						}
1302						result2 = false;
1303					} else {
1304						wpepError = '';
1305						current.find( '.wpepError' ).remove();
1306						result2 = true;
1307					}
1308				}
1309
1310			}
1311		);
1312
1313		var termContainer = jQuery( "#theForm-" + current_form_id + " #termsCondition-" + current_form_id ).is( ':checked' );
1314		
1315		if (termContainer == false) {
1316			if (jQuery( "#theForm-" + current_form_id + " div.termsCondition.wpep-required" ).find( '.wpepError' ).length == 0) {
1317				wpepError = jQuery( '<span />' ).attr( 'class', 'wpepError' ).html( 'Required Field' );
1318				jQuery( "#theForm-" + current_form_id + " div.termsCondition.wpep-required" ).append( jQuery( wpepError ) );
1319			}
1320			termCond = false;		
1321		} else {
1322			wpepError = '';
1323			jQuery( "#theForm-" + current_form_id + " div.termsCondition.wpep-required" ).find( '.wpepError' ).remove();
1324			termCond = true;		
1325		}
1326		
1327		var current           = jQuery( event.target );
1328		var result3           = false;
1329		var next              = jQuery( event.target );
1330		var currentActiveStep = jQuery( event.target ).parents( '.form-wizard' ).find( '.form-wizard-steps .active' );
1331
1332		if ( jQuery('input[name="wpep-selected-amount"]').length > 0 ) {
1333			
1334			if ( jQuery('input[name="wpep-selected-amount"]').val() == '' ) {
1335				result3 = false;
1336				
1337				return false;
1338			}  else {
1339			
1340				result3 = true;
1341			} 
1342		}
1343
1344		var selected_payment_tab = current.parents( 'form' ).find( 'ul.wpep_tabs li.tab-link.current' ).data( 'tab' );
1345		var finalCheck = jQuery( "#theForm-" + current_form_id + " .wizard-fieldset.show .fieldMainWrapper div.wpep-required" ).find( "span.wpepError" ).length;
1346		if(finalCheck != 0){
1347			jQuery( '.wpepLoader' ).remove();
1348		}
1349
1350		if (jQuery( 'input[name="card_on_file"]' ).is( ':checked' )) {
1351			var card_on_file = jQuery( 'input[name="card_on_file"]' ).val();
1352			if(finalCheck <= 0){
1353				jQuery('.wpep-single-form-' + current_form_id).attr('disabled', 'disabled');
1354				jQuery('.wpep-single-form-' + current_form_id).css('cursor', 'not-allowed');
1355				jQuery('.wpep-wizard-form-' + current_form_id).css('cursor', 'not-allowed');
1356-				jQuery('.wpep-wizard-form-' + current_form_id).attr('disabled', 'disabled');
1357				createPayment(false, current_form_id, currency, card_on_file, false);
1358			}
1359			
1360		}else{
1361			// if payment type is credit card
1362			creditcard = 'creditCard-' + current_form_id;
1363			
1364			
1365			
1366			if (
1367				selected_payment_tab == creditcard 
1368				&& result1 == true 
1369				&& result3 == true 
1370				&& wpepError == '' 
1371				&& termCond == true 
1372				&& finalCheck == 0
1373				) {
1374				 handlePaymentMethodSubmission(event, card, current_form_id, currency);
1375			}/* else if (selected_payment_tab == 'googlePay' && result1 == true && result2 == true && result3 == true && emailCheck == true && wpepError == '' && termCond == true && finalCheck == 0) { // if payment type is google pay
1376				// handlePaymentMethodSubmission(event, card, current_form_id, currency);
1377			}*/ else if (result1 == true && result2 == true && result3 == true && emailCheck == true && wpepError == '' && termCond == true && finalCheck == 0) { // if payment type is google pay
1378				return true;
1379			}
1380			 
1381		}
1382		
1383		
1384					
1385	}
1386
1387
1388
1389	jQuery('.wizard-section').css('visibility', 'visible');
1390    jQuery('.parent-loader').remove();
1391
1392	jQuery("form div.qty").append('<div class="outer-button"><div class="inc btnqty"><i class="fa fa-plus"></i></div><div class="dec btnqty"><i class="fa fa-minus"></i></div></div>');
1393	jQuery(".btnqty").click('click', function () {
1394		
1395		var form_id = jQuery(this).parents('form').data('id');
1396		var currency = jQuery(this).parents('form').data('currency');
1397
1398		var $button = jQuery(this);
1399		var oldQty = $button.parent().parent().find("input").val();
1400		if ($button.html() == '<i class="fa fa-plus"></i>') {
1401			var newQty = parseFloat(oldQty) + 1;
1402		} else {
1403			// Don't allow decrementing less than zero
1404			if (oldQty > 0) {
1405				var newQty = parseFloat(oldQty) - 1;
1406			} else {
1407				newQty = 0;
1408			}
1409		}
1410
1411		$button.parent().parent().find("input").val(newQty);
1412
1413		calculate(form_id, currency);
1414		if (typeof applePay.destroy === "function") { 
1415// 			applePay.destroy();
1416
1417			displayApplePay( payments, form_id, currency ,applePay); 
1418		}
1419		if (typeof googlePay.destroy === "function") { 
1420			googlePay.destroy();
1421			displayGooglePay( payments, form_id, currency ,googlePay); 
1422		}
1423		if (typeof afterpay.destroy === "undefined") { 
1424			// afterpay.destroy();
1425			displayAfterPay( payments, form_id, currency );
1426		}
1427
1428		if (typeof cashAppPay.destroy === "undefined") { 
1429			// cashAppPay.destroy();
1430			displayCashApp( payments, form_id, currency );	
1431		}		
1432
1433		console.clear();
1434
1435	});
1436
1437
1438	jQuery( ".form-control" ).on(
1439		'focus',
1440		function () {
1441			var tmpThis = jQuery( this ).val();
1442			if (tmpThis == '') {
1443				jQuery( this ).parent().addClass( "focus-input" );
1444			} else if (tmpThis != '') {
1445				jQuery( this ).parent().addClass( "focus-input" );
1446			}
1447		}
1448	).on(
1449		'blur',
1450		function () {
1451			var tmpThis = jQuery( this ).val();
1452			if (tmpThis == '') {
1453				jQuery( this ).parent().removeClass( "focus-input" );
1454				jQuery( this ).siblings( '.wizard-form-error' ).slideDown( "3000" );
1455			} else if (tmpThis != '') {
1456				jQuery( this ).parent().addClass( "focus-input" );
1457				jQuery( this ).siblings( '.wizard-form-error' ).slideUp( "3000" );
1458			}
1459		}
1460	);
1461
1462	jQuery( '.paynow' ).click(
1463		function () {
1464
1465			var form_id = jQuery( this ).parents( 'form' ).data( 'id' );
1466			
1467			if ( jQuery(`#theForm-${form_id} input[name="wpep-discount"]`).length > 0 ) { 
1468				jQuery(`#theForm-${form_id} input[name="wpep-discount"]`).remove();
1469			}
1470
1471			if ( jQuery(`#theForm-${form_id} .wpep-alert-coupon`).length > 0 ) {
1472				jQuery(`#theForm-${form_id} .wpep-alert-coupon`).remove();
1473			}
1474
1475			jQuery( 'form[data-id="' + form_id + '"] .display' ).text( jQuery( this ).text() );
1476			jQuery( 'form[data-id="' + form_id + '"] .display' ).next().next( 'input[name="one_unit_cost"]' ).val( jQuery( this ).text() ).trigger('change');
1477			jQuery( 'form[data-id="' + form_id + '"] .display' ).next( 'input[name="wpep-selected-amount"]' ).val( jQuery( this ).text() ).trigger('change');
1478			//jQuery( '#one_unit_cost' ).val( jQuery( this ).text().trim() );
1479			jQuery( '#wpep_quantity_' + form_id ).val( 1 );
1480			jQuery( 'form[data-id="' + form_id + '"] .wpep-single-form-' + current_form_id).removeClass( 'wpep-disabled' );
1481			jQuery( 'form[data-id="' + form_id + '"] .wpep-wizard-form-' + current_form_id).removeClass( 'wpep-disabled' );
1482
1483			jQuery( 'form[data-id="' + form_id + '"] .showPayment' ).removeClass( 'shcusIn' );
1484			jQuery( 'form[data-id="' + form_id + '"] .customPayment' ).text( jQuery( this ).val() );
1485
1486			// jQuery('#wpep_amount_'+form_id).val(jQuery(this).text().replace('$',''));
1487		}
1488	);
1489
1490	jQuery( '.otherPayment' ).on(
1491		'change',
1492		function (e) {
1493
1494			var form_id      = jQuery( this ).parents( 'form' ).data( 'id' );
1495			var currency     = jQuery( this ).parents( 'form' ).data( 'currency' );
1496			var currencyType = jQuery( this ).parents( 'form' ).data( 'currency-type' );
1497			var max          = parseFloat( jQuery( this ).attr( 'max' ) );
1498			var min          = parseFloat( jQuery( this ).attr( 'min' ) );
1499			var val          = jQuery( this ).val();
1500			jQuery( '#one_unit_cost' ).val( val );
1501			jQuery( '#wpep_quantity_' + form_id ).val( 1 );
1502
1503			if ( jQuery(`#theForm-${form_id} input[name="wpep-discount"]`).length > 0 ) { 
1504				jQuery(`#theForm-${form_id} input[name="wpep-discount"]`).remove();
1505			}
1506		
1507			if ( jQuery(`#theForm-${form_id} .wpep-alert-coupon`).length > 0 ) {
1508				jQuery(`#theForm-${form_id} .wpep-alert-coupon`).remove();
1509			}
1510
1511
1512			if (val != '' && val >= min && val <= max) {
1513
1514				currency = prepare_display_amount(currencyType, currency, val);
1515			
1516				jQuery( this ).val( val );
1517				jQuery( 'form[data-id="' + form_id + '"] .display' ).text( currency );
1518				jQuery( 'form[data-id="' + form_id + '"] .display' ).next( 'input[name="wpep-selected-amount"]' ).val( jQuery( this ).val() ).trigger('change');
1519				jQuery( 'form[data-id="' + form_id + '"] .wpep-single-form-' + current_form_id).removeClass( 'wpep-disabled' );
1520				jQuery( 'form[data-id="' + form_id + '"] .wpep-wizard-form-' + current_form_id).removeClass( 'wpep-disabled' );
1521
1522			} else {
1523
1524				currency = prepare_display_amount(currencyType, currency);
1525				
1526				jQuery( this ).val( '' );
1527				jQuery( 'form[data-id="' + form_id + '"] .display' ).text( '' );
1528				jQuery( 'form[data-id="' + form_id + '"] .display' ).next( 'input[name="wpep-selected-amount"]' ).val( '' ).trigger('change');
1529				jQuery( 'form[data-id="' + form_id + '"] .wpep-single-form-' + current_form_id).addClass( 'wpep-disabled' );
1530				jQuery( 'form[data-id="' + form_id + '"] .wpep-wizard-form-' + current_form_id).addClass( 'wpep-disabled' );
1531			}
1532
1533		}
1534	);
1535
1536	function prepare_display_amount(currencyType, currency, val) {
1537
1538		if (currencyType == 'symbol') {
1539
1540			if (currency == 'USD') {
1541				currency = '$' + val;
1542			}
1543
1544			if (currency == 'CAD') {
1545				currency = 'C$' + val;
1546			}
1547
1548			if (currency == 'AUD') {
1549				currency = 'A$' + val;
1550			}
1551
1552			if (currency == 'JPY') {
1553				currency = 'Â¥' + val;
1554			}
1555
1556			if (currency == 'GBP') {
1557				currency = '£' + val;
1558			}
1559
1560		} else {
1561
1562			currency = val + ' ' + currency;
1563
1564		}
1565
1566		return currency;
1567
1568	}
1569
1570
1571	jQuery( '.wpep_delete_tabular_product' ).click(
1572		function() {
1573
1574			var form_id  = jQuery( this ).parents( 'form' ).data( 'id' );
1575			
1576			if ( jQuery(`#theForm-${form_id} input[name="wpep-discount"]`).length > 0 ) { 
1577				jQuery(`#theForm-${form_id} input[name="wpep-discount"]`).remove();
1578			}
1579		
1580			if ( jQuery(`#theForm-${form_id} .wpep-alert-coupon`).length > 0 ) {
1581				jQuery(`#theForm-${form_id} .wpep-alert-coupon`).remove();
1582			}
1583
1584			var currency = jQuery( this ).parents( 'form' ).data( 'currency' );
1585
1586			jQuery( this ).closest( '.wpItem' ).hide();
1587			calculate( form_id, currency );
1588
1589		}
1590	);
1591
1592});
1593
1594jQuery(window).on('load', function () {
1595	jQuery( '.cp-apply' ).on('click', function(e){
1596		e.preventDefault();
1597		e.stopImmediatePropagation();
1598
1599		var form_id = jQuery(this).parents('form.wpep_payment_form').data('id');
1600		var discount = 'no';
1601		if ( jQuery(`#theForm-${form_id} input[name="wpep-discount"]`).length > 0 ) { 
1602			discount = 'yes';	
1603		}
1604
1605		var currencies = ['CAD', 'USD', 'EUR', 'JPY', 'AUD', 'GBP'];
1606		var currency_symbols = ['C$', 'A$', '¥', '£', '€', '$'];
1607		// var gross_amount = jQuery('#theForm-' + form_id).find('input[name="gross_total"]').val();
1608		var gross_amount = jQuery('#theForm-' + form_id).find('#gross_total-'+ form_id).val();
1609		// gross_amount = gross_amount.replace(/,/g, '');
1610		// gross_amount = gross_amount.trim();
1611		if(wpep_local_vars.currencySymbolType == 'code'){
1612			var currency = wpep_local_vars.wpep_square_currency_new;
1613			// gross_amount = gross_amount.replace(wpep_local_vars.wpep_square_currency_new, '');
1614		} else if (wpep_local_vars.currencySymbolType == 'symbol') {
1615			var currency = wpep_local_vars.wpep_currency_symbol;
1616			// gross_amount = gross_amount.replace(wpep_local_vars.wpep_currency_symbol, '');
1617		}
1618		// gross_amount     = gross_amount.match( /\d+/g ).map( Number );
1619		var data = {
1620			'action': 'wpep_apply_coupon',
1621			'current_form_id': form_id,
1622			'coupon_code': jQuery(this).siblings('input[name="wpep-coupon"]').val(),
1623			'total_amount': gross_amount,
1624			'discounted': discount,
1625			'currency': currency,
1626			'cp_submit': jQuery(this).val()
1627		};
1628
1629		jQuery.post(
1630			wpep_local_vars.ajax_url,
1631			data,
1632			function (response) {
1633				var response = jQuery.parseJSON(response); // create an object with the key of the array
1634
1635				if ( response.status == 'success') {
1636
1637					var discountPrice = parseFloat(response.discount).toFixed(2); 
1638					var totalPrice = parseFloat(response.total).toFixed(2); 
1639
1640					if ( jQuery(`#theForm-${form_id} input[name="wpep-discount"]`).length <= 0 ) {
1641
1642						if ( jQuery(`#theForm-${form_id} .wpep-alert-coupon`).length > 0 ) {
1643							jQuery(`#theForm-${form_id} .wpep-alert-coupon`).remove();
1644						}
1645						
1646						jQuery(`#theForm-${form_id}`).append(`<input type="hidden" name="wpep-discount" value="${discountPrice}" />`);
1647						jQuery(`#wpep-coupons-${form_id}`).prepend(`<div class="wpep-alert-coupon wpep-alert wpep-alert-success wpep-alert-dismissable"><a href="#" class="wpep-dismiss-coupon wpep-alert-close">×</a>${response.message_success}</div>`);
1648						jQuery(`#theForm-${form_id}`).find('input[name="wpep-selected-amount"]').val(`${totalPrice} ${response.currency}`).trigger('change');
1649						jQuery(`#theForm-${form_id}`).find(`small#amount_display_${form_id}`).text(`${totalPrice} ${response.currency}`);
1650					
1651					} else {
1652						jQuery(`#wpep-coupons-${form_id}`).prepend(`<div class="wpep-alert-coupon wpep-alert wpep-alert-danger wpep-alert-dismissable"><a href="#" class="wpep-dismiss-coupon wpep-alert-close">×</a>Coupon already applied!</div>`);
1653					}
1654					
1655				}
1656
1657				if (response.status == 'failed') {
1658
1659					if ( jQuery(`#theForm-${form_id} .wpep-alert-coupon`).length > 0 ) {
1660						jQuery(`#theForm-${form_id} .wpep-alert-coupon`).remove();
1661					}
1662
1663					jQuery(`#wpep-coupons-${form_id}`).prepend(`<div class="wpep-alert-coupon wpep-alert wpep-alert-danger wpep-alert-dismissable"><a href="#" class="wpep-dismiss-coupon wpep-alert-close">×</a>${response.message_failed}</div>`);
1664					
1665				}
1666
1667			}
1668		)
1669
1670	});
1671if (jQuery('.ext_number').is(':visible')) {
1672	jQuery('.ext_number').on('input', function() {
1673		var inputElement = jQuery(this); // save the reference to the element
1674		setTimeout(function() {
1675		  var enteredValue = parseInt(inputElement.val());
1676		  var minValue = parseInt(inputElement.attr('min'));
1677		  var maxValue = parseInt(inputElement.attr('max'));
1678		  if (enteredValue < minValue || enteredValue > maxValue) {
1679			inputElement.val('');
1680		  }
1681		}, 1000);
1682	  });
1683	}
1684
1685})
1686jQuery( document ).on( 'click', '.wpep-dismiss-coupon', function(e) {
1687	e.preventDefault();
1688	jQuery( '.wpep-alert-coupon' ).remove();
1689});
1690let current_form_id = jQuery( 'form.wpep_payment_form' ).data( 'id' );
1691
1692
1693jQuery(document).on('input', 'input[name="wpep_quantity"]', function() {
1694	var value       = parseInt( this.value);
1695	var current_form_id = jQuery( 'form.wpep_payment_form' ).data( 'id' );
1696	wpep_update_amount_with_quantity( current_form_id, value );
1697});
1698
1699
1700function wpep_update_amount_with_quantity(current_form_id, value) {
1701
1702	var amount_field_id           = "amount_display_" + current_form_id;
1703	var amount_with_currency      = document.getElementById( amount_field_id ).innerHTML.trim();
1704	var amount_and_currency_split = amount_with_currency.split( " " );
1705	var currency                  = amount_and_currency_split[1];
1706	var one_unit_cost             = jQuery( '#one_unit_cost' ).val();
1707	var one_unit_cost                 = one_unit_cost.split( " " )[0];
1708	var one_unit_cost = one_unit_cost.replace("$", ""); // remove dollar sign
1709	var new_amount                = one_unit_cost * value;
1710	document.getElementById( amount_field_id ).innerHTML = new_amount + ' ' + currency;
1711	jQuery( 'form[data-id="' + current_form_id + '"] .display' ).next( 'input[name="wpep-selected-amount"]' ).val( new_amount + ' ' + currency ).trigger('change');
1712	var discount = 'no';
1713	if ( jQuery(`#theForm-${current_form_id} input[name="wpep-discount"]`).length > 0 ) { 
1714		discount = 'yes';	
1715	}
1716	var data = {
1717		'action': 'wpep_apply_coupon',
1718		'current_form_id': current_form_id,
1719		'coupon_code': jQuery('.cp-apply').siblings('input[name="wpep-coupon"]').val(),
1720		'total_amount': new_amount,
1721		'discounted': discount,
1722		'currency': currency,
1723		'cp_submit': jQuery('.cp-apply').val()
1724	};
1725
1726	jQuery.post(
1727		wpep_local_vars.ajax_url,
1728		data,
1729		function (response) {
1730			var response = jQuery.parseJSON(response); // create an object with the key of the array
1731
1732			if ( response.status == 'success') {
1733
1734				var discountPrice = parseFloat(response.discount).toFixed(2); 
1735				var totalPrice = parseFloat(response.total).toFixed(2); 
1736
1737				if ( jQuery(`#theForm-${current_form_id} input[name="wpep-discount"]`).length <= 0 ) {
1738
1739					if ( jQuery(`#theForm-${current_form_id} .wpep-alert-coupon`).length > 0 ) {
1740						jQuery(`#theForm-${current_form_id} .wpep-alert-coupon`).remove();
1741					}
1742					
1743					jQuery(`#theForm-${current_form_id}`).append(`<input type="hidden" name="wpep-discount" value="${discountPrice}" />`);
1744					jQuery(`#wpep-coupons-${current_form_id}`).prepend(`<div class="wpep-alert-coupon wpep-alert wpep-alert-success wpep-alert-dismissable"><a href="#" class="wpep-dismiss-coupon wpep-alert-close">×</a>${response.message_success}</div>`);
1745					jQuery(`#theForm-${current_form_id}`).find('input[name="wpep-selected-amount"]').val(`${totalPrice} ${response.currency}`).trigger('change');
1746					jQuery(`#theForm-${current_form_id}`).find(`small#amount_display_${current_form_id}`).text(`${totalPrice} ${response.currency}`);
1747				
1748				} else {
1749					jQuery(`#wpep-coupons-${current_form_id}`).prepend(`<div class="wpep-alert-coupon wpep-alert wpep-alert-danger wpep-alert-dismissable"><a href="#" class="wpep-dismiss-coupon wpep-alert-close">×</a>Coupon already applied!</div>`);
1750				}
1751				
1752			}
1753
1754			if (response.status == 'failed') {
1755
1756				if ( jQuery(`#theForm-${current_form_id} .wpep-alert-coupon`).length > 0 ) {
1757					jQuery(`#theForm-${current_form_id} .wpep-alert-coupon`).remove();
1758				}
1759
1760				jQuery(`#wpep-coupons-${current_form_id}`).prepend(`<div class="wpep-alert-coupon wpep-alert wpep-alert-danger wpep-alert-dismissable"><a href="#" class="wpep-dismiss-coupon wpep-alert-close">×</a>${response.message_failed}</div>`);
1761				
1762			}
1763
1764		}
1765	)
1766
1767}
1768
1769
1770function wpep_increaseValue(current_form_id) {
1771
1772	if ( jQuery(`#theForm-${current_form_id} input[name="wpep-discount"]`).length > 0 ) { 
1773		jQuery(`#theForm-${current_form_id} input[name="wpep-discount"]`).remove();
1774	}
1775
1776	if ( jQuery(`#theForm-${current_form_id} .wpep-alert-coupon`).length > 0 ) {
1777		jQuery(`#theForm-${current_form_id} .wpep-alert-coupon`).remove();
1778	}
1779
1780	var quantity_id = 'wpep_quantity_' + current_form_id;
1781	var value       = parseInt( document.getElementById( quantity_id ).value, 10 );
1782
1783	value = isNaN( value ) ? 0 : value;
1784	value++;
1785	document.getElementById( quantity_id ).value = value;
1786
1787	wpep_update_amount_with_quantity( current_form_id, value );
1788
1789}
1790
1791function wpep_decreaseValue(current_form_id) {
1792
1793	if ( jQuery(`#theForm-${current_form_id} input[name="wpep-discount"]`).length > 0 ) { 
1794		jQuery(`#theForm-${current_form_id} input[name="wpep-discount"]`).remove();
1795	}
1796
1797	if ( jQuery(`#theForm-${current_form_id} .wpep-alert-coupon`).length > 0 ) {
1798		jQuery(`#theForm-${current_form_id} .wpep-alert-coupon`).remove();
1799	}
1800	
1801	var quantity_id = 'wpep_quantity_' + current_form_id;
1802	var value       = parseInt( document.getElementById( quantity_id ).value, 10 );
1803
1804	if (1 !== value) {
1805		value             = isNaN( value ) ? 0 : value;
1806		value < 1 ? value = 1 : '';
1807		value--;
1808		document.getElementById( quantity_id ).value = value;
1809		wpep_update_amount_with_quantity( current_form_id, value );
1810	}
1811
1812}
1813
1814function calculate(form_id, currency) {
1815
1816	var currency_codes = ['CAD', 'GBP', 'AUD', 'JPY', 'EUR', 'USD'];
1817	var currency_symbol = ['C$', '£', 'A$', '¥', '€', '$'];
1818		if (wpep_local_vars.currencySymbolType == 'symbol') {
1819		jQuery.each( currency_codes, function( i, val ) {
1820			if( currency == val ) {
1821				currency = currency_symbol[i];
1822			}	
1823		});
1824	}
1825
1826	if (wpep_local_vars.currencySymbolType == 'code') {
1827
1828		jQuery.each( currency_symbol, function( i, val ) {
1829			if( currency == val ) {
1830				currency = currency_codes[i];
1831			}
1832		});
1833	}
1834
1835	var item_display = 'yes';
1836
1837	if ( jQuery( 'form[data-id="' + form_id + '"] .wpItem' ).length ) {
1838
1839		jQuery( ".wpItem" ).each(
1840			function () {
1841
1842				var priceVal = jQuery( this ).find( 'input.price' ).val();
1843				var qtyVal   = jQuery( this ).find( "input.qty" ).val();
1844				var costVal  = (priceVal * qtyVal);
1845				jQuery( this ).find( 'input.cost' ).val( (costVal).toFixed( 2 ) );
1846
1847			}
1848		);
1849
1850		var subtotalVal = 0;
1851		jQuery( '.cost' ).each(
1852			function () {
1853
1854				item_display = jQuery( this ).closest( '.wpItem' ).css( 'display' ) == 'none' ? 'no' : 'yes';
1855				if ('yes' == item_display) {
1856					subtotalVal += parseFloat( jQuery( this ).val() );
1857					
1858				}
1859
1860			}
1861		);
1862
1863		jQuery( '.subtotal' ).val( (subtotalVal).toFixed( 2 ) );
1864
1865		var total = parseFloat( subtotalVal );
1866
1867		total     = (total).toFixed( 2 );
1868		
1869		jQuery( 'form[data-id="' + form_id + '"] .display' ).text( total + ' ' + currency );
1870
1871		var layout = jQuery('#wpep_amount_layout').val();
1872		if (layout !== 'tabular_layout') {
1873			jQuery( 'form[data-id="' + form_id + '"] .display' ).next( 'input[name="wpep-selected-amount"]' ).val( currency ).trigger('change');
1874		}
1875		jQuery( 'form[data-id="' + form_id + '"] .wpep-single-form-' + current_form_id).removeClass( 'wpep-disabled' );
1876		jQuery( 'form[data-id="' + form_id + '"] .wpep-wizard-form-' + current_form_id).removeClass( 'wpep-disabled' );
1877
1878	}
1879}
1880
1881const filterNum = (str) => {
1882	const numericalChar = new Set([ ".",",","0","1","2","3","4","5","6","7","8","9" ]);
1883	str = str.split("").filter(char => numericalChar.has(char)).join("");
1884	return str;
1885}
1886
1887jQuery( window ).load(
1888	function () {
1889		
1890	jQuery('.wpep_payment_form').each(function() {
1891		var current_form_id = jQuery(this).attr('data-id');
1892		
1893		jQuery('ul.wpep_tabs-' + current_form_id + ' li').click(function () {
1894			
1895				var tab_id = jQuery( this ).attr( 'data-tab' );
1896				if ('cashapp' === tab_id || 'achdebit' === tab_id  || 'googlePay' === tab_id ||
1897					'afterpay' === tab_id ||  'applePay' === tab_id ){
1898						jQuery('.wpep-single-form-' + current_form_id).attr('disabled', 'disabled');
1899						jQuery('.wpep-single-form-' + current_form_id).css('cursor', 'not-allowed');
1900						jQuery('.wpep-wizard-form-' + current_form_id).attr('disabled', 'disabled');
1901						jQuery('.wpep-wizard-form-' + current_form_id).css('cursor', 'not-allowed');
1902						jQuery('.cp-apply').prop('disabled', false);
1903						jQuery('.cp-apply').css('cursor', 'default');
1904				}else{
1905					jQuery('.wpep-single-form-' + current_form_id).prop('disabled', false);
1906					jQuery('.wpep-single-form-' + current_form_id).css('cursor', 'pointer');
1907					jQuery('.wpep-wizard-form-' + current_form_id).prop('disabled', false);
1908					jQuery('.wpep-wizard-form-' + current_form_id).css('cursor', 'pointer');
1909				}
1910				jQuery( 'ul.wpep_tabs-' + current_form_id + ' li' ).removeClass( 'current' );
1911				jQuery( '.tab-content-' + current_form_id ).removeClass( 'current' );
1912				jQuery( this ).find('.tab-content-'+current_form_id).addClass( 'current' );
1913				jQuery( this ).addClass( 'current' );
1914				jQuery( "#" + tab_id ).addClass( 'current' );
1915				
1916				if(tab_id != 'applePayfather-'+current_form_id){
1917				    jQuery('#applePayfather-'+current_form_id).css('display', 'none');
1918				} else {
1919				     jQuery('#applePayfather-' + current_form_id).css('display', 'block');
1920				}
1921				
1922			}
1923		);
1924 });
1925	 
1926
1927    jQuery( 'input[name="wpep-selected-amount"]' ).on('change paste keyup', function() {	
1928
1929		var form_id = jQuery(this).parents('form.wpep_payment_form').data('id');
1930		var discount = 0.00;
1931		var signup_total = 0.00;
1932		//var amount = parseFloat(jQuery('#theForm-' + form_id).find('#amount_display_' + form_id).text());
1933		var amount = parseFloat( filterNum( jQuery(this).val() ) );
1934		if ( jQuery(`#theForm-${form_id}`).find('input[name="wpep-signup-amount"]').length > 0 ) {
1935			var signup_total = parseFloat(jQuery(`#theForm-${form_id}`).find('input[name="wpep-signup-amount"]').val());
1936		}
1937		//var gross_total = parseFloat(jQuery(`#theForm-${form_id}`).find('input[name="gross_total"]').val());
1938		var total_amount = amount + signup_total;
1939		if (isNaN(total_amount)) {
1940			if(!localStorage.getItem("alertDisplayed")) {
1941				
1942				localStorage.setItem("alertDisplayed", "true");
1943			}
1944			var total_amount = 0;
1945		}
1946		var unit_cost = 0;
1947		if ( jQuery( '#one_unit_cost' ).length > 0 ) {
1948			var one_unit_cost = jQuery( '#one_unit_cost' ).val();
1949			unit_cost = parseFloat(one_unit_cost.split( " " )[0]).toFixed(2);
1950		}
1951		jQuery(`#theForm-${form_id}`).find('.wpep-fee-subtotal .fee_value').text( unit_cost + ' ' + wpep_local_vars.wpep_square_currency_new );
1952		jQuery(`#theForm-${form_id}`).find('.wpep-fee-total .fee_value').text( parseFloat( total_amount ).toFixed(2) + ' ' + wpep_local_vars.wpep_square_currency_new );
1953		jQuery(`#amount_display_${form_id}`).siblings('input[name="wpep-selected-amount"]').val(parseFloat( total_amount ).toFixed(2));
1954		if(wpep_local_vars.currencySymbolType == 'symbol'){
1955			var currency = wpep_local_vars.wpep_currency_symbol;
1956		} else if(wpep_local_vars.currencySymbolType == 'code'){
1957			var currency = wpep_local_vars.wpep_square_currency_new;
1958		}else{
1959			var currency = '';
1960		}
1961		
1962		jQuery(`#amount_display_${form_id}`).text(parseFloat( total_amount ).toFixed(2) + ' ' + currency);
1963		if ( jQuery(`#theForm-${form_id}`).find('input[name="gross_total"]').length > 0 ) {
1964			jQuery(`#theForm-${form_id}`).find('input[name="gross_total"]').val(total_amount);
1965		}
1966		if ( jQuery(`#theForm-${form_id}`).find('input[name="wpep-discount"]').length > 0 ) {
1967			discount = parseFloat(jQuery(`#theForm-${form_id}`).find('input[name="wpep-discount"]').val());
1968		}
1969
1970		var extra_fee = jQuery(this).parents('form.wpep_payment_form').find('.is_extra_fee').val();
1971		if ( extra_fee == 1 ) {
1972			var data = {
1973				'action': 'wpep_calculate_fee_data',
1974				'dataType': 'html',
1975				'current_form_id': form_id,
1976				'total_amount': amount,
1977				'discount': discount,
1978				'currency': wpep_local_vars.wpep_square_currency_new,
1979			};
1980			
1981			jQuery.post(
1982				wpep_local_vars.ajax_url,
1983				data,
1984				function (response) {
1985					jQuery(`#wpep-payment-details-${form_id}`).html(response);
1986					var get_total = jQuery(`#wpep-payment-details-${form_id}`).find('.wpep-fee-total span.fee_value').text();
1987					jQuery(`#amount_display_${form_id}`).text(get_total);
1988					jQuery(`#amount_display_${form_id}`).siblings('input[name="wpep-selected-amount"]').val(get_total);	
1989					
1990					let currency   = jQuery('#wpep_form_currency').val();
1991					let current_form_id = form_id;
1992					
1993					if (typeof googlePay.destroy === "function") { 
1994						/* googlePay.destroy();
1995						displayGooglePay( payments, current_form_id, currency ,googlePay); */
1996					}
1997
1998					if (typeof afterpay.destroy === "function") { 
1999						/* afterpay.destroy();
2000						displayAfterPay( payments, current_form_id, currency ); */
2001					}
2002
2003					if (typeof cashAppPay.destroy === "function") { 
2004						/* cashAppPay.destroy();
2005						displayCashApp( payments, current_form_id, currency ); */	
2006					}
2007
2008					// console.clear();
2009				}
2010			);
2011
2012		} 
2013		
2014	});
2015})
2016
2017
2018
2019function wpep_delete_cof(customer_id, card_on_file, current_form_id, delete_id) {
2020
2021	var data = {
2022		'action': 'wpep_delete_cof',
2023		'customer_id': customer_id,
2024		'card_on_file': card_on_file,
2025		'current_form_id': current_form_id
2026	};
2027
2028	jQuery.post(
2029		wpep_local_vars.ajax_url,
2030		data,
2031		function (response) {
2032			if ('success' == response) {
2033				jQuery( '#' + delete_id ).closest( "li" ).remove();
2034			}
2035		}
2036	).done(function () {});
2037
2038}
2039
2040function afterPaybuildPaymentRequest(payments, current_form_id, currency) {
2041
2042
2043	// var finalamoutn = amount;
2044	if ( jQuery('input[name="wpep-selected-amount"]').val().trim() != '' && wpep_local_vars.wpep_square_amount_type != 'payment_tabular' ) {
2045	  amount = jQuery('input[name="wpep-selected-amount"]').val();
2046	} else {
2047	  amount = jQuery('#amount_display_' + current_form_id).text();
2048	}
2049	
2050	coupon_apply = jQuery('#wpep-coupons-' + current_form_id).length;
2051	if(coupon_apply > 0 ){
2052		 jQuery('.cp-apply').click(function() {
2053			setTimeout(function() {
2054				if ( jQuery('input[name="wpep-selected-amount"]').val().trim() != '') {
2055					amount = jQuery('input[name="wpep-selected-amount"]').val();
2056				} else {
2057					amount = jQuery('#amount_display_' + current_form_id).text();
2058				}
2059			}, 1000);
2060		})
2061	}
2062	amount               = amount.trim();
2063	amount 				 = amount.replace("$", "");
2064	var min          = parseFloat( jQuery( '.otherPayment' ).attr( 'min' ) );
2065	if(amount == 0){
2066		amount = min;
2067	}
2068
2069	const req = payments.paymentRequest({
2070	  countryCode: 'US',
2071	  currencyCode: currency,
2072	  total: {
2073		amount: amount.replace(/[^0-9\.]/gi, '').toString("#0000\\.0000"),
2074		label: 'Total',
2075	  },
2076	  requestShippingContact: true,
2077	});
2078 
2079	// Note how afterpay has its own listeners
2080	req.addEventListener('afterpay_shippingaddresschanged', function (_address) {
2081	  return {
2082		shippingOptions: [
2083		  {
2084			amount: '0.00',
2085			id: 'shipping-option-1',
2086			label: 'Free',
2087			taxLineItems: [
2088			  {
2089				amount: '0.00',
2090				label: 'Tax'
2091			  }
2092			],
2093			total: {
2094			  amount: amount.replace(/[^0-9\.]/gi, '').toString("#0000\\.0000"),
2095			  label: 'total',
2096			},
2097		  },
2098		],
2099	  };
2100	});
2101
2102	return req;
2103}
2104function cashAppbuildPaymentRequest(payments, current_form_id, currency) {
2105	/* if ( jQuery('input[name="wpep-selected-amount"]').val().trim() != '' && wpep_local_vars.wpep_square_amount_type != 'payment_tabular' ) {
2106	  amount = jQuery('input[name="wpep-selected-amount"]').val();
2107	} else {
2108	  amount = jQuery('#amount_display_' + current_form_id).text();
2109	} */
2110	amount = jQuery('#amount_display_' + current_form_id).text();
2111	coupon_apply = jQuery('#wpep-coupons-' + current_form_id).length;
2112	if(coupon_apply > 0 ){
2113		 jQuery('.cp-apply').click(function() {
2114			setTimeout(function() {
2115				if ( jQuery('input[name="wpep-selected-amount"]').val().trim() != '') {
2116					amount = jQuery('input[name="wpep-selected-amount"]').val();
2117				} else {
2118					amount = jQuery('#amount_display_' + current_form_id).text();
2119				}
2120			}, 1000);
2121		})
2122	}
2123	amount = amount.trim();
2124	amount = amount.split(' ');
2125	amount = amount[0];
2126	amount = amount.replace("$", "");
2127	var min          = parseFloat( jQuery( '.otherPayment' ).attr( 'min' ) );
2128		if(amount == 0){
2129			amount = min;
2130		}
2131  
2132	jQuery('#cashapp-amount').hide();
2133	paymentRequest = payments.paymentRequest({
2134	  countryCode: 'US',
2135	  currencyCode: currency,
2136	  total: {
2137		amount: amount.toString(),
2138		label: 'Total',
2139	  },
2140	});
2141  
2142
2143  return paymentRequest;
2144}
2145
2146
2147function gpaybuildPaymentRequest(payments, current_form_id, currency, googlePay) {
2148
2149
2150var req = {};
2151	/* if ( false ) {
2152	  amount = jQuery('input[name="wpep-selected-amount"]').val();
2153	} else {
2154	  amount = jQuery('#amount_display_' + current_form_id).text();
2155	} */
2156	amount = jQuery('#amount_display_' + current_form_id).text();
2157	coupon_apply = jQuery('#wpep-coupons-' + current_form_id).length;
2158	if(coupon_apply > 0 ){
2159		 jQuery('.cp-apply').click(function() {
2160			setTimeout(function() {
2161				if ( jQuery('input[name="wpep-selected-amount"]').val().trim() != '') {
2162					amount = jQuery('input[name="wpep-selected-amount"]').val();
2163				} else {
2164					amount = jQuery('#amount_display_' + current_form_id).text();
2165				}
2166			}, 1000);
2167		})
2168	}
2169	amount = amount.trim();
2170	amount = amount.split(' ')[0]; 
2171	amount = amount.replace('$', '');  
2172	// amount = parseInt(amount).toString();
2173
2174	 req[current_form_id] = payments.paymentRequest({
2175	  countryCode: 'US',
2176	  currencyCode: currency,
2177	  total: {
2178		amount: amount.replace(/[^0-9\.]/gi, '').toString("#0000\\.0000"),
2179		label: 'Total',
2180	  },
2181	  requestShippingContact: true,
2182	});
2183 
2184	// Note how afterpay has its own listeners
2185	req[current_form_id].addEventListener('afterpay_shippingaddresschanged', function (_address) {
2186	  return {
2187		shippingOptions: [
2188		  {
2189			amount: '0.00',
2190			id: 'shipping-option-1',
2191			label: 'Free',
2192			taxLineItems: [
2193			  {
2194				amount: '0.00',
2195				label: 'Tax'
2196			  }
2197			],
2198			total: {
2199			  amount: amount.replace(/[^0-9\.]/gi, '').toString("#0000\\.0000"),
2200			  label: 'total',
2201			},
2202		  },
2203		],
2204	  };
2205	});
2206	
2207	return req[current_form_id];
2208  }
2209
2210  async function initializeAfterpay(payments, current_form_id, currency) {
2211	var max          = parseFloat( jQuery( '.otherPayment' ).attr( 'max' ) );
2212	var min          = parseFloat( jQuery( '.otherPayment' ).attr( 'min' ) );
2213	var val          = jQuery(  '.otherPayment'  ).val();
2214	if('code' == wpep_local_vars.currencySymbolType) {
2215		currency = wpep_local_vars.wpep_square_currency_new;
2216	}
2217	var amount           = jQuery( '#amount_display_' + current_form_id ).text();
2218	amount               = amount.trim();
2219	amount 				 = amount.replace("$", "");
2220	
2221	if (val == '') {
2222		jQuery( '.otherPayment' ).val(min);
2223		val = min;
2224	}
2225	if (!isNaN(val) && val >= min && val <= max) {
2226		const paymentRequest = afterPaybuildPaymentRequest(payments, current_form_id, currency);
2227		afterpay = await payments.afterpayClearpay(paymentRequest);
2228		await afterpay.attach('#afterpay-button-'+current_form_id);
2229		return afterpay;
2230	}
2231	else if (!isNaN(amount) && wpep_local_vars.wpep_square_user_defined_amount != 'on') {
2232		const paymentRequest = afterPaybuildPaymentRequest(payments, current_form_id, currency);
2233		afterpay = await payments.afterpayClearpay(paymentRequest);
2234		
2235		setTimeout(function(){ 
2236			afterpay.attach('#afterpay-button-'+current_form_id);
2237		}, 2000);
2238		return afterpay;
2239	}
2240	else if (!isNaN(amount) 
2241		&& 
2242		wpep_local_vars.wpep_square_amount_type == 'payment_radio' 
2243		|| wpep_local_vars.wpep_square_amount_type == 'payment_drop' 
2244		|| wpep_local_vars.wpep_square_amount_type == 'payment_custom' 
2245		|| wpep_local_vars.wpep_square_amount_type == 'payment_tabular'  ) {
2246		const paymentRequest = afterPaybuildPaymentRequest(payments, current_form_id, currency);
2247		afterpay = await payments.afterpayClearpay(paymentRequest);
2248		await afterpay.attach('#afterpay-button-'+current_form_id);
2249		return afterpay;
2250	}
2251	else{
2252		jQuery('#afterpay-amount').show(); 
2253	} 
2254}
2255async function applepaybuildPaymentRequest( payments, current_form_id, currency, applePay ) {
2256
2257var req = {};
2258	/* if ( false ) {
2259	  amount = jQuery('input[name="wpep-selected-amount"]').val();
2260	} else {
2261	  amount = jQuery('#amount_display_' + current_form_id).text();
2262	} */
2263	amount = jQuery('#amount_display_' + current_form_id).text();
2264	coupon_apply = jQuery('#wpep-coupons-' + current_form_id).length;
2265	if(coupon_apply > 0 ){
2266		 jQuery('.cp-apply').click(function() {
2267			setTimeout(function() {
2268				if ( jQuery('input[name="wpep-selected-amount"]').val().trim() != '') {
2269					amount = jQuery('input[name="wpep-selected-amount"]').val();
2270				} else {
2271					amount = jQuery('#amount_display_' + current_form_id).text();
2272				}
2273			}, 1000);
2274		})
2275	}
2276	amount = amount.trim();
2277	amount = amount.split(' ')[0]; 
2278	amount = amount.replace('$', '');  
2279	// amount = parseInt(amount).toString();
2280
2281	 req[current_form_id] = payments.paymentRequest({
2282	  countryCode: 'US',
2283	  currencyCode: currency,
2284	  total: {
2285		amount: amount.replace(/[^0-9\.]/gi, '').toString("#0000\\.0000"),
2286		label: 'Total',
2287	  },
2288	  requestShippingContact: true,
2289	});
2290	
2291
2292	return req[current_form_id];
2293  }
2294 async function initializeApplepay(payments, current_form_id, currency,applePay) {
2295
2296    if(applePay == undefined){
2297		var applePay = {};
2298	}
2299	// if (jQuery( '#apple-pay-button-'+current_form_id).html().length > 1) {
2300		// applePay.destroy();
2301	// }
2302		
2303	
2304	var max          = parseFloat( jQuery( '.otherPayment' ).attr( 'max' ) );
2305	var min          = parseFloat( jQuery( '.otherPayment' ).attr( 'min' ) );
2306	var val          = jQuery(  '.otherPayment'  ).val();
2307
2308	var amount           = jQuery( '#amount_display_' + current_form_id ).text();
2309	amount               = amount.trim();
2310	amount               = amount.split(' ');
2311	amount               = amount[0];
2312	amount 				 = amount.replace(wpep_local_vars.wpep_currency_symbol, "");
2313	if (val == '') {
2314		jQuery( '.otherPayment' ).val(min);
2315		val = min;
2316	}
2317	
2318
2319	 if ((val != '' && val >= min && val <= max) || (!isNaN(amount) && amount >= min && amount <= max) && wpep_local_vars.wpep_square_user_defined_amount == 'on') {
2320		
2321		const paymentRequest = await applepaybuildPaymentRequest(payments, current_form_id, currency, applePay);
2322		
2323		applePay = await payments.applePay(paymentRequest);
2324		
2325		
2326		//await applePay[current_form_id].attach('#apple-pay-button-'+current_form_id);
2327		jQuery('#applepay-amount').hide();
2328		
2329		return applePay;
2330	 }else if (!isNaN(amount) && wpep_local_vars.wpep_square_user_defined_amount != 'on') {
2331		
2332		// if(applePay != undefined){
2333			
2334			// applePay.destroy();
2335		// }
2336		
2337		const paymentRequest = await applepaybuildPaymentRequest(payments, current_form_id, currency, applePay);
2338	
2339		applePay = await payments.applePay(paymentRequest);
2340		
2341		//await applePay[current_form_id].attach('#apple-pay-button-'+current_form_id);
2342
2343		jQuery('#applepay-amount').hide();
2344	
2345		return applePay;
2346	}else if (!isNaN(amount) && wpep_local_vars.wpep_square_amount_type == 'payment_radio' || wpep_local_vars.wpep_square_amount_type == 'payment_drop' || wpep_local_vars.wpep_square_amount_type == 'payment_tabular'  ) {
2347		
2348		const paymentRequest = await applepaybuildPaymentRequest(payments, current_form_id, currency, applePay);
2349	
2350	    applePay = await payments.applePay(paymentRequest);
2351		
2352		//await applePay[current_form_id].attach('#apple-pay-button-'+current_form_id);
2353		jQuery('#applepay-amount').hide();
2354	
2355		return applePay;
2356	}else{
2357		jQuery('#applepay-amount').show();
2358		
2359	} 
2360  }
2361
2362  async function initializeGooglepay(payments, current_form_id, currency,googlePay) {
2363
2364
2365	if(googlePay == undefined){
2366		var googlePay = {};
2367	}
2368	
2369
2370
2371	if (jQuery( '#google-pay-button-'+current_form_id).html().length > 1) {
2372		googlePay.destroy();
2373	}
2374	var max          = parseFloat( jQuery( '.otherPayment' ).attr( 'max' ) );
2375	var min          = parseFloat( jQuery( '.otherPayment' ).attr( 'min' ) );
2376	var val          = jQuery(  '.otherPayment'  ).val();
2377
2378	var amount           = jQuery( '#amount_display_' + current_form_id ).text();
2379	amount               = amount.trim();
2380	amount               = amount.split(' ');
2381	amount               = amount[0];
2382	amount 				 = amount.replace(wpep_local_vars.wpep_currency_symbol, "");
2383
2384	if (val == '') {
2385		jQuery( '.otherPayment' ).val(min);
2386		val = min;
2387	}
2388	 if ((val != '' && val >= min && val <= max) || (!isNaN(amount) && amount >= min && amount <= max) && wpep_local_vars.wpep_square_user_defined_amount == 'on') {
2389		const paymentRequest = gpaybuildPaymentRequest(payments, current_form_id, currency, googlePay);
2390	
2391		googlePay[current_form_id] = await payments.googlePay(paymentRequest);
2392		
2393		
2394		await googlePay[current_form_id].attach('#google-pay-button-'+current_form_id);
2395		jQuery('#gpay-amount').hide();
2396		
2397
2398		return googlePay[current_form_id];
2399	 }else if (!isNaN(amount) && wpep_local_vars.wpep_square_user_defined_amount != 'on') {
2400		const paymentRequest = gpaybuildPaymentRequest(payments, current_form_id, currency, googlePay);
2401		googlePay = await payments.googlePay(paymentRequest);
2402		await googlePay.attach('#google-pay-button-'+current_form_id);
2403		jQuery('#gpay-amount').hide();
2404		return googlePay;
2405	}else if (!isNaN(amount) && wpep_local_vars.wpep_square_amount_type == 'payment_radio' || wpep_local_vars.wpep_square_amount_type == 'payment_drop' || wpep_local_vars.wpep_square_amount_type == 'payment_tabular'  ) {
2406		const paymentRequest = gpaybuildPaymentRequest(payments, current_form_id, currency, googlePay);
2407		googlePay = await payments.googlePay(paymentRequest);
2408		await googlePay.attach('#google-pay-button-'+current_form_id);
2409		jQuery('#gpay-amount').hide();
2410		return googlePay;
2411	}else{
2412		jQuery('#gpay-amount').show();
2413	} 
2414  }
2415
2416 async function initializeCashApp(payments, current_form_id, currency) {
2417	var max          = parseFloat( jQuery( '.otherPayment' ).attr( 'max' ) );
2418	var min          = parseFloat( jQuery( '.otherPayment' ).attr( 'min' ) );
2419	var val          = jQuery(  '.otherPayment'  ).val();
2420
2421	var amount           = jQuery( '#amount_display_' + current_form_id ).text();
2422	amount               = amount.trim();
2423	amount 				 = amount.replace(currency+" ", "");
2424	if (val == '') {
2425		jQuery( '.otherPayment' ).val(min);
2426		val = min;
2427	}
2428	if ((val != '' && val >= min && val <= max) || (!isNaN(amount) && amount >= min && amount <= max) && wpep_local_vars.wpep_square_user_defined_amount == 'on') {
2429		const paymentRequest = cashAppbuildPaymentRequest(payments, current_form_id, currency);
2430		cashAppPay = await payments.cashAppPay(paymentRequest,{
2431		  redirectURL: 'https://my.website/checkout',
2432		  referenceId: 'my-website-00000001',
2433		});
2434		await cashAppPay.attach('#cash-app-pay-'+current_form_id);
2435		return cashAppPay;
2436	} else if (!isNaN(amount) && wpep_local_vars.wpep_square_user_defined_amount != 'on') {
2437		const paymentRequest = cashAppbuildPaymentRequest(payments, current_form_id, currency)
2438		cashAppPay = await payments.cashAppPay(paymentRequest,{
2439		  redirectURL: 'https://my.website/checkout',
2440		  referenceId: 'my-website-00000001',
2441		});
2442		await cashAppPay.attach('#cash-app-pay-'+current_form_id);
2443		return cashAppPay;
2444	} else if (
2445		wpep_local_vars.wpep_square_amount_type == 'payment_radio' 
2446		|| wpep_local_vars.wpep_square_amount_type == 'payment_custom' 
2447		|| wpep_local_vars.wpep_square_amount_type == 'payment_drop' 
2448		|| wpep_local_vars.wpep_square_amount_type == 'payment_tabular'  
2449		) {
2450		const paymentRequest = cashAppbuildPaymentRequest(payments, current_form_id, currency)
2451		cashAppPay = await payments.cashAppPay(paymentRequest,{
2452		  redirectURL: 'https://my.website/checkout',
2453		  referenceId: 'my-website-00000001',
2454		});
2455		await cashAppPay.attach('#cash-app-pay-'+current_form_id);
2456		return cashAppPay;
2457	}else{
2458		jQuery('#cashapp-amount').show();
2459	} 
2460  }
2461
2462
2463
2464
2465
2466function initializePayments( appId, locationId ) {
2467	return window.Square.payments(appId, locationId);
2468}
2469function destroyGooglePay() {
2470  if(jQuery('#google-pay-button').is(':visible')){
2471	googlePay.destroy();
2472  }
2473}
2474
2475async function displayApplePay(payments, current_form_id, currency,applePay, app_btn) {
2476	
2477	var amount           = jQuery( '#amount_display_' + current_form_id ).text();
2478	amount               = amount.trim();
2479	amount 				 = amount.replace(currency, "");
2480	if(applePay == undefined){
2481		var applePay = {};
2482	}
2483	
2484		
2485	//let googlePay = undefined;
2486	if(currency !== amount){
2487	    
2488	  
2489		try {
2490			/* const divElement = document.getElementById("testing_apple");
2491
2492			// Convert the applePay object to a string
2493			const applePayString = JSON.stringify(applePay, null, 2);
2494
2495			// Create a text node with the string representation of the applePay object
2496			const textNode = document.createTextNode(applePayString);
2497
2498			// Append the text node to the div element
2499			divElement.appendChild(textNode); */
2500		
2501			applePay = await initializeApplepay(payments, current_form_id, currency,applePay[current_form_id]);
2502		
2503		  		
2504
2505
2506	} catch (e) {
2507			console.error('Initializing Applepay failed', e);
2508		}
2509	} else {
2510		jQuery('#applePay-'+current_form_id).html('<p>Please define amount from Admin</p>')
2511	}
2512	
2513	return applePay;
2514
2515}
2516
2517async function displayGooglePay(payments, current_form_id, currency,googlePay) {
2518	
2519	var amount           = jQuery( '#amount_display_' + current_form_id ).text();
2520	amount               = amount.trim();
2521	amount 				 = amount.replace(currency, "");
2522	if(googlePay == undefined){
2523		var googlePay = {};
2524	}
2525	//let googlePay = undefined;
2526	if(currency !== amount){
2527		try {
2528			googlePay[current_form_id] = await initializeGooglepay(payments, current_form_id, currency,googlePay[current_form_id]);
2529			
2530			
2531
2532			let timeoutpayId;
2533
2534			function handleDOMChanges() {
2535			  clearTimeout(timeoutpayId);
2536
2537			  timeoutpayId = setTimeout(async function() {
2538				try {
2539				  googlePay[current_form_id] = await initializeGooglepay(payments, current_form_id, currency, googlePay[current_form_id]);
2540				 
2541				 
2542				} catch (e) {
2543				  console.error('Initializing Googlepay failed', e);
2544				}
2545			  }, 2000);
2546			}
2547
2548			// Use Mutation Observer to detect DOM changes
2549			const observer = new MutationObserver(handleDOMChanges);
2550
2551			// Observe changes in the amount display element
2552			const amountDisplayElement = document.getElementById('amount_display_' + current_form_id);
2553			if (amountDisplayElement) {
2554			  observer.observe(amountDisplayElement, { subtree: true, childList: true });
2555			}
2556		  
2557			
2558
2559
2560
2561	} catch (e) {
2562			console.error('Initializing Googlepay failed', e);
2563		}
2564	} else {
2565		jQuery('#google-pay-button-'+current_form_id).html('<p>Please define amount from Admin</p>')
2566	}
2567
2568
2569
2570	return googlePay[current_form_id];
2571
2572}
2573
2574
2575	/* jQuery('.other-'+current_form_id).click( function () {
2576		let timeoutId;
2577		jQuery('.other-'+current_form_id).on('input', function() {
2578			clearTimeout(timeoutId);
2579			timeoutId = setTimeout(function() {
2580				if (googlePay[current_form_id]) {
2581					googlePay[current_form_id].destroy();
2582				}
2583				let newGooglePay = undefined;
2584				try {
2585					newGooglePay =  initializeGooglepay(payments, current_form_id, currency,googlePay[current_form_id]);
2586				} catch (e) {
2587					console.error('Initializing Googlepay failed', e);
2588				}
2589				googlePay[current_form_id] = newGooglePay;
2590			}, 1000); 
2591		});
2592	});  */
2593	/* let timeoutQtyId;
2594	jQuery('#wpep_quantity_'+current_form_id).on('input', function() {
2595		clearTimeout(timeoutQtyId);
2596    	timeoutQtyId = setTimeout(function() {
2597			if (googlePay) {
2598				googlePay.destroy();
2599			}
2600			let newGooglePay = undefined;
2601			try {
2602				newGooglePay =  initializeGooglepay(payments, current_form_id, currency,googlePay[current_form_id]);
2603			} catch (e) {
2604				console.error('Initializing Googlepay failed', e);
2605			}
2606			googlePay = newGooglePay;
2607		}, 1000); 
2608	});  */
2609
2610
2611
2612	/* let timeoutClickId;
2613	jQuery('input[name="wpep-selected-amount"]').on('change', function() {
2614		if (googlePay) {
2615				googlePay.destroy();
2616			}
2617			clearTimeout(timeoutClickId);
2618			timeoutClickId = setTimeout(function() {
2619			if (googlePay) {
2620				jQuery('#google-pay-button').html('');
2621			}
2622			let newGooglePay = undefined;
2623			try {
2624				newGooglePay =  initializeGooglepay(payments, current_form_id, currency);
2625			} catch (e) {
2626				console.error('Initializing Googlepay failed', e);
2627			}
2628			googlePay = newGooglePay;
2629		}, 1000); 
2630  }); */
2631		
2632
2633
2634
2635async function displayAfterPay(payments, current_form_id, currency) {
2636	
2637	var amount           = jQuery( '#amount_display_' + current_form_id ).text();
2638	amount               = amount.trim();
2639	amount 				 = amount.replace(currency+" ", "");
2640	if(currency !== amount){
2641	
2642		let afterpay;
2643		try {
2644			jQuery('.loader').show();
2645			afterpay = await initializeAfterpay(payments, current_form_id, currency);
2646			jQuery('.loader').hide();
2647		} catch (e) {
2648			console.error('Initializing Afterpay/Clearpay failed', e);
2649		}
2650	}else{
2651			jQuery('#afterpay-amount').show();
2652			
2653	} 
2654	
2655	jQuery('.other-'+current_form_id).click( function () {
2656	let timeoutId;
2657		jQuery('.other-'+current_form_id).on('input', function() {
2658
2659				jQuery('#afterpay-amount').hide();
2660				
2661			clearTimeout(timeoutId);
2662			timeoutId = setTimeout(function() {
2663			 if (afterpay) {	
2664					afterpay.destroy();
2665				}
2666				 
2667			   let afterpay;
2668				try {
2669					jQuery('.loader').show();
2670					afterpay =  initializeAfterpay(payments, current_form_id, currency);
2671					jQuery('.loader').hide();
2672				} catch (e) {
2673					console.error('Initializing Afterpay/Clearpay failed', e);
2674				}
2675			  
2676			 
2677			}, 1000); 
2678		  });
2679	});
2680  
2681	let timeoutQtyId;
2682	jQuery('#wpep_quantity_'+current_form_id).on('input', function() {
2683
2684		jQuery('#afterpay-amount').hide();
2685		
2686	clearTimeout(timeoutQtyId);
2687    timeoutQtyId = setTimeout(function() {
2688     
2689		if (afterpay) {	
2690			afterpay.destroy();
2691		}
2692	   let afterpay;
2693		try {
2694			jQuery('.loader').show();
2695			afterpay =  initializeAfterpay(payments, current_form_id, currency);
2696			jQuery('.loader').hide();
2697		} catch (e) {
2698			console.error('Initializing Afterpay/Clearpay failed', e);
2699		}
2700	  
2701	 
2702    }, 1000); 
2703  });
2704// Product Table
2705
2706//Drop Down & Radio clicked event
2707	/* */let timeoutChangeId;
2708	jQuery('input[name="wpep-selected-amount"]').on('change', function() {
2709	
2710	
2711	jQuery('#afterpay-amount').hide();
2712	if (jQuery( '#afterpay-button-'+current_form_id).html().length > 1) {	
2713		afterpay.destroy();
2714	}
2715	clearTimeout(timeoutChangeId);
2716    timeoutChangeId = setTimeout(function() {
2717     
2718		 
2719	   let afterpay;
2720		try {
2721			jQuery('.loader').show();
2722			afterpay =  initializeAfterpay(payments, current_form_id, currency);
2723			jQuery('.loader').hide();
2724		} catch (e) {
2725			console.error('Initializing Afterpay/Clearpay failed', e);
2726		}
2727	  
2728	 
2729    }, 2500); 
2730  }); 
2731	let timeoutpayId;
2732	jQuery('.payamount-'+current_form_id).on('click', function(event) {
2733		
2734		jQuery('#afterpay-amount').hide();
2735		
2736		clearTimeout(timeoutpayId);
2737		timeoutpayId = setTimeout(function() {
2738			if (afterpay) {
2739			afterpay.destroy();
2740		}
2741		let afterpay;
2742			try {
2743
2744				afterpay =  initializeAfterpay(payments, current_form_id, currency);
2745				jQuery('.loader').hide();
2746			} catch (e) {
2747				console.error('Initializing Afterpay/Clearpay failed', e);
2748			}
2749		  
2750		 
2751		}, 2000); 
2752	  });	
2753	return afterpay;		
2754}
2755jQuery('.other-'+current_form_id).click( function () {
2756	let timeoutId;
2757	jQuery('.other-'+current_form_id).on('input', function() {
2758		if ( wpep_local_vars.cashapp == 'on') {
2759			jQuery('#cashapp-amount').hide();
2760			clearTimeout(timeoutId);
2761			timeoutId = setTimeout(function() {
2762				if(cashAppPay){
2763					cashAppPay.destroy();
2764				} 
2765				let cashAppPay;
2766				  try {
2767						
2768					// Check if Cash App Pay is already attached before reinitializing
2769					if (typeof cashAppPay === 'undefined') {
2770						var current_form_id = jQuery(  'form.wpep_payment_form'  ).data( 'id' );
2771						var currency        = jQuery(  'form.wpep_payment_form'  ).data( 'currency' );
2772						jQuery('.loader').show();
2773					  cashAppPay =  initializeCashApp(payments,current_form_id, currency);
2774						jQuery('.loader').hide();	
2775					}
2776				  } catch (e) {
2777					console.error('Initializing Cash App Pay failed', e);
2778				  }
2779			
2780			}, 1000); 
2781		}
2782	});
2783	let timeoutQtyId;
2784	jQuery('#wpep_quantity_'+current_form_id).on('input', function() {
2785		if ( wpep_local_vars.cashapp == 'on') {
2786			jQuery('#cashapp-amount').hide();
2787			if(jQuery('#cash_app_pay_v1_element').is(':visible')){
2788				
2789			}  
2790			clearTimeout(timeoutId);
2791			timeoutId = setTimeout(function() {
2792				if(cashAppPay){
2793					cashAppPay.destroy();
2794				} 
2795				let cashAppPay;
2796				  try {
2797						
2798					// Check if Cash App Pay is already attached before reinitializing
2799					if (typeof cashAppPay === 'undefined') {
2800						var current_form_id = jQuery(  'form.wpep_payment_form'  ).data( 'id' );
2801						var currency        = jQuery(  'form.wpep_payment_form'  ).data( 'currency' );
2802						jQuery('.loader').show();
2803					  cashAppPay =  initializeCashApp(payments,current_form_id, currency);
2804						jQuery('.loader').hide();	
2805					}
2806					
2807				  } catch (e) {
2808					console.error('Initializing Cash App Pay failed', e);
2809				  }
2810			
2811			}, 1000); 
2812		}
2813	});
2814});
2815jQuery(window).on('load', function() {
2816		if(wpep_local_vars.recaptcha_version == 'v3' && wpep_local_vars.enable_recaptcha == 'on'){
2817			grecaptcha.ready(function() {
2818				grecaptcha.execute(wpep_local_vars.recaptcha_site_key_v3, {action:'validate_captcha'})
2819						  .then(function(token) {
2820					
2821					document.getElementById('g-recaptcha-response').value = token;
2822					jQuery('.wpep_payment_form').append('<input type="hidden" id="wpep_recaptcha" name="wpep_recaptcha" value="'+token+'">');
2823
2824				});
2825			});
2826		} 
2827		jQuery('.payamount-'+current_form_id).click( function (event) {
2828		if ( wpep_local_vars.cashapp == 'on') {
2829			let timeoutId;
2830			jQuery('#cashapp-amount').hide();
2831			if (cashAppPay) {
2832				cashAppPay.destroy();
2833			}
2834			clearTimeout(timeoutId);
2835			timeoutId = setTimeout(function() {
2836				let cashAppPay;
2837					try {
2838					// Check if Cash App Pay is already attached before reinitializing
2839					if (typeof cashAppPay === 'undefined') {
2840						var current_form_id = jQuery(  'form.wpep_payment_form'  ).data( 'id' );
2841						var currency        = jQuery(  'form.wpep_payment_form'  ).data( 'currency' );
2842					  cashAppPay =  initializeCashApp(payments,current_form_id, currency);
2843						jQuery('.loader').hide();	
2844					}
2845					} catch (e) {
2846						console.error('Initializing Cash App Pay failed', e);
2847					}
2848				}, 1000); 
2849			}
2850		})
2851	jQuery('input[name="wpep-selected-amount"]').on('change', function() {
2852		if ( wpep_local_vars.cashapp == 'on') {
2853			let timeChangeId;
2854			jQuery('#cashapp-amount').hide();
2855			if (jQuery('#cash_app_pay_v1_element').is(":visible") && jQuery('#cash_app_pay_v1_element').html().length > 1) {
2856				cashAppPay.destroy();
2857			}
2858			clearTimeout(timeChangeId);
2859			timeChangeId = setTimeout(function() {
2860				let cashAppPay;
2861					try {
2862						// Check if Cash App Pay is already attached before reinitializing
2863						if (typeof cashAppPay === 'undefined') {
2864							var current_form_id = jQuery(  'form.wpep_payment_form'  ).data( 'id' );
2865							var currency        = jQuery(  'form.wpep_payment_form'  ).data( 'currency' );
2866							cashAppPay =  initializeCashApp(payments,current_form_id, currency);
2867							jQuery('.loader').hide();	
2868						}
2869					} catch (e) {
2870						console.error('Initializing Cash App Pay failed', e);
2871					}
2872				}, 1000);
2873			}
2874		})
2875	});
2876
2877async function displayCashApp(payments, current_form_id, currency) {
2878
2879	var amount           = jQuery( '#amount_display_' + current_form_id ).text();
2880	amount               = amount.trim();
2881	amount 				 = amount.replace(currency+" ", "");
2882	
2883	if(currency !== amount){
2884		let cashAppPay;
2885		try {
2886			jQuery('.loader').show();
2887		  cashAppPay = await initializeCashApp(payments,current_form_id, currency);
2888		  jQuery('.loader').hide();
2889		} catch (e) {
2890		  console.error('Initializing Cash App Pay failed', e);
2891		}
2892	} else {
2893		jQuery('#cashapp-amount').show();
2894	}
2895	
2896	return cashAppPay;	
2897
2898	
2899}
2900

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.