PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.7.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.7.1
1.7.1 1.7.0 1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 All 51 releases
← All changes | assets/stripe-checkout.js +1 -1 1.4.2 → 1.7.1 View file →
@@ -1 +1 @@
1 -class oe{constructor(_,p,h){this.form=_,this.data=p,this.paymentArgs=p.payment_args,this.intent=p.intent,this.paymentLoader=h,this.$t=this.translate.bind(this)}translate(_){var h;return(((h=window.fct_stripe_data)==null?void 0:h.translations)||{})[_]||_}async init(){var x,E,T;const _=document.querySelector("[data-fluent-cart-checkout-page-checkout-button]"),p=document.querySelector(".fluent-cart-checkout_embed_payment_container_stripe"),h=this.form.querySelector(".fluent_cart_payment_methods");h&&(h.style.display="none");const t=this,n=Stripe((x=this.paymentArgs)==null?void 0:x.public_key),i={...this.intent};this.data.appearance&&(i.appearance=this.data.appearance),i.locale=((E=window.fct_stripe_data)==null?void 0:E.locale)||"auto";const c=await n.elements(i),m={fields:{billingDetails:{name:"never",email:"never"}},terms:{card:"never",wallet:"never",apple_pay:"never",google_pay:"never",amazon_pay:"never",paypal:"never"}},s=await c.create("payment",m);s.mount(".fluent-cart-checkout_embed_payment_container_stripe");const r=(T=window.fluentcart_checkout_vars)==null?void 0:T.submit_button;s.on("loaderror",function(o){var L,e,v;window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_failed",{detail:{payment_method:"stripe"}}));const y=document.getElementById("fct_loading_payment_processor");y&&y.remove();let l=(L=o==null?void 0:o.error)==null?void 0:L.message,u="";if(((e=window==null?void 0:window.fluentcart_checkout_info)==null?void 0:e.is_admin)!=="1"){l=t.$t("Payment module not available to checkout! Please reload again, or contact admin!"),u=`<p style="color:red; display:none;" class="hidden-error">${(v=o==null?void 0:o.error)==null?void 0:v.message}</p>`;const f=document.createElement("a");f.className="toggle-error",f.style.cursor="pointer",f.textContent=t.$t("See Errors"),f.addEventListener("click",function(){document.querySelector(".hidden-error").style.display=document.querySelector(".hidden-error").style.display==="none"?"block":"none"}),p.prepend(f)}const a=document.createElement("p");a.style.color="red",a.innerHTML=l+u,p.prepend(a),window.is_stripe_ready=!1,t.paymentLoader.disableCheckoutButton(r==null?void 0:r.text)}),s.on("ready",function(o){window.is_stripe_ready=!0,window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_success",{detail:{payment_method:"stripe"}}));const y=document.getElementById("fct_loading_payment_processor");if(y&&y.remove(),_&&_.id==="fluent_cart_custom_checkout_btn")t.paymentLoader.disableCheckoutButton(t.$t("Pay Now"));else{const l=t.form.querySelector('input[name="_fct_pay_method"]:checked');l&&l.value==="stripe"&&t.paymentLoader.enableCheckoutButton(r.text)}s.addEventListener("change",function(l){window.is_stripe_ready=l.complete,document.querySelectorAll(".fct-error-message").forEach(a=>a.remove()),window.is_stripe_ready?_&&_.id==="fluent_cart_custom_checkout_btn"?t.paymentLoader.enableCheckoutButton(t.$t("Pay Now")):t.paymentLoader.enableCheckoutButton(r.text):t.paymentLoader.disableCheckoutButton(r!=null&&r.text?r.text:t.$t("Place Order"))}),window.addEventListener("fluent_cart_payment_next_action_stripe",l=>{var I,N,C,O,A,B,H,j,D,U,J;(I=t.paymentLoader)==null||I.changeLoaderStatus("processing");const u=document.querySelector(".fct-loader");(N=u==null?void 0:u.classList)==null||N.add("active");const a=(C=l.detail)==null?void 0:C.response;let L=(O=a==null?void 0:a.payment_args)==null?void 0:O.success_url;(A=a==null?void 0:a.payment_args)==null||A.custom_payment_url;const e=a==null?void 0:a.fc_customer;let v=null,f="intent";((B=a==null?void 0:a.response)==null?void 0:B.object)==="subscription"?(f=(j=(H=a==null?void 0:a.payment_args)==null?void 0:H.vendor_subscription_info)==null?void 0:j.type,v=(U=(D=a==null?void 0:a.payment_args)==null?void 0:D.vendor_subscription_info)==null?void 0:U.clientSecret):v=(J=a==null?void 0:a.response)==null?void 0:J.client_secret;const ee=function(M){new Toastify({text:M,className:"warning",duration:2e3,escapeMarkup:!1,close:!0}).showToast()};c.submit().then(M=>{const P=f==="setup"?n.confirmSetup:n.confirmPayment,$=f==="setup"?"setupIntent":"paymentIntent",te={elements:c,clientSecret:v,confirmParams:{return_url:L,payment_method_data:{billing_details:{address:{city:e!=null&&e.city?e==null?void 0:e.city:null,country:e!=null&&e.country?e==null?void 0:e.country:null,postal_code:e!=null&&e.postcode?e==null?void 0:e.postcode:null,state:e!=null&&e.state?e==null?void 0:e.state:null,line1:e!=null&&e.address_1?e==null?void 0:e.address_1:null},name:e==null?void 0:e.name,email:e==null?void 0:e.email}}},redirect:"if_required"};P(te).then(k=>{var X,z,W,F,G,K;(X=t.paymentLoader)==null||X.changeLoaderStatus("confirming"),k!=null&&k.error&&(t.paymentLoader.enableCheckoutButton(r.text),ee((z=k==null?void 0:k.error)==null?void 0:z.message),(W=t.paymentLoader)==null||W.hideLoader());const d=k[$];if(d!=null&&d.status&&(d.status==="succeeded"||d.status==="processing"||d.status==="requires_capture")){(F=t.paymentLoader)==null||F.changeLoaderStatus("completed");const ae=new URLSearchParams(window.location.search).get("mode")||"order",Q=(K=(G=a==null?void 0:a.payment_args)==null?void 0:G.vendor_subscription_info)==null?void 0:K.trx_hash,ne=new URLSearchParams({action:"fluent_cart_confirm_stripe_payment",intentId:d.id,mode:ae,...Q?{trx_hash:Q}:{}}).toString(),w=new XMLHttpRequest;w.open("POST",window.fluentcart_checkout_vars.ajaxurl,!0),w.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),w.onreadystatechange=function(){var V,Y,Z;if(w.readyState===4)if(w.status>=200&&w.status<300)try{let g=JSON.parse(w.responseText);g&&(t.paymentLoader.triggerPaymentCompleteEvent(g),g.redirect_url&&(L=g.redirect_url)),(V=t.paymentLoader)==null||V.changeLoaderStatus("redirecting"),window.CheckoutHelper?window.CheckoutHelper.handleCheckoutRedirect(L):window.location.href=L}catch{(Y=t.paymentLoader)==null||Y.changeLoaderStatus(t.$t("Payment confirmation failed")),setTimeout(function(){var S,R;(S=t.paymentLoader)==null||S.hideLoader(),(R=t.paymentLoader)==null||R.enableCheckoutButton(r==null?void 0:r.text)},1e3)}else(Z=t.paymentLoader)==null||Z.changeLoaderStatus(t.$t("Payment confirmation failed")),setTimeout(function(){var g,S;(g=t.paymentLoader)==null||g.hideLoader(),(S=t.paymentLoader)==null||S.enableCheckoutButton(r==null?void 0:r.text)},1e3)},w.onerror=function(){},w.send(ne)}else if((d==null?void 0:d.status)==="requires_action"||(d==null?void 0:d.status)==="requires_source_action")return q(d)})}).catch(M=>{var P,$;u.classList.remove("active"),(P=t.paymentLoader)==null||P.changeLoaderStatus(t.$t("Payment confirmation failed")),($=t.paymentLoader)==null||$.hideLoader()})})});const q=o=>{var l,u;switch((l=t.paymentLoader)==null||l.changeLoaderStatus(t.$t("redirecting for action")),(u=o.next_action)==null?void 0:u.type){case"redirect_to_url":window.location.href=o.next_action.redirect_to_url.url;break;case"cashapp_handle_redirect_or_display_qr_code":o.next_action.cashapp_handle_redirect_or_display_qr_code.hosted_instructions_url&&(window.location.href=o.next_action.cashapp_handle_redirect_or_display_qr_code.hosted_instructions_url);break;case"display_boleto":window.location.href=o.next_action.boleto_display_details.hosted_voucher_url;break;case"oxxo_display_details":window.location.href=o.next_action.oxxo_display_details.hosted_voucher_url;break;case"alipay_handle_redirect":window.location.href=o.next_action.alipay_handle_redirect.url;break;case"konbini_display_details":window.location.href=o.next_action.konbini_display_details.hosted_voucher_url;break;case"display_bank_transfer_instructions":window.location.href=o.next_action.display_bank_transfer_instructions.hosted_instructions_url;break;case"verify_with_microdeposits":window.location.href=o.next_action.verify_with_microdeposits.hosted_verification_url;break;case"wechat_pay_display_qr_code":o.next_action.wechat_pay_display_qr_code.hosted_instructions_url&&(window.location.href=o.next_action.wechat_pay_display_qr_code.hosted_instructions_url);break;case"promptpay_display_qr_code":o.next_action.promptpay_display_qr_code.hosted_instructions_url&&(window.location.href=o.next_action.promptpay_display_qr_code.hosted_instructions_url);break}};window.addEventListener("fluent_cart_validate_checkout_stripe",function(o){if(!window.is_stripe_ready){const y=document.createElement("div");y.className="fct-error-message",y.textContent=t.$t("Card details are not valid!"),document.querySelector(".fluent-cart-checkout-page-checkout-form-order-summary").appendChild(y),n.confirmPayment({elements:c,confirmParams:{return_url:"https://stripe.com"},redirect:"if_required"})}})}}window.addEventListener("fluent_cart_load_payments_stripe",function(b){window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading",{detail:{payment_method:"stripe"}})),window.fluentcart.$t;const _=document.querySelector(".fluent-cart-checkout_embed_payment_container_stripe");t(),h(),fetch(b.detail.paymentInfoUrl,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":b.detail.nonce},credentials:"include"}).then(async n=>{var c,m,s;if(n=await n.json(),(n==null?void 0:n.status)==="failed"){p(n==null?void 0:n.message),window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_failed",{detail:{payment_method:"stripe"}}));return}if(((c=n==null?void 0:n.intent)==null?void 0:c.amount)<=0&&((m=n==null?void 0:n.intent)==null?void 0:m.mode)!=="subscription"){let q=function(E){return r[E]||E};var i=q;const r=((s=window.fct_stripe_data)==null?void 0:s.translations)||{};p(q("Total amount is not valid, please add some items to cart!"));const x=document.getElementById("fct_loading_payment_processor");x&&x.remove();return}new oe(b.detail.form,n,b.detail.paymentLoader).init()}).catch(n=>{var m;const i=((m=window.fct_stripe_data)==null?void 0:m.translations)||{};function c(s){return i[s]||s}p(c("An error occurred while parsing the response.")),window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_failed",{detail:{payment_method:"stripe"}}))});function p(n){if(!n)return;const i=document.createElement("div");i.className="fct-error-message",i.textContent=n,_.appendChild(i);const c=document.getElementById("fct_loading_payment_processor");c&&c.remove()}function h(){var m;const n=document.createElement("p");n.id="fct_loading_payment_processor";const i=((m=window.fct_stripe_data)==null?void 0:m.translations)||{};function c(s){return i[s]||s}n.textContent=c("Loading Payment Processor..."),_.appendChild(n)}function t(){document.querySelectorAll(".fct-error-message").forEach(i=>i.remove())}});
1 +(function(){let G=null,K=null,Q=null,M=null,T=null,U=null,F=null;window.addEventListener("fluent_cart_payment_next_action_stripe",o=>{typeof G=="function"&&G(o)}),window.addEventListener("fluent_cart_before_checkout_stripe",o=>{typeof K=="function"&&K(o)}),window.addEventListener("fluent_cart_validate_checkout_stripe",o=>{typeof Q=="function"&&Q(o)}),document.addEventListener("change",o=>{const c=o.target;if(!c||c.name!=="save_payment_method"||typeof U!="function")return;const s=(c.form||document).querySelector('input[name="_fct_pay_method"]:checked');!s||s.value!=="stripe"||U(c)});function H(){F&&(F.disconnect(),F=null)}function qt(o){var s,g;if(!o||o.nodeType!==1)return!1;const c=document.querySelector(".fluent-cart-checkout_embed_payment_container_stripe");return c&&c.contains(o)||(s=o.closest)!=null&&s.call(o,".fct-order-processing, .fct-loader")?!1:o.tagName==="IFRAME"?!0:!!((g=o.querySelector)!=null&&g.call(o,"iframe"))}function Pt(o,c){var s;o==null||o.hideLoader(),(s=c==null?void 0:c.classList)==null||s.remove("active")}function Tt(o,c){H(),document.body&&(F=new MutationObserver(s=>{for(const g of s)for(const e of g.addedNodes)if(qt(e)){Pt(o,c),H();return}}),F.observe(document.body,{childList:!0,subtree:!0}))}class Mt{constructor(c,s,g){this.form=c,this.data=s,this.paymentArgs=s.payment_args,this.intent=s.intent,this.paymentLoader=g,this.$t=this.translate.bind(this)}translate(c){var g;return(((g=window.fct_stripe_data)==null?void 0:g.translations)||{})[c]||c}bindSaveCardConsent(c){var r,m,u,b;U=null;const s=this.form.querySelector('input[name="save_payment_method"]');if(!s||!c||typeof c.update!="function"||((r=window.fluentcart_checkout_info)==null?void 0:r.has_subscription)==="yes"||((m=this.intent)==null?void 0:m.mode)==="subscription"||((u=this.intent)==null?void 0:u.mode)==="setup")return;U=w=>{var l;const N=w.checked?"off_session":null;try{c.update({setupFutureUsage:N})}catch{(l=this.paymentLoader)==null||l.load("stripe")}};const e=((b=this.intent)==null?void 0:b.setup_future_usage)||null;(s.checked?"off_session":null)!==e&&U(s)}async init(){var R,tt,et;M=null,T=null;const c=document.querySelector("[data-fluent-cart-checkout-page-checkout-button]"),s=document.querySelector(".fluent-cart-checkout_embed_payment_container_stripe"),g=this.form.querySelector(".fluent_cart_payment_methods");g&&(g.style.display="none");const e=this,r=Stripe((R=this.paymentArgs)==null?void 0:R.public_key),m={...this.intent};this.data.appearance&&(m.appearance=this.data.appearance),Array.isArray(this.data.fonts)&&this.data.fonts.length&&(m.fonts=this.data.fonts),m.locale=((tt=window.fct_stripe_data)==null?void 0:tt.locale)||"auto";const u=await r.elements(m),b={fields:{billingDetails:{name:"never",email:"never"}},terms:{card:"never",wallet:"never",apple_pay:"never",google_pay:"never",amazon_pay:"never",paypal:"never"}},w=await u.create("payment",b);if(w.mount(".fluent-cart-checkout_embed_payment_container_stripe"),this.bindSaveCardConsent(u),this.consentCheckbox=null,s){const p=s.parentNode.querySelector(".fct-system-charge-consent");if(p&&p.remove(),this.data.system_consent){let a;if(this.data.consent_required){a=document.createElement("label"),a.className="fct-system-charge-consent",a.style.cssText="display:flex;gap:6px;align-items:flex-start;margin-top:8px;font-size:12px;opacity:0.85;cursor:pointer;";const f=document.createElement("input");f.type="checkbox",f.name="_fct_system_consent",f.value="yes",f.style.cssText="margin-top:2px;flex-shrink:0;",a.appendChild(f);const h=document.createElement("span");h.textContent=this.data.system_consent,a.appendChild(h),this.consentCheckbox=f}else a=document.createElement("p"),a.className="fct-system-charge-consent",a.style.cssText="margin-top:8px;font-size:12px;opacity:0.75;",a.textContent=this.data.system_consent;s.insertAdjacentElement("afterend",a)}}const N=()=>!this.data.consent_required||this.consentCheckbox&&this.consentCheckbox.checked;this.consentOk=N;const l=(et=window.fluentcart_checkout_vars)==null?void 0:et.submit_button;w.on("loaderror",function(p){var i,t,S;window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_failed",{detail:{payment_method:"stripe"}}));const a=document.getElementById("fct_loading_payment_processor");a&&a.remove();let f=(i=p==null?void 0:p.error)==null?void 0:i.message,h="";if(((t=window==null?void 0:window.fluentcart_checkout_info)==null?void 0:t.is_admin)!=="1"){f=e.$t("Payment module not available to checkout! Please reload again, or contact admin!"),h=`<p style="color:red; display:none;" class="hidden-error">${(S=p==null?void 0:p.error)==null?void 0:S.message}</p>`;const L=document.createElement("a");L.className="toggle-error",L.style.cursor="pointer",L.textContent=e.$t("See Errors"),L.addEventListener("click",function(){document.querySelector(".hidden-error").style.display=document.querySelector(".hidden-error").style.display==="none"?"block":"none"}),s.prepend(L)}const d=document.createElement("p");d.style.color="red",d.innerHTML=f+h,s.prepend(d),window.is_stripe_ready=!1,e.paymentLoader.disableCheckoutButton(l==null?void 0:l.text)}),w.on("ready",function(p){window.is_stripe_ready=!0,window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_success",{detail:{payment_method:"stripe"}})),requestAnimationFrame(()=>{const d=document.querySelector(".__PrivateStripeElement");d&&(d.style.setProperty("display","flex","important"),d.style.setProperty("justify-content","center","important"),d.style.setProperty("padding","8px 0 0 0","important"))});const a=document.getElementById("fct_loading_payment_processor");if(a&&a.remove(),c&&c.id==="fluent_cart_custom_checkout_btn")e.paymentLoader.disableCheckoutButton(e.$t("Pay Now"));else{const d=e.form.querySelector('input[name="_fct_pay_method"]:checked');d&&d.value==="stripe"&&e.consentOk()?e.paymentLoader.enableCheckoutButton(l.text):d&&d.value==="stripe"&&e.paymentLoader.disableCheckoutButton(l!=null&&l.text?l.text:e.$t("Place Order"))}const f=function(){var i,t;if((t=(i=e.paymentLoader)==null?void 0:i.isSubmitting)!=null&&t.call(i))return;const d=e.form.querySelector('input[name="_fct_pay_method"]:checked');d&&d.value!=="stripe"||(window.is_stripe_ready&&e.consentOk()?c&&c.id==="fluent_cart_custom_checkout_btn"?e.paymentLoader.enableCheckoutButton(e.$t("Pay Now")):e.paymentLoader.enableCheckoutButton(l.text):e.paymentLoader.disableCheckoutButton(l!=null&&l.text?l.text:e.$t("Place Order")))};e.consentCheckbox&&e.consentCheckbox.addEventListener("change",f),w.addEventListener("change",function(d){window.is_stripe_ready=d.complete,document.querySelectorAll(".fct-error-message").forEach(t=>t.remove()),f()});const h=function(d,i=2e3){new Toastify({text:d,className:"warning",duration:i,escapeMarkup:!1,close:!0}).showToast()};K=d=>{var i;typeof((i=d.detail)==null?void 0:i.waitFor)=="function"&&(M=u.submit(),T=u,d.detail.waitFor(M.then(t=>T!==u?(h(e.$t("The payment form was refreshed. Please place the order again.")),!1):t!=null&&t.error?(M=null,T=null,h(t.error.message),!1):!0).catch(t=>(T===u&&(M=null,T=null),h((t==null?void 0:t.message)||e.$t("Payment failed. Please try again.")),!1))))},G=d=>{var at,rt,it,ot,ct,st,dt,lt,ut,_t,pt,ft,ht,mt;H(),(at=e.paymentLoader)==null||at.changeLoaderStatus("processing");const i=document.querySelector(".fct-loader");(rt=i==null?void 0:i.classList)==null||rt.add("active");const t=(it=d.detail)==null?void 0:it.response;let S=(ot=t==null?void 0:t.payment_args)==null?void 0:ot.success_url;const L=((ct=t==null?void 0:t.payment_args)==null?void 0:ct.gateway_return_url)||S;(st=t==null?void 0:t.payment_args)==null||st.custom_payment_url;const n=t==null?void 0:t.fc_customer;let $=null,J="intent";((dt=t==null?void 0:t.response)==null?void 0:dt.object)==="subscription"?(J=(ut=(lt=t==null?void 0:t.payment_args)==null?void 0:lt.vendor_subscription_info)==null?void 0:ut.type,$=(pt=(_t=t==null?void 0:t.payment_args)==null?void 0:_t.vendor_subscription_info)==null?void 0:pt.clientSecret):((ft=t==null?void 0:t.response)==null?void 0:ft.object)==="setup_intent"?(J="setup",$=(ht=t==null?void 0:t.response)==null?void 0:ht.client_secret):$=(mt=t==null?void 0:t.response)==null?void 0:mt.client_secret;const Y=function(){var y,C;(y=i==null?void 0:i.classList)==null||y.remove("active"),(C=e.paymentLoader)==null||C.hideLoader(),h(e.$t("We could not verify your payment status. Please do not pay again. Contact the store to check your order status."),-1)},nt=function(y){var O,A;if(!((O=t==null?void 0:t.payment_args)!=null&&O.gateway_return_url))return!1;const C=new URL(L,window.location.href);return typeof y=="string"&&/^(pi|seti)_[a-zA-Z0-9_]+$/.test(y)&&C.searchParams.set(y.indexOf("seti_")===0?"setup_intent":"payment_intent",y),(A=e.paymentLoader)==null||A.changeLoaderStatus("redirecting"),window.CheckoutHelper?window.CheckoutHelper.handleCheckoutRedirect(C.toString()):window.location.href=C.toString(),!0},$t=T===u?M:null;M=null,T=null,($t||u.submit()).then(y=>{var B,W,z;if(y!=null&&y.error){H(),(B=i==null?void 0:i.classList)==null||B.remove("active"),(W=e.paymentLoader)==null||W.hideLoader(),(z=e.paymentLoader)==null||z.enableCheckoutButton(l==null?void 0:l.text),h(y.error.message);return}const C=J==="setup"?r.confirmSetup:r.confirmPayment,O=J==="setup"?"setupIntent":"paymentIntent",A={elements:u,clientSecret:$,confirmParams:{return_url:L,payment_method_data:{billing_details:{address:{city:n!=null&&n.city?n==null?void 0:n.city:null,country:n!=null&&n.country?n==null?void 0:n.country:null,postal_code:n!=null&&n.postcode?n==null?void 0:n.postcode:null,state:n!=null&&n.state?n==null?void 0:n.state:null,line1:n!=null&&n.address_1?n==null?void 0:n.address_1:null},name:n==null?void 0:n.name,email:n==null?void 0:n.email}}},redirect:"if_required"};return Tt(e.paymentLoader,i),C(A).then(P=>{var yt,gt,wt,kt,vt,bt,xt,Lt,St,Ct;H(),(yt=i==null?void 0:i.classList)==null||yt.add("active"),(gt=e.paymentLoader)==null||gt.changeLoaderStatus("confirming");const V=((kt=(wt=t==null?void 0:t.payment_args)==null?void 0:wt.vendor_subscription_info)==null?void 0:kt.trx_hash)||((vt=t==null?void 0:t.payment_args)==null?void 0:vt.trx_hash);if(P!=null&&P.error){const Z=((xt=(bt=P.error)==null?void 0:bt.payment_intent)==null?void 0:xt.id)||((St=(Lt=P.error)==null?void 0:Lt.setup_intent)==null?void 0:St.id),I=function(E){var v,q,_;if((v=i==null?void 0:i.classList)==null||v.remove("active"),(q=e.paymentLoader)==null||q.hideLoader(),!E){h(e.$t("We could not record that failed attempt. Please reload the page before trying again."),-1);return}e.paymentLoader.enableCheckoutButton(l.text),h((_=P==null?void 0:P.error)==null?void 0:_.message)};if(Z&&V){const E=new URLSearchParams({action:"fluent_cart_confirm_stripe_payment",intentId:Z,trx_hash:V}).toString(),v=new XMLHttpRequest;v.open("POST",window.fluentcart_checkout_vars.ajaxurl,!0),v.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),v.timeout=15e3,v.onload=function(){let q=v.status===200;try{const _=JSON.parse(v.responseText||"{}");q=q||(_==null?void 0:_.transaction_status)==="failed"||(_==null?void 0:_.transaction_status)==="succeeded"}catch{}I(q)},v.onerror=function(){I(!1)},v.ontimeout=function(){I(!1)},v.send(E)}else I(!0);return}const k=P[O];if(k!=null&&k.status&&(k.status==="succeeded"||k.status==="processing"||k.status==="requires_capture")){(Ct=e.paymentLoader)==null||Ct.changeLoaderStatus("completed");const Z=new URLSearchParams(window.location.search).get("mode")||"order",I=new URLSearchParams({action:"fluent_cart_confirm_stripe_payment",intentId:k.id,mode:Z,...V?{trx_hash:V}:{}}).toString();let E=!1;const v=function(){E||(E=!0,!nt(k.id)&&Y())},q=function(){E||(E=!0,Y())},_=new XMLHttpRequest;_.open("POST",window.fluentcart_checkout_vars.ajaxurl,!0),_.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),_.timeout=15e3,_.onreadystatechange=function(){var Et;if(!(_.readyState!==4||E))if(_.status>=200&&_.status<300)try{let D=JSON.parse(_.responseText);D&&(e.paymentLoader.triggerPaymentCompleteEvent(D),D.redirect_url&&(S=D.redirect_url)),E=!0,(Et=e.paymentLoader)==null||Et.changeLoaderStatus("redirecting"),window.CheckoutHelper?window.CheckoutHelper.handleCheckoutRedirect(S):window.location.href=S}catch{v()}else[0,502,503,504].indexOf(_.status)!==-1?q():v()},_.onerror=q,_.ontimeout=q,_.send(I)}else if((k==null?void 0:k.status)==="requires_action"||(k==null?void 0:k.status)==="requires_source_action")return X(k)})}).catch(()=>{var O,A,B,W,z;H();const y=(A=(O=t==null?void 0:t.response)==null?void 0:O.latest_invoice)==null?void 0:A.payment_intent,C=((W=(B=t==null?void 0:t.response)==null?void 0:B.pending_setup_intent)==null?void 0:W.id)||(typeof y=="string"?y:y==null?void 0:y.id)||((z=t==null?void 0:t.response)==null?void 0:z.id);nt(C)||Y()})}});const x=p=>{var a;p&&((a=e.paymentLoader)==null||a.changeLoaderStatus(e.$t("redirecting for action")),window.location.href=p)},j=()=>{var p,a,f,h;(a=(p=document.querySelector(".fct-loader"))==null?void 0:p.classList)==null||a.remove("active"),(f=e.paymentLoader)==null||f.hideLoader(),(h=e.paymentLoader)==null||h.enableCheckoutButton(l==null?void 0:l.text)},X=p=>{var f,h,d,i,t,S,L,n,$;const a=p.next_action||{};switch(a.type){case"redirect_to_url":x((f=a.redirect_to_url)==null?void 0:f.url);break;case"cashapp_handle_redirect_or_display_qr_code":x((h=a.cashapp_handle_redirect_or_display_qr_code)==null?void 0:h.hosted_instructions_url);break;case"display_boleto":x((d=a.boleto_display_details)==null?void 0:d.hosted_voucher_url);break;case"oxxo_display_details":x((i=a.oxxo_display_details)==null?void 0:i.hosted_voucher_url);break;case"alipay_handle_redirect":x((t=a.alipay_handle_redirect)==null?void 0:t.url);break;case"konbini_display_details":x((S=a.konbini_display_details)==null?void 0:S.hosted_voucher_url);break;case"display_bank_transfer_instructions":x((L=a.display_bank_transfer_instructions)==null?void 0:L.hosted_instructions_url);break;case"verify_with_microdeposits":x((n=a.verify_with_microdeposits)==null?void 0:n.hosted_verification_url);break;case"wechat_pay_display_qr_code":j();break;case"promptpay_display_qr_code":j();break;default:($=e.paymentLoader)==null||$.hideLoader();break}};Q=function(p){if(!window.is_stripe_ready){const a=document.createElement("div");a.className="fct-error-message",a.textContent=e.$t("Card details are not valid!"),document.querySelector(".fluent-cart-checkout-page-checkout-form-order-summary").appendChild(a),r.confirmPayment({elements:u,confirmParams:{return_url:"https://stripe.com"},redirect:"if_required"})}}}}window.addEventListener("fluent_cart_load_payments_stripe",function(o){window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading",{detail:{payment_method:"stripe"}})),window.fluentcart.$t;const c=document.querySelector(".fluent-cart-checkout_embed_payment_container_stripe");e(),g(),fetch(o.detail.paymentInfoUrl,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":o.detail.nonce},credentials:"include"}).then(async r=>{var u,b,w,N;if(r=await r.json(),(r==null?void 0:r.status)==="failed"){s(r==null?void 0:r.message),window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_failed",{detail:{payment_method:"stripe"}}));return}if(((u=r==null?void 0:r.intent)==null?void 0:u.amount)<=0&&((b=r==null?void 0:r.intent)==null?void 0:b.mode)!=="subscription"&&((w=r==null?void 0:r.intent)==null?void 0:w.mode)!=="setup"){let x=function(X){return l[X]||X};var m=x;const l=((N=window.fct_stripe_data)==null?void 0:N.translations)||{};s(x("Total amount is not valid, please add some items to cart!"));const j=document.getElementById("fct_loading_payment_processor");j&&j.remove();return}new Mt(o.detail.form,r,o.detail.paymentLoader).init()}).catch(r=>{var b;const m=((b=window.fct_stripe_data)==null?void 0:b.translations)||{};function u(w){return m[w]||w}s(u("An error occurred while parsing the response.")),window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_failed",{detail:{payment_method:"stripe"}}))});function s(r){if(!r)return;const m=document.createElement("div");m.className="fct-error-message",m.textContent=r,c.appendChild(m);const u=document.getElementById("fct_loading_payment_processor");u&&u.remove()}function g(){var b;const r=document.createElement("p");r.id="fct_loading_payment_processor";const m=((b=window.fct_stripe_data)==null?void 0:b.translations)||{};function u(w){return m[w]||w}r.textContent=u("Loading Payment Processor..."),c.appendChild(r)}function e(){document.querySelectorAll(".fct-error-message").forEach(m=>m.remove())}})})();