From 1f62a3099bee2d8f08cbfb74e31c2c7e04da095b Mon Sep 17 00:00:00 2001 From: Chris Barton Date: Wed, 13 Nov 2024 12:56:51 -0800 Subject: [PATCH] chore: add missing type definitions for Adyen APM Fixes #882, #883, #885 --- test/types/alternative-payment-methods.ts | 21 +++++++++++++++++++++ types/lib/alternative-payment-methods.d.ts | 22 ++++++++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 test/types/alternative-payment-methods.ts diff --git a/test/types/alternative-payment-methods.ts b/test/types/alternative-payment-methods.ts new file mode 100644 index 00000000..70814a04 --- /dev/null +++ b/test/types/alternative-payment-methods.ts @@ -0,0 +1,21 @@ +export default function alternativePaymentMethods () { + const apm = window.recurly.AlternativePaymentMethods({ + allowedPaymentMethods: ['ideal', 'sofort', 'cashapp'], + blockedPaymentMethods: ['bacs'], + containerSelector: '#payment-methods', + amount: 1000, + currency: 'EUR', + countryCode: 'NL', + returnURL: 'https://example.com/return', + adyen: { + publicKey: 'public-key', + }, + }); + + apm.on('error', () => {}); + // @ts-expect-error + apm.start({}); + apm.start().then(() => {}); + apm.submit({}).then(() => {}); + apm.handleAction({}).then(() => {}); +} diff --git a/types/lib/alternative-payment-methods.d.ts b/types/lib/alternative-payment-methods.d.ts index 96168dd7..42b3eae4 100644 --- a/types/lib/alternative-payment-methods.d.ts +++ b/types/lib/alternative-payment-methods.d.ts @@ -3,7 +3,7 @@ import { Emitter } from './emitter'; export type AlternativePaymentMethodEvents = 'token' | 'error' | 'valid'; -export type AlternativePaymentMethodType = 'boleto'; +export type AlternativePaymentMethodType = 'boleto' | 'ideal' | 'sofort' | 'paypal' | 'cashapp' | 'bacs'; export type ChannelType = 'iOS' | 'Android' | 'Web'; @@ -16,15 +16,15 @@ export type AdyenAlternativePaymentMethodOptions = { publicKey: string, /** - * Indicate a test or a live environment. + * Indicate a test or a live environment. Defaults to `"test"`. */ env?: AdyenEnvironmentType, /** - * Show or hides a Pay Button for each payment method. Defaults to false. + * Show or hides a Pay Button for each payment method. Defaults to `false`. * When the button is disable you need to call the submit() function when the payment form is valid. */ - showPayButton?: false, + showPayButton?: boolean, /** * Additional Adyen Configuration. @@ -71,13 +71,14 @@ export type AlternativePaymentMethodStartOptions = { countryCode: string; /** - * The customer's locale. This is used to set the language rendered in the UI. + * The customer's locale. This is used to set the language rendered in the UI. Defaults to `"en-US"`. */ locale?: string; /** * The platform where a payment transaction takes place. * This field can be used for filtering out payment methods that are only available on specific platforms. + * Defaults to `"Web"`. */ channel?: ChannelType, @@ -89,7 +90,12 @@ export type AlternativePaymentMethodStartOptions = { /** * Sets additional customer fields on the generated token. */ - customer?: CustomerOptions + customer?: CustomerOptions, + + /** + * The URL to return to after the shopper completes the payment. + */ + returnURL?: string }; export type AlternativePaymentMethodSubmitOptions = { @@ -103,7 +109,7 @@ export interface AlternativePaymentMethodsInstance extends Emitter Promise; + start: () => Promise; /** * Submit the customer payment information and produce a token. @@ -121,4 +127,4 @@ export interface AlternativePaymentMethodsInstance extends Emitter Promise; } -export type AlternativePaymentMethods = () => AlternativePaymentMethodsInstance; +export type AlternativePaymentMethods = (config: AlternativePaymentMethodStartOptions) => AlternativePaymentMethodsInstance;