JezK
Edit File: sc-order-confirm-provider2.js
import{proxyCustomElement,HTMLElement,createEvent,h,Host}from"@stencil/core/internal/client";import{s as speak}from"./index2.js";import"./fetch.js";import{e as expand}from"./index5.js";import{s as state}from"./mutations2.js";import{s as state$1}from"./store4.js";import{c as createErrorNotice}from"./mutations3.js";import{c as clearCheckout}from"./mutations4.js";import{d as defineCustomElement$6}from"./sc-alert2.js";import{d as defineCustomElement$5}from"./sc-button2.js";import{d as defineCustomElement$4}from"./sc-dashboard-module2.js";import{d as defineCustomElement$3}from"./sc-dialog2.js";import{d as defineCustomElement$2}from"./sc-icon2.js";import{d as defineCustomElement$1}from"./sc-spinner2.js";import{a as addQueryArgs}from"./add-query-args.js";import{a as apiFetch}from"./index4.js";const scOrderConfirmProviderCss=".confirm__icon{margin-bottom:var(--sc-spacing-medium);display:flex;justify-content:center}.confirm__icon-container{background:var(--sc-color-primary-500);width:55px;height:55px;border-radius:999999px;display:flex;align-items:center;justify-content:center;font-size:26px;line-height:1;color:white}sc-dialog::part(overlay){backdrop-filter:blur(4px)}",ScOrderConfirmProviderStyle0=scOrderConfirmProviderCss,ScOrderConfirmProvider=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.scOrderPaid=createEvent(this,"scOrderPaid",7),this.scSetState=createEvent(this,"scSetState",7),this.showSuccessModal=!1,this.manualPaymentMethod=void 0,this.checkoutStatus=void 0,this.successUrl=void 0}handleConfirmOrderEvent(){"confirming"===this.checkoutStatus?this.confirmOrder():"confirmed"===this.checkoutStatus&&speak(wp.i18n.__("Order has been confirmed. Please select continue to go to the next step.","surecart"))}async confirmOrder(){var e,t,s,o;try{state.checkout=await apiFetch({method:"PATCH",path:addQueryArgs(`surecart/v1/checkouts/${null===(e=null==state?void 0:state.checkout)||void 0===e?void 0:e.id}/confirm`,{expand:expand})}),this.scSetState.emit("CONFIRMED")}catch(e){console.error(e),createErrorNotice(e)}finally{this.manualPaymentMethod=(null===(t=state.checkout)||void 0===t?void 0:t.manual_payment_method)||null;const e=state.checkout,c=state.formId;if(null===(s=null==e?void 0:e.current_upsell)||void 0===s?void 0:s.permalink)return setTimeout((()=>{var t;return window.location.assign(addQueryArgs(null===(t=null==e?void 0:e.current_upsell)||void 0===t?void 0:t.permalink,{sc_checkout_id:null==e?void 0:e.id,sc_form_id:c}))}),50),void clearCheckout();const i=(null===(o=null==e?void 0:e.metadata)||void 0===o?void 0:o.success_url)||this.successUrl;if(i){this.scSetState.emit("REDIRECT");const t=addQueryArgs(i,{sc_order:null==e?void 0:e.id});setTimeout((()=>window.location.assign(t)),50)}else this.showSuccessModal=!0;clearCheckout()}}getSuccessUrl(){var e,t,s,o,c;const i=(null===(t=null===(e=state.checkout)||void 0===e?void 0:e.metadata)||void 0===t?void 0:t.success_url)||this.successUrl;return i?addQueryArgs(i,{sc_order:null===(s=state.checkout)||void 0===s?void 0:s.id}):null===(c=null===(o=null===window||void 0===window?void 0:window.scData)||void 0===o?void 0:o.pages)||void 0===c?void 0:c.dashboard}handleSuccessModal(){this.showSuccessModal&&setTimeout((()=>{var e;null===(e=this.continueButton)||void 0===e||e.focus()}),50)}render(){var e,t,s,o,c,i,r,n,a,d;return h(Host,{key:"23ea682f197a8dba118628be80b95fcd6bca042f"},h("slot",{key:"b49138493aa4b86147ca69fec428dab62af8fd82"}),h("sc-dialog",{key:"f9fb9fe80452e7d397f7b4b5d639615ffde6f5d9",open:!!this.showSuccessModal,style:{"--body-spacing":"var(--sc-spacing-xxx-large)","--width":"400px"},noHeader:!0,onScRequestClose:e=>e.preventDefault()},h("div",{key:"70ce3e2764616a1ec685e5176f41e2381c462f82",class:"confirm__icon"},h("div",{key:"8b07ac141660edbdca3855473b0060e37d40955c",class:"confirm__icon-container"},h("sc-icon",{key:"dd3362a844697ae077420671c82ad0b5658cbff8",name:"check"}))),h("sc-dashboard-module",{key:"178cb4426acb703c033eb0769498ac0de8763ef6",heading:(null===(t=null===(e=null==state$1?void 0:state$1.text)||void 0===e?void 0:e.success)||void 0===t?void 0:t.title)||wp.i18n.__("Thanks for your order!","surecart"),style:{"--sc-dashboard-module-spacing":"var(--sc-spacing-x-large)",textAlign:"center"}},h("span",{key:"44b6d8fcf9dbebdfdc0cbc351fa899a69eb47466",slot:"description"},(null===(o=null===(s=null==state$1?void 0:state$1.text)||void 0===s?void 0:s.success)||void 0===o?void 0:o.description)||wp.i18n.__("Your payment was successful. A receipt is on its way to your inbox.","surecart")),!!(null===(c=this.manualPaymentMethod)||void 0===c?void 0:c.name)&&!!(null===(i=this.manualPaymentMethod)||void 0===i?void 0:i.instructions)&&h("sc-alert",{key:"7d464418bcd7baa53b6145843a431c3625cdc15d",type:"info",open:!0,style:{"text-align":"left"}},h("span",{key:"5b4278490c3c21116ec9e83b625a04acf743f251",slot:"title"},null===(r=this.manualPaymentMethod)||void 0===r?void 0:r.name),h("div",{key:"61c09fb86c656dc77acb31c56d68f10e7e50b2e7",innerHTML:null===(n=this.manualPaymentMethod)||void 0===n?void 0:n.instructions})),h("sc-button",{key:"77d3d960fbd46b5a951d321ee201f34835aed439",href:this.getSuccessUrl(),size:"large",type:"primary",ref:e=>this.continueButton=e},(null===(d=null===(a=null==state$1?void 0:state$1.text)||void 0===a?void 0:a.success)||void 0===d?void 0:d.button)||wp.i18n.__("Continue","surecart"),h("sc-icon",{key:"80b3621d1cf7e6669f7ff471f6fc024f5378b4d8",name:"arrow-right",slot:"suffix"})))))}get el(){return this}static get watchers(){return{checkoutStatus:["handleConfirmOrderEvent"],showSuccessModal:["handleSuccessModal"]}}static get style(){return ScOrderConfirmProviderStyle0}},[1,"sc-order-confirm-provider",{checkoutStatus:[1,"checkout-status"],successUrl:[1,"success-url"],showSuccessModal:[32],manualPaymentMethod:[32]},void 0,{checkoutStatus:["handleConfirmOrderEvent"],showSuccessModal:["handleSuccessModal"]}]);function defineCustomElement(){"undefined"!=typeof customElements&&["sc-order-confirm-provider","sc-alert","sc-button","sc-dashboard-module","sc-dialog","sc-icon","sc-spinner"].forEach((e=>{switch(e){case"sc-order-confirm-provider":customElements.get(e)||customElements.define(e,ScOrderConfirmProvider);break;case"sc-alert":customElements.get(e)||defineCustomElement$6();break;case"sc-button":customElements.get(e)||defineCustomElement$5();break;case"sc-dashboard-module":customElements.get(e)||defineCustomElement$4();break;case"sc-dialog":customElements.get(e)||defineCustomElement$3();break;case"sc-icon":customElements.get(e)||defineCustomElement$2();break;case"sc-spinner":customElements.get(e)||defineCustomElement$1()}}))}export{ScOrderConfirmProvider as S,defineCustomElement as d};