!function(e){var a=acf.Field.extend({type:"payment_form",wait:"load",events:{"click .paypal-button":"onClickPaypalButton","click .credit-card-button:not(disabled)":"onClickCreditCardButton","click .payment-methods input":"onClickPaymentMethods"},$input:function(){return this.$("input.payment-input")},$control:function(){return this.$(".frontend-admin-payment")},$remainingSubmits:function(){return this.$(".remaining-submits")},$form:function(){return this.$el.parents("form")},addSuccess:function(){this.$input().trigger("change"),this.showNotice({text:acf.__("Payment Successful..."),type:"success"}),this.$control().addClass("paid")},requestHandler:function(a,t){var n=new FormData(this.$form()[0]);for(var i in paymentData={field:this.get("key"),feap_nonce:payment_vars.cc_nonce,method:a,action:"frontend_admin/payments/new_payment"},paymentData)n.append(i,paymentData[i]);void 0!==t&&n.append("card",t),"paypal"==a&&(n.append("page_url",window.location.href),paypalWindow=this.paypalPopUp(600,600),paypalWindow.document.write(acf.__("Loading Paypal...")));var o=this;e.ajax({url:acf.get("ajaxurl"),type:"post",data:n,cache:!1,processData:!1,contentType:!1,success:function(e){return e.success?e.data.redirect?(acf.unload.reset(),localStorage.setItem("feaToken-"+o.get("key"),"0"),localStorage.setItem("feaToken-"+o.get("key"),"0"),paypalWindow.location=e.data.redirect):(e.data.payment&&o.$input().val(e.data.payment),o.addSuccess()):(o.showNotice({text:e.data.message,type:"warning"}),o.$("button.disabled").removeClass("disabled").next(".fea-loader").addClass("acf-hidden")),null}})},paypalPopUp:function(e,a){var t,n;return t=window.screen.width/2-(e/2+10),n=window.screen.height/2-(a/2+50),window.open("","paypalWindow","status=no,height="+a+",width="+e+",resizable=yes,left="+t+",top="+n+",screenX="+t+",screenY="+n+",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no")},onClickPaymentMethods:function(a,t){var n=t.parent("label"),i=n.hasClass("selected");this.$(".selected").removeClass("selected"),n.addClass("selected");var o=this.$(".payment-method");o.addClass("frontend-admin-hidden"),i?(n.removeClass("selected"),t.prop("checked",!1).trigger("change")):o.each((function(){e(this).data("type")==t.val()&&e(this).removeClass("frontend-admin-hidden")}))},onClickPaypalButton:function(e,a){"undefined"==typeof paypalWindow||paypalWindow.closed?this.requestHandler("paypal"):paypalWindow.focus()},onClickCreditCardButton:function(e,a){if(a.hasClass("disabled")||a.addClass("disabled").next(".fea-loader").removeClass("acf-hidden"),""==payment_vars.stripe_spk)return this.showNotice({text:acf.__("Could not connect to Stripe. Please check your API keys."),type:"warning"}),void a.removeClass("disabled").next(".fea-loader").addClass("acf-hidden");if("undefined"!=typeof Stripe&&(Stripe.setPublishableKey(payment_vars.stripe_spk),0==this.$("input.stripeToken").length)){var t=this;Stripe.card.createToken(this.$form(),(function(e,n){if(n.error)return t.showNotice({text:n.error.message,type:"warning"}),void a.removeClass("disabled").next(".fea-loader").addClass("acf-hidden");t.requestHandler("stripe",n.id)}))}},showCard:function(){if(this.$(".card-wrapper").length)new Card({form:".fea-cc-fields",container:".card-wrapper",formSelectors:{numberInput:"input.number",expiryInput:"input.exp",cvcInput:"input.cvc",nameInput:"input.name"},width:300,formatting:!0,messages:{validDate:"valid\ndate",monthYear:"mm/yyyy"},placeholders:{number:"•••• •••• •••• ••••",name:"Full Name",expiry:"••/••",cvc:"•••"},masks:{cardNumber:"•"},debug:!1})},paypalComplete:function(){let a=this,t=a.get("key");e(window).on("storage",(function(e){var n=e.originalEvent;n.key=="feaToken-"+t&&"0"==n.oldValue&&"0"!=n.newValue&&(a.$input().val(n.newValue),paypalWindow.close(),a.addSuccess())}))},initialize:async function(){this.paypalComplete(),await this.showCard(),this.$(".card-skeleton").remove()}});acf.registerFieldType(a)}(jQuery);