@atlas-kitchen/adyen-web
Version:
3 lines (2 loc) • 5.54 kB
JavaScript
import{createElement as t}from"../../external/preact/dist/preact.js";import{UIElement as e}from"../internal/UIElement/UIElement.js";import o from"./defaultProps.js";import{DropinComponent as n}from"./components/DropinComponent.js";import{CoreProvider as i}from"../../core/Context/CoreProvider.js";import{getCommonProps as r}from"./components/utils.js";import s from"./elements/createElements.js";import a from"./elements/createStoredElements.js";import h from"./elements/createInstantPaymentElements.js";import{hasOwnProperty as d}from"../../utils/hasOwnProperty.js";import p from"../../core/Errors/SRPanelProvider.js";import l from"./elements/splitPaymentMethods.js";import{TxVariants as m}from"../tx-variants.js";function c(t,e,o){return e in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}function y(t){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{},n=Object.keys(o);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(o).filter((function(t){return Object.getOwnPropertyDescriptor(o,t).enumerable})))),n.forEach((function(e){c(t,e,o[e])}))}return t}function u(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 o=Object.getOwnPropertySymbols(t);e.push.apply(e,o)}return e}(Object(e)).forEach((function(o){Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(e,o))})),t}const f=["paywithgoogle","googlepay","applepay"];class v extends e{storeElementRefOnCore(){this.core.storeElementReference(this)}formatProps(t){return u(y({type:"dropin"},super.formatProps(t)),{instantPaymentTypes:Array.from(new Set(t.instantPaymentTypes)).filter((t=>f.includes(t)))})}get isValid(){return!!this.dropinRef&&!!this.dropinRef.state.activePaymentMethod&&!!this.dropinRef.state.activePaymentMethod.isValid}showValidation(){return this.dropinRef.state.activePaymentMethod&&this.dropinRef.state.activePaymentMethod.showValidation(),this}setStatus(t,e={}){var o;return null===(o=this.dropinRef)||void 0===o||o.setStatus(t,e),this}get activePaymentMethod(){var t,e;return(null===(t=this.dropinRef)||void 0===t?void 0:t.state)||(null===(e=this.dropinRef)||void 0===e?void 0:e.state.activePaymentMethod)?this.dropinRef.state.activePaymentMethod:null}get data(){return this.activePaymentMethod?this.dropinRef.state.activePaymentMethod.data:null}displayFinalAnimation(t){this.props.disableFinalAnimation||this.dropinRef.setStatus(t)}submit(){if(!this.activePaymentMethod)throw new Error("No active payment method.");this.activePaymentMethod.isValid||this.activePaymentMethod.showValidation(),this.activePaymentMethod.isInstantPayment&&this.closeActivePaymentMethod(),this.activePaymentMethod.submit()}handleAction(t,e={}){var o,n;if(!t||!t.type){if(d(t,"action")&&d(t,"resultCode"))throw new Error('handleAction::Invalid Action - the passed action object itself has an "action" property and a "resultCode": have you passed in the whole response object by mistake?');throw new Error('handleAction::Invalid Action - the passed action object does not have a "type" property')}if("redirect"!==t.type&&(null===(o=this.activePaymentMethod)||void 0===o?void 0:o.updateWithAction))return this.activePaymentMethod.updateWithAction(t);this.elementRef instanceof v&&(e=y({},null===(n=this.elementRef.activePaymentMethod)||void 0===n?void 0:n.props,e));const i=this.core.createFromAction(t,u(y({},e),{elementRef:this.elementRef,onAdditionalDetails:this.handleAdditionalDetails,isDropin:!0}));return i?(this.setStatus(i.props.statusType,{component:i}),this.componentFromAction=i,this):null}closeActivePaymentMethod(){this.dropinRef.closeActivePaymentMethod()}handleKeyPress(t){if("Enter"===t.key||"Enter"===t.code){var e,o;if("radio"===(null===(o=document)||void 0===o||null===(e=o.activeElement)||void 0===e?void 0:e.getAttribute("role")))return;super.handleKeyPress(t)}}onEnterKeyPressed(t,e){var o,n;const i=null!==(n=this.activePaymentMethod)&&void 0!==n?n:e;null===(o=this.activePaymentMethod)||void 0===o||o.onEnterKeyPressed(t,i)}render(){return t(i,{i18n:this.props.i18n,loadingContext:this.props.loadingContext,resources:this.resources},t(p,{srPanel:this.props.modules.srPanel},t(n,u(y({},this.props),{core:this.core,elementRef:this.elementRef,onCreateElements:this.handleCreate,ref:t=>{this.dropinRef=t}}))))}constructor(t,e){super(t,e),c(this,"dropinRef",null),c(this,"paymentMethodsConfiguration",void 0),c(this,"componentFromAction",void 0),c(this,"handleCreate",(()=>{var t,e;const{paymentMethodsConfiguration:o,showStoredPaymentMethods:n,showPaymentMethods:i,instantPaymentTypes:d}=this.props,{paymentMethods:p,storedPaymentMethods:m,instantPaymentMethods:c,fastlanePaymentMethod:f}=l(this.core.paymentMethodsResponse,d),v=r(u(y({},this.props),{elementRef:this.elementRef})),P=i?s(p,o,v,this.core):[],M=h(c,o,v,this.core);var b;return[n?a(null!==(b=null===(t=(e=this.props).filterStoredPaymentMethods)||void 0===t?void 0:t.call(e,m))&&void 0!==b?b:m,o,v,this.core):[],P,M,f?s([f],o,v,this.core):[]]})),c(this,"handleOrder",(({order:t})=>{this.updateParent({order:t})})),this.submit=this.submit.bind(this),this.handleAction=this.handleAction.bind(this),this.props.paymentMethodComponents.forEach((t=>this.core.register(t))),this.paymentMethodsConfiguration=this.props.paymentMethodsConfiguration||{}}}c(v,"type",m.dropin),c(v,"defaultProps",o);export{v as default};
//# sourceMappingURL=Dropin.js.map