|
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
|
+(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())}})})(); |