@adyen/adyen-web
Version:
[](https://www.npmjs.com/package/@adyen/adyen-web)
3 lines (2 loc) • 2.65 kB
JavaScript
import{createElement as e}from"../../external/preact/dist/preact.js";import{UIElement as o}from"../internal/UIElement/UIElement.js";import t from"../../utils/browserInfo.js";import n from"./components/AmazonPayComponent.js";import s from"./defaultProps.js";import{getCheckoutDetails as r}from"./services.js";import{TxVariants as i}from"../tx-variants.js";import{sanitizeResponse as p,verifyPaymentDidNotFail as a}from"../internal/UIElement/utils.js";import{AnalyticsInfoEvent as c,InfoEventType as l}from"../../core/Analytics/events/AnalyticsInfoEvent.js";function h(e,o,t){return o in e?Object.defineProperty(e,o,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[o]=t,e}class u 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:u.type,...e&&{checkoutSessionId:e}},browserInfo:this.browserInfo}}beforeRender(e){const o=new c({type:l.rendered,component:this.type,configData:{...e,showPayButton:this.props.showPayButton},...e?.isExpress&&{isExpress:e.isExpress},...e?.expressPage&&{expressPage:e.expressPage}});this.analytics.sendAnalytics(o)}getShopperDetails(){const{amazonCheckoutSessionId:e,configuration:o={},loadingContext:t,clientKey:n}=this.props;if(!e)return console.error("Could not shopper details. Missing checkoutSessionId.");const s={checkoutSessionId:e,getDeliveryAddress:!0,publicKeyId:o.publicKeyId,region:o.region};return r(t,n,s)}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 s={checkoutSessionId:e,getDeclineFlowUrl:!0,publicKeyId:o.publicKeyId,region:o.region};r(t,n,s).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 t()}submit(){const e=this.componentRef&&this.componentRef.getSubmitFunction();if(e)return e();this.makePaymentsCall().then(p).then(a).then(this.handleResponse).catch(this.handleFailedResult)}componentToRender(){return e(n,{ref:e=>{this.componentRef=e},showPayButton:this.props.showPayButton,onClick:this.props.onClick,onError:this.props.onError,onSignOut:this.props.onSignOut,...this.props})}}h(u,"type",i.amazonpay),h(u,"defaultProps",s);export{u as AmazonPayElement,u as default};
//# sourceMappingURL=AmazonPay.js.map