@adyen/adyen-web
Version:
[](https://www.npmjs.com/package/@adyen/adyen-web)
3 lines (2 loc) • 5.71 kB
JavaScript
import{createElement as t}from"../../external/preact/dist/preact.js";import{UIElement as e}from"../internal/UIElement/UIElement.js";import n from"./defaultProps.js";import{DropinComponent as o}from"./components/DropinComponent.js";import i from"./elements/createElements.js";import r from"./elements/createStoredElements.js";import s from"./elements/createInstantPaymentElements.js";import{hasOwnProperty as a}from"../../utils/hasOwnProperty.js";import h from"./elements/splitPaymentMethods.js";import{TxVariants as d}from"../tx-variants.js";function l(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){l(t,e,n[e])})}return t}function p(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}const c=["paywithgoogle","googlepay","applepay"];class y extends e{reportIntegrationFlavor(){this.analytics.sendFlavor("dropin")}storeElementRefOnCore(){this.core.storeElementReference(this)}formatProps(t){return p(m({},super.formatProps(t)),{instantPaymentTypes:Array.from(new Set(t.instantPaymentTypes)).filter(t=>c.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 n;return null===(n=this.dropinRef)||void 0===n||n.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){var e;this.props.disableFinalAnimation||null===(e=this.dropinRef)||void 0===e||e.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()}updateAmount(t,e){var n;this.props=m({},this.props,t&&{amount:t},e&&{secondaryAmount:e}),null===(n=this.amountProviderRef.current)||void 0===n||n.update(t,e),this.paymentMethodElements.forEach(n=>{n.updateAmount(t,e)})}handleElementsCreated(t){t&&0!==t.length||(this.paymentMethodElements=[]),this.paymentMethodElements=t}handleAction(t,e={}){var n,o;if(!t||!t.type){if(a(t,"action")&&a(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===(n=this.activePaymentMethod)||void 0===n?void 0:n.updateWithAction))return this.activePaymentMethod.updateWithAction(t);this.elementRef instanceof y&&(e=m({},null===(o=this.elementRef.activePaymentMethod)||void 0===o?void 0:o.props,e));const i=this.core.createFromAction(t,p(m({},e),{elementRef:this.elementRef,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,n;if("radio"===(null===(n=document)||void 0===n||null===(e=n.activeElement)||void 0===e?void 0:e.getAttribute("role")))return;super.handleKeyPress(t)}}onEnterKeyPressed(t,e){var n,o;const i=null!==(n=this.activePaymentMethod)&&void 0!==n?n:e;null===(o=this.activePaymentMethod)||void 0===o||o.onEnterKeyPressed(t,i)}componentToRender(){return t(o,p(m({},this.props),{core:this.core,elementRef:this.elementRef,onCreateElements:this.handleCreate,onElementsCreated:this.handleElementsCreated,ref:t=>{this.dropinRef=t}}))}constructor(t,e){super(t,e),l(this,"dropinRef",null),l(this,"paymentMethodsConfiguration",void 0),l(this,"componentFromAction",void 0),l(this,"paymentMethodElements",[]),l(this,"handleCreate",()=>{var t,e,n;const{paymentMethodsConfiguration:o,showStoredPaymentMethods:a,showPaymentMethods:d,instantPaymentTypes:l}=this.props,{paymentMethods:m,storedPaymentMethods:p,instantPaymentMethods:c,fastlanePaymentMethod:y}=h(this.core.paymentMethodsResponse,l),u={elementRef:this.elementRef,isDropin:!0},f=d?i(m,o,u,this.core):[],v=s(c,o,u,this.core);return[a?r(null!==(t=null===(e=(n=this.props).filterStoredPaymentMethods)||void 0===e?void 0:e.call(n,p))&&void 0!==t?t:p,o,u,this.core):[],f,v,y?i([y],o,u,this.core):[]]}),l(this,"handleOrder",({order:t})=>{this.updateParent({order:t})}),this.submit=this.submit.bind(this),this.handleAction=this.handleAction.bind(this),this.handleElementsCreated=this.handleElementsCreated.bind(this),this.props.paymentMethodComponents.forEach(t=>this.core.register(t)),this.paymentMethodsConfiguration=this.props.paymentMethodsConfiguration||{}}}l(y,"type",d.dropin),l(y,"defaultProps",n);export{y as default};
//# sourceMappingURL=Dropin.js.map