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 trunk → 1.6.5 View file →
@@ -1 +1 @@
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())}})})();
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())}});