Skip to content

Commit

Permalink
chore: add missing type definitions for Adyen APM
Browse files Browse the repository at this point in the history
Fixes #882, #883, #885
  • Loading branch information
cbarton committed Nov 13, 2024
1 parent b258a60 commit 1f62a30
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
21 changes: 21 additions & 0 deletions test/types/alternative-payment-methods.ts
Original file line number Diff line number Diff line change
@@ -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(() => {});
}
22 changes: 14 additions & 8 deletions types/lib/alternative-payment-methods.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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.
Expand Down Expand Up @@ -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,

Expand All @@ -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 = {
Expand All @@ -103,7 +109,7 @@ export interface AlternativePaymentMethodsInstance extends Emitter<AlternativePa
/**
* Start the PaymentMethods and render the components.
*/
start: (data: AlternativePaymentMethodStartOptions) => Promise<void>;
start: () => Promise<void>;

/**
* Submit the customer payment information and produce a token.
Expand All @@ -121,4 +127,4 @@ export interface AlternativePaymentMethodsInstance extends Emitter<AlternativePa
handleAction: (paymentResponse: any) => Promise<void>;
}

export type AlternativePaymentMethods = () => AlternativePaymentMethodsInstance;
export type AlternativePaymentMethods = (config: AlternativePaymentMethodStartOptions) => AlternativePaymentMethodsInstance;

0 comments on commit 1f62a30

Please sign in to comment.