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