FileMaster
Search
Toggle Dark Mode
Home
/
.
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
components
Edit File: sc-subscription.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{p as productNameWithPrice}from"./price.js";import{d as defineCustomElement$F}from"./sc-alert2.js";import{d as defineCustomElement$E}from"./sc-block-ui2.js";import{d as defineCustomElement$D}from"./sc-button2.js";import{d as defineCustomElement$C}from"./sc-cancel-dialog2.js";import{d as defineCustomElement$B}from"./sc-cancel-discount2.js";import{d as defineCustomElement$A}from"./sc-cancel-survey2.js";import{d as defineCustomElement$z}from"./sc-card2.js";import{d as defineCustomElement$y}from"./sc-cc-logo2.js";import{d as defineCustomElement$x}from"./sc-choice2.js";import{d as defineCustomElement$w}from"./sc-choices2.js";import{d as defineCustomElement$v}from"./sc-dashboard-module2.js";import{d as defineCustomElement$u}from"./sc-dialog2.js";import{d as defineCustomElement$t}from"./sc-divider2.js";import{d as defineCustomElement$s}from"./sc-flex2.js";import{d as defineCustomElement$r}from"./sc-form2.js";import{d as defineCustomElement$q}from"./sc-form-control2.js";import{d as defineCustomElement$p}from"./sc-format-number2.js";import{d as defineCustomElement$o}from"./sc-icon2.js";import{d as defineCustomElement$n}from"./sc-line-item2.js";import{d as defineCustomElement$m}from"./sc-manual-payment-method2.js";import{d as defineCustomElement$l}from"./sc-payment-method2.js";import{d as defineCustomElement$k}from"./sc-product-line-item2.js";import{d as defineCustomElement$j}from"./sc-product-line-item-note2.js";import{d as defineCustomElement$i}from"./sc-prose2.js";import{d as defineCustomElement$h}from"./sc-quantity-select2.js";import{d as defineCustomElement$g}from"./sc-skeleton2.js";import{d as defineCustomElement$f}from"./sc-spinner2.js";import{d as defineCustomElement$e}from"./sc-stacked-list2.js";import{d as defineCustomElement$d}from"./sc-stacked-list-row2.js";import{d as defineCustomElement$c}from"./sc-subscription-cancel2.js";import{d as defineCustomElement$b}from"./sc-subscription-details2.js";import{d as defineCustomElement$a}from"./sc-subscription-next-payment2.js";import{d as defineCustomElement$9}from"./sc-subscription-reactivate2.js";import{d as defineCustomElement$8}from"./sc-subscription-status-badge2.js";import{d as defineCustomElement$7}from"./sc-tag2.js";import{d as defineCustomElement$6}from"./sc-text2.js";import{d as defineCustomElement$5}from"./sc-textarea2.js";import{d as defineCustomElement$4}from"./sc-toggle2.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 scSubscriptionCss=":host{display:block}.subscription{display:grid;gap:0.5em}.subscription a{text-decoration:none;font-weight:var(--sc-font-weight-semibold);display:inline-flex;align-items:center;gap:0.25em;color:var(--sc-color-primary-500)}.subscription a.cancel{color:var(--sc-color-danger-500)}@media screen and (max-width: 720px){.subscription__action-buttons{--sc-flex-column-gap:var(--sc-spacing-xxx-small)}.subscription__action-buttons::part(base){flex-direction:column}.subscription__action-buttons sc-button::part(base){width:auto;height:2em}}",ScSubscriptionStyle0=scSubscriptionCss,ScSubscription$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.subscriptionId=void 0,this.showCancel=void 0,this.heading=void 0,this.query=void 0,this.protocol=void 0,this.subscription=void 0,this.updatePaymentMethodUrl=void 0,this.loading=void 0,this.cancelModal=void 0,this.resubscribeModal=void 0,this.busy=void 0,this.error=void 0}componentWillLoad(){onFirstVisible(this.el,(()=>{this.subscription||this.getSubscription()}))}async cancelPendingUpdate(){var e;if(confirm(wp.i18n.__("Are you sure you want to cancel the pending update to your plan?","surecart")))try{this.busy=!0,this.subscription=await apiFetch({path:addQueryArgs(`surecart/v1/subscriptions/${null===(e=this.subscription)||void 0===e?void 0:e.id}/`,{expand:["price","price.product","current_period","period.checkout","purchase","purchase.license","license.activations","discount","discount.coupon"]}),method:"PATCH",data:{purge_pending_update:!0}})}catch(e){(null==e?void 0:e.message)?this.error=e.message:this.error=wp.i18n.__("Something went wrong","surecart"),console.error(this.error)}finally{this.busy=!1}}async renewSubscription(){var e;try{this.error="",this.busy=!0,this.subscription=await apiFetch({path:addQueryArgs(`surecart/v1/subscriptions/${null===(e=this.subscription)||void 0===e?void 0:e.id}/renew`,{expand:["price","price.product","current_period","period.checkout","purchase","purchase.license","license.activations","discount","discount.coupon"]}),method:"PATCH"})}catch(e){this.error=(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.busy=!1}}async getSubscription(){var e;try{this.loading=!0,this.subscription=await await apiFetch({path:addQueryArgs(`surecart/v1/subscriptions/${this.subscriptionId||(null===(e=this.subscription)||void 0===e?void 0:e.id)}`,{expand:["price","price.product","current_period"],...this.query||{}})})}catch(e){(null==e?void 0:e.message)?this.error=e.message:this.error=wp.i18n.__("Something went wrong","surecart"),console.error(this.error)}finally{this.loading=!1}}renderName(e){var t;return"string"!=typeof(null===(t=null==e?void 0:e.price)||void 0===t?void 0:t.product)?productNameWithPrice(null==e?void 0:e.price):wp.i18n.__("Subscription","surecart")}renderRenewalText(e){const t=h("sc-subscription-status-badge",{subscription:e});return(null==e?void 0:e.cancel_at_period_end)&&e.current_period_end_at?h("span",null,t," ", /* translators: %s: current period end date */ wp.i18n.sprintf(wp.i18n.__("Your plan will be canceled on %s","surecart"),e.current_period_end_at_date)):"trialing"===e.status&&e.trial_end_at?h("span",null,t," ", /* translators: %s: trial end date */ wp.i18n.sprintf(wp.i18n.__("Your plan begins on %s","surecart"),e.trial_end_at_date)):"active"===e.status&&e.current_period_end_at?h("span",null,t," ", /* translators: %s: current period end date */ wp.i18n.sprintf(wp.i18n.__("Your plan renews on %s","surecart"),e.current_period_end_at_date)):t}renderEmpty(){return h("slot",{name:"empty"},wp.i18n.__("This subscription does not exist.","surecart"))}renderLoading(){return h("sc-stacked-list-row",{style:{"--columns":"2"},"mobile-size":0},h("div",{style:{padding:"0.5em"}},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(){return this.loading?this.renderLoading():this.subscription?h(Fragment,null,h("sc-subscription-next-payment",{subscription:this.subscription,updatePaymentMethodUrl:this.updatePaymentMethodUrl},h("sc-subscription-details",{subscription:this.subscription}))):this.renderEmpty()}render(){var e,t,s,i,n,o,c,r;const a=(null==this?void 0:this.subscription.payment_method)||(null==this?void 0:this.subscription.manual_payment);return h("sc-dashboard-module",{key:"41b533c4fe48a6299c339e827291c248b3cda3e9",heading:this.heading||wp.i18n.__("Current Plan","surecart"),class:"subscription",error:this.error},!!this.subscription&&(null===(e=null==this?void 0:this.subscription)||void 0===e?void 0:e.can_modify)&&h("sc-flex",{key:"5540b28a8d2bc8831103f0c694e6e90323e534f9",slot:"end",class:"subscription__action-buttons"},this.updatePaymentMethodUrl&&a&&h("sc-button",{key:"498086a691572e02bd6f9d76ceacc23a5a3befe0",type:"link",href:this.updatePaymentMethodUrl},h("sc-icon",{key:"122fc7153cb0d66bbb7a0a444dd49df0f876ebcc",name:"credit-card",slot:"prefix"}),wp.i18n.__("Update Payment Method","surecart")),!a&&h("sc-button",{key:"b9f98d824335b33c1858ef5560556f90d320b268",type:"link",href:addQueryArgs(window.location.href,{action:"create",model:"payment_method",id:null==this?void 0:this.subscription.id,...!1===(null===(t=null==this?void 0:this.subscription)||void 0===t?void 0:t.live_mode)?{live_mode:!1}:{}})},h("sc-icon",{key:"d9316cd6c5a70bad426a8313d68e6c3857c5db7a",name:"credit-card",slot:"prefix"}),wp.i18n.__("Add Payment Method","surecart")),!!Object.keys(null===(s=this.subscription)||void 0===s?void 0:s.pending_update).length&&h("sc-button",{key:"8153eb62aa38de9051e08df68c1ccc0ca1aaa8b2",type:"link",onClick:()=>this.cancelPendingUpdate()},h("sc-icon",{key:"ee83f4c17853b238ebe9087a490c7200e69e073c",name:"x-octagon",slot:"prefix"}),wp.i18n.__("Cancel Scheduled Update","surecart")),(null===(i=null==this?void 0:this.subscription)||void 0===i?void 0:i.cancel_at_period_end)?h("sc-button",{type:"link",onClick:()=>this.renewSubscription()},h("sc-icon",{name:"repeat",slot:"prefix"}),wp.i18n.__("Restore Plan","surecart")):"canceled"!==(null===(n=this.subscription)||void 0===n?void 0:n.status)&&(null===(o=this.subscription)||void 0===o?void 0:o.current_period_end_at)&&this.showCancel&&h("sc-button",{type:"link",onClick:()=>this.cancelModal=!0},h("sc-icon",{name:"x",slot:"prefix"}),wp.i18n.__("Cancel Plan","surecart")),"canceled"===(null===(c=this.subscription)||void 0===c?void 0:c.status)&&h("sc-button",{key:"6497cbc56f4386c0d70f9a2dddf30a0bfe8c38fd",type:"link",...(null===(r=this.subscription)||void 0===r?void 0:r.payment_method)||(null==this?void 0:this.subscription.manual_payment)?{onClick:()=>this.resubscribeModal=!0}:{href:null==this?void 0:this.updatePaymentMethodUrl}},h("sc-icon",{key:"cb01f33008de985aa68a2b805d672fc6b28add8e",name:"repeat",slot:"prefix"}),wp.i18n.__("Resubscribe","surecart"))),h("sc-card",{key:"6d5b5af082c5c4d3ef920d03f9e01df220bf760f",style:{"--overflow":"hidden"},noPadding:!0},this.renderContent()),this.busy&&h("sc-block-ui",{key:"dbbf45e0dc55da0096a0eb70c241a370b61cd233",spinner:!0}),h("sc-cancel-dialog",{key:"a9a37e6ebdd3600566b70f6e1d77ae7902a4f04b",subscription:this.subscription,protocol:this.protocol,open:this.cancelModal,onScRequestClose:()=>this.cancelModal=!1,onScRefresh:()=>this.getSubscription()},h("slot",{key:"3c020dd10acfb4d2454d4e2d59031c922d51e478",name:"cancel-popup-content",slot:"cancel-popup-content"})),h("sc-subscription-reactivate",{key:"2c5dd253a7d565c13e91f91737cf4e1064a54550",subscription:this.subscription,open:this.resubscribeModal,onScRequestClose:()=>this.resubscribeModal=!1,onScRefresh:()=>this.getSubscription()}))}get el(){return this}static get style(){return ScSubscriptionStyle0}},[1,"sc-subscription",{subscriptionId:[1,"subscription-id"],showCancel:[4,"show-cancel"],heading:[1],query:[16],protocol:[16],subscription:[1040],updatePaymentMethodUrl:[1,"update-payment-method-url"],loading:[32],cancelModal:[32],resubscribeModal:[32],busy:[32],error:[32]}]);function defineCustomElement$1(){"undefined"!=typeof customElements&&["sc-subscription","sc-alert","sc-block-ui","sc-button","sc-cancel-dialog","sc-cancel-discount","sc-cancel-survey","sc-card","sc-cc-logo","sc-choice","sc-choices","sc-dashboard-module","sc-dialog","sc-divider","sc-flex","sc-form","sc-form-control","sc-format-number","sc-icon","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-stacked-list","sc-stacked-list-row","sc-subscription-cancel","sc-subscription-details","sc-subscription-next-payment","sc-subscription-reactivate","sc-subscription-status-badge","sc-tag","sc-text","sc-textarea","sc-toggle","sc-tooltip","sc-visually-hidden"].forEach((e=>{switch(e){case"sc-subscription":customElements.get(e)||customElements.define(e,ScSubscription$1);break;case"sc-alert":customElements.get(e)||defineCustomElement$F();break;case"sc-block-ui":customElements.get(e)||defineCustomElement$E();break;case"sc-button":customElements.get(e)||defineCustomElement$D();break;case"sc-cancel-dialog":customElements.get(e)||defineCustomElement$C();break;case"sc-cancel-discount":customElements.get(e)||defineCustomElement$B();break;case"sc-cancel-survey":customElements.get(e)||defineCustomElement$A();break;case"sc-card":customElements.get(e)||defineCustomElement$z();break;case"sc-cc-logo":customElements.get(e)||defineCustomElement$y();break;case"sc-choice":customElements.get(e)||defineCustomElement$x();break;case"sc-choices":customElements.get(e)||defineCustomElement$w();break;case"sc-dashboard-module":customElements.get(e)||defineCustomElement$v();break;case"sc-dialog":customElements.get(e)||defineCustomElement$u();break;case"sc-divider":customElements.get(e)||defineCustomElement$t();break;case"sc-flex":customElements.get(e)||defineCustomElement$s();break;case"sc-form":customElements.get(e)||defineCustomElement$r();break;case"sc-form-control":customElements.get(e)||defineCustomElement$q();break;case"sc-format-number":customElements.get(e)||defineCustomElement$p();break;case"sc-icon":customElements.get(e)||defineCustomElement$o();break;case"sc-line-item":customElements.get(e)||defineCustomElement$n();break;case"sc-manual-payment-method":customElements.get(e)||defineCustomElement$m();break;case"sc-payment-method":customElements.get(e)||defineCustomElement$l();break;case"sc-product-line-item":customElements.get(e)||defineCustomElement$k();break;case"sc-product-line-item-note":customElements.get(e)||defineCustomElement$j();break;case"sc-prose":customElements.get(e)||defineCustomElement$i();break;case"sc-quantity-select":customElements.get(e)||defineCustomElement$h();break;case"sc-skeleton":customElements.get(e)||defineCustomElement$g();break;case"sc-spinner":customElements.get(e)||defineCustomElement$f();break;case"sc-stacked-list":customElements.get(e)||defineCustomElement$e();break;case"sc-stacked-list-row":customElements.get(e)||defineCustomElement$d();break;case"sc-subscription-cancel":customElements.get(e)||defineCustomElement$c();break;case"sc-subscription-details":customElements.get(e)||defineCustomElement$b();break;case"sc-subscription-next-payment":customElements.get(e)||defineCustomElement$a();break;case"sc-subscription-reactivate":customElements.get(e)||defineCustomElement$9();break;case"sc-subscription-status-badge":customElements.get(e)||defineCustomElement$8();break;case"sc-tag":customElements.get(e)||defineCustomElement$7();break;case"sc-text":customElements.get(e)||defineCustomElement$6();break;case"sc-textarea":customElements.get(e)||defineCustomElement$5();break;case"sc-toggle":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 ScSubscription=ScSubscription$1,defineCustomElement=defineCustomElement$1;export{ScSubscription,defineCustomElement};
Save
Back