@adyen/adyen-web
Version:
[](https://www.npmjs.com/package/@adyen/adyen-web)
3 lines (2 loc) • 10.1 kB
JavaScript
import{createElement as t}from"../../external/preact/dist/preact.js";import o from"./components/CardInput/CardInput.js";import e from"../../utils/browserInfo.js";import i from"../internal/SecuredFields/binLookup/triggerBinLookUp.js";import{fieldTypeToSnakeCase as n,isSecuredField as s}from"../internal/SecuredFields/utils.js";import{reject as r}from"../../utils/commonUtils.js";import{shouldIncludeInstallmentsInPaymentData as a}from"./components/CardInput/utils.js";import l from"../internal/ClickToPay/services/create-clicktopay-service.js";import d from"./components/ClickToPayWrapper.js";import{TxVariants as u}from"../tx-variants.js";import{UIElement as c}from"../internal/UIElement/UIElement.js";import p from"../internal/PayButton/PayButton.js";import h,{IMPLEMENTATION_ERROR as m}from"../../core/Errors/AdyenCheckoutError.js";import y from"./components/CardInput/defaultProps.js";import{AnalyticsInfoEvent as f,InfoEventType as v}from"../../core/Analytics/events/AnalyticsInfoEvent.js";function b(t,o,e){return o in t?Object.defineProperty(t,o,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[o]=e,t}function g(t){for(var o=1;o<arguments.length;o++){var e=null!=arguments[o]?arguments[o]:{},i=Object.keys(e);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(e).filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.forEach(function(o){b(t,o,e[o])})}return t}function P(t,o){return o=null!=o?o:{},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):function(t){var o=Object.keys(t);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(t);o.push.apply(o,e)}return o}(Object(o)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}),t}class C extends c{setStatus(t,o){var e,i;return(null===(e=this.componentRef)||void 0===e?void 0:e.setStatus)&&this.componentRef.setStatus(t,o),(null===(i=this.clickToPayRef)||void 0===i?void 0:i.setStatus)&&this.clickToPayRef.setStatus(t,o),this}getPaymentMethodConfigFromResponse(t){var o;return(null==t?void 0:t.fundingSource)?null===(o=this.core.paymentMethodsResponse)||void 0===o?void 0:o.findByFundingSource(t.type,t.fundingSource):super.getPaymentMethodConfigFromResponse(t)}formatProps(t){var o,e,i,n,s,r,a,l,d,c,p,f,v,b,C,S,k,R,B,O,T,w;const j=null!==(o=null===(s=t.session)||void 0===s||null===(n=s.configuration)||void 0===n?void 0:n.enableStoreDetails)&&void 0!==o?o:t.enableStoreDetails,I=!(0===(null===(r=t.amount)||void 0===r?void 0:r.value))&&j,M=t.storedPaymentMethodId||t.id,A=M&&(null==t||null===(a=t.supportedShopperInteractions)||void 0===a?void 0:a.includes("Ecommerce"));if(M&&!A)throw new h(m,"You are trying to create a storedCard from a stored PM that does not support Ecommerce interactions");return g(P(g({},t),{holderNameRequired:!!t.hasHolderName&&t.holderNameRequired,hasCVC:!(t.brand&&"bcmc"===t.brand||t.hideCVC),billingAddressRequired:!t.storedPaymentMethodId&&t.billingAddressRequired,billingAddressMode:t.onAddressLookup?y.billingAddressMode:t.billingAddressMode,brand:null!==(e=t.brand)&&void 0!==e?e:u.card,countryCode:t.countryCode?t.countryCode.toLowerCase():null,configuration:P(g({},t.configuration),{socialSecurityNumberMode:null!==(i=null===(l=t.configuration)||void 0===l?void 0:l.socialSecurityNumberMode)&&void 0!==i?i:"auto"}),brandsConfiguration:t.brandsConfiguration||(null===(d=t.configuration)||void 0===d?void 0:d.brandsConfiguration)||{},icon:t.icon||(null===(c=t.configuration)||void 0===c?void 0:c.icon),installmentOptions:(null===(f=t.session)||void 0===f||null===(p=f.configuration)||void 0===p?void 0:p.installmentOptions)||t.installmentOptions,enableStoreDetails:j,showStoreDetailsCheckbox:I,clickToPayConfiguration:P(g({},t.clickToPayConfiguration),{disableOtpAutoFocus:(null===(v=t.clickToPayConfiguration)||void 0===v?void 0:v.disableOtpAutoFocus)||!1,shopperEmail:(null===(b=t.clickToPayConfiguration)||void 0===b?void 0:b.shopperEmail)||(null===(S=this.core.options)||void 0===S||null===(C=S.session)||void 0===C?void 0:C.shopperEmail),telephoneNumber:(null===(k=t.clickToPayConfiguration)||void 0===k?void 0:k.telephoneNumber)||(null===(B=this.core.options)||void 0===B||null===(R=B.session)||void 0===R?void 0:R.telephoneNumber),locale:(null===(O=t.clickToPayConfiguration)||void 0===O?void 0:O.locale)||(null===(w=t.i18n)||void 0===w||null===(T=w.locale)||void 0===T?void 0:T.replace("-","_"))})}),M&&{storedPaymentMethodId:M})}formatData(){var t;const o=this.state.selectedBrandValue;return P(g({paymentMethod:g({type:C.type},this.state.data,this.props.storedPaymentMethodId&&{storedPaymentMethodId:this.props.storedPaymentMethodId,holderName:null!==(t=this.props.holderName)&&void 0!==t?t:""},o&&{brand:o},this.props.fundingSource&&{fundingSource:this.props.fundingSource},this.state.fastlaneData&&{fastlaneData:btoa(JSON.stringify(this.state.fastlaneData))})},this.state.billingAddress&&{billingAddress:this.state.billingAddress},this.state.socialSecurityNumber&&{socialSecurityNumber:this.state.socialSecurityNumber},this.storePaymentMethodPayload,a(this.state.installments)&&{installments:this.state.installments}),{browserInfo:this.browserInfo,origin:!!window&&window.location.origin})}beforeRender(t){if(null==t?void 0:t.originalAction)return;const o=new f(g({type:v.rendered,component:this.type,configData:P(g({},t),{showPayButton:this.props.showPayButton})},(null==t?void 0:t.oneClick)&&{isStoredPaymentMethod:!0,brand:t.brand}));this.analytics.sendAnalytics(o)}updateStyles(t){var o;return(null===(o=this.componentRef)||void 0===o?void 0:o.updateStyles)&&this.componentRef.updateStyles(t),this}setFocusOn(t){var o;return(null===(o=this.componentRef)||void 0===o?void 0:o.setFocusOn)&&this.componentRef.setFocusOn(t),this}processBinLookupResponse(t,o=!1){var e;return(null===(e=this.componentRef)||void 0===e?void 0:e.processBinLookupResponse)&&this.componentRef.processBinLookupResponse(t,o),this}handleUnsupportedCard(t){var o;return(null===(o=this.componentRef)||void 0===o?void 0:o.handleUnsupportedCard)&&this.componentRef.handleUnsupportedCard(t),this}onBinLookup(t){if(!t.isReset){var o,e;const i=r("supportedBrandsRaw").from(t);null===(o=(e=this.props).onBinLookup)||void 0===o||o.call(e,i)}}get storePaymentMethodPayload(){var t,o;if((null===(t=this.props.storedPaymentMethodId)||void 0===t?void 0:t.length)>0)return{};if(0===(null===(o=this.props.amount)||void 0===o?void 0:o.value))return this.props.enableStoreDetails?{storePaymentMethod:!0}:{};return this.props.showStoreDetailsCheckbox&&void 0!==this.state.storePaymentMethod?{storePaymentMethod:Boolean(this.state.storePaymentMethod)}:{}}get isValid(){return!!this.state.isValid}get icon(){var t;return null!==(t=this.props.icon)&&void 0!==t?t:this.resources.getImage()(this.props.brand)}get brands(){const{brands:t,brandsConfiguration:o}=this.props;return t?t.map(t=>{var e,i;return{icon:null!==(e=null===(i=o[t])||void 0===i?void 0:i.icon)&&void 0!==e?e:this.props.modules.resources.getImage()(t),name:t}}):[]}get displayName(){return this.props.storedPaymentMethodId?`•••• ${this.props.lastFour}`:this.props.name||C.type}get accessibleName(){return(this.props.name||C.type)+(this.props.storedPaymentMethodId?" "+this.props.i18n.get("creditCard.storedCard.description.ariaLabel").replace("%@",this.props.lastFour):"")}get browserInfo(){return e()}renderCardInput(e=!0){return t(o,P(g({setComponentRef:this.setComponentRef},this.props,this.state),{onSubmitAnalytics:this.submitAnalytics,onChange:this.setState,onSubmit:this.submit,handleKeyPress:this.handleKeyPress,payButton:this.payButton,onBrand:this.onBrand,onBinValue:this.onBinValue,brand:this.props.brand,brandsIcons:this.brands,isPayButtonPrimaryVariant:e,resources:this.resources,onFocus:this.onFocus,onBlur:this.onBlur,onConfigSuccess:this.onConfigSuccess}))}componentToRender(){return t(d,{configuration:this.props.clickToPayConfiguration,clickToPayService:this.clickToPayService,isStandaloneComponent:!1,setClickToPayRef:this.setClickToPayRef,onSetStatus:this.setElementStatus,onSubmit:this.handleClickToPaySubmit,onError:this.handleError},t=>this.renderCardInput(t))}constructor(o,e){var r;(super(o,e),b(this,"clickToPayService",void 0),b(this,"clickToPayRef",null),b(this,"setClickToPayRef",t=>{this.clickToPayRef=t}),b(this,"onBrand",t=>{var o,e;null===(o=(e=this.props).onBrand)||void 0===o||o.call(e,t)}),b(this,"handleClickToPaySubmit",t=>{this.setState({data:g({},t),valid:{},errors:{},isValid:!0}),this.submit()}),b(this,"onConfigSuccess",t=>{var o,e;const i=new f({component:this.type,type:v.configured});this.submitAnalytics(i),null===(o=(e=this.props).onConfigSuccess)||void 0===o||o.call(e,t)}),b(this,"onFocus",t=>{const o=new f({component:this.type,type:v.focus,target:n(t.fieldType)});var e,i,r,a;(this.submitAnalytics(o),s(t.fieldType))?null===(e=(i=this.props).onFocus)||void 0===e||e.call(i,t.event):null===(r=(a=this.props).onFocus)||void 0===r||r.call(a,t)}),b(this,"onBlur",t=>{const o=new f({component:this.type,type:v.unfocus,target:n(t.fieldType)});var e,i,r,a;(this.submitAnalytics(o),s(t.fieldType))?null===(e=(i=this.props).onBlur)||void 0===e||e.call(i,t.event):null===(r=(a=this.props).onBlur)||void 0===r||r.call(a,t)}),b(this,"onBinValue",i(this)),b(this,"payButton",o=>{var e,i;const n=0===(null===(e=this.props.amount)||void 0===e?void 0:e.value),s=(null===(i=this.props.storedPaymentMethodId)||void 0===i?void 0:i.length)>0;return t(p,P(g({},o),{label:n&&!s?this.props.i18n.get("payButton.saveDetails"):"",onClick:this.submit}))}),e&&!e._disableClickToPay&&"prepaid"!==this.props.fundingSource)&&(this.clickToPayService=l(this.props.configuration,this.props.clickToPayConfiguration,this.props.environment,this.analytics),null===(r=this.clickToPayService)||void 0===r||r.initialize())}}b(C,"type",u.scheme),b(C,"defaultProps",g({showFormInstruction:!0,_disableClickToPay:!1,doBinLookup:!0},r(["type","setComponentRef"]).from(y)));export{C as CardElement,C as default};
//# sourceMappingURL=Card.js.map