(()=>{"use strict";var t={574(t,e,i){i.d(e,{convertFormToFields:()=>a}),i(428),new Map;const a=(t,e=[])=>t.serializeArray().reduce((t,i)=>{if(e.includes(i.name))return t;const a=[];i.name.replace(/([^\[\]]*)/g,(t,e)=>{""!==e&&a.push(e)});const n=i.name.endsWith("[]");return a.reduce((t,e,s)=>{var r,o;return s===a.length-1?n?(t[e]=null!==(r=t[e])&&void 0!==r?r:[],t[e].push(i.value)):t[e]=i.value:t[e]=null!==(o=t[e])&&void 0!==o?o:{},t[e]},t),t},{})},428(t){t.exports=window.jQuery}},e={};function i(a){var n=e[a];if(void 0!==n)return n.exports;var s=e[a]={exports:{}};return t[a](s,s.exports,i),s.exports}i.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return i.d(e,{a:e}),e},i.d=(t,e)=>{for(var a in e)i.o(e,a)&&!i.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:e[a]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var a={};i.r(a),i.d(a,{AddPaymentMethodController:()=>I,BaseController:()=>w,CartController:()=>v,CheckoutController:()=>M,ExpressCheckoutController:()=>A,MiniCartController:()=>S,ProductController:()=>C});var n=i(428),s=i.n(n);const r=window.wp.apiFetch;var o=i.n(r);const d=window.wcStripe.actions;var h=i.n(d);const c=window.wcStripe.cart;var l=i.n(c);const m=window.wcStripe.stripeSDK,u=window.wcStripe.checkoutFields;var y=i.n(u);const p=window.wcStripe.utils;class g{stripe;promises=[];_isPaymentMethodAvailable=!0;static attributionDataStored=!1;constructor({context:t,gateway:e,selector:i=null}){this.cart=l(),this.gateway=e,this.context=t,this.selector=i,this.actions=h(),this.fields=new(y())(t,this),this.gateway.setController(this),this.initActions(),this.gateway.initialize()}initActions(){}initialize(){this.loadStripeSDK().then(async()=>{await this.createPaymentElement()}).catch(t=>{console.log(t)})}async loadStripeSDK(){try{const t=await(0,m.loadStripeSDK)();this.stripe=t,this.actions.doAction("stripe_sdk_loaded",t,this)}catch(t){throw console.log(`Error loading Stripe SDK. ${t}`),t}}async createPaymentElement(){if(!this.isPaymentMethodAvailable())return this._isPaymentMethodAvailable=!1,void this.onPaymentUnavailable();this.gateway.onPaymentMethodAvailable();let t=!1;try{t=await this.gateway.canMakePayment()}catch(e){t=!1,console.error("Payment method availability check failed:",e)}if(!t)return this._isPaymentMethodAvailable=!1,void this.onPaymentUnavailable();this._isPaymentMethodAvailable=!0;const e=this.getElementContainer();if(e)if(this.gateway.shouldMountElement(e)){if(e instanceof NodeList)for(let t=0;t<e.length;t++){const i=e[t];await this.gateway.mountPaymentElement(i)}else await this.gateway.mountPaymentElement(e);this.$paymentElement=s()(e),this.onPaymentElementReady()}else this.onPaymentElementReady()}isPaymentMethodAvailable(){return this.cart.isPaymentMethodAvailable(this.gateway.id)}getPaymentElement(){return this.$paymentElement}destroyPaymentElement(){this.gateway.destroyPaymentElement?.()}disablePaymentElement(t=!0){this.gateway.disablePaymentElement?.(),t&&this?.$paymentElement&&this.$paymentElement.addClass("disabled")}enablePaymentElement(){this.gateway.enablePaymentElement?.(),this.$paymentElement&&this.$paymentElement.removeClass("disabled")}displayPaymentElement(){this.getPaymentElement()?.show()}hidePaymentElement(){this.getPaymentElement()?.hide()}needsShipping(){return this.cart.needsShipping()}getElementContainer(){let t=document.querySelector(this.selector);return this.actions.applyFilters("get_element_container",t,this)}onPaymentUnavailable(){this.actions.doAction("payment_unavailable",this)}onPaymentElementReady(){this.actions.doAction("payment_element_ready",this)}onCancel(){this.enablePaymentElement()}onError(t,e){this.currentError?(this.submitError(this.currentError),this.currentError=null):this.submitError(t),this.enablePaymentElement(),s()(document.body).triggerHandler("wc_stripe_on_error",[this,e,t])}async onShippingChange(t){try{return this.promises.length&&(await Promise.all(this.promises),this.promises=[]),this.cart.updateShipping({payment_method:this.gateway.id,...t})}catch(t){throw t}}onBillingChange(t){return this.cart.updateBilling({payment_method:this.gateway.id,...t}).then(t=>t).catch(t=>{throw t})}submitError(t){this.displayErrorMessage(t,"div.woocommerce-notices-wrapper")}displayErrorMessage(t,e=""){let i;if(t=(0,p.getErrorMessage)(t),i=(e=this.actions.applyFilters("get_error_message_selector",e,this,this.gateway.id))?s()(e):s()(this.selector).closest("form"),i.length){s()(".woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message, .is-error, .is-success").remove();const e=Array.isArray(t)?t.map(t=>`<li>${t}</li>`).join(""):`<li>${t}</li>`;i.prepend(`<div class="woocommerce-NoticeGroup ${this.context.getPage()}">\n                <ul class="woocommerce-error" role="alert">${e}</ul>\n                </div>`),s().scroll_to_notices?.(i)}}getShippingPrefix(){return"shipping"}onClick(){this.storeAttributionValues()}async validate(){return!0}async submit(t=null){t&&this.populateCheckoutFields(t),this.showProcessing();try{const t=await o()({method:"POST",url:(0,p.getRestRoute)("cart/checkout"),data:this.getCartCheckoutData()});if(t.result&&"success"===t.result){const e=(0,p.isNextActionRequired)(t.redirect);if(e){const t=await this.handleIntentConfirmation(e);window.location.href=this.getPostAuthenticationRedirectUrl(e,t)}else window.location=t.redirect}else t.messages&&this.submitError(t.messages)}catch(t){this.submitError(t)}finally{this.hideProcessing()}}async handleIntentConfirmation(t,e={}){const i={skipElements:"requires_payment_method"!==t.status,...e};let a;if("payment_intent"===t.type?a=await this.gateway.confirmPayment(t,i):"setup_intent"===t.type&&(a=await this.gateway.confirmSetup(t,i)),a.error)throw a.error;if("payment_intent"===t.type){const t=a.paymentIntent?.status;if("requires_action"===t&&this.gateway.isPaymentCancelled(a))throw{code:"payment_cancelled"};if("requires_payment_method"===t)throw{code:a.paymentIntent?.last_payment_error?.code,message:a.paymentIntent?.last_payment_error?.message}}else if("setup_intent"===t.type){const t=a.setupIntent?.status;if("requires_action"===t)throw{code:"payment_cancelled"};if("requires_payment_method"===t)throw{code:a.setupIntent?.last_setup_error?.code,message:a.setupIntent?.last_setup_error?.message}}return a}getPostAuthenticationRedirectUrl(t,e){const i=new URL(decodeURI(t.return_url));return"payment_intent"===t.type?(i.searchParams.set("payment_intent",e.paymentIntent.id),i.searchParams.set("payment_intent_client_secret",e.paymentIntent.client_secret)):(i.searchParams.set("setup_intent",e.setupIntent.id),i.searchParams.set("setup_intent_client_secret",e.setupIntent.client_secret)),i.toString()}getCartCheckoutData(){return{payment_method:this.gateway.id,context:this.context.getPage(),...(0,p.fieldsToJson)()}}getProcessingSelector(){return"body"}showProcessing(){s()(this.getProcessingSelector())?.block({message:null,overlayCSS:{background:"#fff",opacity:.6}})}hideProcessing(){s()(this.getProcessingSelector())?.unblock()}getProcessingMessage(){return'<div class="wc-stripe-loader">\n                        <div></div>\n                        <div></div>\n                        <div></div>\n                      </div>'}isOrderAttributionEnabled(){return"undefined"!=typeof wc_order_attribution&&null!==document.querySelector("wc-order-attribution-inputs")}storeAttributionValues(){if(g.attributionDataStored)return;if(this.context.isCheckout()||!this.isOrderAttributionEnabled())return;const t=wc_order_attribution.params.prefix;s()('input[type="hidden"][name^="'+t+'"]').each((t,e)=>{const i=s()(e),a=i.attr("name");(0,p.setFieldValue)(a,i.val())}),g.attributionDataStored=!0}getLineItems(){return this.cart.getLineItems()}getShippingOptions(){return this.cart.getShippingOptions()}getSelectedShippingMethod(){return this.cart.getSelectedShippingMethod()}getCurrency(){return this.cart.getCurrency()}getTotal(t="string"){return this.cart.getTotal()}getTotalCents(){return this.cart.getTotalCents()}getSubtotalCents(){return this.cart.getSubtotalCents()}needsPayment(){return this.cart.needsPayment()}populateCheckoutFields(t,e={}){e=this.actions.applyFilters("field_population_options",{skipShipping:!1,needsShipping:this.needsShipping(),...e},this),this.fields.populate(t,e),this.actions.doAction("after_populate_checkout_fields",this)}onPaymentRequiresAction(t){}}const w=g,_=window.wcStripe.product;var P=i.n(_),b=i(574);const C=class extends w{_cartItemKey;_excludedKeys=["add-to-cart","quantity","variation_id"];constructor(t){super(t),this.product=P()}initialize(){this.actions.addAction("product_updated",this.onProductUpdated.bind(this)),this.actions.addAction("cart_updated",this.onCartUpdated.bind(this)),this.actions.addAction("before_cart_calculation",this.onBeforeCartCalculation.bind(this)),this.actions.addAction("after_cart_calculation",this.onAfterCartCalculation.bind(this)),this.actions.addAction("removed_from_cart",this.onRemovedFromCart.bind(this),20),this.actions.addAction("before_remove_cart_item",this.onBeforeRemoveCartItem.bind(this)),this.actions.addAction("after_remove_cart_item",this.onAfterRemoveCartItem.bind(this)),this.actions.addFilter("cart_calculation_enabled",this.onCartCalculationEnabled.bind(this)),super.initialize()}onCartCalculationEnabled(t){return t||this._isPaymentMethodAvailable}onPaymentElementReady(){super.onPaymentElementReady(),this.product.isVariableProduct()&&(!this.product.isVariationSelected()||!this.product.isInStock()||this.product.getTotalCents()<=0?this.disablePaymentElement(!0):this.enablePaymentElement()),s()(`li.payment_method_${this.gateway.id}`).show(),s()(".wc-stripe-product-checkout-container").addClass("active")}onPaymentUnavailable(){super.onPaymentUnavailable(),s()(`li.payment_method_${this.gateway.id}`).hide()}needsShipping(){return this.cart.isEmpty()||!this.cart.needsShipping()?this.product.needsShipping():this.cart.needsShipping()}getElementContainer(){let t=document.querySelector(this.selector);if(!t){const e=this.gateway.id,i=e.replace(/_/g,"-"),a=[`#wc-${e}-product-button`,`#wc-${i}-product-button`,`#wc-${e}-product`,`#wc-${e}-container`,`#wc-${i}-container`];for(const e of a)if(t=document.querySelector(e),t)return t}return super.getElementContainer()}submitError(t){this.hideProcessing(),this.displayErrorMessage(t,"div.woocommerce-notices-wrapper")}onClick(){super.onClick(),this.promises.push(this.addToCart())}addToCart(){return this.cart.addToCart({payment_method:this.gateway.id,product_id:this.product.getId(),variation_id:this.product.getVariationId(),qty:this.product.getQuantity(),variation:this.product.getVariationData(),...this.actions.applyFilters("add_to_cart_data",(0,b.convertFormToFields)(s()("form.cart"),this._excludedKeys),this)}).then(t=>{if(!t.code)return this._cartItemKey=t.cart_item_key,t.order_id;this.currentError=t}).catch(async t=>(this.currentError=t,this.gateway.supports("payment_sheet")&&(this.gateway.closePaymentSheet(),await this.createPaymentElement()),this.submitError(t.message)))}async removeCartItem(){this._cartItemKey&&await this.cart.removeCartItem(this._cartItemKey)}async onProductUpdated(t,e){this._destroyPaymentElement||(this._destroyPaymentElement=t.needsShipping()!==e?.needsShipping),!t.isInStock()||t.getTotalCents()<=0?this.disablePaymentElement(!0):!t.isVariableProduct()||t.isVariationSelected()?t.needsCartCalculation()||(this._destroyPaymentElement?(await this.destroyPaymentElement(),this._destroyPaymentElement=null,await this.createPaymentElement()):this._doingCartCalculation||(this.gateway.updateElements(),this.enablePaymentElement())):this.disablePaymentElement(!0)}onBeforeCartCalculation(){this._doingCartCalculation=!0,this.disablePaymentElement(!0),s()(".single_add_to_cart_button").prop("disabled",!0)}async onAfterCartCalculation(){this._doingCartCalculation=!1,this.enablePaymentElement(!0),s()(".single_add_to_cart_button").prop("disabled",!1),this.product.isVariableProduct()&&this._destroyPaymentElement&&(await this.destroyPaymentElement(),this._destroyPaymentElement=null),await this.createPaymentElement()}onBeforeRemoveCartItem(){this.disablePaymentElement(!0)}onAfterRemoveCartItem(){this.enablePaymentElement(!0)}async onRemovedFromCart(){await this.destroyPaymentElement(),await this.createPaymentElement()}onCartUpdated(){this.gateway.supports("elements")&&this.gateway.updateElements()}onCancel(){s()(".single_add_to_cart_button").prop("disabled",!0),this.removeCartItem().finally(()=>{s()(".single_add_to_cart_button").prop("disabled",!1),super.onCancel()})}getTotal(){return this.cart.isEmpty()?this.product.getTotal():super.getTotal()}getTotalCents(){return this.cart.isEmpty()?this.product.getTotalCents():super.getTotalCents()}getLineItems(){return this.cart.isEmpty()?this.product.getLineItems():super.getLineItems()}},v=class extends w{initActions(){super.initActions(),this.actions.addAction("cart_updated",this.onCartUpdated.bind(this),20),this.actions.addAction("shipping_method_changed",this.onShippingSelected.bind(this))}async onCartUpdated(t){try{if(this.gateway.isPaymentSheetOpen())return;t.hasChanged("needsShipping")&&this.gateway.destroyPaymentElement(),await this.loadStripeSDK(),await this.createPaymentElement()}catch(t){console.error("Error reloading payment elements:",t)}}onPaymentElementReady(){super.onPaymentElementReady(),s()(`li.payment_method_${this.gateway.id}`).show(),s()(".wc_stripe_cart_payment_methods").addClass("active")}onPaymentUnavailable(){super.onPaymentUnavailable(),s()(`li.payment_method_${this.gateway.id}`).hide()}onShippingSelected(){this.storeAttributionValues()}getElementContainer(){let t=document.querySelector(this.selector);if(!t){const e=this.gateway.id,i=e.replace(/_/g,"-"),a=[`#wc-${e}-cart-button`,`#wc-${i}-cart-button`,`#wc-${i}-container`];for(const e of a)if(t=document.querySelector(e),t)return this.selector=e,super.getElementContainer()}return super.getElementContainer()}},S=class extends w{initialize(){super.initialize(),this.actions.addAction("mini_cart_ready",()=>{super.initialize()}),this.actions.addAction("cart_updated",this.onCartUpdated.bind(this))}onCartUpdated(t){if(!this.cart.isEmpty()){if(this.gateway.isPaymentSheetOpen())return;t.hasChanged("needsShipping")&&this.gateway.destroyPaymentElement(),super.initialize()}}onPaymentElementReady(){s()(this.selector).show(),super.onPaymentElementReady()}getElementContainer(){let t=document.querySelector(this.selector);const e=this.gateway.id,i=[`.wc-${e.replace(/_/g,"-")}-mini-cart`,`.wc-${e}-mini-cart`,`.wc-${e}-minicart`];if(!t){for(const e of i)if(t=document.querySelector(e),t)return this.selector=e,super.getElementContainer();t||s()(".woocommerce-mini-cart__buttons").prepend(`<a class="wc-${e}-mini-cart"></a>`)}return super.getElementContainer()}},f=window.wcStripe.order;var E=i.n(f);const k=class extends w{async createPaymentMethod(){try{this.disablePlaceOrderButton(),await this.gateway.createPaymentMethod(),await this.submit(null)}catch(t){this.submitError(t)}finally{this.enablePlaceOrderButton()}}async createSetupIntent(t={}){try{this.disablePlaceOrderButton();const e=await o()({method:"POST",url:(0,p.getRestRoute)("setup-intent"),data:{payment_method:this.gateway.id,context:this.context.getPage(),payment_method_id:this.gateway.getPaymentMethodId(),...this.context.isOrderPay()&&{order_id:this.order.getId(),order_key:this.order.getOrderKey()},...t}});if(["requires_confirmation","requires_payment_method","requires_action"].includes(e.status)){const t=await this.handleIntentConfirmation(e);this.gateway.setPaymentMethodId(t.setupIntent.payment_method)}this.gateway.setSetupIntentId(e.id),this.submitForm()}catch(t){this.gateway.setPaymentMethodId(""),this.submitError(t)}finally{this.enablePlaceOrderButton()}}onPaymentMethodSelected(t){if(this.gateway.id===t)if(this.gateway.supports("place_order_button"))this.displayPlaceOrderButton();else{if(!this.isPaymentMethodAvailable())return this.displayPlaceOrderButton();this.isSavedPaymentMethodSelected()||this.gateway.hasPaymentMethodId()?(this.hidePaymentElement(),this.displayPlaceOrderButton()):(this.displayPaymentElement(),this.hidePlaceOrderButton())}else t?.indexOf("stripe_")<0&&this.displayPlaceOrderButton(),this.gateway.supports("place_order_button")||this.hidePaymentElement()}onPaymentUnavailable(){super.onPaymentUnavailable(),s()(`li.payment_method_${this.gateway.id}`).hide()}submitError(t){this.context.isOrderPay()?this.displayErrorMessage(t,"#order_review"):this.context.isCheckout()?this.displayErrorMessage(t,"form.checkout"):this.context.isAddPaymentMethod()&&this.displayErrorMessage(t,"#add_payment_method")}getElementContainer(){return document.querySelector(this.selector)||s()("#place_order").after(`<div id="wc-${this.gateway.id}-checkout-button" class="wc-${this.gateway.id}-checkout-button" style="${this.gateway.getPaymentElementStyles()}"></div>`),super.getElementContainer()}getForm(){return this.context.isCheckout()?s()("form.checkout"):s()(this.selector).closest("form")}triggerPaymentMethodSelected(){this.onPaymentMethodSelected(s()('[name="payment_method"]:checked').val())}isPaymentGatewaySelected(){return s()('[name="payment_method"]:checked')?.val()===this.gateway.id}isSavedPaymentMethodSelected(){const t=`[name="wc-${this.gateway.id}-payment-token"]`;return s()(t).length>0&&"new"!==s()(`${t}:checked`).val()}disablePlaceOrderButton(){s()("#place_order").prop("disabled",!0)}enablePlaceOrderButton(){s()("#place_order").prop("disabled",!1)}displayPlaceOrderButton(){s()("#place_order").removeClass("wc-stripe-hide")}hidePlaceOrderButton(){s()("#place_order").addClass("wc-stripe-hide")}},M=class extends k{wcCheckoutForm=null;constructor(t){super(t),this.order=E(),(0,p.registerPaymentMethod)(this.gateway)}initActions(){this.actions.addAction("updated_checkout",this.onUpdatedCheckout.bind(this)),this.actions.addAction("payment_method_selected",this.onPaymentMethodSelected.bind(this)),this.actions.addAction("payment_intent_requires_actions",this.onPaymentRequiresAction.bind(this)),this.actions.addAction("setup_intent_requires_actions",this.onPaymentRequiresAction.bind(this)),this.actions.addAction("checkout_order_review",this.onCheckoutOrderReview.bind(this)),s()(document.body).on("change",`[name="wc-${this.gateway.id}-payment-token"]`,this.onPaymentTokenChange.bind(this)),s()(document.body).on("change",`[name="wc-${this.gateway.id}-new-payment-method"]`,this.onSavePaymentMethodChange.bind(this)),s()(document.body).on("click",`li.payment_method_${this.gateway.id} .wc-stripe-saved-method, li.payment_method_${this.gateway.id} .woocommerce-SavedPaymentMethods-new`,this.onSavedTokenChanged.bind(this)),s()(document.body).on("click",`li.payment_method_${this.gateway.id} .wc-stripe-saved-method__see-more`,this.onSeeMoreClick.bind(this)),this.context.isCheckout()?(s()("form.checkout").on(`checkout_place_order_${this.gateway.id}`,this.onCheckoutPlaceOrder.bind(this)),this.actions.addAction(`checkout_error_${this.gateway.id}`,this.onCheckoutError.bind(this))):(s()(document.body).on("click","#place_order",this.onPlaceOrderClick.bind(this)),s()(window).on("load",()=>{s()(document.body).trigger("wc-credit-card-form-init")}))}isPaymentMethodAvailable(){if(this.context.isCheckout()){const t=this.gateway.getOption("paymentSections",[]);if(Array.isArray(t)&&t.length>0&&!t.includes("checkout"))return!1}return super.isPaymentMethodAvailable()}onUpdatedCheckout(t,e){super.initialize(),this.triggerPaymentMethodSelected(),this.initSavedMethods()}initSavedMethods(){const t=this.getSavedMethodsList();if(!t.length)return;const e=this.getSelectedToken(t);e.length&&t.prepend(e),this.hideSavedMethods(t)}onPaymentElementReady(){super.onPaymentElementReady(),this.triggerPaymentMethodSelected(),s()(`li.payment_method_${this.gateway.id}`).show().addClass("active"),this.gateway.supports("payment_sheet")&&(this.gateway.settings.hasPaymentTokens||this.gateway.settings.description?s()(`.payment_method_${this.gateway.id} .payment_box`).removeClass("hide-payment-box"):s()(`.payment_method_${this.gateway.id} .payment_box`).addClass("hide-payment-box"))}onCheckoutPlaceOrder(t,e=null){return this.wcCheckoutForm=e,!(!this.isSavedPaymentMethodSelected()&&!this.gateway.hasPaymentMethodId()&&!this.gateway.hasSetupIntentId()&&(this.gateway.supports("form_validation")||this.isTermsAndConditionsValid()?(this.processCheckout(),1):(this.submitError({code:"terms"}),1)))}onPlaceOrderClick(t){this.isPaymentGatewaySelected()&&(t.preventDefault(),this.onCheckoutPlaceOrder(null)&&this.submitForm())}onCheckoutError(t){this.gateway.supports("checkout_error")&&this.gateway.setPaymentMethodId("")}onClick(){if(!this.isTermsAndConditionsValid())throw this.submitError({code:"terms"}),new Error;if(this.context.isCheckout()&&this.gateway.supports("form_validation")&&!this.isCheckoutFormValid())throw this.validateCheckoutForm().then(t=>{if(!t.success)return this.submitError(t.messages)}),new Error}onPaymentTokenChange(t){this.isPaymentGatewaySelected()&&(this.isSavedPaymentMethodSelected()?(this.gateway.supports("place_order_button")||(this.hidePaymentElement(),this.displayPlaceOrderButton()),this.collapseSavedMethods()):(this.gateway.supports("place_order_button")||(this.displayPaymentElement(),this.hidePlaceOrderButton()),this.collapseSavedMethods()))}onSavedTokenChanged(t){const e=s()(t.currentTarget);e.closest(".woocommerce-SavedPaymentMethods").children("li").removeClass("selected"),e.addClass("selected"),e.find('input[type="radio"]').prop("checked",!0).trigger("change")}onSeeMoreClick(t){t.preventDefault(),t.stopPropagation();const e=s()(t.currentTarget).closest(".woocommerce-SavedPaymentMethods");e.find(".wc-stripe-saved-method:hidden").length>0?this.showSavedMethods(e):this.hideSavedMethods(e)}collapseSavedMethods(){const t=this.getSavedMethodsList(),e=this.getSelectedToken(t);e.length&&t.prepend(e),this.hideSavedMethods(t);const i=t.find(".wc-stripe-see-more a");i.text(i.data("showMore"))}hideSavedMethods(t){t.removeClass("wc-saved-payment-methods__expanded"),t.find(".wc-stripe-saved-method").not(":first").hide()}showSavedMethods(t){t.addClass("wc-saved-payment-methods__expanded"),t.find(".wc-stripe-saved-method").show()}getSelectedToken(t){return t.find('input[type="radio"]:checked').closest(".wc-stripe-saved-method")}getSavedMethodsList(){return s()(`li.payment_method_${this.gateway.id} .woocommerce-SavedPaymentMethods`)}async onPaymentRequiresAction(t){if(this.isPaymentGatewaySelected()&&(!this.gateway.supports("payment_sheet")||this.gateway.isPaymentSheetOpen()))try{const e=await this.handleIntentConfirmation(t,{skipElements:this.isSavedPaymentMethodSelected()});window.location.href=this.getPostAuthenticationRedirectUrl(t,e)}catch(t){return this.gateway.clearElementSubmitted(),this.gateway.setPaymentMethodId(""),this.gateway.setSetupIntentId(""),this.getForm().removeClass("processing").unblock?.(),this.submitError(t)}}onCheckoutOrderReview(t){this.isPaymentGatewaySelected()&&(this.gateway.setPaymentMethodId(t.payment_method_id),s()(`[name="wc-${this.gateway.id}-payment-token"][value="new"]`).trigger("click"))}onSavePaymentMethodChange(t){const e=s()(t.currentTarget);this.gateway.setSavePaymentMethod(e.is(":checked")),this.gateway.updateElements()}async processCheckout(){try{await this.gateway.validatePaymentElement(),this.actions.applyFilters("wc_stripe_should_create_payment_method",this.gateway.shouldCreatePaymentMethod())?await this.createPaymentMethod():await this.submit(null)}catch(t){this.submitError(t)}}async submit(t=null){if(t&&this.populateCheckoutFields(t,{skipBilling:!0}),this.gateway.supports("payment_sheet")&&(this.hidePaymentElement(),this.displayPlaceOrderButton()),this.context.isOrderPay())return this.gateway.isSetupMode()?await this.createSetupIntent():await this.processOrderPay();this.submitForm()}async processOrderPay(){try{this.showProcessing();const t=await this.order.processPayment(this.gateway.id,(0,p.convertFormToFields)(this.getForm()));if(t.complete)this.submitForm();else{const e=(0,p.isNextActionRequired)(t.redirect);e&&(await this.handleIntentConfirmation(e),this.submitForm())}}catch(t){return this.gateway.setPaymentMethodId(""),this.submitError(t)}finally{this.hideProcessing()}}populateCheckoutFields(t,e={}){if(super.populateCheckoutFields(t,e),t.paymentMethodId){const e=`${this.gateway.id}_payment_method_id`;s()(`[name="${e}"]`).length||s()("form.checkout").append(`<input type="hidden" name="${e}" value="${t.paymentMethodId}" />`),this.gateway.setPaymentMethodId(t.paymentMethodId)}}submitForm(){this.actions.applyFilters("checkout_submit_form",!0)&&this.getForm().trigger("submit")}isCheckoutFormValid(){const t=[];return s()("form.checkout .validate-required:visible").each((e,i)=>{const a=s()(i).find("input, select, textarea").first();if(a.length&&a.is(":visible")){const e=a.attr("name");"checkbox"===a.attr("type")?a.is(":checked")||t.push(e):""!==a.val()&&null!==a.val()||t.push(e)}}),0===t.length}isTermsAndConditionsValid(){return!s()('[name="terms"]').filter(":visible").length||s()('[name="terms"]').is(":checked")}async validateCheckoutForm(){try{return this.disablePaymentElement(),this.showProcessing(),await o()({method:"POST",url:(0,p.getRestRoute)("checkout/form-validation"),data:(0,p.convertFormToFields)(s()("form.checkout"))})}catch(t){return{success:!0}}finally{this.enablePaymentElement(),this.hideProcessing()}}getProcessingSelector(){return this.context.isOrderPay()?"form#order_review":"form.checkout"}needsShipping(){return!1}getCurrency(){return this.context.isOrderPay()?this.order.getCurrency():this.cart.getCurrency()}getTotalCents(){return this.context.isOrderPay()?this.order.getTotalCents():this.cart.getTotalCents()}needsPayment(){return this.context.isOrderPay()?this.order.needsPayment():this.cart.needsPayment()}getLineItems(){return this.context.isOrderPay()?this.order.getLineItems():super.getLineItems()}},A=class extends w{initActions(){this.actions.addAction("updated_checkout",this.onUpdatedCheckout.bind(this)),this.actions.addAction("payment_intent_requires_actions",this.onPaymentRequiresAction.bind(this)),this.actions.addAction("setup_intent_requires_actions",this.onPaymentRequiresAction.bind(this))}onUpdatedCheckout(){super.initialize()}onPaymentElementReady(){s()(this.selector).show().addClass("active"),s()(this.selector).closest(".wc-stripe-banner-checkout").addClass("active"),super.onPaymentElementReady()}onPaymentUnavailable(){super.onPaymentUnavailable(),s()(`li.banner_payment_method_${this.gateway.id}`).hide()}onClick(){s()('[name="terms"]').prop("checked",!0).trigger("change");const t=s()(`[name="payment_method"][value="${this.gateway.id}"]`);t.prop("checked",!0).trigger("click"),t.trigger("change"),s()(`[name="wc-${this.gateway.id}-payment-token"][value="new"]`).trigger("click")}async onShippingChange(t){if(t?.shipping_method){const e=(0,p.extractShippingMethod)(t.shipping_method);for(const t in e){const i=e[t],a=s()(`[name="shipping_method[${t}]"][value="${i}"]`);a.length?a.prop("checked",!0):this._updateRequired=!0}}return super.onShippingChange(t)}async onPaymentRequiresAction(t){if(t.gateway_id===this.gateway.id&&this.gateway.isPaymentSheetOpen()){const e=await this.handleIntentConfirmation(t);window.location.href=this.getPostAuthenticationRedirectUrl(t,e)}}async submit(t=null){t&&this.populateCheckoutFields(t),this._updateRequired&&await this.triggerUpdatedCheckout(),s()('[name="payment_method"]').val(this.gateway.id),this.actions.doAction("before_form_submit",this),this.getForm().trigger("submit")}populateCheckoutFields(t,e={}){if(super.populateCheckoutFields(t,e),t.paymentMethodId){const e=`${this.gateway.id}_payment_method_id`;s()(`[name="${e}"]`).length||s()("form.checkout").append(`<input type="hidden" name="${e}" value="${t.paymentMethodId}" />`)}}triggerUpdatedCheckout(){return new Promise(t=>{s()(document.body).one("updated_checkout",t),s()('[name="billing_country"], [name="shipping_country"]').trigger("change"),s()(document.body).trigger("update_checkout",{update_shipping_method:!1})})}needsShipping(){return this.cart.needsShipping()}getForm(){return s()(this.selector).closest("form")}},I=class extends k{initActions(){this.actions.addAction("payment_method_selected",this.onPaymentMethodSelected.bind(this)),s()(document.body).on("click","#place_order",this.onPlaceOrderClick.bind(this))}onPaymentElementReady(){super.onPaymentElementReady(),this.triggerPaymentMethodSelected()}async onPlaceOrderClick(t){if(this.isPaymentGatewaySelected()){t.preventDefault();try{await this.gateway.validatePaymentElement()}catch(t){return this.submitError(t)}await this.createPaymentMethod()}}async submit(t=null){this.gateway.supports("payment_sheet")&&(this.hidePaymentElement(),this.displayPlaceOrderButton()),await this.createSetupIntent()}submitError(t){super.submitError(t),this.gateway.supports("payment_sheet")&&(this.displayPaymentElement(),this.hidePlaceOrderButton())}submitForm(){this.getForm().trigger("submit")}isPaymentMethodAvailable(){var t;const e=(0,p.getSetting)("paymentMethods");return null!==(t=e?.[this.gateway.id]?.supports?.includes("add_payment_method"))&&void 0!==t&&t}needsShipping(){return!1}};(this.wcStripe=this.wcStripe||{}).controllers=a})();