|
1
|
|
-let X=null,z=null,N=null;window.addEventListener("fluent_cart_payment_next_action_stripe",x=>{typeof X=="function"&&X(x)});window.addEventListener("fluent_cart_validate_checkout_stripe",x=>{typeof z=="function"&&z(x)});document.addEventListener("change",x=>{const c=x.target;if(!c||c.name!=="save_payment_method"||typeof N!="function")return;const s=(c.form||document).querySelector('input[name="_fct_pay_method"]:checked');!s||s.value!=="stripe"||N(c)});class ge{constructor(c,s,k){this.form=c,this.data=s,this.paymentArgs=s.payment_args,this.intent=s.intent,this.paymentLoader=k,this.$t=this.translate.bind(this)}translate(c){var k;return(((k=window.fct_stripe_data)==null?void 0:k.translations)||{})[c]||c}bindSaveCardConsent(c){var a,u,_,f;N=null;const s=this.form.querySelector('input[name="save_payment_method"]');if(!s||!c||typeof c.update!="function"||((a=window.fluentcart_checkout_info)==null?void 0:a.has_subscription)==="yes"||((u=this.intent)==null?void 0:u.mode)==="subscription"||((_=this.intent)==null?void 0:_.mode)==="setup")return;N=m=>{var r;const E=m.checked?"off_session":null;try{c.update({setupFutureUsage:E})}catch{(r=this.paymentLoader)==null||r.load("stripe")}};const e=((f=this.intent)==null?void 0:f.setup_future_usage)||null;(s.checked?"off_session":null)!==e&&N(s)}async init(){var T,$,J;const c=document.querySelector("[data-fluent-cart-checkout-page-checkout-button]"),s=document.querySelector(".fluent-cart-checkout_embed_payment_container_stripe"),k=this.form.querySelector(".fluent_cart_payment_methods");k&&(k.style.display="none");const e=this,a=Stripe((T=this.paymentArgs)==null?void 0:T.public_key),u={...this.intent};this.data.appearance&&(u.appearance=this.data.appearance),u.locale=(($=window.fct_stripe_data)==null?void 0:$.locale)||"auto";const _=await a.elements(u),f={fields:{billingDetails:{name:"never",email:"never"}},terms:{card:"never",wallet:"never",apple_pay:"never",google_pay:"never",amazon_pay:"never",paypal:"never"}},m=await _.create("payment",f);if(m.mount(".fluent-cart-checkout_embed_payment_container_stripe"),this.bindSaveCardConsent(_),this.consentCheckbox=null,s){const o=s.parentNode.querySelector(".fct-system-charge-consent");if(o&&o.remove(),this.data.system_consent){let d;if(this.data.consent_required){d=document.createElement("label"),d.className="fct-system-charge-consent",d.style.cssText="display:flex;gap:6px;align-items:flex-start;margin-top:8px;font-size:12px;opacity:0.85;cursor:pointer;";const p=document.createElement("input");p.type="checkbox",p.name="_fct_system_consent",p.value="yes",p.style.cssText="margin-top:2px;flex-shrink:0;",d.appendChild(p);const i=document.createElement("span");i.textContent=this.data.system_consent,d.appendChild(i),this.consentCheckbox=p}else d=document.createElement("p"),d.className="fct-system-charge-consent",d.style.cssText="margin-top:8px;font-size:12px;opacity:0.75;",d.textContent=this.data.system_consent;s.insertAdjacentElement("afterend",d)}}const E=()=>!this.data.consent_required||this.consentCheckbox&&this.consentCheckbox.checked;this.consentOk=E;const r=(J=window.fluentcart_checkout_vars)==null?void 0:J.submit_button;m.on("loaderror",function(o){var n,S,O;window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_failed",{detail:{payment_method:"stripe"}}));const d=document.getElementById("fct_loading_payment_processor");d&&d.remove();let p=(n=o==null?void 0:o.error)==null?void 0:n.message,i="";if(((S=window==null?void 0:window.fluentcart_checkout_info)==null?void 0:S.is_admin)!=="1"){p=e.$t("Payment module not available to checkout! Please reload again, or contact admin!"),i=`<p style="color:red; display:none;" class="hidden-error">${(O=o==null?void 0:o.error)==null?void 0:O.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"}),s.prepend(t)}const l=document.createElement("p");l.style.color="red",l.innerHTML=p+i,s.prepend(l),window.is_stripe_ready=!1,e.paymentLoader.disableCheckoutButton(r==null?void 0:r.text)}),m.on("ready",function(o){window.is_stripe_ready=!0,window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_success",{detail:{payment_method:"stripe"}})),requestAnimationFrame(()=>{const i=document.querySelector(".__PrivateStripeElement");i&&(i.style.setProperty("display","flex","important"),i.style.setProperty("justify-content","center","important"),i.style.setProperty("padding","8px 0 0 0","important"))});const d=document.getElementById("fct_loading_payment_processor");if(d&&d.remove(),c&&c.id==="fluent_cart_custom_checkout_btn")e.paymentLoader.disableCheckoutButton(e.$t("Pay Now"));else{const i=e.form.querySelector('input[name="_fct_pay_method"]:checked');i&&i.value==="stripe"&&e.consentOk()?e.paymentLoader.enableCheckoutButton(r.text):i&&i.value==="stripe"&&e.paymentLoader.disableCheckoutButton(r!=null&&r.text?r.text:e.$t("Place Order"))}const p=function(){const i=e.form.querySelector('input[name="_fct_pay_method"]:checked');i&&i.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(r.text):e.paymentLoader.disableCheckoutButton(r!=null&&r.text?r.text:e.$t("Place Order")))};e.consentCheckbox&&e.consentCheckbox.addEventListener("change",p),m.addEventListener("change",function(i){window.is_stripe_ready=i.complete,document.querySelectorAll(".fct-error-message").forEach(n=>n.remove()),p()}),X=i=>{var W,V,G,K,Q,Y,Z,R,ee,te,ne,ae,oe,re;(W=e.paymentLoader)==null||W.changeLoaderStatus("processing");const l=document.querySelector(".fct-loader");(V=l==null?void 0:l.classList)==null||V.add("active");const n=(G=i.detail)==null?void 0:G.response;let S=(K=n==null?void 0:n.payment_args)==null?void 0:K.success_url;const O=((Q=n==null?void 0:n.payment_args)==null?void 0:Q.gateway_return_url)||S;(Y=n==null?void 0:n.payment_args)==null||Y.custom_payment_url;const t=n==null?void 0:n.fc_customer;let I=null,H="intent";((Z=n==null?void 0:n.response)==null?void 0:Z.object)==="subscription"?(H=(ee=(R=n==null?void 0:n.payment_args)==null?void 0:R.vendor_subscription_info)==null?void 0:ee.type,I=(ne=(te=n==null?void 0:n.payment_args)==null?void 0:te.vendor_subscription_info)==null?void 0:ne.clientSecret):((ae=n==null?void 0:n.response)==null?void 0:ae.object)==="setup_intent"?(H="setup",I=(oe=n==null?void 0:n.response)==null?void 0:oe.client_secret):I=(re=n==null?void 0:n.response)==null?void 0:re.client_secret;const F=function(D,q=2e3){new Toastify({text:D,className:"warning",duration:q,escapeMarkup:!1,close:!0}).showToast()};_.submit().then(D=>{var ie,ce;const q=H==="setup"?a.confirmSetup:a.confirmPayment,A=H==="setup"?"setupIntent":"paymentIntent",j={elements:_,clientSecret:I,confirmParams:{return_url:O,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"};(ie=e.paymentLoader)==null||ie.hideLoader(),(ce=l==null?void 0:l.classList)==null||ce.remove("active"),q(j).then(v=>{var se,de,le,_e,ue,pe,me,he,ye,fe;(se=l==null?void 0:l.classList)==null||se.add("active"),(de=e.paymentLoader)==null||de.changeLoaderStatus("confirming");const U=((_e=(le=n==null?void 0:n.payment_args)==null?void 0:le.vendor_subscription_info)==null?void 0:_e.trx_hash)||((ue=n==null?void 0:n.payment_args)==null?void 0:ue.trx_hash);if(v!=null&&v.error){const B=((me=(pe=v.error)==null?void 0:pe.payment_intent)==null?void 0:me.id)||((ye=(he=v.error)==null?void 0:he.setup_intent)==null?void 0:ye.id),C=function(w){var h,L,g;if((h=l==null?void 0:l.classList)==null||h.remove("active"),(L=e.paymentLoader)==null||L.hideLoader(),!w){F(e.$t("We could not record that failed attempt. Please reload the page before trying again."),-1);return}e.paymentLoader.enableCheckoutButton(r.text),F((g=v==null?void 0:v.error)==null?void 0:g.message)};if(B&&U){const w=new URLSearchParams({action:"fluent_cart_confirm_stripe_payment",intentId:B,trx_hash:U}).toString(),h=new XMLHttpRequest;h.open("POST",window.fluentcart_checkout_vars.ajaxurl,!0),h.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),h.timeout=15e3,h.onload=function(){let L=h.status===200;try{const g=JSON.parse(h.responseText||"{}");L=L||(g==null?void 0:g.transaction_status)==="failed"||(g==null?void 0:g.transaction_status)==="succeeded"}catch{}C(L)},h.onerror=function(){C(!1)},h.ontimeout=function(){C(!1)},h.send(w)}else C(!0);return}const y=v[A];if(y!=null&&y.status&&(y.status==="succeeded"||y.status==="processing"||y.status==="requires_capture")){(fe=e.paymentLoader)==null||fe.changeLoaderStatus("completed");const B=new URLSearchParams(window.location.search).get("mode")||"order",C=new URLSearchParams({action:"fluent_cart_confirm_stripe_payment",intentId:y.id,mode:B,...U?{trx_hash:U}:{}}).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 h,L,g;if(w.readyState===4)if(w.status>=200&&w.status<300)try{let b=JSON.parse(w.responseText);b&&(e.paymentLoader.triggerPaymentCompleteEvent(b),b.redirect_url&&(S=b.redirect_url)),(h=e.paymentLoader)==null||h.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 M,we;(M=e.paymentLoader)==null||M.hideLoader(),(we=e.paymentLoader)==null||we.enableCheckoutButton(r==null?void 0:r.text)},1e3)}else(g=e.paymentLoader)==null||g.changeLoaderStatus(e.$t("Payment confirmation failed")),setTimeout(function(){var b,M;(b=e.paymentLoader)==null||b.hideLoader(),(M=e.paymentLoader)==null||M.enableCheckoutButton(r==null?void 0:r.text)},1e3)},w.onerror=function(){},w.send(C)}else if((y==null?void 0:y.status)==="requires_action"||(y==null?void 0:y.status)==="requires_source_action")return P(y)})}).catch(D=>{var q,A,j;(q=l==null?void 0:l.classList)==null||q.remove("active"),(A=e.paymentLoader)==null||A.changeLoaderStatus(e.$t("Payment confirmation failed")),(j=e.paymentLoader)==null||j.hideLoader()})}});const P=o=>{var p,i;switch((p=e.paymentLoader)==null||p.changeLoaderStatus(e.$t("redirecting for action")),(i=o.next_action)==null?void 0:i.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}};z=function(o){if(!window.is_stripe_ready){const d=document.createElement("div");d.className="fct-error-message",d.textContent=e.$t("Card details are not valid!"),document.querySelector(".fluent-cart-checkout-page-checkout-form-order-summary").appendChild(d),a.confirmPayment({elements:_,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 c=document.querySelector(".fluent-cart-checkout_embed_payment_container_stripe");e(),k(),fetch(x.detail.paymentInfoUrl,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":x.detail.nonce},credentials:"include"}).then(async a=>{var _,f,m,E;if(a=await a.json(),(a==null?void 0:a.status)==="failed"){s(a==null?void 0:a.message),window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_failed",{detail:{payment_method:"stripe"}}));return}if(((_=a==null?void 0:a.intent)==null?void 0:_.amount)<=0&&((f=a==null?void 0:a.intent)==null?void 0:f.mode)!=="subscription"&&((m=a==null?void 0:a.intent)==null?void 0:m.mode)!=="setup"){let P=function($){return r[$]||$};var u=P;const r=((E=window.fct_stripe_data)==null?void 0:E.translations)||{};s(P("Total amount is not valid, please add some items to cart!"));const T=document.getElementById("fct_loading_payment_processor");T&&T.remove();return}new ge(x.detail.form,a,x.detail.paymentLoader).init()}).catch(a=>{var f;const u=((f=window.fct_stripe_data)==null?void 0:f.translations)||{};function _(m){return u[m]||m}s(_("An error occurred while parsing the response.")),window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_failed",{detail:{payment_method:"stripe"}}))});function s(a){if(!a)return;const u=document.createElement("div");u.className="fct-error-message",u.textContent=a,c.appendChild(u);const _=document.getElementById("fct_loading_payment_processor");_&&_.remove()}function k(){var f;const a=document.createElement("p");a.id="fct_loading_payment_processor";const u=((f=window.fct_stripe_data)==null?void 0:f.translations)||{};function _(m){return u[m]||m}a.textContent=_("Loading Payment Processor..."),c.appendChild(a)}function e(){document.querySelectorAll(".fct-error-message").forEach(u=>u.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())}})})(); |