UNPKG

@adyen/adyen-web

Version:

[![npm](https://img.shields.io/npm/v/@adyen/adyen-web.svg)](https://www.npmjs.com/package/@adyen/adyen-web)

3 lines (2 loc) 3.2 kB
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 i,LogEventSubtype as s,LogEventType as a}from"../../core/Analytics/events/AnalyticsLogEvent.js";import{AnalyticsInfoEvent as r,UiTarget as c,InfoEventType as l}from"../../core/Analytics/events/AnalyticsInfoEvent.js";import d,{REPARENT_WITHOUT_AUTO_START_ERROR_MSG as p}from"./DonationCampaignService.js";function u(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function m(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},o=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),o.forEach(function(e){u(t,e,n[e])})}return t}function h(t,e){return e=null!=e?e:{},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):function(t){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e.push.apply(e,n)}return e}(Object(e)).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))}),t}class y extends e{static isServiceMode(t){return"rootNode"in t&&!!t.rootNode}async initialiseServiceMode(t,e){if(t.session)if(t.session.sessionsDonationInitiated)console.error(p);else{t.session.sessionsDonationInitiated=!0;try{const n=await new d(t,e).initialise();n&&(this.props=m({},this.props,n),this.mount(e.rootNode))}catch(e){var n,o;null===(o=t.options.donation)||void 0===o||null===(n=o.onDonationFailure)||void 0===n||n.call(o,e)}}}get data(){return this.state.data}get isValid(){return this.state.isValid}setState(t){this.state=m({},this.state,t)}donate(){const t=new i({component:y.type,type:a.submit,subType:s.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 i({component:y.type,type:a.closed,subType:s.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:y.type,type:l.selected,selectedValue:JSON.stringify(t.data.amount),target:c.donationAmountButton});this.core.modules.analytics.sendAnalytics(e)}componentToRender(){return t(n,h(m({},this.props),{ref:t=>{this.componentRef=t},onChange:this.setState,onDonate:this.donate,onCancel:this.cancel,onAmountSelected:this.amountSelected}))}constructor(t,e){const n=y.isServiceMode(e);super(t,n?void 0:e),u(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)}}u(y,"type",o.donation),u(y,"defaultProps",{onCancel:()=>{},onDonate:()=>{}});export{y as default}; //# sourceMappingURL=Donation.js.map