JezK
Edit File: sc-mollie-add-method.js.map
{"file":"sc-mollie-add-method.js","mappings":";;;;;;;;;;;;;;;;AAAA,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AACpD,gCAAe,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8ECkDF,UAAE;;;;;;;;;;;;;;;;;;;;;;8EAyBF,UAAE;;;;;;;;;;;;;;;;;;0zBAqCS,eAAO,CAAC,UAAE,kSAEnC,UAAE,6LAOV,UAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/ui/sc-mollie-add-method/sc-mollie-add-method.css?tag=sc-mollie-add-method&encapsulation=shadow","src/components/ui/sc-mollie-add-method/sc-mollie-add-method.tsx"],"sourcesContent":[":host {\n display: block;\n}\n","import { Component, h, Prop, State } from '@stencil/core';\nimport { sprintf, __ } from '@wordpress/i18n';\nimport { addQueryArgs } from '@wordpress/url';\nimport { Pagination, PaymentIntent, PaymentMethodType } from 'src/types';\nimport apiFetch from '../../../functions/fetch';\n\n@Component({\n tag: 'sc-mollie-add-method',\n styleUrl: 'sc-mollie-add-method.css',\n shadow: true,\n})\nexport class ScMollieAddMethod {\n @Prop() country: string;\n @Prop() successUrl: string;\n @Prop() processorId: string;\n @Prop() currency: string;\n @Prop() liveMode: boolean;\n @Prop() customerId: string;\n\n @State() methods: PaymentMethodType[] = [];\n @State() loading: boolean;\n @State() error: string;\n @State() selectedMethodId: string;\n @State() paymentIntent: PaymentIntent;\n\n componentWillLoad() {\n this.fetchMethods();\n }\n\n async createPaymentIntent() {\n try {\n this.loading = true;\n this.error = '';\n this.paymentIntent = await apiFetch({\n method: 'POST',\n path: 'surecart/v1/payment_intents',\n data: {\n processor_type: 'mollie',\n live_mode: this.liveMode,\n customer_id: this.customerId,\n return_url: this.successUrl,\n payment_method_type: this.selectedMethodId,\n currency: this.currency,\n refresh_status: true,\n },\n });\n if (this.paymentIntent.processor_data?.mollie?.checkout_url) {\n window.location.assign(this.paymentIntent.processor_data?.mollie?.checkout_url);\n }\n } catch (e) {\n console.error(e);\n this.error = e?.message || __('Something went wrong', 'surecart');\n this.loading = false;\n }\n }\n\n async fetchMethods() {\n try {\n this.loading = true;\n const response = (await apiFetch({\n path: addQueryArgs(`surecart/v1/processors/${this.processorId}/payment_method_types`, {\n amount: 0,\n country: this.country,\n currency: this.currency,\n reusable: true,\n }),\n })) as {\n object: 'list';\n pagination: Pagination;\n data: PaymentMethodType[];\n };\n this.methods = response?.data || [];\n if (this.methods?.length) {\n this.selectedMethodId = this.methods?.[0]?.id;\n }\n } catch (e) {\n this.error = e?.message || __('Something went wrong', 'surecart');\n console.error(e);\n } finally {\n this.loading = false;\n }\n }\n\n handleSubmit() {\n this.createPaymentIntent();\n }\n\n renderLoading() {\n return (\n <sc-card>\n <sc-skeleton style={{ width: '50%', marginBottom: '0.5em' }}></sc-skeleton>\n <sc-skeleton style={{ width: '30%', marginBottom: '0.5em' }}></sc-skeleton>\n <sc-skeleton style={{ width: '60%', marginBottom: '0.5em' }}></sc-skeleton>\n </sc-card>\n );\n }\n\n render() {\n if (this.loading && !this.methods?.length) {\n return this.renderLoading();\n }\n\n return (\n <sc-form onScFormSubmit={() => this.handleSubmit()} style={{ position: 'relative' }}>\n <sc-toggles collapsible={false} theme=\"container\">\n {(this.methods || []).map(method => (\n <sc-toggle show-control shady borderless open={this.selectedMethodId === method?.id} onScShow={() => (this.selectedMethodId = method?.id)}>\n <span slot=\"summary\" class=\"sc-payment-toggle-summary\">\n {!!method?.image && <img src={method?.image} />}\n <span>{method?.description}</span>\n </span>\n\n <sc-card>\n <sc-payment-selected label={sprintf(__('%s selected.', 'surecart'), method?.description)}>\n {!!method?.image && <img slot=\"icon\" src={method?.image} style={{ width: '32px' }} />}\n {__('Another step will appear after submitting your order to add this payment method.', 'surecart')}\n </sc-payment-selected>\n </sc-card>\n </sc-toggle>\n ))}\n </sc-toggles>\n <sc-button type=\"primary\" submit full loading={this.loading}>\n {__('Add Payment Method', 'surecart')}\n </sc-button>\n {this.loading && <sc-block-ui z-index={9} style={{ '--sc-block-ui-opacity': '0.75' }} />}\n </sc-form>\n );\n }\n}\n"],"version":3}