1 | type Stripe = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Post treasury financial accounts financial account features |
6 | * Updates the Features associated with a FinancialAccount. |
7 | */ |
8 | export async function main( |
9 | auth: Stripe, |
10 | financial_account: string, |
11 | body: { |
12 | card_issuing?: { requested: boolean; [k: string]: unknown }; |
13 | deposit_insurance?: { requested: boolean; [k: string]: unknown }; |
14 | expand?: string[]; |
15 | financial_addresses?: { |
16 | aba?: { requested: boolean; [k: string]: unknown }; |
17 | [k: string]: unknown; |
18 | }; |
19 | inbound_transfers?: { |
20 | ach?: { requested: boolean; [k: string]: unknown }; |
21 | [k: string]: unknown; |
22 | }; |
23 | intra_stripe_flows?: { requested: boolean; [k: string]: unknown }; |
24 | outbound_payments?: { |
25 | ach?: { requested: boolean; [k: string]: unknown }; |
26 | us_domestic_wire?: { requested: boolean; [k: string]: unknown }; |
27 | [k: string]: unknown; |
28 | }; |
29 | outbound_transfers?: { |
30 | ach?: { requested: boolean; [k: string]: unknown }; |
31 | us_domestic_wire?: { requested: boolean; [k: string]: unknown }; |
32 | [k: string]: unknown; |
33 | }; |
34 | } |
35 | ) { |
36 | const url = new URL( |
37 | `https://api.stripe.com/v1/treasury/financial_accounts/${financial_account}/features` |
38 | ); |
39 |
|
40 | const response = await fetch(url, { |
41 | method: "POST", |
42 | headers: { |
43 | "Content-Type": "application/x-www-form-urlencoded", |
44 | Authorization: "Bearer " + auth.token, |
45 | }, |
46 | body: encodeParams(body), |
47 | }); |
48 | if (!response.ok) { |
49 | const text = await response.text(); |
50 | throw new Error(`${response.status} ${text}`); |
51 | } |
52 | return await response.json(); |
53 | } |
54 |
|
55 | function encodeParams(o: any) { |
56 | function iter(o: any, path: string) { |
57 | if (Array.isArray(o)) { |
58 | o.forEach(function (a) { |
59 | iter(a, path + "[]"); |
60 | }); |
61 | return; |
62 | } |
63 | if (o !== null && typeof o === "object") { |
64 | Object.keys(o).forEach(function (k) { |
65 | iter(o[k], path + "[" + k + "]"); |
66 | }); |
67 | return; |
68 | } |
69 | data.push(path + "=" + o); |
70 | } |
71 | const data: string[] = []; |
72 | Object.keys(o).forEach(function (k) { |
73 | if (o[k] !== undefined) { |
74 | iter(o[k], k); |
75 | } |
76 | }); |
77 | return new URLSearchParams(data.join("&")); |
78 | } |
79 |
|