UNPKG

@atlas-kitchen/adyen-web

Version:
3 lines (2 loc) 4.02 kB
import{createElement as e}from"../../external/preact/dist/preact.js";import{UIElement as o}from"../internal/UIElement/UIElement.js";import{CoreProvider as t}from"../../core/Context/CoreProvider.js";import r from"../../utils/browserInfo.js";import i from"../internal/ClickToPay/services/create-clicktopay-service.js";import{CtpState as n}from"../internal/ClickToPay/services/ClickToPayService.js";import s from"../internal/ClickToPay/context/ClickToPayProvider.js";import c from"../internal/ClickToPay/ClickToPayComponent.js";import a from"../../core/Errors/AdyenCheckoutError.js";import{TxVariants as l}from"../tx-variants.js";function p(e,o,t){return o in e?Object.defineProperty(e,o,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[o]=t,e}function u(e){for(var o=1;o<arguments.length;o++){var t=null!=arguments[o]?arguments[o]:{},r=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(t).filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})))),r.forEach((function(o){p(e,o,t[o])}))}return e}function h(e,o){return o=null!=o?o:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):function(e){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);o.push.apply(o,t)}return o}(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))})),e}class m extends o{get isValid(){return!0}get browserInfo(){return r()}formatData(){var e,o;const{srcScheme:t,srcCorrelationId:r,srcTokenReference:i,srcCheckoutPayload:n,srcDigitalCardId:s}=this.state.data;return{paymentMethod:u({type:m.type},t&&{srcScheme:t},r&&{srcCorrelationId:r},i&&{srcTokenReference:i},n&&{srcCheckoutPayload:n},s&&{srcDigitalCardId:s}),browserInfo:this.browserInfo,origin:null===(o=window)||void 0===o||null===(e=o.location)||void 0===e?void 0:e.origin}}formatProps(e){var o,t,r,i,n,s;return h(u({},e),{disableOtpAutoFocus:e.disableOtpAutoFocus||!1,shopperEmail:e.shopperEmail||(null===(t=this.core.options)||void 0===t||null===(o=t.session)||void 0===o?void 0:o.shopperEmail),telephoneNumber:e.telephoneNumber||(null===(i=this.core.options)||void 0===i||null===(r=i.session)||void 0===r?void 0:r.telephoneNumber),locale:e.locale||(null===(s=e.i18n)||void 0===s||null===(n=s.locale)||void 0===n?void 0:n.replace("-","_"))})}async isAvailable(){return this.clickToPayService?this.clickToPayService.shopperAccountFound?Promise.resolve():new Promise(((e,o)=>{this.clickToPayService.subscribeOnStateChange((t=>{this.clickToPayService.shopperAccountFound&&e(),t!==n.NotAvailable&&t!==n.Login&&t!==n.Idle||o()}))})):Promise.reject()}render(){return e(t,{i18n:this.props.i18n,loadingContext:this.props.loadingContext,resources:this.resources},e(s,{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(c,null)))}constructor(e,o){var t;super(e,o),p(this,"clickToPayService",void 0),p(this,"ctpConfiguration",void 0),p(this,"handleClickToPaySubmit",(e=>{this.setState({data:u({},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=i(this.props.configuration,this.ctpConfiguration,this.props.environment),null===(t=this.clickToPayService)||void 0===t||t.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")}}p(m,"type",l.clicktopay);export{m as ClickToPayElement,m as default}; //# sourceMappingURL=ClickToPay.js.map