@adyen/adyen-web
Version:
[](https://www.npmjs.com/package/@adyen/adyen-web)
3 lines (2 loc) • 3 kB
JavaScript
import{createElement as e}from"../../external/preact/dist/preact.js";import{UIElement as t}from"../internal/UIElement/UIElement.js";import n from"./CustomCardInput/CustomCardInput.js";import s from"../../utils/browserInfo.js";import o from"../internal/SecuredFields/binLookup/triggerBinLookUp.js";import{getCardImageUrl as r,fieldTypeToSnakeCase as i}from"../internal/SecuredFields/utils.js";import{TxVariants as a}from"../tx-variants.js";import{AnalyticsInfoEvent as d,InfoEventType as p}from"../../core/Analytics/events/AnalyticsInfoEvent.js";import{DUAL_BRANDS_THAT_NEED_SELECTION_MECHANISM as u}from"../Card/constants.js";function c(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class l extends t{formatProps(e){return{...e,type:a.customCard}}formatData(){const e=this.state.selectedBrandValue;return{paymentMethod:{type:"scheme",...this.state.data,...e&&{brand:e}},browserInfo:this.browserInfo,origin:!!window&&window.location.origin}}updateStyles(e){return this.componentRef?.updateStyles&&this.componentRef.updateStyles(e),this}setFocusOn(e){return this.componentRef?.setFocusOn&&this.componentRef.setFocusOn(e),this}processBinLookupResponse(e){return this.componentRef?.processBinLookupResponse&&this.componentRef.processBinLookupResponse(e),this}dualBrandingChangeHandler(e){return this.componentRef?.dualBrandingChangeHandler&&this.componentRef.dualBrandingChangeHandler(e),this}handleUnsupportedCard(e){return this.componentRef?.handleUnsupportedCard&&this.componentRef.handleUnsupportedCard(e),this}onBinLookup(e){const t={...e};if(t.rootNode=this._node,!t.isReset){t.supportedBrandsRaw=e.supportedBrandsRaw?.map(e=>(e.brandImageUrl=this.props.brandsConfiguration[e.brand]?.icon??r(e.brand,this.resources),e));let n=!1,s=!1;e.supportedBrandsRaw?.length>1&&(n=!0,s=e.detectedBrands.some(e=>u.includes(e))),t.dualBrandingType=null,n&&(t.dualBrandingType=s?"Dual Branded (Selectable): Regulation mandates that you must provide a brand selection mechanism":"Dual Branded (Display-only): No selection mechanism required")}this.props.onBinLookup(t)}get isValid(){return!!this.state.isValid}get browserInfo(){return s()}componentToRender(){return e(n,{ref:e=>{this.componentRef=e},...this.props,...this.state,handleKeyPress:this.handleKeyPress,rootNode:this._node,onChange:this.setState,onBinValue:this.onBinValue,implementationType:"custom",resources:this.resources,brand:this.brand,onFocus:this.onFocus,onSubmitAnalytics:this.submitAnalytics})}constructor(...e){super(...e),c(this,"brand",a.card),c(this,"onBinValue",o(this)),c(this,"onFocus",e=>{const t=new d({component:this.type,type:!0===e.focus?p.focus:p.unfocus,target:i(e.fieldType)});this.submitAnalytics(t),this.props.onFocus?.(e)}),c(this,"onEnterKeyPressed",(e,t)=>{this.props.onEnterKeyPressed?.(e,t)})}}c(l,"type",a.customCard),c(l,"defaultProps",{onBinLookup:()=>{},brandsConfiguration:{}});export{l as CustomCard,l as default};
//# sourceMappingURL=CustomCard.js.map