From 500bdd79408ea408d67f8124aad1b548816763a0 Mon Sep 17 00:00:00 2001 From: Andrei Bents Date: Mon, 23 Sep 2024 16:43:31 +0200 Subject: [PATCH 1/2] Add payment request to payments module --- src/types.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index d90307b..44fe179 100644 --- a/src/types.ts +++ b/src/types.ts @@ -527,11 +527,13 @@ export interface RevolutCheckoutCardField extends RevolutCheckoutInstance { validate: () => void } +export type PaymentRequestPaymentMethod = 'applePay' | 'googlePay' + export interface PaymentRequestInstance { /** Render the payment request button */ render: () => Promise /** Check if user can make payment via a supported payment request method */ - canMakePayment: () => Promise<'applePay' | 'googlePay' | 'basicCard' | null> + canMakePayment: () => Promise /** Manually destroy the payment request if needed */ destroy: () => void } @@ -657,6 +659,32 @@ export interface WidgetPaymentRequestInstance extends PaymentRequestInstance, RevolutCheckoutInstance {} +export interface PaymentsModulePaymentRequestOptions + extends Omit< + PaymentRequestOptions, + 'token' | 'target' | 'disableApplePay' | 'disableBasicCard' + > { + /** The amount to be paid by the customer, in the lowest denomination (e.g. cents). */ + amount: number + /** ISO 4217 currency code in upper case. */ + currency: string + /** Preferred method ('applePay' or 'googlePay') or an array of methods in order of preference */ + preferredPaymentMethod?: + | PaymentRequestPaymentMethod + | Array + /** A function to create a Revolut order at a later time within the flow */ + createOrder: () => Promise<{ publicId: string }> +} + +export interface PaymentsModulePaymentRequest { + ( + target: HTMLElement, + options: PaymentsModulePaymentRequestOptions + ): PaymentRequestInstance + + destroy: () => void +} + export interface RevolutCheckoutInstance { /** * Show full-screen payment form with card field and user email. @@ -689,6 +717,8 @@ export interface RevolutCheckoutInstance { export interface RevolutPaymentsModuleInstance { /** Accept payments via Revolut pay v2 */ revolutPay: PaymentsModuleRevolutPayInstance + /** Accept payments via Apple Pay or Google Pay */ + paymentRequest: PaymentsModulePaymentRequest /** Manually destroy the instance */ destroy: () => void /** Controls the language of the text in the widget */ @@ -834,3 +864,4 @@ export interface RevolutCheckout { ) => RevolutPaymentsModuleInstance upsell: (option: RevolutUpsellModuleOptions) => RevolutUpsellModuleInstance } + From 3be08573a2bef65178fc8e32378b33920de8de95 Mon Sep 17 00:00:00 2001 From: Andrei Bents Date: Mon, 23 Sep 2024 16:50:32 +0200 Subject: [PATCH 2/2] fix lint --- src/types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index 44fe179..9304762 100644 --- a/src/types.ts +++ b/src/types.ts @@ -864,4 +864,3 @@ export interface RevolutCheckout { ) => RevolutPaymentsModuleInstance upsell: (option: RevolutUpsellModuleOptions) => RevolutUpsellModuleInstance } -