UNPKG

@atlas-kitchen/adyen-web

Version:
3 lines (2 loc) 10.3 kB
import{createElement as t}from"../../external/preact/dist/preact.js";import o from"./components/CardInput/CardInput.js";import{CoreProvider as e}from"../../core/Context/CoreProvider.js";import i from"../../utils/browserInfo.js";import s from"../internal/SecuredFields/binLookup/triggerBinLookUp.js";import{fieldTypeToSnakeCase as n}from"../internal/SecuredFields/utils.js";import{reject as r}from"../../utils/commonUtils.js";import{hasValidInstallmentsObject as a,getCardConfigData as l}from"./components/CardInput/utils.js";import d from"../internal/ClickToPay/services/create-clicktopay-service.js";import u from"./components/ClickToPayWrapper.js";import p from"../../core/Errors/SRPanelProvider.js";import{TxVariants as c}from"../tx-variants.js";import{UIElement as h}from"../internal/UIElement/UIElement.js";import m from"../internal/PayButton/PayButton.js";import{ANALYTICS_RENDERED_STR as y,ANALYTICS_CONFIGURED_STR as f,ANALYTICS_FOCUS_STR as v,ANALYTICS_UNFOCUS_STR as b}from"../../core/Analytics/constants.js";import{ALL_SECURED_FIELDS as g}from"../internal/SecuredFields/lib/constants.js";import{hasOwnProperty as P}from"../../utils/hasOwnProperty.js";import C,{IMPLEMENTATION_ERROR as S}from"../../core/Errors/AdyenCheckoutError.js";import k from"./components/CardInput/defaultProps.js";import{AnalyticsInfoEvent as j}from"../../core/Analytics/AnalyticsInfoEvent.js";function O(t,o,e){return o in t?Object.defineProperty(t,o,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[o]=e,t}function R(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){O(t,o,e[o])}))}return t}function T(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 B extends h{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}formatProps(t){var o,e,i,s,n,r,a,l,d,u,p,h,m,y,f,v,b,g,P,j;const O=null!==(j=null===(e=t.session)||void 0===e||null===(o=e.configuration)||void 0===o?void 0:o.enableStoreDetails)&&void 0!==j?j:t.enableStoreDetails,B=!(0===(null===(i=t.amount)||void 0===i?void 0:i.value))&&O,I=t.storedPaymentMethodId||t.id,w=I&&(null==t||null===(s=t.supportedShopperInteractions)||void 0===s?void 0:s.includes("Ecommerce"));if(I&&!w)throw new C(S,"You are trying to create a storedCard from a stored PM that does not support Ecommerce interactions");var A,M;return R(T(R({},t),{holderNameRequired:!!t.hasHolderName&&t.holderNameRequired,hasCVC:!(t.brand&&"bcmc"===t.brand||t.hideCVC),billingAddressRequired:!t.storedPaymentMethodId&&t.billingAddressRequired,billingAddressMode:t.onAddressLookup?k.billingAddressMode:t.billingAddressMode,brand:null!==(A=t.brand)&&void 0!==A?A:c.card,countryCode:t.countryCode?t.countryCode.toLowerCase():null,configuration:T(R({},t.configuration),{socialSecurityNumberMode:null!==(M=null===(n=t.configuration)||void 0===n?void 0:n.socialSecurityNumberMode)&&void 0!==M?M:"auto"}),brandsConfiguration:t.brandsConfiguration||(null===(r=t.configuration)||void 0===r?void 0:r.brandsConfiguration)||{},icon:t.icon||(null===(a=t.configuration)||void 0===a?void 0:a.icon),installmentOptions:(null===(d=t.session)||void 0===d||null===(l=d.configuration)||void 0===l?void 0:l.installmentOptions)||t.installmentOptions,enableStoreDetails:O,showStoreDetailsCheckbox:B,clickToPayConfiguration:T(R({},t.clickToPayConfiguration),{disableOtpAutoFocus:(null===(u=t.clickToPayConfiguration)||void 0===u?void 0:u.disableOtpAutoFocus)||!1,shopperEmail:(null===(p=t.clickToPayConfiguration)||void 0===p?void 0:p.shopperEmail)||(null===(m=this.core.options)||void 0===m||null===(h=m.session)||void 0===h?void 0:h.shopperEmail),telephoneNumber:(null===(y=t.clickToPayConfiguration)||void 0===y?void 0:y.telephoneNumber)||(null===(v=this.core.options)||void 0===v||null===(f=v.session)||void 0===f?void 0:f.telephoneNumber),locale:(null===(b=t.clickToPayConfiguration)||void 0===b?void 0:b.locale)||(null===(P=t.i18n)||void 0===P||null===(g=P.locale)||void 0===g?void 0:g.replace("-","_"))})}),I&&{storedPaymentMethodId:I})}formatData(){const t=this.state.selectedBrandValue;var o;return T(R({paymentMethod:R({type:B.type},this.state.data,this.props.storedPaymentMethodId&&{storedPaymentMethodId:this.props.storedPaymentMethodId,holderName:null!==(o=this.props.holderName)&&void 0!==o?o:""},t&&{brand:t},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})}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)}}submitAnalytics(t){const o=t instanceof j;(o&&t.type===y||o&&t.type===f)&&("scheme"===this.constructor.type&&P(this.props,"supportedShopperInteractions")&&(t.isStoredPaymentMethod=!0,t.brand=this.props.brand),o&&t.type===y&&(t.configData=l(this.props))),super.submitAnalytics(t)}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!==(i=null===(e=o[t])||void 0===e?void 0:e.icon)&&void 0!==i?i:this.props.modules.resources.getImage()(t),name:t}})):[]}get displayName(){return this.props.storedPaymentMethodId?`•••• ${this.props.lastFour}`:this.props.name||B.type}get accessibleName(){return(this.props.name||B.type)+(this.props.storedPaymentMethodId?" "+this.props.i18n.get("creditCard.storedCard.description.ariaLabel").replace("%@",this.props.lastFour):"")}get browserInfo(){return i()}renderCardInput(e=!0){return t(o,T(R({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}))}render(){return t(e,{i18n:this.props.i18n,loadingContext:this.props.loadingContext,resources:this.resources},t(p,{srPanel:this.props.modules.srPanel},t(u,{amount:this.props.amount,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 i;(super(o,e),O(this,"clickToPayService",void 0),O(this,"clickToPayRef",null),O(this,"setClickToPayRef",(t=>{this.clickToPayRef=t})),O(this,"onBrand",(t=>{var o,e;null===(o=(e=this.props).onBrand)||void 0===o||o.call(e,t)})),O(this,"handleClickToPaySubmit",(t=>{this.setState({data:R({},t),valid:{},errors:{},isValid:!0}),this.submit()})),O(this,"onConfigSuccess",(t=>{var o,e;const i=new j({type:f});this.submitAnalytics(i),null===(o=(e=this.props).onConfigSuccess)||void 0===o||o.call(e,t)})),O(this,"onFocus",(t=>{const o=new j({type:v,target:n(t.fieldType)});var e,i,s,r;(this.submitAnalytics(o),g.includes(t.fieldType))?null===(e=(i=this.props).onFocus)||void 0===e||e.call(i,t.event):null===(s=(r=this.props).onFocus)||void 0===s||s.call(r,t)})),O(this,"onBlur",(t=>{const o=new j({type:b,target:n(t.fieldType)});var e,i,s,r;(this.submitAnalytics(o),g.includes(t.fieldType))?null===(e=(i=this.props).onBlur)||void 0===e||e.call(i,t.event):null===(s=(r=this.props).onBlur)||void 0===s||s.call(r,t)})),O(this,"onBinValue",s(this)),O(this,"payButton",(o=>{var e,i;const s=0===(null===(e=this.props.amount)||void 0===e?void 0:e.value),n=(null===(i=this.props.storedPaymentMethodId)||void 0===i?void 0:i.length)>0;return t(m,T(R({},o),{amount:this.props.amount,secondaryAmount:this.props.secondaryAmount,label:s&&!n?this.props.i18n.get("payButton.saveDetails"):"",onClick:this.submit}))})),e&&!e._disableClickToPay)&&(this.clickToPayService=d(this.props.configuration,this.props.clickToPayConfiguration,this.props.environment),null===(i=this.clickToPayService)||void 0===i||i.initialize())}}O(B,"type",c.scheme),O(B,"defaultProps",R({showFormInstruction:!0,_disableClickToPay:!1,doBinLookup:!0},r(["type","setComponentRef"]).from(k)));export{B as CardElement,B as default}; //# sourceMappingURL=Card.js.map