FileMaster
Search
Toggle Dark Mode
Home
/
.
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
components
Edit File: sc-order.js
import{proxyCustomElement,HTMLElement,h,Fragment}from"@stencil/core/internal/client";import{a as apiFetch}from"./fetch.js";import{o as onFirstVisible}from"./lazy.js";import{f as formatTaxDisplay}from"./tax.js";import{d as defineCustomElement$s}from"./sc-alert2.js";import{d as defineCustomElement$r}from"./sc-block-ui2.js";import{d as defineCustomElement$q}from"./sc-button2.js";import{d as defineCustomElement$p}from"./sc-card2.js";import{d as defineCustomElement$o}from"./sc-cc-logo2.js";import{d as defineCustomElement$n}from"./sc-dashboard-module2.js";import{d as defineCustomElement$m}from"./sc-divider2.js";import{d as defineCustomElement$l}from"./sc-empty2.js";import{d as defineCustomElement$k}from"./sc-flex2.js";import{d as defineCustomElement$j}from"./sc-format-bytes2.js";import{d as defineCustomElement$i}from"./sc-icon2.js";import{d as defineCustomElement$h}from"./sc-line-item2.js";import{d as defineCustomElement$g}from"./sc-order-manual-instructions2.js";import{d as defineCustomElement$f}from"./sc-order-status-badge2.js";import{d as defineCustomElement$e}from"./sc-payment-method2.js";import{d as defineCustomElement$d}from"./sc-product-line-item2.js";import{d as defineCustomElement$c}from"./sc-product-line-item-note2.js";import{d as defineCustomElement$b}from"./sc-purchase-downloads-list2.js";import{d as defineCustomElement$a}from"./sc-quantity-select2.js";import{d as defineCustomElement$9}from"./sc-skeleton2.js";import{d as defineCustomElement$8}from"./sc-spacing2.js";import{d as defineCustomElement$7}from"./sc-spinner2.js";import{d as defineCustomElement$6}from"./sc-stacked-list2.js";import{d as defineCustomElement$5}from"./sc-stacked-list-row2.js";import{d as defineCustomElement$4}from"./sc-tag2.js";import{d as defineCustomElement$3}from"./sc-text2.js";import{d as defineCustomElement$2}from"./sc-tooltip2.js";import{a as addQueryArgs}from"./add-query-args.js";const scOrderCss=":host{display:block}.order__row{padding:var(--sc-spacing-large);display:grid;gap:var(--sc-spacing-small)}",ScOrderStyle0=scOrderCss,ScOrder$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.orderId=void 0,this.customerIds=void 0,this.heading=void 0,this.order=void 0,this.purchases=void 0,this.loading=void 0,this.busy=void 0,this.error=void 0}componentDidLoad(){onFirstVisible(this.el,(()=>{this.fetchOrder(),this.fetchDownloads()}))}async fetchOrder(){try{this.loading=!0,await this.getOrder()}catch(e){console.error(this.error),this.error=(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.loading=!1}}async fetchDownloads(){try{this.busy=!0,this.purchases=await apiFetch({path:addQueryArgs("surecart/v1/purchases",{expand:["product","product.downloads","download.media"],order_ids:[this.orderId],customer_ids:this.customerIds,downloadable:!0})})}catch(e){console.error(this.error),this.error=(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.busy=!1}}async getOrder(){this.order=await apiFetch({path:addQueryArgs(`surecart/v1/orders/${this.orderId}`,{expand:["checkout","checkout.checkout_fees","checkout.shipping_fees","checkout.line_items","line_item.price","line_item.fees","line_item.variant","variant.image","price.product","checkout.manual_payment_method","checkout.payment_method","checkout.selected_shipping_choice","shipping_choice.shipping_method","payment_method.card","payment_method.payment_instrument","payment_method.paypal_account","payment_method.bank_account","checkout.discount","discount.promotion","checkout.charge"]})})}renderLoading(){return h("sc-flex",{flexDirection:"column",style:{gap:"1em"}},h("sc-skeleton",{style:{width:"20%",display:"inline-block"}}),h("sc-skeleton",{style:{width:"60%",display:"inline-block"}}),h("sc-skeleton",{style:{width:"40%",display:"inline-block"}}))}renderCheckoutFees(e){var t,s,i,o;return(null===(s=null===(t=null==e?void 0:e.checkout_fees)||void 0===t?void 0:t.data)||void 0===s?void 0:s.length)?h(Fragment,null,null===(o=null===(i=null==e?void 0:e.checkout_fees)||void 0===i?void 0:i.data)||void 0===o?void 0:o.map((e=>h("sc-line-item",{key:e.id},h("span",{slot:"description"},e.description),h("span",{slot:"price"},e.display_amount))))):null}renderShippingFees(e){var t,s,i,o;return(null===(s=null===(t=null==e?void 0:e.shipping_fees)||void 0===t?void 0:t.data)||void 0===s?void 0:s.length)?h(Fragment,null,null===(o=null===(i=null==e?void 0:e.shipping_fees)||void 0===i?void 0:i.data)||void 0===o?void 0:o.map((e=>h("sc-line-item",{key:e.id},h("span",{slot:"description"},e.description),h("span",{slot:"price"},e.display_amount))))):null}renderEmpty(){return h("sc-empty",{icon:"shopping-bag"},wp.i18n.__("Order not found.","surecart"))}renderContent(){var e,t,s,i,o,n,l,a;if(this.loading)return this.renderLoading();if(!(null===(e=this.order)||void 0===e?void 0:e.id))return this.renderEmpty();const r=null===(t=this.order)||void 0===t?void 0:t.checkout,d=null===(s=null==r?void 0:r.selected_shipping_choice)||void 0===s?void 0:s.shipping_method,c=null==d?void 0:d.name;return h(Fragment,null,((null===(i=null==r?void 0:r.line_items)||void 0===i?void 0:i.data)||[]).map((e=>{var t,s,i,o,n,l;const a=null===(t=null==e?void 0:e.price)||void 0===t?void 0:t.product;return h("sc-product-line-item",{key:e.id,image:null==e?void 0:e.image,name:null==a?void 0:a.name,price:null===(s=null==e?void 0:e.price)||void 0===s?void 0:s.name,variant:null==e?void 0:e.variant_display_options,editable:!1,removable:!1,quantity:e.quantity,note:null==e?void 0:e.display_note,amount:e.subtotal_display_amount,trial:null===(i=null==e?void 0:e.price)||void 0===i?void 0:i.trial_text,interval:`${null===(o=null==e?void 0:e.price)||void 0===o?void 0:o.short_interval_text} ${null===(n=null==e?void 0:e.price)||void 0===n?void 0:n.short_interval_count_text}`,scratch:null==e?void 0:e.scratch_display_amount,purchasableStatus:null==e?void 0:e.purchasable_status_display,fees:null===(l=null==e?void 0:e.fees)||void 0===l?void 0:l.data,reviewButtonLink:(null==a?void 0:a.review_url)||""})})),(null==r?void 0:r.subtotal_amount)!==(null==r?void 0:r.total_amount)&&h("sc-line-item",null,h("span",{slot:"description"},wp.i18n.__("Subtotal","surecart")),h("span",{slot:"price",style:{"font-weight":"var(--sc-font-weight-semibold)",color:"var(--sc-color-gray-800)"}},null==r?void 0:r.subtotal_display_amount)),this.renderCheckoutFees(r),!!(null==r?void 0:r.trial_amount)&&h("sc-line-item",null,h("span",{slot:"description"},wp.i18n.__("Trial","surecart")),h("span",{slot:"price",style:{"font-weight":"var(--sc-font-weight-semibold)",color:"var(--sc-color-gray-800)"}},null==r?void 0:r.trial_display_amount)),!!(null==r?void 0:r.discounts)&&h("sc-line-item",null,h("span",{slot:"description"},wp.i18n.__("Discounts","surecart")),h("span",{slot:"price",style:{"font-weight":"var(--sc-font-weight-semibold)",color:"var(--sc-color-gray-800)"}},null==r?void 0:r.discounts_display)),!!(null===(n=null===(o=null==r?void 0:r.discount)||void 0===o?void 0:o.promotion)||void 0===n?void 0:n.code)&&h("sc-line-item",null,h("span",{slot:"description"},wp.i18n.__("Discount","surecart"),h("br",null),h("sc-tag",{type:"success"},wp.i18n.__("Coupon:","surecart")," ",null===(a=null===(l=null==r?void 0:r.discount)||void 0===l?void 0:l.promotion)||void 0===a?void 0:a.code)),h("span",{slot:"price",style:{"font-weight":"var(--sc-font-weight-semibold)",color:"var(--sc-color-gray-800)"}},null==r?void 0:r.discounts_display_amount)),!!(null==r?void 0:r.shipping_amount)&&h(Fragment,null,h("sc-line-item",null,h("span",{slot:"description"},`${wp.i18n.__("Shipping","surecart")} ${c?`(${c})`:""}`),h("span",{slot:"price",style:{"font-weight":"var(--sc-font-weight-semibold)",color:"var(--sc-color-gray-800)"}},null==r?void 0:r.shipping_display_amount)),this.renderShippingFees(r)),!!(null==r?void 0:r.tax_amount)&&h("sc-line-item",null,h("span",{slot:"description"},`${formatTaxDisplay(null==r?void 0:r.tax_label,"estimated"===(null==r?void 0:r.tax_status))} (${null==r?void 0:r.tax_percent}%)`),h("span",{slot:"price"},null==r?void 0:r.tax_display_amount),!!(null==r?void 0:r.tax_inclusive_amount)&&h("span",{slot:"price-description"},`(${wp.i18n.__("included","surecart")})`)),h("sc-divider",{style:{"--spacing":"var(--sc-spacing-x-small)"}}),h("sc-line-item",{style:{width:"100%","--price-size":"var(--sc-font-size-x-large)"}},h("span",{slot:"title"},wp.i18n.__("Total","surecart")),h("span",{slot:"price"},null==r?void 0:r.total_display_amount),h("span",{slot:"currency"},null==r?void 0:r.currency)),!!(null==r?void 0:r.proration_amount)&&h("sc-line-item",null,h("span",{slot:"description"},wp.i18n.__("Proration","surecart")),h("span",{slot:"price",style:{"font-weight":"var(--sc-font-weight-semibold)",color:"var(--sc-color-gray-800)"}},null==r?void 0:r.proration_display_amount)),!!(null==r?void 0:r.applied_balance_amount)&&h("sc-line-item",null,h("span",{slot:"description"},wp.i18n.__("Applied Balance","surecart")),h("span",{style:{"font-weight":"var(--sc-font-weight-semibold)",color:"var(--sc-color-gray-800)"},slot:"price"},null==r?void 0:r.applied_balance_display_amount)),!!(null==r?void 0:r.credited_balance_amount)&&h("sc-line-item",null,h("span",{slot:"description"},wp.i18n.__("Credited Balance","surecart")),h("span",{slot:"price",style:{"font-weight":"var(--sc-font-weight-semibold)",color:"var(--sc-color-gray-800)"}},null==r?void 0:r.credited_balance_display_amount)),(null==r?void 0:r.amount_due)!==(null==r?void 0:r.total_amount)&&h("sc-line-item",{style:{width:"100%","--price-size":"var(--sc-font-size-x-large)"}},h("span",{slot:"title"},wp.i18n.__("Amount Due","surecart")),h("span",{slot:"price"},null==r?void 0:r.amount_due_display_amount),h("span",{slot:"currency"},null==r?void 0:r.currency)),h("sc-divider",{style:{"--spacing":"var(--sc-spacing-x-small)"}}),!!(null==r?void 0:r.paid_amount)&&h("sc-line-item",{style:{width:"100%","--price-size":"var(--sc-font-size-x-large)"}},h("span",{slot:"title"},wp.i18n.__("Paid","surecart")),h("span",{slot:"price"},null==r?void 0:r.paid_display_amount),h("span",{slot:"currency"},null==r?void 0:r.currency)),!!(null==r?void 0:r.refunded_amount)&&h(Fragment,null,h("sc-line-item",{style:{width:"100%","--price-size":"var(--sc-font-size-x-large)"}},h("span",{slot:"description"},wp.i18n.__("Refunded","surecart")),h("span",{slot:"price"},null==r?void 0:r.refunded_display_amount)),h("sc-line-item",{style:{width:"100%","--price-size":"var(--sc-font-size-x-large)"}},h("span",{slot:"title"},wp.i18n.__("Net Payment","surecart")),h("span",{slot:"price"},null==r?void 0:r.net_paid_display_amount))),(null==r?void 0:r.tax_reverse_charged_amount)>0&&h("sc-line-item",null,h("span",{slot:"description"},wp.i18n.__("*Tax to be paid on reverse charge basis","surecart"))))}render(){var e,t,s,i,o,n,l;const a=null===(e=null==this?void 0:this.order)||void 0===e?void 0:e.checkout,r=null==a?void 0:a.manual_payment_method;return h("sc-spacing",{key:"7baa9d8769ea98769a3f14a60f1985be2ce82174",style:{"--spacing":"var(--sc-spacing-large)"}},h("sc-dashboard-module",{key:"a0d98170ed638ea4ac6a90887d1c0df85471b147",error:this.error},h("span",{key:"14bcd2638c59c7e77372166ea4e60b1094a098cc",slot:"heading"},this.loading?h("sc-skeleton",{style:{width:"120px"}}):`#${null===(t=null==this?void 0:this.order)||void 0===t?void 0:t.number}`),!this.loading&&!(null==a?void 0:a.live_mode)&&h("sc-tag",{key:"1dd3d392b038a493a88fbf2f1448d0097ac31425",type:"warning",slot:"end"},wp.i18n.__("Test Mode","surecart")),!!(null==r?void 0:r.name)&&!!(null==r?void 0:r.instructions)&&h("sc-order-manual-instructions",{key:"a2eafd910a50861caa870fcd1eddd084fab4684b",manualPaymentTitle:null==r?void 0:r.name,manualPaymentInstructions:null==r?void 0:r.instructions}),h("sc-card",{key:"5323d081c8d7640fed4ff3faeb9f1edb0f3b32fe","no-padding":!this.loading},this.loading?this.renderLoading():h(Fragment,null,h("sc-stacked-list",null,h("sc-stacked-list-row",{style:{"--columns":"2"}},h("div",null,wp.i18n.__("Order Status","surecart")),h("sc-order-status-badge",{status:null===(s=null==this?void 0:this.order)||void 0===s?void 0:s.status})),h("sc-stacked-list-row",{style:{"--columns":"2"}},h("div",null,wp.i18n.__("Date","surecart")),h("span",null,null===(i=this.order)||void 0===i?void 0:i.created_at_date)),h("sc-stacked-list-row",{style:{"--columns":"2"}},h("div",null,wp.i18n.__("Payment Method","surecart")),h("sc-payment-method",{paymentMethod:null==a?void 0:a.payment_method})),h("div",{class:"order__row"},this.renderContent()))))),(null===(o=this.order)||void 0===o?void 0:o.statement_url)&&h("sc-button",{key:"b2b44c9f352c13b601ba2dabd0f32a1508494527",type:"primary",href:null===(n=this.order)||void 0===n?void 0:n.statement_url,target:"_blank"},h("sc-icon",{key:"4b51d32370d7f669e41333f9046cf81d97a2b4f6",name:"inbox",slot:"prefix"}),wp.i18n.__("Download Receipt/Invoice","surecart")),!!(null===(l=this.purchases)||void 0===l?void 0:l.length)&&h("sc-purchase-downloads-list",{key:"c6160a917a46bc4dc49de6cc04aeae135895ded6",heading:wp.i18n.__("Downloads","surecart"),purchases:this.purchases}))}get el(){return this}static get style(){return ScOrderStyle0}},[1,"sc-order",{orderId:[1,"order-id"],customerIds:[16],heading:[1],order:[32],purchases:[32],loading:[32],busy:[32],error:[32]}]);function defineCustomElement$1(){"undefined"!=typeof customElements&&["sc-order","sc-alert","sc-block-ui","sc-button","sc-card","sc-cc-logo","sc-dashboard-module","sc-divider","sc-empty","sc-flex","sc-format-bytes","sc-icon","sc-line-item","sc-order-manual-instructions","sc-order-status-badge","sc-payment-method","sc-product-line-item","sc-product-line-item-note","sc-purchase-downloads-list","sc-quantity-select","sc-skeleton","sc-spacing","sc-spinner","sc-stacked-list","sc-stacked-list-row","sc-tag","sc-text","sc-tooltip"].forEach((e=>{switch(e){case"sc-order":customElements.get(e)||customElements.define(e,ScOrder$1);break;case"sc-alert":customElements.get(e)||defineCustomElement$s();break;case"sc-block-ui":customElements.get(e)||defineCustomElement$r();break;case"sc-button":customElements.get(e)||defineCustomElement$q();break;case"sc-card":customElements.get(e)||defineCustomElement$p();break;case"sc-cc-logo":customElements.get(e)||defineCustomElement$o();break;case"sc-dashboard-module":customElements.get(e)||defineCustomElement$n();break;case"sc-divider":customElements.get(e)||defineCustomElement$m();break;case"sc-empty":customElements.get(e)||defineCustomElement$l();break;case"sc-flex":customElements.get(e)||defineCustomElement$k();break;case"sc-format-bytes":customElements.get(e)||defineCustomElement$j();break;case"sc-icon":customElements.get(e)||defineCustomElement$i();break;case"sc-line-item":customElements.get(e)||defineCustomElement$h();break;case"sc-order-manual-instructions":customElements.get(e)||defineCustomElement$g();break;case"sc-order-status-badge":customElements.get(e)||defineCustomElement$f();break;case"sc-payment-method":customElements.get(e)||defineCustomElement$e();break;case"sc-product-line-item":customElements.get(e)||defineCustomElement$d();break;case"sc-product-line-item-note":customElements.get(e)||defineCustomElement$c();break;case"sc-purchase-downloads-list":customElements.get(e)||defineCustomElement$b();break;case"sc-quantity-select":customElements.get(e)||defineCustomElement$a();break;case"sc-skeleton":customElements.get(e)||defineCustomElement$9();break;case"sc-spacing":customElements.get(e)||defineCustomElement$8();break;case"sc-spinner":customElements.get(e)||defineCustomElement$7();break;case"sc-stacked-list":customElements.get(e)||defineCustomElement$6();break;case"sc-stacked-list-row":customElements.get(e)||defineCustomElement$5();break;case"sc-tag":customElements.get(e)||defineCustomElement$4();break;case"sc-text":customElements.get(e)||defineCustomElement$3();break;case"sc-tooltip":customElements.get(e)||defineCustomElement$2()}}))}const ScOrder=ScOrder$1,defineCustomElement=defineCustomElement$1;export{ScOrder,defineCustomElement};
Save
Back