UNPKG

@adyen/adyen-web

Version:

[![npm](https://img.shields.io/npm/v/@adyen/adyen-web.svg)](https://www.npmjs.com/package/@adyen/adyen-web)

3 lines (2 loc) 2.88 kB
import{createElement as e}from"../../external/preact/dist/preact.js";import{UIElement as o}from"../internal/UIElement/UIElement.js";import i from"../../utils/browserInfo.js";import t from"../internal/ClickToPay/services/create-clicktopay-service.js";import{CtpState as r}from"../internal/ClickToPay/services/ClickToPayService.js";import s from"../internal/ClickToPay/context/ClickToPayProvider.js";import n from"../internal/ClickToPay/ClickToPayComponent.js";import a from"../../core/Errors/AdyenCheckoutError.js";import{TxVariants as c}from"../tx-variants.js";function l(e,o,i){return o in e?Object.defineProperty(e,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[o]=i,e}class p extends o{get isValid(){return!0}get browserInfo(){return i()}formatData(){const{srcScheme:e,srcCorrelationId:o,srcTokenReference:i,srcCheckoutPayload:t,srcDigitalCardId:r}=this.state.data;return{paymentMethod:{type:p.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!==r.NotAvailable&&i!==r.Login&&i!==r.Idle||o()})}):Promise.reject()}componentToRender(){return e(s,{isStandaloneComponent:!0,configuration:this.ctpConfiguration,clickToPayService:this.clickToPayService,setClickToPayRef:this.setComponentRef,onSetStatus:this.setElementStatus,onSubmit:this.handleClickToPaySubmit,onError:this.handleError},e(n,null))}constructor(e,o){super(e,o),l(this,"clickToPayService",void 0),l(this,"ctpConfiguration",void 0),l(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=t(this.props.configuration,this.ctpConfiguration,this.props.environment,this.analytics),this.clickToPayService?.initialize().catch(e=>{this.handleError(new a("ERROR",e.toString(),{cause:e}))}),this.clickToPayService||console.warn("ClickToPay not initialized - Likely the payment method is not configured or its configuration is missing")}}l(p,"type",c.clicktopay);export{p as ClickToPayElement,p as default}; //# sourceMappingURL=ClickToPay.js.map