From 3bd2427ca5bc107e717b3cfe73d30c5697e0188e Mon Sep 17 00:00:00 2001 From: Andrei Bents Date: Wed, 6 Nov 2024 17:05:09 +0100 Subject: [PATCH 1/4] Add orderId to success/error callbacks --- src/types.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/types.ts b/src/types.ts index 79d3b96..d6cbdb8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -426,9 +426,9 @@ export interface CommonOptions { /** Controls the language of the text in the widget method */ locale?: Locale | 'auto' /** Callback will be called when the payment is completed successfully */ - onSuccess?: () => void + onSuccess?: (payload: { orderId: string }) => void /** Callback if transaction is failed to complete, the reason should be available in the message parameter */ - onError?: (error: RevolutCheckoutError) => void + onError?: (error: RevolutCheckoutError, payload: { orderId: OrderToken | undefined }) => void /** Callback if an user did not complete the transaction and canceled the authorisation or closed the checkout window */ onCancel?: () => void /** Indicates in which case this saved payment method can be used for payments */ @@ -636,9 +636,10 @@ export type RevolutPayEvents = payload: | { type: 'success' + orderId: string } - | { type: 'error'; error: RevolutCheckoutError } - | { type: 'cancel'; dropOffState: RevolutPayDropOffState } + | { type: 'error'; error: RevolutCheckoutError; orderId: string } + | { type: 'cancel'; dropOffState: RevolutPayDropOffState; orderId?: string } } | { type: 'click' From 84392f92da8e1cb32c9e08088d4ce6f45cf738ec Mon Sep 17 00:00:00 2001 From: Andrei Bents Date: Wed, 6 Nov 2024 17:10:22 +0100 Subject: [PATCH 2/4] Fix lint --- src/types.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/types.ts b/src/types.ts index d6cbdb8..7257163 100644 --- a/src/types.ts +++ b/src/types.ts @@ -254,7 +254,7 @@ export type CountryCode = | 'QA' | 'MZ' -export type Locale = typeof LOCALES[number] +export type Locale = (typeof LOCALES)[number] export type ValidationErrorType = | 'validation.card.number.incomplete' @@ -428,7 +428,10 @@ export interface CommonOptions { /** Callback will be called when the payment is completed successfully */ onSuccess?: (payload: { orderId: string }) => void /** Callback if transaction is failed to complete, the reason should be available in the message parameter */ - onError?: (error: RevolutCheckoutError, payload: { orderId: OrderToken | undefined }) => void + onError?: ( + error: RevolutCheckoutError, + payload: { orderId: OrderToken | undefined } + ) => void /** Callback if an user did not complete the transaction and canceled the authorisation or closed the checkout window */ onCancel?: () => void /** Indicates in which case this saved payment method can be used for payments */ @@ -639,16 +642,19 @@ export type RevolutPayEvents = orderId: string } | { type: 'error'; error: RevolutCheckoutError; orderId: string } - | { type: 'cancel'; dropOffState: RevolutPayDropOffState; orderId?: string } + | { + type: 'cancel' + dropOffState: RevolutPayDropOffState + orderId?: string + } } | { type: 'click' payload: null } -export type RevolutPayEventPayload< - T extends RevolutPayEvents['type'] -> = Extract['payload'] +export type RevolutPayEventPayload = + Extract['payload'] export interface PaymentsModuleRevolutPayInstance { mount: ( @@ -871,3 +877,4 @@ export interface RevolutCheckout { ) => RevolutPaymentsModuleInstance upsell: (option: RevolutUpsellModuleOptions) => RevolutUpsellModuleInstance } + From 903c2913ef3107e0308c1e54d3364a854c665fe2 Mon Sep 17 00:00:00 2001 From: Andrei Bents Date: Wed, 6 Nov 2024 17:11:47 +0100 Subject: [PATCH 3/4] Fix lint --- src/types.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/types.ts b/src/types.ts index 7257163..0f2b6f8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -254,7 +254,7 @@ export type CountryCode = | 'QA' | 'MZ' -export type Locale = (typeof LOCALES)[number] +export type Locale = typeof LOCALES[number] export type ValidationErrorType = | 'validation.card.number.incomplete' @@ -653,8 +653,9 @@ export type RevolutPayEvents = payload: null } -export type RevolutPayEventPayload = - Extract['payload'] +export type RevolutPayEventPayload< + T extends RevolutPayEvents['type'] +> = Extract['payload'] export interface PaymentsModuleRevolutPayInstance { mount: ( @@ -877,4 +878,3 @@ export interface RevolutCheckout { ) => RevolutPaymentsModuleInstance upsell: (option: RevolutUpsellModuleOptions) => RevolutUpsellModuleInstance } - From cdfbc3384ddb1e397828e75e441eec90843658fc Mon Sep 17 00:00:00 2001 From: Andrei Bents Date: Wed, 6 Nov 2024 17:13:41 +0100 Subject: [PATCH 4/4] Fix --- src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index 0f2b6f8..d4078fc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -430,7 +430,7 @@ export interface CommonOptions { /** Callback if transaction is failed to complete, the reason should be available in the message parameter */ onError?: ( error: RevolutCheckoutError, - payload: { orderId: OrderToken | undefined } + payload: { orderId: string | undefined } ) => void /** Callback if an user did not complete the transaction and canceled the authorisation or closed the checkout window */ onCancel?: () => void