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.51 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 n 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 l}from"../internal/UIElement/utils.js";function a(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}}submitAnalytics(e){super.submitAnalytics({...e},this.props)}getShopperDetails(){const{amazonCheckoutSessionId:e,configuration:o={},loadingContext:t,clientKey:r}=this.props;if(!e)return console.error("Could not shopper details. Missing checkoutSessionId.");const n={checkoutSessionId:e,getDeliveryAddress:!0,publicKeyId:o.publicKeyId,region:o.region};return i(t,r,n)}handleDeclineFlow(){const{amazonCheckoutSessionId:e,configuration:o={},loadingContext:t,clientKey:r}=this.props;if(!e)return console.error("Could handle the decline flow. Missing checkoutSessionId.");const n={checkoutSessionId:e,getDeclineFlowUrl:!0,publicKeyId:o.publicKeyId,region:o.region};i(t,r,n).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 r()}submit(){const e=this.componentRef&&this.componentRef.getSubmitFunction();if(e)return e();this.makePaymentsCall().then(c).then(l).then(this.handleResponse).catch(this.handleFailedResult)}render(){return e(t,{i18n:this.props.i18n,loadingContext:this.props.loadingContext,resources:this.resources},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}))}}a(u,"type",p.amazonpay),a(u,"defaultProps",s);export{u as AmazonPayElement,u as default}; //# sourceMappingURL=AmazonPay.js.map