PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
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 1.3.20 1.3.19 All 49 releases
← All changes | assets/stripe-checkout.js +1 -1 1.3.21 → 1.6.5 View file →
@@ -1 +1 @@
1 -class te{constructor(_,u,f){this.form=_,this.data=u,this.paymentArgs=u.payment_args,this.intent=u.intent,this.paymentLoader=f,this.$t=this.translate.bind(this)}translate(_){var f;return(((f=window.fct_stripe_data)==null?void 0:f.translations)||{})[_]||_}async init(){var b,q;const _=document.querySelector("[data-fluent-cart-checkout-page-checkout-button]"),u=document.querySelector(".fluent-cart-checkout_embed_payment_container_stripe"),f=this.form.querySelector(".fluent_cart_payment_methods");f&&(f.style.display="none");const t=this,a=Stripe((b=this.paymentArgs)==null?void 0:b.public_key),d={...this.intent};this.data.appearance&&(d.appearance=this.data.appearance);const i=await a.elements(d),y={fields:{billingDetails:{name:"never",email:"never"}},terms:{card:"never",wallet:"never",apple_pay:"never",google_pay:"never",amazon_pay:"never",paypal:"never"}},s=await i.create("payment",y);s.mount(".fluent-cart-checkout_embed_payment_container_stripe");const r=(q=window.fluentcart_checkout_vars)==null?void 0:q.submit_button;s.on("loaderror",function(o){var k,e,v;window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_failed",{detail:{payment_method:"stripe"}}));const p=document.getElementById("fct_loading_payment_processor");p&&p.remove();let l=(k=o==null?void 0:o.error)==null?void 0:k.message,m="";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!"),m=`<p style="color:red; display:none;" class="hidden-error">${(v=o==null?void 0:o.error)==null?void 0:v.message}</p>`;const w=document.createElement("a");w.className="toggle-error",w.style.cursor="pointer",w.textContent=t.$t("See Errors"),w.addEventListener("click",function(){document.querySelector(".hidden-error").style.display=document.querySelector(".hidden-error").style.display==="none"?"block":"none"}),u.prepend(w)}const n=document.createElement("p");n.style.color="red",n.innerHTML=l+m,u.prepend(n),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 p=document.getElementById("fct_loading_payment_processor");if(p&&p.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(n=>n.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 T,C,I,N,O,A,B,H,U,j,D;(T=t.paymentLoader)==null||T.changeLoaderStatus("processing");const m=document.querySelector(".fct-loader");(C=m==null?void 0:m.classList)==null||C.add("active");const n=(I=l.detail)==null?void 0:I.response;let k=(N=n==null?void 0:n.payment_args)==null?void 0:N.success_url;(O=n==null?void 0:n.payment_args)==null||O.custom_payment_url;const e=n==null?void 0:n.fc_customer;let v=null,w="intent";((A=n==null?void 0:n.response)==null?void 0:A.object)==="subscription"?(w=(H=(B=n==null?void 0:n.payment_args)==null?void 0:B.vendor_subscription_info)==null?void 0:H.type,v=(j=(U=n==null?void 0:n.payment_args)==null?void 0:U.vendor_subscription_info)==null?void 0:j.clientSecret):v=(D=n==null?void 0:n.response)==null?void 0:D.client_secret;const Y=function(P){new Toastify({text:P,className:"warning",duration:2e3,escapeMarkup:!1,close:!0}).showToast()};i.submit().then(P=>{const $=w==="setup"?a.confirmSetup:a.confirmPayment,M=w==="setup"?"setupIntent":"paymentIntent",Z={elements:i,clientSecret:v,confirmParams:{return_url:k,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"};$(Z).then(h=>{var Q,J,X,z,W;(Q=t.paymentLoader)==null||Q.changeLoaderStatus("confirming"),h!=null&&h.error&&(console.log("inside error",(J=h==null?void 0:h.error)==null?void 0:J.message),t.paymentLoader.enableCheckoutButton(r.text),Y((X=h==null?void 0:h.error)==null?void 0:X.message),(z=t.paymentLoader)==null||z.hideLoader());const c=h[M];if(c!=null&&c.status&&(c.status==="succeeded"||c.status==="processing"||c.status==="requires_capture")){(W=t.paymentLoader)==null||W.changeLoaderStatus("completed");const R=new URLSearchParams(window.location.search).get("mode")||"order",ee=new URLSearchParams({action:"fluent_cart_confirm_stripe_payment",intentId:c.id,mode:R}).toString(),g=new XMLHttpRequest;g.open("POST",window.fluentcart_checkout_vars.ajaxurl,!0),g.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),g.onreadystatechange=function(){var F,G,K;if(g.readyState===4)if(g.status>=200&&g.status<300)try{let L=JSON.parse(g.responseText);L&&(t.paymentLoader.triggerPaymentCompleteEvent(L),L.redirect_url&&(k=L.redirect_url)),(F=t.paymentLoader)==null||F.changeLoaderStatus("redirecting"),window.CheckoutHelper?window.CheckoutHelper.handleCheckoutRedirect(k):window.location.href=k}catch{(G=t.paymentLoader)==null||G.changeLoaderStatus(t.$t("Payment confirmation failed")),setTimeout(function(){var S,V;(S=t.paymentLoader)==null||S.hideLoader(),(V=t.paymentLoader)==null||V.enableCheckoutButton(r==null?void 0:r.text)},1e3)}else(K=t.paymentLoader)==null||K.changeLoaderStatus(t.$t("Payment confirmation failed")),setTimeout(function(){var L,S;(L=t.paymentLoader)==null||L.hideLoader(),(S=t.paymentLoader)==null||S.enableCheckoutButton(r==null?void 0:r.text)},1e3)},g.onerror=function(){console.log("Request failed")},g.send(ee)}else if((c==null?void 0:c.status)==="requires_action"||(c==null?void 0:c.status)==="requires_source_action")return E(c)})}).catch(P=>{var $,M;console.log(P,"failed"),m.classList.remove("active"),($=t.paymentLoader)==null||$.changeLoaderStatus(t.$t("Payment confirmation failed")),(M=t.paymentLoader)==null||M.hideLoader()})})});const E=o=>{var l,m;(l=t.paymentLoader)==null||l.changeLoaderStatus(t.$t("redirecting for action"));const p=(m=o.next_action)==null?void 0:m.type;switch(p){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:console.log("QR Code:",o.next_action.cashapp_handle_redirect_or_display_qr_code.qr_code);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:console.log("QR Code:",o.next_action.wechat_pay_display_qr_code.qr_code);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:console.log("QR Code:",o.next_action.promptpay_display_qr_code.qr_code);break;default:console.error("Unsupported next_action type:",p);break}};window.addEventListener("fluent_cart_validate_checkout_stripe",function(o){if(!window.is_stripe_ready){const p=document.createElement("div");p.className="fct-error-message",p.textContent=t.$t("Card details are not valid!"),document.querySelector(".fluent-cart-checkout-page-checkout-form-order-summary").appendChild(p),a.confirmPayment({elements:i,confirmParams:{return_url:"https://stripe.com"},redirect:"if_required"})}})}}window.addEventListener("fluent_cart_load_payments_stripe",function(x){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(),f(),fetch(x.detail.paymentInfoUrl,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":x.detail.nonce},credentials:"include"}).then(async a=>{var i,y,s;if(a=await a.json(),(a==null?void 0:a.status)==="failed"&&u(a==null?void 0:a.message),((i=a==null?void 0:a.intent)==null?void 0:i.amount)<=0&&((y=a==null?void 0:a.intent)==null?void 0:y.mode)!=="subscription"){let E=function(q){return r[q]||q};var d=E;const r=((s=window.fct_stripe_data)==null?void 0:s.translations)||{};u(E("Total amount is not valid, please add some items to cart!"));const b=document.getElementById("fct_loading_payment_processor");b&&b.remove();return}new te(x.detail.form,a,x.detail.paymentLoader).init()}).catch(a=>{var y;const d=((y=window.fct_stripe_data)==null?void 0:y.translations)||{};function i(s){return d[s]||s}u(i("An error occurred while parsing the response."))});function u(a){if(!a)return;const d=document.createElement("div");d.className="fct-error-message",d.textContent=a,_.appendChild(d);const i=document.getElementById("fct_loading_payment_processor");i&&i.remove()}function f(){var y;const a=document.createElement("p");a.id="fct_loading_payment_processor";const d=((y=window.fct_stripe_data)==null?void 0:y.translations)||{};function i(s){return d[s]||s}a.textContent=i("Loading Payment Processor..."),_.appendChild(a)}function t(){document.querySelectorAll(".fct-error-message").forEach(d=>d.remove())}});
1 +let z=null,J=null,A=null,I=null;window.addEventListener("fluent_cart_payment_next_action_stripe",i=>{typeof z=="function"&&z(i)});window.addEventListener("fluent_cart_validate_checkout_stripe",i=>{typeof J=="function"&&J(i)});document.addEventListener("change",i=>{const r=i.target;if(!r||r.name!=="save_payment_method"||typeof A!="function")return;const o=(r.form||document).querySelector('input[name="_fct_pay_method"]:checked');!o||o.value!=="stripe"||A(r)});function T(){I&&(I.disconnect(),I=null)}function ve(i){var o,m;if(!i||i.nodeType!==1)return!1;const r=document.querySelector(".fluent-cart-checkout_embed_payment_container_stripe");return r&&r.contains(i)||(o=i.closest)!=null&&o.call(i,".fct-order-processing, .fct-loader")?!1:i.tagName==="IFRAME"?!0:!!((m=i.querySelector)!=null&&m.call(i,"iframe"))}function Le(i,r){var o;i==null||i.hideLoader(),(o=r==null?void 0:r.classList)==null||o.remove("active")}function be(i,r){T(),document.body&&(I=new MutationObserver(o=>{for(const m of o)for(const e of m.addedNodes)if(ve(e)){Le(i,r),T();return}}),I.observe(document.body,{childList:!0,subtree:!0}))}class Se{constructor(r,o,m){this.form=r,this.data=o,this.paymentArgs=o.payment_args,this.intent=o.intent,this.paymentLoader=m,this.$t=this.translate.bind(this)}translate(r){var m;return(((m=window.fct_stripe_data)==null?void 0:m.translations)||{})[r]||r}bindSaveCardConsent(r){var a,u,p,g;A=null;const o=this.form.querySelector('input[name="save_payment_method"]');if(!o||!r||typeof r.update!="function"||((a=window.fluentcart_checkout_info)==null?void 0:a.has_subscription)==="yes"||((u=this.intent)==null?void 0:u.mode)==="subscription"||((p=this.intent)==null?void 0:p.mode)==="setup")return;A=y=>{var c;const E=y.checked?"off_session":null;try{r.update({setupFutureUsage:E})}catch{(c=this.paymentLoader)==null||c.load("stripe")}};const e=((g=this.intent)==null?void 0:g.setup_future_usage)||null;(o.checked?"off_session":null)!==e&&A(o)}async init(){var $,N,V;const r=document.querySelector("[data-fluent-cart-checkout-page-checkout-button]"),o=document.querySelector(".fluent-cart-checkout_embed_payment_container_stripe"),m=this.form.querySelector(".fluent_cart_payment_methods");m&&(m.style.display="none");const e=this,a=Stripe(($=this.paymentArgs)==null?void 0:$.public_key),u={...this.intent};this.data.appearance&&(u.appearance=this.data.appearance),Array.isArray(this.data.fonts)&&this.data.fonts.length&&(u.fonts=this.data.fonts),u.locale=((N=window.fct_stripe_data)==null?void 0:N.locale)||"auto";const p=await a.elements(u),g={fields:{billingDetails:{name:"never",email:"never"}},terms:{card:"never",wallet:"never",apple_pay:"never",google_pay:"never",amazon_pay:"never",paypal:"never"}},y=await p.create("payment",g);if(y.mount(".fluent-cart-checkout_embed_payment_container_stripe"),this.bindSaveCardConsent(p),this.consentCheckbox=null,o){const s=o.parentNode.querySelector(".fct-system-charge-consent");if(s&&s.remove(),this.data.system_consent){let l;if(this.data.consent_required){l=document.createElement("label"),l.className="fct-system-charge-consent",l.style.cssText="display:flex;gap:6px;align-items:flex-start;margin-top:8px;font-size:12px;opacity:0.85;cursor:pointer;";const h=document.createElement("input");h.type="checkbox",h.name="_fct_system_consent",h.value="yes",h.style.cssText="margin-top:2px;flex-shrink:0;",l.appendChild(h);const d=document.createElement("span");d.textContent=this.data.system_consent,l.appendChild(d),this.consentCheckbox=h}else l=document.createElement("p"),l.className="fct-system-charge-consent",l.style.cssText="margin-top:8px;font-size:12px;opacity:0.75;",l.textContent=this.data.system_consent;o.insertAdjacentElement("afterend",l)}}const E=()=>!this.data.consent_required||this.consentCheckbox&&this.consentCheckbox.checked;this.consentOk=E;const c=(V=window.fluentcart_checkout_vars)==null?void 0:V.submit_button;y.on("loaderror",function(s){var n,S,H;window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_failed",{detail:{payment_method:"stripe"}}));const l=document.getElementById("fct_loading_payment_processor");l&&l.remove();let h=(n=s==null?void 0:s.error)==null?void 0:n.message,d="";if(((S=window==null?void 0:window.fluentcart_checkout_info)==null?void 0:S.is_admin)!=="1"){h=e.$t("Payment module not available to checkout! Please reload again, or contact admin!"),d=`<p style="color:red; display:none;" class="hidden-error">${(H=s==null?void 0:s.error)==null?void 0:H.message}</p>`;const t=document.createElement("a");t.className="toggle-error",t.style.cursor="pointer",t.textContent=e.$t("See Errors"),t.addEventListener("click",function(){document.querySelector(".hidden-error").style.display=document.querySelector(".hidden-error").style.display==="none"?"block":"none"}),o.prepend(t)}const _=document.createElement("p");_.style.color="red",_.innerHTML=h+d,o.prepend(_),window.is_stripe_ready=!1,e.paymentLoader.disableCheckoutButton(c==null?void 0:c.text)}),y.on("ready",function(s){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 l=document.getElementById("fct_loading_payment_processor");if(l&&l.remove(),r&&r.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(c.text):d&&d.value==="stripe"&&e.paymentLoader.disableCheckoutButton(c!=null&&c.text?c.text:e.$t("Place Order"))}const h=function(){const d=e.form.querySelector('input[name="_fct_pay_method"]:checked');d&&d.value!=="stripe"||(window.is_stripe_ready&&e.consentOk()?r&&r.id==="fluent_cart_custom_checkout_btn"?e.paymentLoader.enableCheckoutButton(e.$t("Pay Now")):e.paymentLoader.enableCheckoutButton(c.text):e.paymentLoader.disableCheckoutButton(c!=null&&c.text?c.text:e.$t("Place Order")))};e.consentCheckbox&&e.consentCheckbox.addEventListener("change",h),y.addEventListener("change",function(d){window.is_stripe_ready=d.complete,document.querySelectorAll(".fct-error-message").forEach(n=>n.remove()),h()}),z=d=>{var G,K,Q,Y,Z,R,ee,te,ne,ae,re,oe,ie,ce;T(),(G=e.paymentLoader)==null||G.changeLoaderStatus("processing");const _=document.querySelector(".fct-loader");(K=_==null?void 0:_.classList)==null||K.add("active");const n=(Q=d.detail)==null?void 0:Q.response;let S=(Y=n==null?void 0:n.payment_args)==null?void 0:Y.success_url;const H=((Z=n==null?void 0:n.payment_args)==null?void 0:Z.gateway_return_url)||S;(R=n==null?void 0:n.payment_args)==null||R.custom_payment_url;const t=n==null?void 0:n.fc_customer;let j=null,U="intent";((ee=n==null?void 0:n.response)==null?void 0:ee.object)==="subscription"?(U=(ne=(te=n==null?void 0:n.payment_args)==null?void 0:te.vendor_subscription_info)==null?void 0:ne.type,j=(re=(ae=n==null?void 0:n.payment_args)==null?void 0:ae.vendor_subscription_info)==null?void 0:re.clientSecret):((oe=n==null?void 0:n.response)==null?void 0:oe.object)==="setup_intent"?(U="setup",j=(ie=n==null?void 0:n.response)==null?void 0:ie.client_secret):j=(ce=n==null?void 0:n.response)==null?void 0:ce.client_secret;const X=function(q,C=2e3){new Toastify({text:q,className:"warning",duration:C,escapeMarkup:!1,close:!0}).showToast()};p.submit().then(q=>{var se,de,le;if(q!=null&&q.error){T(),(se=_==null?void 0:_.classList)==null||se.remove("active"),(de=e.paymentLoader)==null||de.hideLoader(),(le=e.paymentLoader)==null||le.enableCheckoutButton(c==null?void 0:c.text),X(q.error.message);return}const C=U==="setup"?a.confirmSetup:a.confirmPayment,B=U==="setup"?"setupIntent":"paymentIntent",D={elements:p,clientSecret:j,confirmParams:{return_url:H,payment_method_data:{billing_details:{address:{city:t!=null&&t.city?t==null?void 0:t.city:null,country:t!=null&&t.country?t==null?void 0:t.country:null,postal_code:t!=null&&t.postcode?t==null?void 0:t.postcode:null,state:t!=null&&t.state?t==null?void 0:t.state:null,line1:t!=null&&t.address_1?t==null?void 0:t.address_1:null},name:t==null?void 0:t.name,email:t==null?void 0:t.email}}},redirect:"if_required"};return be(e.paymentLoader,_),C(D).then(v=>{var _e,ue,pe,he,me,ye,fe,we,ge,xe;T(),(_e=_==null?void 0:_.classList)==null||_e.add("active"),(ue=e.paymentLoader)==null||ue.changeLoaderStatus("confirming");const F=((he=(pe=n==null?void 0:n.payment_args)==null?void 0:pe.vendor_subscription_info)==null?void 0:he.trx_hash)||((me=n==null?void 0:n.payment_args)==null?void 0:me.trx_hash);if(v!=null&&v.error){const W=((fe=(ye=v.error)==null?void 0:ye.payment_intent)==null?void 0:fe.id)||((ge=(we=v.error)==null?void 0:we.setup_intent)==null?void 0:ge.id),P=function(x){var f,L,k;if((f=_==null?void 0:_.classList)==null||f.remove("active"),(L=e.paymentLoader)==null||L.hideLoader(),!x){X(e.$t("We could not record that failed attempt. Please reload the page before trying again."),-1);return}e.paymentLoader.enableCheckoutButton(c.text),X((k=v==null?void 0:v.error)==null?void 0:k.message)};if(W&&F){const x=new URLSearchParams({action:"fluent_cart_confirm_stripe_payment",intentId:W,trx_hash:F}).toString(),f=new XMLHttpRequest;f.open("POST",window.fluentcart_checkout_vars.ajaxurl,!0),f.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),f.timeout=15e3,f.onload=function(){let L=f.status===200;try{const k=JSON.parse(f.responseText||"{}");L=L||(k==null?void 0:k.transaction_status)==="failed"||(k==null?void 0:k.transaction_status)==="succeeded"}catch{}P(L)},f.onerror=function(){P(!1)},f.ontimeout=function(){P(!1)},f.send(x)}else P(!0);return}const w=v[B];if(w!=null&&w.status&&(w.status==="succeeded"||w.status==="processing"||w.status==="requires_capture")){(xe=e.paymentLoader)==null||xe.changeLoaderStatus("completed");const W=new URLSearchParams(window.location.search).get("mode")||"order",P=new URLSearchParams({action:"fluent_cart_confirm_stripe_payment",intentId:w.id,mode:W,...F?{trx_hash:F}:{}}).toString(),x=new XMLHttpRequest;x.open("POST",window.fluentcart_checkout_vars.ajaxurl,!0),x.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),x.onreadystatechange=function(){var f,L,k;if(x.readyState===4)if(x.status>=200&&x.status<300)try{let b=JSON.parse(x.responseText);b&&(e.paymentLoader.triggerPaymentCompleteEvent(b),b.redirect_url&&(S=b.redirect_url)),(f=e.paymentLoader)==null||f.changeLoaderStatus("redirecting"),window.CheckoutHelper?window.CheckoutHelper.handleCheckoutRedirect(S):window.location.href=S}catch{(L=e.paymentLoader)==null||L.changeLoaderStatus(e.$t("Payment confirmation failed")),setTimeout(function(){var O,ke;(O=e.paymentLoader)==null||O.hideLoader(),(ke=e.paymentLoader)==null||ke.enableCheckoutButton(c==null?void 0:c.text)},1e3)}else(k=e.paymentLoader)==null||k.changeLoaderStatus(e.$t("Payment confirmation failed")),setTimeout(function(){var b,O;(b=e.paymentLoader)==null||b.hideLoader(),(O=e.paymentLoader)==null||O.enableCheckoutButton(c==null?void 0:c.text)},1e3)},x.onerror=function(){},x.send(P)}else if((w==null?void 0:w.status)==="requires_action"||(w==null?void 0:w.status)==="requires_source_action")return M(w)})}).catch(q=>{var C,B,D;T(),(C=_==null?void 0:_.classList)==null||C.remove("active"),(B=e.paymentLoader)==null||B.changeLoaderStatus(e.$t("Payment confirmation failed")),(D=e.paymentLoader)==null||D.hideLoader()})}});const M=s=>{var h,d;switch((h=e.paymentLoader)==null||h.changeLoaderStatus(e.$t("redirecting for action")),(d=s.next_action)==null?void 0:d.type){case"redirect_to_url":window.location.href=s.next_action.redirect_to_url.url;break;case"cashapp_handle_redirect_or_display_qr_code":s.next_action.cashapp_handle_redirect_or_display_qr_code.hosted_instructions_url&&(window.location.href=s.next_action.cashapp_handle_redirect_or_display_qr_code.hosted_instructions_url);break;case"display_boleto":window.location.href=s.next_action.boleto_display_details.hosted_voucher_url;break;case"oxxo_display_details":window.location.href=s.next_action.oxxo_display_details.hosted_voucher_url;break;case"alipay_handle_redirect":window.location.href=s.next_action.alipay_handle_redirect.url;break;case"konbini_display_details":window.location.href=s.next_action.konbini_display_details.hosted_voucher_url;break;case"display_bank_transfer_instructions":window.location.href=s.next_action.display_bank_transfer_instructions.hosted_instructions_url;break;case"verify_with_microdeposits":window.location.href=s.next_action.verify_with_microdeposits.hosted_verification_url;break;case"wechat_pay_display_qr_code":s.next_action.wechat_pay_display_qr_code.hosted_instructions_url&&(window.location.href=s.next_action.wechat_pay_display_qr_code.hosted_instructions_url);break;case"promptpay_display_qr_code":s.next_action.promptpay_display_qr_code.hosted_instructions_url&&(window.location.href=s.next_action.promptpay_display_qr_code.hosted_instructions_url);break}};J=function(s){if(!window.is_stripe_ready){const l=document.createElement("div");l.className="fct-error-message",l.textContent=e.$t("Card details are not valid!"),document.querySelector(".fluent-cart-checkout-page-checkout-form-order-summary").appendChild(l),a.confirmPayment({elements:p,confirmParams:{return_url:"https://stripe.com"},redirect:"if_required"})}}}}window.addEventListener("fluent_cart_load_payments_stripe",function(i){window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading",{detail:{payment_method:"stripe"}})),window.fluentcart.$t;const r=document.querySelector(".fluent-cart-checkout_embed_payment_container_stripe");e(),m(),fetch(i.detail.paymentInfoUrl,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":i.detail.nonce},credentials:"include"}).then(async a=>{var p,g,y,E;if(a=await a.json(),(a==null?void 0:a.status)==="failed"){o(a==null?void 0:a.message),window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_failed",{detail:{payment_method:"stripe"}}));return}if(((p=a==null?void 0:a.intent)==null?void 0:p.amount)<=0&&((g=a==null?void 0:a.intent)==null?void 0:g.mode)!=="subscription"&&((y=a==null?void 0:a.intent)==null?void 0:y.mode)!=="setup"){let M=function(N){return c[N]||N};var u=M;const c=((E=window.fct_stripe_data)==null?void 0:E.translations)||{};o(M("Total amount is not valid, please add some items to cart!"));const $=document.getElementById("fct_loading_payment_processor");$&&$.remove();return}new Se(i.detail.form,a,i.detail.paymentLoader).init()}).catch(a=>{var g;const u=((g=window.fct_stripe_data)==null?void 0:g.translations)||{};function p(y){return u[y]||y}o(p("An error occurred while parsing the response.")),window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_failed",{detail:{payment_method:"stripe"}}))});function o(a){if(!a)return;const u=document.createElement("div");u.className="fct-error-message",u.textContent=a,r.appendChild(u);const p=document.getElementById("fct_loading_payment_processor");p&&p.remove()}function m(){var g;const a=document.createElement("p");a.id="fct_loading_payment_processor";const u=((g=window.fct_stripe_data)==null?void 0:g.translations)||{};function p(y){return u[y]||y}a.textContent=p("Loading Payment Processor..."),r.appendChild(a)}function e(){document.querySelectorAll(".fct-error-message").forEach(u=>u.remove())}});