Skip to content

Commit

Permalink
Add payment request to payments module (#83)
Browse files Browse the repository at this point in the history
* Add payment request to payments module

---------

Co-authored-by: Andrei Bents <[email protected]>
  • Loading branch information
andrewbents and Andrei Bents authored Sep 24, 2024
1 parent 70dd405 commit 6c86dac
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>
/** Check if user can make payment via a supported payment request method */
canMakePayment: () => Promise<'applePay' | 'googlePay' | 'basicCard' | null>
canMakePayment: () => Promise<PaymentRequestPaymentMethod | null>
/** Manually destroy the payment request if needed */
destroy: () => void
}
Expand Down Expand Up @@ -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<PaymentRequestPaymentMethod>
/** 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.
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 6c86dac

Please sign in to comment.