@adyen/adyen-web
Version:
[](https://www.npmjs.com/package/@adyen/adyen-web)
3 lines (2 loc) • 1.3 kB
JavaScript
import{isReadyToPayRequest as t,initiatePaymentRequest as e}from"./requests.js";import{resolveEnvironment as n}from"./utils.js";import a from"../../utils/Script.js";import i from"./config.js";function o(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}class s{async getGooglePaymentsClient(t){var e;if(!(null===(e=window.google)||void 0===e?void 0:e.payments)){const t=new a({src:i.URL,component:"googlepay",analytics:this.analytics});await t.load()}return new google.payments.api.PaymentsClient(t)}isReadyToPay(e){return this.paymentsClient?this.paymentsClient.then(n=>n.isReadyToPay(t(e))):Promise.reject(new Error("Google Pay is not available"))}prefetchPaymentData(t,n){if(!this.paymentsClient)throw new Error("Google Pay is not available");const a=e(t,n);this.paymentsClient.then(t=>t.prefetchPaymentData(a))}initiatePayment(t,n){if(!this.paymentsClient)throw new Error("Google Pay is not available");const a=e(t,n);return this.paymentsClient.then(t=>t.loadPaymentData(a))}constructor(t,e,a){o(this,"analytics",void 0),o(this,"paymentsClient",void 0);const i=n(t);this.analytics=e,this.paymentsClient=this.getGooglePaymentsClient({environment:i,paymentDataCallbacks:a})}}export{s as default};
//# sourceMappingURL=GooglePayService.js.map