Skip to content

Commit

Permalink
add custom methods types to account-onboarding (ga) (#60)
Browse files Browse the repository at this point in the history
* add custom methods to account-onboarding
  • Loading branch information
kaiying-stripe authored Nov 7, 2023
1 parent 128b7a1 commit c0c3356
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/shared.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
IStripeConnectInitParams,
StripeConnectInstance,
ConnectElementTagName
ConnectElementTagName,
ConnectHTMLElementRecord
} from "../types";

export type LoadConnectAndInitialize = (
Expand Down Expand Up @@ -119,14 +120,14 @@ export const initStripeConnect = (
create: tagName => {
let htmlName = componentNameMapping[tagName];
if (!htmlName) {
htmlName = tagName as ConnectElementHTMLName;
htmlName = (tagName as unknown) as ConnectElementHTMLName;
}
const element = document.createElement(htmlName);
stripeConnectInstance.then(instance => {
(element as any).setConnector((instance as any).connect);
});

return element;
return element as ConnectHTMLElementRecord[typeof tagName];
},
update: updateOptions => {
stripeConnectInstance.then(instance => {
Expand Down
27 changes: 26 additions & 1 deletion types/shared.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,38 @@ export interface IStripeConnectInitParams {
locale?: string;
}

type ConnectHTMLElementRecordFallback = {
[key in string]: HTMLElement | null;
};
type ConnectHTMLElementRecordBase = {
[tagName in ConnectElementTagName]: HTMLElement;
};

interface ConnectHTMLElementRecord
extends ConnectHTMLElementRecordBase,
ConnectHTMLElementRecordFallback {
"account-onboarding": HTMLElement & {
setFullTermsOfServiceUrl: (termOfServiceUrl: string | undefined) => void;
setRecipientTermsOfServiceUrl: (
recipientTermsOfServiceUrl: string | undefined
) => void;
setPrivacyPolicyUrl: (privacyPolicyUrl: string | undefined) => void;
setSkipTermsOfServiceCollection: (
skipTermsOfServiceCollection: boolean | undefined
) => void;
setOnExit: (listener: () => void) => void;
};
}

export interface StripeConnectInstance {
/**
* Creates a Connect element.
* @tagName Name of the Connect component to create.
* @returns An HTML component corresponding to that connect component
*/
create: (tagName: ConnectElementTagName) => HTMLElement;
create: <T extends ConnectElementTagName>(
tagName: T
) => ConnectHTMLElementRecord[T];

/**
* Updates the Connect instance with new parameters.
Expand Down

0 comments on commit c0c3356

Please sign in to comment.