UNPKG

@atlas-kitchen/adyen-web

Version:
3 lines (2 loc) 3.63 kB
import{render as t}from"../../../external/preact/dist/preact.js";import e from"../../../utils/getProp.js";import r from"../../../utils/uuid.js";import o from"../../../core/Errors/AdyenCheckoutError.js";import{NO_CHECKOUT_ATTEMPT_ID as n,ANALYTICS_RENDERED_STR as s}from"../../../core/Analytics/constants.js";import{on as i,off as c}from"../../../utils/listenerUtils.js";import{AnalyticsInfoEvent as p}from"../../../core/Analytics/AnalyticsInfoEvent.js";function a(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function u(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},o=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(r).filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable})))),o.forEach((function(e){a(t,e,r[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 r=Object.getOwnPropertySymbols(t);e.push.apply(e,r)}return e}(Object(e)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))})),t}class l{buildElementProps(t){this.props=this.formatProps(u({},this.constructor.defaultProps,t))}formatProps(t){return t}formatData(){return{}}setUpAnalytics(t){return null}submitAnalytics(t){return null}handleKeyPress(t){return null}setState(t){this.state=u({},this.state,t)}get data(){var t;const r=e(this.props,"modules.risk.data");var o;const s=null!==(o=null===(t=e(this.props,"modules.analytics.getCheckoutAttemptId"))||void 0===t?void 0:t())&&void 0!==o?o:n,i=this.state.order||this.props.order,c=this.formatData();return c.paymentMethod&&s&&(c.paymentMethod.checkoutAttemptId=s),h(u({},r&&{riskData:{clientData:r}},i&&{order:{orderData:i.orderData,pspReference:i.pspReference}},c),{clientStateDataIndicator:!0})}activate(){}render(){throw new Error("Payment method cannot be rendered.")}mount(e){const r="string"==typeof e?document.querySelector(e):e;if(!r)throw new Error("Component could not mount. Root node was not found.");const o=!this._node;var n;(this._node&&this.unmount(),this._node=r,i(this._node,"keypress",this.handleKeyPress,!1),this._component=this.render(),t(this._component,r),o)&&(this.props.modules&&this.props.modules.analytics&&this.setUpAnalytics({containerWidth:r&&r.offsetWidth,component:this.props.isDropin?"dropin":null!==(n=this.constructor.analyticsType)&&void 0!==n?n:this.constructor.type,flavor:this.props.isDropin?"dropin":"components"}).then((()=>{if(!this.props.isDropin){const t=new p({type:s});this.submitAnalytics(t)}})));return this}update(t){return this.props=this.formatProps(u({},this.props,t)),this.state={},this.unmount().mount(this._node)}unmount(){return c(this._node,"keypress",this.handleKeyPress),this._node&&t(null,this._node),this}remove(){this.unmount(),this.core&&this.core.remove(this)}constructor(t,e){a(this,"_id",`${this.constructor.type}-${r()}`),a(this,"core",void 0),a(this,"props",void 0),a(this,"state",{}),a(this,"_component",void 0),a(this,"_node",null);const n=function(t){return!!t&&("function"==typeof t.initialize&&"function"==typeof t.createFromAction)}(t);if(!n)throw new o("IMPLEMENTATION_ERROR",`Trying to initialise the component '${this.constructor.type}' without a reference to an instance of AdyenCheckout`);this.core=t,this.buildElementProps(e),this.handleKeyPress=this.handleKeyPress.bind(this)}}a(l,"defaultProps",{});export{l as default}; //# sourceMappingURL=BaseElement.js.map