D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
diafdxji
/
shihty.com
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
surecart
/
Filename :
p-5ababc08.entry.js
back
Copy
import{r as t,h as e,a as i}from"./p-e97fde0a.js";import{a as s}from"./p-dd3464cd.js";import{o as n}from"./p-b719a497.js";import{a as o}from"./p-401e165e.js";import"./p-d3366af3.js";const a=":host{display:block}";const d=a;const r=class{constructor(e){t(this,e);this.heading=undefined;this.subscription=undefined;this.paymentMethods=undefined;this.manualPaymentMethods=undefined;this.error=undefined;this.loading=undefined;this.busy=undefined;this.method=undefined}renderLoading(){return e("sc-card",{noPadding:true},e("sc-stacked-list",null,e("sc-stacked-list-row",{style:{"--columns":"4"},"mobile-size":500},[...Array(4)].map((()=>e("sc-skeleton",{style:{width:"100px",display:"inline-block"}}))))))}renderEmpty(){return e("slot",{name:"empty"},e("sc-card",null,e("sc-empty",{icon:"credit-card"},wp.i18n.__("You do not have any payment methods.","surecart"))))}currentPaymentMethodId(){var t,e,i,s,n;return((t=this.subscription)===null||t===void 0?void 0:t.manual_payment)?(e=this.subscription)===null||e===void 0?void 0:e.manual_payment_method:((s=(i=this.subscription)===null||i===void 0?void 0:i.payment_method)===null||s===void 0?void 0:s.id)||((n=this.subscription)===null||n===void 0?void 0:n.payment_method)}hasPaymentMethods(){var t,e;return((t=this.paymentMethods)===null||t===void 0?void 0:t.length)&&((e=this.manualPaymentMethods)===null||e===void 0?void 0:e.length)}componentWillLoad(){n(this.el,(()=>{this.getPaymentMethods()}))}async getPaymentMethods(){var t,e,i;if(this.hasPaymentMethods())return;const s=((e=(t=this.subscription)===null||t===void 0?void 0:t.customer)===null||e===void 0?void 0:e.id)||((i=this.subscription)===null||i===void 0?void 0:i.customer);if(!s)return;try{this.loading=true;await this.fetchMethods(s)}catch(t){this.error=(t===null||t===void 0?void 0:t.messsage)||wp.i18n.__("Something went wrong","surecart");console.error(this.error)}finally{this.loading=false}}async fetchMethods(t){var e,i;this.paymentMethods=await s({path:o(`surecart/v1/payment_methods`,{expand:["card","customer","billing_agreement","paypal_account","payment_instrument","bank_account"],customer_ids:[t],reusable:true,live_mode:(e=this.subscription)===null||e===void 0?void 0:e.live_mode})});this.manualPaymentMethods=await s({path:o(`surecart/v1/manual_payment_methods`,{reusable:true,archived:false,live_mode:(i=this.subscription)===null||i===void 0?void 0:i.live_mode})})}async deleteMethod(t){const e=confirm(wp.i18n.__("Are you sure you want to remove this payment method?","surecart"));if(!e)return;try{this.busy=true;await s({path:`surecart/v1/payment_methods/${t===null||t===void 0?void 0:t.id}/detach`,method:"PATCH"});this.paymentMethods=this.paymentMethods.filter((e=>e.id!==t.id))}catch(t){this.error=(t===null||t===void 0?void 0:t.messsage)||wp.i18n.__("Something went wrong","surecart");console.error(this.error)}finally{this.busy=false}}async updateMethod(t){var e,i;const{payment_method:n}=await t.target.getFormJson();if(n===this.currentPaymentMethodId()){return}try{const t=(this.manualPaymentMethods||[]).some((t=>t.id===n));this.busy=true;this.subscription=await s({path:`surecart/v1/subscriptions/${(e=this.subscription)===null||e===void 0?void 0:e.id}`,method:"PATCH",data:{...!t?{payment_method:n,manual_payment:false}:{manual_payment_method:n,manual_payment:true}}});window.location.assign(o(window.location.href,{action:"edit",model:"subscription",id:(i=this.subscription)===null||i===void 0?void 0:i.id}))}catch(t){this.error=(t===null||t===void 0?void 0:t.messsage)||wp.i18n.__("Something went wrong","surecart");console.error(this.error)}finally{this.busy=false}}renderContent(){var t,i;if(this.loading){return this.renderLoading()}if(!((t=this.paymentMethods)===null||t===void 0?void 0:t.length)&&!((i=this.manualPaymentMethods)===null||i===void 0?void 0:i.length)){return this.renderEmpty()}return e("sc-form",{onScSubmit:t=>this.updateMethod(t)},e("sc-choices",null,this.renderList()),e("sc-button",{type:"primary",submit:true,full:true,size:"large",busy:this.busy,disabled:this.busy},wp.i18n.__("Update Payment Method","surecart")))}renderList(){const t=this.paymentMethods.map((t=>{const{id:i,card:s,live_mode:n,paypal_account:o}=t;return e("sc-choice",{checked:this.currentPaymentMethodId()===i,name:"payment_method",value:i,required:true},e("sc-flex",{justifyContent:"flex-start","align-items":"center"},e("sc-payment-method",{paymentMethod:t})," ",!n&&e("sc-tag",{type:"warning",size:"small"},wp.i18n.__("Test","surecart"))),e("div",{slot:"description"},!!(s===null||s===void 0?void 0:s.exp_month)&&e("span",null,wp.i18n.__("Exp.","surecart"),s===null||s===void 0?void 0:s.exp_month,"/",s===null||s===void 0?void 0:s.exp_year),!!o&&(o===null||o===void 0?void 0:o.email)),this.currentPaymentMethodId()===i&&e("sc-tag",{type:"info",slot:"price"},wp.i18n.__("Current Payment Method","surecart")))}));const i=this.manualPaymentMethods.map((t=>{const{id:i}=t;return e("sc-choice",{checked:this.currentPaymentMethodId()===i,name:"payment_method",value:i,required:true},e("sc-flex",{justifyContent:"flex-start","align-items":"center"},e("sc-manual-payment-method",{paymentMethod:t,showDescription:true})),this.currentPaymentMethodId()===i&&e("sc-tag",{type:"info",slot:"price"},wp.i18n.__("Current Payment Method","surecart")))}));return[...t,...i]}render(){var t;return e("sc-dashboard-module",{key:"bcccdabb73db36b9dce56414c49743df32b72edf",heading:this.heading||wp.i18n.__("Update Payment Method","surecart"),class:"subscription",error:this.error},e("sc-button",{key:"8ecb723d0664e9692e8a25ae065a04f9a267763f",slot:"end",type:"link",href:o(window.location.href,{action:"create",model:"payment_method",...((t=this.subscription)===null||t===void 0?void 0:t.live_mode)===false?{live_mode:false}:{},success_url:window.location.href})},e("sc-icon",{key:"a18f1370421aa462d94b534b883c1370e83975b8",name:"plus",slot:"prefix"}),wp.i18n.__("Add New","surecart")),this.renderContent(),this.busy&&e("sc-block-ui",{key:"ec236ef462e384db41156527a4edd3174614dea2",spinner:true}))}get el(){return i(this)}};r.style=d;export{r as sc_subscription_payment_method}; //# sourceMappingURL=p-5ababc08.entry.js.map