@adyen/adyen-web
Version:
[](https://www.npmjs.com/package/@adyen/adyen-web)
3 lines (2 loc) • 2.45 kB
JavaScript
import{createElement as t}from"../../external/preact/dist/preact.js";import{UIElement as e}from"../internal/UIElement/UIElement.js";import n from"./components/DonationComponent.js";import{TxVariants as o}from"../tx-variants.js";import{AnalyticsLogEvent as s,LogEventSubtype as i,LogEventType as a}from"../../core/Analytics/events/AnalyticsLogEvent.js";import{AnalyticsInfoEvent as r,UiTarget as c,InfoEventType as d}from"../../core/Analytics/events/AnalyticsInfoEvent.js";import l,{REPARENT_WITHOUT_AUTO_START_ERROR_MSG as m}from"./DonationCampaignService.js";function p(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}class h extends e{static isServiceMode(t){return"rootNode"in t&&!!t.rootNode}async initialiseServiceMode(t,e){if(t.session)if(t.session.sessionsDonationInitiated)console.error(m);else{t.session.sessionsDonationInitiated=!0;try{const n=await new l(t,e).initialise();n&&(this.props={...this.props,...n},this.mount(e.rootNode))}catch(e){t.options.donation?.onDonationFailure?.(e)}}}get data(){return this.state.data}get isValid(){return this.state.isValid}setState(t){this.state={...this.state,...t}}donate(){const t=new s({component:h.type,type:a.submit,subType:i.donation,message:"Making donation"});this.core.modules.analytics.sendAnalytics(t);const{data:e,isValid:n}=this;this.props.onDonate({data:e,isValid:n},this)}cancel(){const t=new s({component:h.type,type:a.closed,subType:i.donation,message:"Opting to not make donation"});this.core.modules.analytics.sendAnalytics(t);const{data:e,isValid:n}=this;this.isInServiceMode&&this.unmount(),this.props.onCancel({data:e,isValid:n})}amountSelected(t){const e=new r({component:h.type,type:d.selected,selectedValue:JSON.stringify(t.data.amount),target:c.donationAmountButton});this.core.modules.analytics.sendAnalytics(e)}componentToRender(){return t(n,{...this.props,ref:t=>{this.componentRef=t},onChange:this.setState,onDonate:this.donate,onCancel:this.cancel,onAmountSelected:this.amountSelected})}constructor(t,e){const n=h.isServiceMode(e);super(t,n?void 0:e),p(this,"isInServiceMode",!1),this.donate=this.donate.bind(this),this.cancel=this.cancel.bind(this),this.amountSelected=this.amountSelected.bind(this),this.isInServiceMode=n,t.session&&n&&this.initialiseServiceMode(t,e)}}p(h,"type",o.donation),p(h,"defaultProps",{onCancel:()=>{},onDonate:()=>{}});export{h as default};
//# sourceMappingURL=Donation.js.map