FileMaster
Search
Toggle Dark Mode
Home
/
.
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
components
Edit File: sc-mollie-add-method.js
import{proxyCustomElement,HTMLElement,h}from"@stencil/core/internal/client";import{a as apiFetch}from"./fetch.js";import{d as defineCustomElement$c}from"./sc-block-ui2.js";import{d as defineCustomElement$b}from"./sc-button2.js";import{d as defineCustomElement$a}from"./sc-card2.js";import{d as defineCustomElement$9}from"./sc-divider2.js";import{d as defineCustomElement$8}from"./sc-form2.js";import{d as defineCustomElement$7}from"./sc-icon2.js";import{d as defineCustomElement$6}from"./sc-payment-selected2.js";import{d as defineCustomElement$5}from"./sc-skeleton2.js";import{d as defineCustomElement$4}from"./sc-spinner2.js";import{d as defineCustomElement$3}from"./sc-toggle2.js";import{d as defineCustomElement$2}from"./sc-toggles2.js";import{a as addQueryArgs}from"./add-query-args.js";const scMollieAddMethodCss=":host{display:block}",ScMollieAddMethodStyle0=scMollieAddMethodCss,ScMollieAddMethod$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.country=void 0,this.successUrl=void 0,this.processorId=void 0,this.currency=void 0,this.liveMode=void 0,this.customerId=void 0,this.methods=[],this.loading=void 0,this.error=void 0,this.selectedMethodId=void 0,this.paymentIntent=void 0}componentWillLoad(){this.fetchMethods()}async createPaymentIntent(){var e,t,s,o;try{this.loading=!0,this.error="",this.paymentIntent=await apiFetch({method:"POST",path:"surecart/v1/payment_intents",data:{processor_type:"mollie",live_mode:this.liveMode,customer_id:this.customerId,return_url:this.successUrl,payment_method_type:this.selectedMethodId,currency:this.currency,refresh_status:!0}}),(null===(t=null===(e=this.paymentIntent.processor_data)||void 0===e?void 0:e.mollie)||void 0===t?void 0:t.checkout_url)&&window.location.assign(null===(o=null===(s=this.paymentIntent.processor_data)||void 0===s?void 0:s.mollie)||void 0===o?void 0:o.checkout_url)}catch(e){console.error(e),this.error=(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart"),this.loading=!1}}async fetchMethods(){var e,t,s;try{this.loading=!0;const o=await apiFetch({path:addQueryArgs(`surecart/v1/processors/${this.processorId}/payment_method_types`,{amount:0,country:this.country,currency:this.currency,reusable:!0})});this.methods=(null==o?void 0:o.data)||[],(null===(e=this.methods)||void 0===e?void 0:e.length)&&(this.selectedMethodId=null===(s=null===(t=this.methods)||void 0===t?void 0:t[0])||void 0===s?void 0:s.id)}catch(e){this.error=(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart"),console.error(e)}finally{this.loading=!1}}handleSubmit(){this.createPaymentIntent()}renderLoading(){return h("sc-card",null,h("sc-skeleton",{style:{width:"50%",marginBottom:"0.5em"}}),h("sc-skeleton",{style:{width:"30%",marginBottom:"0.5em"}}),h("sc-skeleton",{style:{width:"60%",marginBottom:"0.5em"}}))}render(){var e;return this.loading&&!(null===(e=this.methods)||void 0===e?void 0:e.length)?this.renderLoading():h("sc-form",{onScFormSubmit:()=>this.handleSubmit(),style:{position:"relative"}},h("sc-toggles",{collapsible:!1,theme:"container"},(this.methods||[]).map((e=>h("sc-toggle",{"show-control":!0,shady:!0,borderless:!0,open:this.selectedMethodId===(null==e?void 0:e.id),onScShow:()=>this.selectedMethodId=null==e?void 0:e.id},h("span",{slot:"summary",class:"sc-payment-toggle-summary"},!!(null==e?void 0:e.image)&&h("img",{src:null==e?void 0:e.image}),h("span",null,null==e?void 0:e.description)),h("sc-card",null,h("sc-payment-selected",{label:wp.i18n.sprintf(wp.i18n.__("%s selected.","surecart"),null==e?void 0:e.description)},!!(null==e?void 0:e.image)&&h("img",{slot:"icon",src:null==e?void 0:e.image,style:{width:"32px"}}),wp.i18n.__("Another step will appear after submitting your order to add this payment method.","surecart"))))))),h("sc-button",{type:"primary",submit:!0,full:!0,loading:this.loading},wp.i18n.__("Add Payment Method","surecart")),this.loading&&h("sc-block-ui",{"z-index":9,style:{"--sc-block-ui-opacity":"0.75"}}))}static get style(){return ScMollieAddMethodStyle0}},[1,"sc-mollie-add-method",{country:[1],successUrl:[1,"success-url"],processorId:[1,"processor-id"],currency:[1],liveMode:[4,"live-mode"],customerId:[1,"customer-id"],methods:[32],loading:[32],error:[32],selectedMethodId:[32],paymentIntent:[32]}]);function defineCustomElement$1(){"undefined"!=typeof customElements&&["sc-mollie-add-method","sc-block-ui","sc-button","sc-card","sc-divider","sc-form","sc-icon","sc-payment-selected","sc-skeleton","sc-spinner","sc-toggle","sc-toggles"].forEach((e=>{switch(e){case"sc-mollie-add-method":customElements.get(e)||customElements.define(e,ScMollieAddMethod$1);break;case"sc-block-ui":customElements.get(e)||defineCustomElement$c();break;case"sc-button":customElements.get(e)||defineCustomElement$b();break;case"sc-card":customElements.get(e)||defineCustomElement$a();break;case"sc-divider":customElements.get(e)||defineCustomElement$9();break;case"sc-form":customElements.get(e)||defineCustomElement$8();break;case"sc-icon":customElements.get(e)||defineCustomElement$7();break;case"sc-payment-selected":customElements.get(e)||defineCustomElement$6();break;case"sc-skeleton":customElements.get(e)||defineCustomElement$5();break;case"sc-spinner":customElements.get(e)||defineCustomElement$4();break;case"sc-toggle":customElements.get(e)||defineCustomElement$3();break;case"sc-toggles":customElements.get(e)||defineCustomElement$2()}}))}const ScMollieAddMethod=ScMollieAddMethod$1,defineCustomElement=defineCustomElement$1;export{ScMollieAddMethod,defineCustomElement};
Save
Back