FileMaster
Search
Toggle Dark Mode
Home
/
.
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
components
Edit File: sc-upcoming-invoice.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{p as productNameWithPrice}from"./price.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-coupon-form2.js";import{d as defineCustomElement$m}from"./sc-dashboard-module2.js";import{d as defineCustomElement$l}from"./sc-divider2.js";import{d as defineCustomElement$k}from"./sc-flex2.js";import{d as defineCustomElement$j}from"./sc-form2.js";import{d as defineCustomElement$i}from"./sc-form-control2.js";import{d as defineCustomElement$h}from"./sc-format-number2.js";import{d as defineCustomElement$g}from"./sc-icon2.js";import{d as defineCustomElement$f}from"./sc-input2.js";import{d as defineCustomElement$e}from"./sc-line-item2.js";import{d as defineCustomElement$d}from"./sc-manual-payment-method2.js";import{d as defineCustomElement$c}from"./sc-payment-method2.js";import{d as defineCustomElement$b}from"./sc-product-line-item2.js";import{d as defineCustomElement$a}from"./sc-product-line-item-note2.js";import{d as defineCustomElement$9}from"./sc-prose2.js";import{d as defineCustomElement$8}from"./sc-quantity-select2.js";import{d as defineCustomElement$7}from"./sc-skeleton2.js";import{d as defineCustomElement$6}from"./sc-spinner2.js";import{d as defineCustomElement$5}from"./sc-tag2.js";import{d as defineCustomElement$4}from"./sc-text2.js";import{d as defineCustomElement$3}from"./sc-tooltip2.js";import{d as defineCustomElement$2}from"./sc-visually-hidden2.js";import{a as addQueryArgs}from"./add-query-args.js";const scUpcomingInvoiceCss=":host{display:block;position:relative}.upcoming-invoice{display:grid;gap:var(--sc-spacing-large)}.upcoming-invoice>*{display:grid;gap:var(--sc-spacing-medium)}.new-plan{display:grid;gap:0.25em;color:var(--sc-input-label-color)}.new-plan__heading{font-weight:var(--sc-font-weight-bold)}",ScUpcomingInvoiceStyle0=scUpcomingInvoiceCss,ScUpcomingInvoice$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.heading=void 0,this.successUrl=void 0,this.subscriptionId=void 0,this.priceId=void 0,this.variantId=void 0,this.quantity=void 0,this.discount=void 0,this.payment_method=void 0,this.quantityUpdatesEnabled=!0,this.adHocAmount=void 0,this.loading=void 0,this.busy=void 0,this.error=void 0,this.price=void 0,this.invoice=void 0,this.couponError=void 0}componentWillLoad(){onFirstVisible(this.el,(()=>{this.fetchItems()}))}isFutureInvoice(){return this.invoice.start_at>=(new Date).getTime()/1e3}async fetchItems(){var e,t;try{this.loading=!0,await Promise.all([this.getInvoice(),this.getPrice()])}catch(s){console.error(s),this.error=(null===(t=null===(e=null==s?void 0:s.additional_errors)||void 0===e?void 0:e[0])||void 0===t?void 0:t.message)||(null==s?void 0:s.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.loading=!1}}async getPrice(){this.priceId&&(this.price=await apiFetch({path:addQueryArgs(`surecart/v1/prices/${this.priceId}`,{expand:["product"]})}))}async getInvoice(){if(this.subscriptionId)return this.invoice=await apiFetch({method:"PATCH",path:addQueryArgs(`surecart/v1/subscriptions/${this.subscriptionId}/upcoming_period/`,{expand:["period.checkout","checkout.line_items","checkout.checkout_fees","checkout.shipping_fees","line_item.price","line_item.fees","price.product","checkout.payment_method","checkout.manual_payment_method","checkout.discount","discount.promotion","discount.coupon","payment_method.card","payment_method.payment_instrument","payment_method.paypal_account","payment_method.bank_account"]}),data:{price:this.priceId,variant:this.variantId,quantity:this.quantity,...this.adHocAmount?{ad_hoc_amount:this.adHocAmount}:{},...this.discount?{discount:this.discount}:{}}}),this.invoice}async applyCoupon(e){try{this.couponError="",this.busy=!0,this.discount={promotion_code:e.detail},await this.getInvoice()}catch(e){this.couponError=(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.busy=!1}}async updateQuantity(e){try{this.error="",this.busy=!0,this.quantity=e.detail,await this.getInvoice()}catch(e){this.error=(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.busy=!1}}async onSubmit(){try{this.error="",this.busy=!0,await apiFetch({path:`surecart/v1/subscriptions/${this.subscriptionId}`,method:"PATCH",data:{price:this.priceId,quantity:this.quantity,variant:this.variantId,...this.adHocAmount?{ad_hoc_amount:this.adHocAmount}:{},...this.discount?{discount:this.discount}:{}}}),this.successUrl?window.location.assign(this.successUrl):this.busy=!1}catch(e){this.error=(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart"),this.busy=!1}}renderName(e){return"string"!=typeof(null==e?void 0:e.product)?productNameWithPrice(e):wp.i18n.__("Plan","surecart")}renderRenewalText(){var e;return this.isFutureInvoice()?h("div",null,wp.i18n.__("You'll be switched to this plan","surecart")," ",h("strong",null,wp.i18n.__("at the end of your billing cycle on","surecart")," ",null===(e=this.invoice)||void 0===e?void 0:e.start_at_date)):h("div",null,wp.i18n.__("You'll be switched to this plan","surecart")," ",h("strong",null,wp.i18n.__("immediately","surecart")))}renderEmpty(){return h("slot",{name:"empty"},wp.i18n.__("Something went wrong.","surecart"))}renderLoading(){return h("div",null,h("sc-skeleton",{style:{width:"30%",marginBottom:"0.75em"}}),h("sc-skeleton",{style:{width:"20%",marginBottom:"0.75em"}}),h("sc-skeleton",{style:{width:"40%"}}))}renderContent(){var e;if(this.loading)return this.renderLoading();if(!(null===(e=this.invoice)||void 0===e?void 0:e.checkout))return this.renderEmpty();const t=this.invoice.checkout;return h("div",{class:"new-plan"},h("div",{class:"new-plan__heading"},this.renderName(this.price)),h("div",null,h("span",{slot:"price"},null==t?void 0:t.subtotal_display_amount)),h("div",{style:{fontSize:"var(--sc-font-size-small)"}},this.renderRenewalText()))}renderSummary(){var e,t,s,i;if(this.loading)return this.renderLoading();if(!this.invoice)return this.renderEmpty();const n=null===(e=this.invoice)||void 0===e?void 0:e.checkout,o=(null==n?void 0:n.manual_payment)?null==n?void 0:n.manual_payment_method:null,a=null===(t=null==n?void 0:n.checkout_fees)||void 0===t?void 0:t.data,c=null===(s=null==n?void 0:n.shipping_fees)||void 0===s?void 0:s.data;return h(Fragment,null,null===(i=null==n?void 0:n.line_items)||void 0===i?void 0:i.data.map((e=>{var t,s,i,n,o,a,c,r;return h("sc-product-line-item",{image:null===(s=null===(t=e.price)||void 0===t?void 0:t.product)||void 0===s?void 0:s.line_item_image,name:null===(n=null===(i=e.price)||void 0===i?void 0:i.product)||void 0===n?void 0:n.name,price:null===(o=null==e?void 0:e.price)||void 0===o?void 0:o.name,variant:null==e?void 0:e.variant_display_options,editable:this.quantityUpdatesEnabled,purchasableStatus:null==e?void 0:e.purchasable_status_display,removable:!1,note:null==e?void 0:e.display_note,quantity:null==e?void 0:e.quantity,amount:null==e?void 0:e.subtotal_display_amount,interval:`${null===(a=null==e?void 0:e.price)||void 0===a?void 0:a.short_interval_text} ${null===(c=null==e?void 0:e.price)||void 0===c?void 0:c.short_interval_count_text}`,onScUpdateQuantity:e=>this.updateQuantity(e),fees:null===(r=null==e?void 0:e.fees)||void 0===r?void 0:r.data})})),h("sc-line-item",null,h("span",{slot:"description"},wp.i18n.__("Subtotal","surecart")),h("span",{slot:"price"},null==n?void 0:n.subtotal_display_amount)),!!n.proration_amount&&h("sc-line-item",null,h("span",{slot:"description"},wp.i18n.__("Proration Credit","surecart")),h("span",{slot:"price"},null==n?void 0:n.proration_display_amount)),!!n.applied_balance_amount&&h("sc-line-item",null,h("span",{slot:"description"},wp.i18n.__("Applied Balance","surecart")),h("span",{slot:"price"},null==n?void 0:n.applied_balance_display_amount)),(null==a?void 0:a.length)>0&&h(Fragment,null,null==a?void 0:a.map((e=>h("sc-line-item",null,h("span",{slot:"description"},null==e?void 0:e.description),h("span",{slot:"price"},null==e?void 0:e.display_amount))))),!!n.trial_amount&&h("sc-line-item",null,h("span",{slot:"description"},wp.i18n.__("Trial","surecart")),h("span",{slot:"price"},null==n?void 0:n.trial_display_amount)),h("sc-coupon-form",{discount:null==n?void 0:n.discount,discountsDisplayAmount:null==n?void 0:n.discounts_display_amount,label:wp.i18n.__("Add Coupon Code","surecart"),onScApplyCoupon:e=>this.applyCoupon(e),error:this.couponError,collapsed:!0,buttonText:wp.i18n.__("Add Coupon Code","surecart")}),!!(null==n?void 0:n.shipping_amount)&&h(Fragment,null,h("sc-line-item",{style:{marginTop:"var(--sc-spacing-small)"}},h("span",{slot:"description"},wp.i18n.__("Shipping","surecart")),h("span",{slot:"price"},null==n?void 0:n.shipping_display_amount)),(null==c?void 0:c.length)>0&&h(Fragment,null,null==c?void 0:c.map((e=>h("sc-line-item",null,h("span",{slot:"description"},null==e?void 0:e.description),h("span",{slot:"price"},null==e?void 0:e.display_amount)))))),!!n.tax_amount&&h("sc-line-item",null,h("span",{slot:"description"},formatTaxDisplay(null==n?void 0:n.tax_label)),h("span",{slot:"price"},null==n?void 0:n.tax_display_amount)),h("sc-divider",{style:{"--spacing":"0"}}),h("sc-line-item",null,h("span",{slot:"description"},wp.i18n.__("Payment","surecart")),h("a",{href:addQueryArgs(window.location.href,{action:"payment"}),slot:"price-description"},h("sc-flex",{"justify-content":"flex-start","align-items":"center",style:{"--spacing":"0.5em"}},!!o&&h("sc-manual-payment-method",{paymentMethod:o}),!o&&h("sc-payment-method",{paymentMethod:null==n?void 0:n.payment_method}),h("sc-icon",{name:"edit-3"})))),h("sc-line-item",{style:{"--price-size":"var(--sc-font-size-x-large)"}},h("span",{slot:"title"},wp.i18n.__("Total Due","surecart")),h("span",{slot:"price"},null==n?void 0:n.amount_due_display_amount),h("span",{slot:"currency"},n.currency)))}render(){return h("div",{key:"b10a3ae949447dc1819ccb05db85a7bc81b52736",class:"upcoming-invoice"},this.error&&h("sc-alert",{key:"566108b6e160d2435675ffb5636c73e6d7dff483",open:!!this.error,type:"danger"},h("span",{key:"847ccce5c4ac4d52eb546e5a7e56f23f615c26a7",slot:"title"},wp.i18n.__("Error","surecart")),this.error),h(Fragment,{key:"6adf9fff95502e4a523b15773c4acace46795bd7"},h("sc-dashboard-module",{key:"b82791688a0e35453cbe385b8e67c5cd031ecf6f",heading:wp.i18n.__("New Plan","surecart"),class:"plan-preview",error:this.error},h("sc-card",{key:"11e15e24b6932699ac8f3a309fb3febb7b088513"},this.renderContent())),h("sc-dashboard-module",{key:"d596f01b5b1a9d22070b87e0d4fb9ba426e3f997",heading:wp.i18n.__("Summary","surecart"),class:"plan-summary"},h("sc-form",{key:"857969b5d3dc420fe897e485e442a867927f1433",onScFormSubmit:()=>this.onSubmit()},h("sc-card",{key:"6b54b82af3c54a6ca7ffdeb34726ea80163909e5"},this.renderSummary()),h("sc-button",{key:"3796db232e4e4b38863a51b3f1d39259df176dd6",type:"primary",full:!0,submit:!0,loading:this.loading||this.busy,disabled:this.loading||this.busy},wp.i18n.__("Confirm","surecart")))),h("sc-text",{key:"04cbf28734337a138b1dc1ccbd15a6db73e4a793",style:{"--text-align":"center","--font-size":"var(--sc-font-size-small)","--line-height":"var(--sc-line-height-normal)"}},h("slot",{key:"31c98b3d458af68ea1d6eaf55d6ecbc338392805",name:"terms"}))),this.busy&&h("sc-block-ui",{key:"08c9d4aaaf3acd6d10278ef26421ac791b8ec5c5"}))}get el(){return this}static get style(){return ScUpcomingInvoiceStyle0}},[1,"sc-upcoming-invoice",{heading:[1],successUrl:[1,"success-url"],subscriptionId:[1,"subscription-id"],priceId:[1,"price-id"],variantId:[1,"variant-id"],quantity:[2],discount:[1040],payment_method:[1040],quantityUpdatesEnabled:[4,"quantity-updates-enabled"],adHocAmount:[2,"ad-hoc-amount"],loading:[32],busy:[32],error:[32],price:[32],invoice:[32],couponError:[32]}]);function defineCustomElement$1(){"undefined"!=typeof customElements&&["sc-upcoming-invoice","sc-alert","sc-block-ui","sc-button","sc-card","sc-cc-logo","sc-coupon-form","sc-dashboard-module","sc-divider","sc-flex","sc-form","sc-form-control","sc-format-number","sc-icon","sc-input","sc-line-item","sc-manual-payment-method","sc-payment-method","sc-product-line-item","sc-product-line-item-note","sc-prose","sc-quantity-select","sc-skeleton","sc-spinner","sc-tag","sc-text","sc-tooltip","sc-visually-hidden"].forEach((e=>{switch(e){case"sc-upcoming-invoice":customElements.get(e)||customElements.define(e,ScUpcomingInvoice$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-coupon-form":customElements.get(e)||defineCustomElement$n();break;case"sc-dashboard-module":customElements.get(e)||defineCustomElement$m();break;case"sc-divider":customElements.get(e)||defineCustomElement$l();break;case"sc-flex":customElements.get(e)||defineCustomElement$k();break;case"sc-form":customElements.get(e)||defineCustomElement$j();break;case"sc-form-control":customElements.get(e)||defineCustomElement$i();break;case"sc-format-number":customElements.get(e)||defineCustomElement$h();break;case"sc-icon":customElements.get(e)||defineCustomElement$g();break;case"sc-input":customElements.get(e)||defineCustomElement$f();break;case"sc-line-item":customElements.get(e)||defineCustomElement$e();break;case"sc-manual-payment-method":customElements.get(e)||defineCustomElement$d();break;case"sc-payment-method":customElements.get(e)||defineCustomElement$c();break;case"sc-product-line-item":customElements.get(e)||defineCustomElement$b();break;case"sc-product-line-item-note":customElements.get(e)||defineCustomElement$a();break;case"sc-prose":customElements.get(e)||defineCustomElement$9();break;case"sc-quantity-select":customElements.get(e)||defineCustomElement$8();break;case"sc-skeleton":customElements.get(e)||defineCustomElement$7();break;case"sc-spinner":customElements.get(e)||defineCustomElement$6();break;case"sc-tag":customElements.get(e)||defineCustomElement$5();break;case"sc-text":customElements.get(e)||defineCustomElement$4();break;case"sc-tooltip":customElements.get(e)||defineCustomElement$3();break;case"sc-visually-hidden":customElements.get(e)||defineCustomElement$2()}}))}const ScUpcomingInvoice=ScUpcomingInvoice$1,defineCustomElement=defineCustomElement$1;export{ScUpcomingInvoice,defineCustomElement};
Save
Back