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