PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.6
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.6
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/paypal-checkout.js +1 -1 1.3.21 → 1.6.6 View file →
@@ -1 +1 @@
1 -class C{constructor(a,p,t,n){this.form=a,this.orderHandler=p,this.data=t,this.paymentLoader=n,this.$t=this.translate.bind(this)}translate(a){var t;return(((t=window.fct_paypal_data)==null?void 0:t.translations)||{})[a]||a}init(){var m,_;const a=this,p=this.data,t=(_=(m=this.data)==null?void 0:m.intent)==null?void 0:_.mode;let n=document.querySelector(".fluent-cart-checkout_embed_payment_container_paypal");n.innerHTML="";const e=this.form.querySelector(".fluent_cart_payment_methods");e&&(e.style.display="none");let l=null;t==="payment"?this.onetimePaymentHandler(a,p,l,n):t==="subscription"&&this.subscriptionPaymentHandler(a,p,l,n)}handleConfirmFailed(a){var p;(p=this.paymentLoader)==null||p.changeLoaderStatus(a||this.$t("Payment confirmation failed")),setTimeout(()=>{var t,n;(t=this.paymentLoader)==null||t.hideLoader(),(n=this.paymentLoader)==null||n.enableCheckoutButton()},1e3)}async onetimePaymentHandler(a,p,t,n){const e=this,m=new URLSearchParams(window.location.search).get("mode")||"order";paypal.Buttons({style:{shape:"pill",layout:"vertical",label:"paypal",size:"responsive",disableMaxWidth:!0},createOrder:()=>{var o;return(o=e.paymentLoader)==null||o.changeLoaderStatus("processing"),t.response.paypalOrderId},onApprove:(o,i)=>{var d;return(d=e.paymentLoader)==null||d.changeLoaderStatus("confirming"),i.order.capture().then(u=>{var h,y,f;if(u.id){(h=e.paymentLoader)==null||h.changeLoaderStatus("completed");const w=new URLSearchParams({action:"fluent_cart_confirm_paypal_payment",payId:u.id,ref_id:(y=t==null?void 0:t.data)!=null&&y.transaction.uuid?(f=t==null?void 0:t.data)==null?void 0:f.transaction.uuid:e.$t("uuid not found"),mode:m}),c=new XMLHttpRequest;c.open("POST",window.fluentcart_checkout_vars.ajaxurl,!0),c.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),c.onload=function(){var g;if(c.status>=200&&c.status<300)try{const r=JSON.parse(c.responseText);r!=null&&r.redirect_url?(e.paymentLoader.triggerPaymentCompleteEvent(r),(g=e.paymentLoader)==null||g.changeLoaderStatus("redirecting"),window.CheckoutHelper?window.CheckoutHelper.handleCheckoutRedirect(r.redirect_url):window.location.href=r.redirect_url):e.handleConfirmFailed((r==null?void 0:r.message)||e.$t("Payment confirmation failed"))}catch(r){console.error("An error occurred while parsing the response:",r==null?void 0:r.message),e.handleConfirmFailed(e.$t("Payment confirmation failed"))}else e.handleConfirmFailed(e.$t("Payment confirmation failed"))},c.onerror=function(){try{const g=JSON.parse(c.responseText)}catch(g){console.error("An error occurred:",g)}},c.send(w.toString())}})},onCancel:o=>{var i,d;(i=e.paymentLoader)==null||i.changeLoaderStatus("canceled"),(d=e.paymentLoader)==null||d.hideLoader(),e.paymentLoader.enableCheckoutButton()},onShippingChange:(o,i)=>i.resolve(),onError:o=>{e.handlePaypalError(o,t)},onClick:async function(o,i){var d,u,h,y;if(typeof a.orderHandler=="function"){let f=await a.orderHandler();if(!f)return(d=e.paymentLoader)==null||d.changeLoaderStatus(e.$t("Order creation failed")),(u=e.paymentLoader)==null||u.hideLoader(),i.reject();t=f}else return(h=e.paymentLoader)==null||h.changeLoaderStatus(e.$t("Not proper order handler")),(y=e.paymentLoader)==null||y.hideLoader(),i.reject()}}).render(n).then(()=>{window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_success",{detail:{payment_method:"paypal"}}));const o=document.getElementById("fct_loading_payment_processor");o&&o.remove()});const s=document.createElement("p");s.id="fct-extra-checkout-text-for-paypal",s.style.textAlign="center",s.style.marginTop="10px",s.style.fontSize="14px",s.style.color="#666",s.textContent=e.$t("Choose any option to continue"),n.appendChild(s)}async subscriptionPaymentHandler(a,p,t,n){const e=this,m=new URLSearchParams(window.location.search).get("mode")||"order";paypal.Buttons({style:{shape:"pill",layout:"vertical",label:"paypal",size:"responsive",disableMaxWidth:!0},createSubscription:function(o,i){return i.subscription.create({plan_id:t.response.planId,custom_id:t.data.subscription.uuid,application_context:{shipping_preference:"NO_SHIPPING"}})},onApprove:function(o,i){var d,u,h,y,f;if((d=e.paymentLoader)==null||d.changeLoaderStatus("confirming"),o.subscriptionID){console.log(t,o),(u=e.paymentLoader)==null||u.changeLoaderStatus("completed");const w=new URLSearchParams({action:"fluent_cart_confirm_paypal_subscription",order_id:o.orderID,subscription_id:o.subscriptionID,ref_id:(h=t==null?void 0:t.data)==null?void 0:h.transaction.uuid,mode:m}),c=new XMLHttpRequest;c.open("POST",window.fluentcart_checkout_vars.ajaxurl,!0),c.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),c.onload=function(){var g;if(c.status>=200&&c.status<300)try{const r=JSON.parse(c.responseText);r!=null&&r.redirect_url?(e.paymentLoader.triggerPaymentCompleteEvent(r),(g=e.paymentLoader)==null||g.changeLoaderStatus("redirecting"),window.CheckoutHelper?window.CheckoutHelper.handleCheckoutRedirect(r.redirect_url):window.location.href=r.redirect_url):e.handleConfirmFailed((r==null?void 0:r.message)||e.$t("Payment confirmation failed"))}catch(r){console.error("An error occurred while parsing the response:",r),e.handleConfirmFailed(e.$t("Payment confirmation failed"))}else e.handleConfirmFailed(e.$t("Payment confirmation failed"))},c.send(w.toString())}else(y=e.paymentLoader)==null||y.changeLoaderStatus(e.$t("No Subscription ID")),(f=e.paymentLoader)==null||f.hideLoader()},onCancel:o=>{var i,d;(i=e.paymentLoader)==null||i.changeLoaderStatus("canceled"),(d=e.paymentLoader)==null||d.hideLoader(),e.paymentLoader.enableCheckoutButton()},onShippingChange(o,i){return i.resolve()},onClick:async function(o,i){var d,u,h,y,f;if((d=e.paymentLoader)==null||d.changeLoaderStatus(e.$t("no processing")),typeof a.orderHandler=="function"){let w=await a.orderHandler();if(!w)return(u=e.paymentLoader)==null||u.changeLoaderStatus(e.$t("Order creation failed")),(h=e.paymentLoader)==null||h.hideLoader(),i.reject();t=w}else return(y=e.paymentLoader)==null||y.changeLoaderStatus(e.$t("not proper order handler")),(f=e.paymentLoader)==null||f.hideLoader(),i.reject()},onError:function(o){e.handlePaypalError(o,t)}}).render(n).then(()=>{window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_success",{detail:{payment_method:"paypal"}}));const o=document.getElementById("fct_loading_payment_processor");o&&o.remove()});const s=document.createElement("p");s.id="fct-extra-checkout-text-for-paypal",s.style.textAlign="center",s.style.marginTop="10px",s.style.fontSize="14px",s.style.color="#666",s.textContent=e.$t("Choose any option to continue"),n.appendChild(s)}handlePaypalError(a,p){var n,e;let t=this.$t("An unknown error occurred");if(a!=null&&a.message)try{const l=a.message.match(/{.*}/s);l?t=JSON.parse(l[0]).message||t:t=a.message}catch{t=a.message||t}(n=this.paymentLoader)==null||n.changeLoaderStatus(a),(e=this.paymentLoader)==null||e.hideLoader(),this.paymentLoader.enableCheckoutButton()}}window.addEventListener("fluent_cart_load_payments_paypal",function(L){window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading",{detail:{payment_method:"paypal"}})),window.fluentcart.$t,p(),fetch(L.detail.paymentInfoUrl,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":L.detail.nonce},credentials:"include"}).then(async t=>{t=await t.json(),(t==null?void 0:t.status)==="failed"&&a(t==null?void 0:t.message),new C(L.detail.form,L.detail.orderHandler,t,L.detail.paymentLoader).init()}).catch(t=>{var m;const n=((m=window.fct_paypal_data)==null?void 0:m.translations)||{};function e(_){return n[_]||_}let l=(t==null?void 0:t.message)||e("An error occurred while loading PayPal.");a(l)});function a(t){const n=document.createElement("div");n.style.color="red",n.className="fct-error-message",n.textContent=t,document.querySelector(".fluent-cart-checkout_embed_payment_container_paypal").appendChild(n);const l=document.getElementById("fct_loading_payment_processor");l&&l.remove()}function p(){var m;let t=document.querySelector(".fluent-cart-checkout_embed_payment_container_paypal");const n=document.createElement("p");n.id="fct_loading_payment_processor";const e=((m=window.fct_paypal_data)==null?void 0:m.translations)||{};function l(_){return e[_]||_}n.textContent=l("Loading Payment Processor..."),t.appendChild(n)}});
1 +(function(){let f=0;class L{constructor(o,r,e,a){this.form=o,this.orderHandler=r,this.data=e,this.paymentLoader=a,this.$t=this.translate.bind(this)}translate(o){var e;return(((e=window.fct_paypal_data)==null?void 0:e.translations)||{})[o]||o}init(){var c,p,s;const o=this,r=this.data,e=(p=(c=this.data)==null?void 0:c.intent)==null?void 0:p.mode;f++;let a=document.querySelector(".fluent-cart-checkout_embed_payment_container_paypal");a.innerHTML="";const t=this.form.querySelector(".fluent_cart_payment_methods");if(t&&(t.style.display="none"),a){const i=a.parentNode.querySelector(".fct-system-charge-consent");if(i&&i.remove(),r!=null&&r.system_consent){const d=document.createElement("p");d.className="fct-system-charge-consent",d.style.cssText="margin-top:8px;font-size:12px;opacity:0.75;",d.textContent=r.system_consent,a.insertAdjacentElement("afterend",d)}}let n=null;if(e==="payment")this.onetimePaymentHandler(o,r,n,a);else if(e==="subscription")this.subscriptionPaymentHandler(o,r,n,a);else if(e==="setup"){if(((s=window.fct_paypal_data)==null?void 0:s.vault_setup_unavailable)==="yes"){this.renderSetupUnavailable(a);return}this.setupPaymentHandler(o,r,n,a)}}handleConfirmFailed(o){var r;(r=this.paymentLoader)==null||r.changeLoaderStatus(o||this.$t("Payment confirmation failed")),setTimeout(()=>{var e,a;(e=this.paymentLoader)==null||e.hideLoader(),(a=this.paymentLoader)==null||a.enableCheckoutButton()},1e3)}redirectToConfirmationPage(o){window.CheckoutHelper?window.CheckoutHelper.handleCheckoutRedirect(o):window.location.href=o}sendConfirmationRequest(o){const r=this,e=new XMLHttpRequest;e.open("POST",window.fluentcart_checkout_vars.ajaxurl,!0),e.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),e.onload=function(){var a,t;if(e.status>=200&&e.status<300)try{const n=JSON.parse(e.responseText);(n==null?void 0:n.status)==="pending"&&(n!=null&&n.redirect_url)?((a=r.paymentLoader)==null||a.changeLoaderStatus((n==null?void 0:n.message)||r.$t("Your payment is being reviewed. We will confirm your order once it completes.")),setTimeout(()=>{var c;(c=r.paymentLoader)==null||c.changeLoaderStatus("redirecting"),r.redirectToConfirmationPage(n.redirect_url)},2500)):n!=null&&n.redirect_url?(r.paymentLoader.triggerPaymentCompleteEvent(n),(t=r.paymentLoader)==null||t.changeLoaderStatus("redirecting"),r.redirectToConfirmationPage(n.redirect_url)):r.handleConfirmFailed((n==null?void 0:n.message)||r.$t("Payment confirmation failed"))}catch{r.handleConfirmFailed(r.$t("Payment confirmation failed"))}else r.handleConfirmFailed(r.$t("Payment confirmation failed"))},e.onerror=function(){r.handleConfirmFailed(r.$t("Payment confirmation failed"))},e.send(o.toString())}finalizeButtonsRender(o,r){const e=this,a=f;o.render(r).then(()=>{if(a!==f)return;window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_success",{detail:{payment_method:"paypal"}}));const n=document.getElementById("fct_loading_payment_processor");n&&n.remove()}).catch(n=>{a===f&&e.renderPaymentMethodFailure(r,(n==null?void 0:n.message)||e.$t("An error occurred while loading PayPal."))});const t=document.createElement("p");t.id="fct-extra-checkout-text-for-paypal",t.style.textAlign="center",t.style.marginTop="10px",t.style.fontSize="14px",t.style.color="#666",t.textContent=this.$t("Choose any option to continue"),r.appendChild(t)}async onetimePaymentHandler(o,r,e,a){const t=this,c=new URLSearchParams(window.location.search).get("mode")||"order",p=paypal.Buttons({style:{shape:"pill",layout:"vertical",label:"paypal",size:"responsive",disableMaxWidth:!0},createOrder:()=>{var s;return(s=t.paymentLoader)==null||s.changeLoaderStatus("processing"),e.response.paypalOrderId},onApprove:(s,i)=>{var d;return(d=t.paymentLoader)==null||d.changeLoaderStatus("confirming"),i.order.capture().then(l=>{var m,u,y;l.id&&((m=t.paymentLoader)==null||m.changeLoaderStatus("completed"),t.sendConfirmationRequest(new URLSearchParams({action:"fluent_cart_confirm_paypal_payment",payId:l.id,ref_id:(u=e==null?void 0:e.data)!=null&&u.transaction.uuid?(y=e==null?void 0:e.data)==null?void 0:y.transaction.uuid:t.$t("uuid not found"),mode:c})))})},onCancel:s=>{var i,d;(i=t.paymentLoader)==null||i.changeLoaderStatus("canceled"),(d=t.paymentLoader)==null||d.hideLoader(),t.paymentLoader.enableCheckoutButton()},onShippingChange:(s,i)=>i.resolve(),onError:s=>{t.handlePaypalError(s,e)},onClick:async function(s,i){var d,l,m,u;if(typeof o.orderHandler=="function"){let y=await o.orderHandler();if(!y)return(d=t.paymentLoader)==null||d.changeLoaderStatus(t.$t("Order creation failed")),(l=t.paymentLoader)==null||l.hideLoader(),i.reject();e=y}else return(m=t.paymentLoader)==null||m.changeLoaderStatus(t.$t("Not proper order handler")),(u=t.paymentLoader)==null||u.hideLoader(),i.reject()}});this.finalizeButtonsRender(p,a)}async setupPaymentHandler(o,r,e,a){const t=this,c=new URLSearchParams(window.location.search).get("mode")||"order",p=paypal.Buttons({style:{shape:"pill",layout:"vertical",label:"paypal",size:"responsive",disableMaxWidth:!0},createVaultSetupToken:()=>{var s;return(s=t.paymentLoader)==null||s.changeLoaderStatus("processing"),e.response.setupTokenId},onApprove:s=>{var i,d,l;(i=t.paymentLoader)==null||i.changeLoaderStatus("confirming"),t.sendConfirmationRequest(new URLSearchParams({action:"fluent_cart_confirm_paypal_vault_setup",setup_token:s.vaultSetupToken,ref_id:(d=e==null?void 0:e.data)!=null&&d.transaction.uuid?(l=e==null?void 0:e.data)==null?void 0:l.transaction.uuid:t.$t("uuid not found"),mode:c}))},onCancel:s=>{var i,d;(i=t.paymentLoader)==null||i.changeLoaderStatus("canceled"),(d=t.paymentLoader)==null||d.hideLoader(),t.paymentLoader.enableCheckoutButton()},onError:s=>{t.handlePaypalError(s,e)},onClick:async function(s,i){var d,l,m,u;if(typeof o.orderHandler=="function"){let y=await o.orderHandler();if(!y)return(d=t.paymentLoader)==null||d.changeLoaderStatus(t.$t("Order creation failed")),(l=t.paymentLoader)==null||l.hideLoader(),i.reject();e=y}else return(m=t.paymentLoader)==null||m.changeLoaderStatus(t.$t("Not proper order handler")),(u=t.paymentLoader)==null||u.hideLoader(),i.reject()}});this.finalizeButtonsRender(p,a)}async subscriptionPaymentHandler(o,r,e,a){const t=this,c=new URLSearchParams(window.location.search).get("mode")||"order",p=paypal.Buttons({style:{shape:"pill",layout:"vertical",label:"paypal",size:"responsive",disableMaxWidth:!0},createSubscription:function(s,i){return i.subscription.create({plan_id:e.response.planId,custom_id:e.data.subscription.uuid,application_context:{shipping_preference:"NO_SHIPPING"}})},onApprove:function(s,i){var d,l,m,u,y;(d=t.paymentLoader)==null||d.changeLoaderStatus("confirming"),s.subscriptionID?((l=t.paymentLoader)==null||l.changeLoaderStatus("completed"),t.sendConfirmationRequest(new URLSearchParams({action:"fluent_cart_confirm_paypal_subscription",order_id:s.orderID,subscription_id:s.subscriptionID,ref_id:(m=e==null?void 0:e.data)==null?void 0:m.transaction.uuid,mode:c}))):((u=t.paymentLoader)==null||u.changeLoaderStatus(t.$t("No Subscription ID")),(y=t.paymentLoader)==null||y.hideLoader())},onCancel:s=>{var i,d;(i=t.paymentLoader)==null||i.changeLoaderStatus("canceled"),(d=t.paymentLoader)==null||d.hideLoader(),t.paymentLoader.enableCheckoutButton()},onShippingChange(s,i){return i.resolve()},onClick:async function(s,i){var d,l,m,u,y;if((d=t.paymentLoader)==null||d.changeLoaderStatus(t.$t("no processing")),typeof o.orderHandler=="function"){let _=await o.orderHandler();if(!_)return(l=t.paymentLoader)==null||l.changeLoaderStatus(t.$t("Order creation failed")),(m=t.paymentLoader)==null||m.hideLoader(),i.reject();e=_}else return(u=t.paymentLoader)==null||u.changeLoaderStatus(t.$t("not proper order handler")),(y=t.paymentLoader)==null||y.hideLoader(),i.reject()},onError:function(s){t.handlePaypalError(s,e)}});this.finalizeButtonsRender(p,a)}renderSetupUnavailable(o){this.renderPaymentMethodFailure(o,this.$t("PayPal is temporarily unavailable for this checkout. Please choose another payment method or try again later."))}renderPaymentMethodFailure(o,r){const e=this.form.querySelector(".fluent_cart_payment_methods");e&&(e.style.display="");const a=document.createElement("div");a.style.color="red",a.className="fct-error-message",a.textContent=r||this.$t("An error occurred while loading PayPal."),o.appendChild(a);const t=document.getElementById("fct_loading_payment_processor");t&&t.remove(),window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading_failed",{detail:{payment_method:"paypal"}}))}handlePaypalError(o,r){var a,t;let e=this.$t("An unknown error occurred");if(o!=null&&o.message)try{const n=o.message.match(/{.*}/s);n?e=JSON.parse(n[0]).message||e:e=o.message}catch{e=o.message||e}(a=this.paymentLoader)==null||a.changeLoaderStatus(o),(t=this.paymentLoader)==null||t.hideLoader(),this.paymentLoader.enableCheckoutButton()}}window.addEventListener("fluent_cart_load_payments_paypal",function(h){window.dispatchEvent(new CustomEvent("fluent_cart_payment_method_loading",{detail:{payment_method:"paypal"}})),window.fluentcart.$t,r(),fetch(h.detail.paymentInfoUrl,{method:"POST",headers:{"Content-Type":"application/json","X-WP-Nonce":h.detail.nonce},credentials:"include"}).then(async e=>{e=await e.json(),(e==null?void 0:e.status)==="failed"&&o(e==null?void 0:e.message),new L(h.detail.form,h.detail.orderHandler,e,h.detail.paymentLoader).init()}).catch(e=>{var c;const a=((c=window.fct_paypal_data)==null?void 0:c.translations)||{};function t(p){return a[p]||p}let n=(e==null?void 0:e.message)||t("An error occurred while loading PayPal.");o(n)});function o(e){const a=document.createElement("div");a.style.color="red",a.className="fct-error-message",a.textContent=e,document.querySelector(".fluent-cart-checkout_embed_payment_container_paypal").appendChild(a);const n=document.getElementById("fct_loading_payment_processor");n&&n.remove()}function r(){var c;let e=document.querySelector(".fluent-cart-checkout_embed_payment_container_paypal");const a=document.createElement("p");a.id="fct_loading_payment_processor";const t=((c=window.fct_paypal_data)==null?void 0:c.translations)||{};function n(p){return t[p]||p}a.textContent=n("Loading Payment Processor..."),e.appendChild(a)}})})();