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) 2.4 kB
import{render as t}from"../../../external/preact/dist/preact.js";import e from"../../../utils/uuid.js";import r from"../../../core/Errors/AdyenCheckoutError.js";import{NO_CHECKOUT_ATTEMPT_ID as o}from"../../../core/Analytics/constants.js";import{on as s,off as n}from"../../../utils/listenerUtils.js";import{createSdkData as i}from"../../../utils/createSdkData.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}class h{buildElementProps(t){this.props=this.formatProps({...this.constructor.defaultProps,...t})}formatProps(t){return t}formatData(){return{}}submitAnalytics(t){return null}handleKeyPress(t){return null}setState(t){this.state={...this.state,...t}}get data(){const t=this.state.order||this.props.order,e=this.formatData(),r=this.core.modules.risk.data,s=this.core.modules.analytics.checkoutAttemptId??o,n=i(s,r);return e.paymentMethod&&s&&(e.paymentMethod.checkoutAttemptId=s),e.paymentMethod&&n&&(e.paymentMethod.sdkData=n),{...r&&{riskData:{clientData:r}},...t&&{order:{orderData:t.orderData,pspReference:t.pspReference}},...e,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.");return this._node&&this.unmount(),this._node=r,s(this._node,"keypress",this.handleKeyPress,!1),this._component=this.render(),t(this._component,r),this}update(t){return this.props=this.formatProps({...this.props,...t}),this.state={},this.unmount().mount(this._node)}unmount(){return n(this._node,"keypress",this.handleKeyPress),this._node&&t(null,this._node),this}remove(){this.unmount(),this.core&&this.core.remove(this)}constructor(t,o){a(this,"_id",`${this.constructor.type}-${e()}`),a(this,"core",void 0),a(this,"props",void 0),a(this,"state",{}),a(this,"_component",void 0),a(this,"_node",null);const s=function(t){return!!t&&("function"==typeof t.initialize&&"function"==typeof t.createFromAction)}(t);if(!s)throw new r("IMPLEMENTATION_ERROR",`Trying to initialise the component '${this.constructor.type}' without a reference to an instance of AdyenCheckout`);this.core=t,this.buildElementProps(o),this.handleKeyPress=this.handleKeyPress.bind(this)}}a(h,"defaultProps",{});export{h as default}; //# sourceMappingURL=BaseElement.js.map