Skip to content

Commit a05e964

Browse files
authored
Add Issuing/Treasury components (#142)
* Update connect-js version dependency * Add Issuing/Treasury components
1 parent ff744fd commit a05e964

File tree

5 files changed

+150
-9
lines changed

5 files changed

+150
-9
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@babel/preset-react": "7.18.6",
5050
"@rollup/plugin-json": "^6.0.0",
5151
"@rollup/plugin-replace": "^2.3.1",
52-
"@stripe/connect-js": "3.3.17",
52+
"@stripe/connect-js": "3.3.20",
5353
"@types/jest": "^24.0.25",
5454
"@types/react": "^16.8.0",
5555
"@types/react-dom": "^16.8.0",
@@ -85,7 +85,7 @@
8585
"zx": "^4.2.0"
8686
},
8787
"peerDependencies": {
88-
"@stripe/connect-js": ">=3.3.16",
88+
"@stripe/connect-js": ">=3.3.20",
8989
"react": ">=16.8.0",
9090
"react-dom": ">=16.8.0"
9191
}

src/Components.tsx

Lines changed: 133 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import {FetchEphemeralKeyFunction} from './types';
12
import {useCreateComponent} from './useCreateComponent';
23
import {useUpdateWithSetter} from './utils/useUpdateWithSetter';
34
import {
45
LoadError,
56
LoaderStart,
67
NotificationCount,
78
StepChange,
8-
PaymentsListDefaultFilters
9+
PaymentsListDefaultFilters,
910
} from '@stripe/connect-js';
1011

1112
export type CommonComponentProps = {
@@ -17,7 +18,9 @@ export const ConnectPayments = ({
1718
defaultFilters,
1819
onLoadError,
1920
onLoaderStart,
20-
}: {defaultFilters?: PaymentsListDefaultFilters} & CommonComponentProps): JSX.Element => {
21+
}: {
22+
defaultFilters?: PaymentsListDefaultFilters;
23+
} & CommonComponentProps): JSX.Element => {
2124
const {wrapper, component: payments} = useCreateComponent('payments');
2225

2326
useUpdateWithSetter(payments, onLoaderStart, (comp, val) => {
@@ -187,6 +190,134 @@ export const ConnectNotificationBanner = ({
187190
return wrapper;
188191
};
189192

193+
export const ConnectIssuingCard = ({
194+
defaultCard,
195+
cardSwitching,
196+
showSpendControls,
197+
fetchEphemeralKey,
198+
onLoadError,
199+
onLoaderStart,
200+
}: {
201+
defaultCard?: string;
202+
cardSwitching?: boolean;
203+
showSpendControls?: boolean;
204+
fetchEphemeralKey?: FetchEphemeralKeyFunction;
205+
} & CommonComponentProps): JSX.Element => {
206+
const {wrapper, component: issuingCard} = useCreateComponent('issuing-card');
207+
208+
useUpdateWithSetter(issuingCard, defaultCard, (comp, val) =>
209+
comp.setDefaultCard(val)
210+
);
211+
useUpdateWithSetter(issuingCard, cardSwitching, (comp, val) =>
212+
comp.setCardSwitching(val)
213+
);
214+
useUpdateWithSetter(issuingCard, showSpendControls, (comp, val) =>
215+
comp.setShowSpendControls(val)
216+
);
217+
useUpdateWithSetter(issuingCard, fetchEphemeralKey, (comp, val) =>
218+
comp.setFetchEphemeralKey(val)
219+
);
220+
useUpdateWithSetter(issuingCard, onLoaderStart, (comp, val) => {
221+
comp.setOnLoaderStart(val);
222+
});
223+
useUpdateWithSetter(issuingCard, onLoadError, (comp, val) => {
224+
comp.setOnLoadError(val);
225+
});
226+
227+
return wrapper;
228+
};
229+
230+
export const ConnectIssuingCardsList = ({
231+
showSpendControls,
232+
issuingProgram,
233+
fetchEphemeralKey,
234+
onLoadError,
235+
onLoaderStart,
236+
}: {
237+
showSpendControls?: boolean;
238+
issuingProgram?: string;
239+
fetchEphemeralKey?: FetchEphemeralKeyFunction;
240+
} & CommonComponentProps): JSX.Element => {
241+
const {wrapper, component: issuingCardsList} =
242+
useCreateComponent('issuing-cards-list');
243+
244+
useUpdateWithSetter(issuingCardsList, showSpendControls, (comp, val) =>
245+
comp.setShowSpendControls(val)
246+
);
247+
useUpdateWithSetter(issuingCardsList, issuingProgram, (comp, val) =>
248+
comp.setIssuingProgram(val)
249+
);
250+
useUpdateWithSetter(issuingCardsList, fetchEphemeralKey, (comp, val) =>
251+
comp.setFetchEphemeralKey(val)
252+
);
253+
useUpdateWithSetter(issuingCardsList, onLoaderStart, (comp, val) => {
254+
comp.setOnLoaderStart(val);
255+
});
256+
useUpdateWithSetter(issuingCardsList, onLoadError, (comp, val) => {
257+
comp.setOnLoadError(val);
258+
});
259+
260+
return wrapper;
261+
};
262+
263+
export const ConnectFinancialAccount = ({
264+
financialAccount,
265+
onLoadError,
266+
onLoaderStart,
267+
}: {
268+
financialAccount: string;
269+
} & CommonComponentProps): JSX.Element => {
270+
const {wrapper, component: financialAccountComponent} =
271+
useCreateComponent('financial-account');
272+
273+
useUpdateWithSetter(
274+
financialAccountComponent,
275+
financialAccount,
276+
(comp, val) => comp.setFinancialAccount(val)
277+
);
278+
useUpdateWithSetter(financialAccountComponent, onLoaderStart, (comp, val) => {
279+
comp.setOnLoaderStart(val);
280+
});
281+
useUpdateWithSetter(financialAccountComponent, onLoadError, (comp, val) => {
282+
comp.setOnLoadError(val);
283+
});
284+
285+
return wrapper;
286+
};
287+
288+
export const ConnectFinancialAccountTransactions = ({
289+
financialAccount,
290+
onLoadError,
291+
onLoaderStart,
292+
}: {
293+
financialAccount: string;
294+
} & CommonComponentProps): JSX.Element => {
295+
const {wrapper, component: financialAccountTransactionsComponent} =
296+
useCreateComponent('financial-account-transactions');
297+
298+
useUpdateWithSetter(
299+
financialAccountTransactionsComponent,
300+
financialAccount,
301+
(comp, val) => comp.setFinancialAccount(val)
302+
);
303+
useUpdateWithSetter(
304+
financialAccountTransactionsComponent,
305+
onLoaderStart,
306+
(comp, val) => {
307+
comp.setOnLoaderStart(val);
308+
}
309+
);
310+
useUpdateWithSetter(
311+
financialAccountTransactionsComponent,
312+
onLoadError,
313+
(comp, val) => {
314+
comp.setOnLoadError(val);
315+
}
316+
);
317+
318+
return wrapper;
319+
};
320+
190321
export const ConnectDocuments = ({
191322
onLoadError,
192323
onLoaderStart,

src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export type FetchEphemeralKeyFunction = (fetchParams: {
2+
issuingCard: string;
3+
nonce: string;
4+
}) => Promise<{
5+
issuingCard: string;
6+
nonce: string;
7+
ephemeralKeySecret: string;
8+
}>;

src/utils/useUpdateWithSetter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import {
55
LoaderStart,
66
NotificationCount,
77
StepChange,
8-
PaymentsListDefaultFilters
8+
PaymentsListDefaultFilters,
99
} from '@stripe/connect-js';
10+
import {FetchEphemeralKeyFunction} from '../types';
1011

1112
export const useUpdateWithSetter = <
1213
T extends HTMLElement,
@@ -16,6 +17,7 @@ export const useUpdateWithSetter = <
1617
| string[]
1718
| PaymentsListDefaultFilters
1819
| (() => void)
20+
| FetchEphemeralKeyFunction
1921
| CollectionOptions
2022
| ((notificationCount: NotificationCount) => void)
2123
| ((loaderStart: LoaderStart) => void)

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,10 +1521,10 @@
15211521
dependencies:
15221522
"@sinonjs/commons" "^3.0.0"
15231523

1524-
"@stripe/connect-js@3.3.17":
1525-
version "3.3.17"
1526-
resolved "https://registry.yarnpkg.com/@stripe/connect-js/-/connect-js-3.3.17.tgz#2c1f11ec88ba57677ddb549cbee140af848009f9"
1527-
integrity sha512-ooowpsc8rsmkVE9i/HcnvyDuPdRNvKAHVoKkWuj4oU9m8EdAGKWFTD/nbnFldlz/nI+2UITx8U0Z+B11sLjNzw==
1524+
"@stripe/connect-js@3.3.20":
1525+
version "3.3.20"
1526+
resolved "https://registry.yarnpkg.com/@stripe/connect-js/-/connect-js-3.3.20.tgz#ffa508f62effcadf7e0774ca222dbc9d60704141"
1527+
integrity sha512-4GingsjdQDJomIMAmTWFJSBifLygc5xWCcYzdcL5nYiePBuHEfYwFKKq7tOO1SIR2jsuHpn6R18xKVijToblWQ==
15281528

15291529
"@tootallnate/once@2":
15301530
version "2.0.0"

0 commit comments

Comments
 (0)