1 | type Stripe = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Get identity verification reports |
6 | * List all verification reports. |
7 | */ |
8 | export async function main( |
9 | auth: Stripe, |
10 | client_reference_id: string | undefined, |
11 | created: any, |
12 | ending_before: string | undefined, |
13 | expand: any, |
14 | limit: string | undefined, |
15 | starting_after: string | undefined, |
16 | type: "document" | "id_number" | undefined, |
17 | verification_session: string | undefined |
18 | ) { |
19 | const url = new URL( |
20 | `https://api.stripe.com/v1/identity/verification_reports` |
21 | ); |
22 | for (const [k, v] of [ |
23 | ["client_reference_id", client_reference_id], |
24 | ["ending_before", ending_before], |
25 | ["limit", limit], |
26 | ["starting_after", starting_after], |
27 | ["type", type], |
28 | ["verification_session", verification_session], |
29 | ]) { |
30 | if (v !== undefined && v !== "") { |
31 | url.searchParams.append(k, v); |
32 | } |
33 | } |
34 | encodeParams({ created, expand }).forEach((v, k) => { |
35 | if (v !== undefined && v !== "") { |
36 | url.searchParams.append(k, v); |
37 | } |
38 | }); |
39 | const response = await fetch(url, { |
40 | method: "GET", |
41 | headers: { |
42 | "Content-Type": "application/x-www-form-urlencoded", |
43 | Authorization: "Bearer " + auth.token, |
44 | }, |
45 | body: undefined, |
46 | }); |
47 | if (!response.ok) { |
48 | const text = await response.text(); |
49 | throw new Error(`${response.status} ${text}`); |
50 | } |
51 | return await response.json(); |
52 | } |
53 |
|
54 | function encodeParams(o: any) { |
55 | function iter(o: any, path: string) { |
56 | if (Array.isArray(o)) { |
57 | o.forEach(function (a) { |
58 | iter(a, path + "[]"); |
59 | }); |
60 | return; |
61 | } |
62 | if (o !== null && typeof o === "object") { |
63 | Object.keys(o).forEach(function (k) { |
64 | iter(o[k], path + "[" + k + "]"); |
65 | }); |
66 | return; |
67 | } |
68 | data.push(path + "=" + o); |
69 | } |
70 | const data: string[] = []; |
71 | Object.keys(o).forEach(function (k) { |
72 | if (o[k] !== undefined) { |
73 | iter(o[k], k); |
74 | } |
75 | }); |
76 | return new URLSearchParams(data.join("&")); |
77 | } |
78 |
|