@atlas-kitchen/adyen-web
Version:
3 lines (2 loc) • 3.04 kB
JavaScript
import{createElement as e}from"../../external/preact/dist/preact.js";import{UIElement as o}from"../internal/UIElement/UIElement.js";import{CoreProvider as i}from"../../core/Context/CoreProvider.js";import t from"../../utils/browserInfo.js";import r from"../internal/ClickToPay/services/create-clicktopay-service.js";import{CtpState as s}from"../internal/ClickToPay/services/ClickToPayService.js";import n from"../internal/ClickToPay/context/ClickToPayProvider.js";import a from"../internal/ClickToPay/ClickToPayComponent.js";import c from"../../core/Errors/AdyenCheckoutError.js";import{TxVariants as l}from"../tx-variants.js";function p(e,o,i){return o in e?Object.defineProperty(e,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[o]=i,e}class h extends o{get isValid(){return!0}get browserInfo(){return t()}formatData(){const{srcScheme:e,srcCorrelationId:o,srcTokenReference:i,srcCheckoutPayload:t,srcDigitalCardId:r}=this.state.data;return{paymentMethod:{type:h.type,...e&&{srcScheme:e},...o&&{srcCorrelationId:o},...i&&{srcTokenReference:i},...t&&{srcCheckoutPayload:t},...r&&{srcDigitalCardId:r}},browserInfo:this.browserInfo,origin:window?.location?.origin}}formatProps(e){return{...e,disableOtpAutoFocus:e.disableOtpAutoFocus||!1,shopperEmail:e.shopperEmail||this.core.options?.session?.shopperEmail,telephoneNumber:e.telephoneNumber||this.core.options?.session?.telephoneNumber,locale:e.locale||e.i18n?.locale?.replace("-","_")}}async isAvailable(){return this.clickToPayService?this.clickToPayService.shopperAccountFound?Promise.resolve():new Promise(((e,o)=>{this.clickToPayService.subscribeOnStateChange((i=>{this.clickToPayService.shopperAccountFound&&e(),i!==s.NotAvailable&&i!==s.Login&&i!==s.Idle||o()}))})):Promise.reject()}render(){return e(i,{i18n:this.props.i18n,loadingContext:this.props.loadingContext,resources:this.resources},e(n,{isStandaloneComponent:!0,configuration:this.ctpConfiguration,amount:this.props.amount,clickToPayService:this.clickToPayService,setClickToPayRef:this.setComponentRef,onSetStatus:this.setElementStatus,onSubmit:this.handleClickToPaySubmit,onError:this.handleError},e(a,null)))}constructor(e,o){super(e,o),p(this,"clickToPayService",void 0),p(this,"ctpConfiguration",void 0),p(this,"handleClickToPaySubmit",(e=>{this.setState({data:{...e},valid:{},errors:{},isValid:!0}),this.submit()})),this.ctpConfiguration={shopperEmail:this.props.shopperEmail,telephoneNumber:this.props.telephoneNumber,merchantDisplayName:this.props.merchantDisplayName,locale:this.props.locale,onReady:this.props.onReady,onTimeout:this.props.onTimeout},this.clickToPayService=r(this.props.configuration,this.ctpConfiguration,this.props.environment),this.clickToPayService?.initialize().catch((e=>{this.handleError(new c("ERROR",e.toString(),{cause:e}))})),this.clickToPayService||console.warn("ClickToPay not initialized - Likely the payment method is not configured or its configuration is missing")}}p(h,"type",l.clicktopay);export{h as ClickToPayElement,h as default};
//# sourceMappingURL=ClickToPay.js.map