UNPKG

@atlas-kitchen/adyen-web

Version:
3 lines (2 loc) 2.84 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 n from"../../utils/browserInfo.js";import r from"./components/AmazonPayComponent.js";import s from"./defaultProps.js";import{getCheckoutDetails as i}from"./services.js";import{TxVariants as p}from"../tx-variants.js";import{sanitizeResponse as c,verifyPaymentDidNotFail as a}from"../internal/UIElement/utils.js";import{ANALYTICS_RENDERED_STR as l,ANALYTICS_EXPRESS_PAGES_ARRAY as u}from"../../core/Analytics/constants.js";import{AnalyticsInfoEvent as h}from"../../core/Analytics/AnalyticsInfoEvent.js";function m(e,o,t){return o in e?Object.defineProperty(e,o,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[o]=t,e}class d extends o{formatProps(e){return{...e,checkoutMode:e.isDropin?"ProcessOrder":e.checkoutMode,environment:e.environment.toUpperCase(),locale:e.locale.replace("-","_"),productType:e.isDropin&&!e.addressDetails?"PayOnly":e.productType}}formatData(){const{amazonCheckoutSessionId:e}=this.props;return{paymentMethod:{type:d.type,...e&&{checkoutSessionId:e}},browserInfo:this.browserInfo}}submitAnalytics(e){if(e instanceof h&&e.type===l){const{isExpress:o,expressPage:t}=this.props,n=t&&u.includes(t);"boolean"==typeof o&&(e.isExpress=o),!0===o&&n&&(e.expressPage=t)}super.submitAnalytics(e)}getShopperDetails(){const{amazonCheckoutSessionId:e,configuration:o={},loadingContext:t,clientKey:n}=this.props;if(!e)return console.error("Could not shopper details. Missing checkoutSessionId.");const r={checkoutSessionId:e,getDeliveryAddress:!0,publicKeyId:o.publicKeyId,region:o.region};return i(t,n,r)}handleDeclineFlow(){const{amazonCheckoutSessionId:e,configuration:o={},loadingContext:t,clientKey:n}=this.props;if(!e)return console.error("Could handle the decline flow. Missing checkoutSessionId.");const r={checkoutSessionId:e,getDeclineFlowUrl:!0,publicKeyId:o.publicKeyId,region:o.region};i(t,n,r).then(((e={})=>{if(!e?.declineFlowUrl)throw e;window.location.assign(e.declineFlowUrl)})).catch((e=>{this.props.onError&&this.props.onError(e,this.componentRef)}))}get isValid(){return!0}get browserInfo(){return n()}submit(){const e=this.componentRef&&this.componentRef.getSubmitFunction();if(e)return e();this.makePaymentsCall().then(c).then(a).then(this.handleResponse).catch(this.handleFailedResult)}render(){return e(t,{i18n:this.props.i18n,loadingContext:this.props.loadingContext,resources:this.resources},e(r,{ref:e=>{this.componentRef=e},showPayButton:this.props.showPayButton,onClick:this.props.onClick,onError:this.props.onError,onSignOut:this.props.onSignOut,...this.props}))}}m(d,"type",p.amazonpay),m(d,"defaultProps",s);export{d as AmazonPayElement,d as default}; //# sourceMappingURL=AmazonPay.js.map