1 | type Stripe = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Get identity verification sessions session |
6 | * Retrieves the details of a VerificationSession that was previously created. |
7 |
|
8 | When the session status is requires_input, you can use this method to retrieve a valid |
9 | client_secret or url to allow re-submission. |
10 | */ |
11 | export async function main(auth: Stripe, session: string, expand: any) { |
12 | const url = new URL( |
13 | `https://api.stripe.com/v1/identity/verification_sessions/${session}` |
14 | ); |
15 | encodeParams({ expand }).forEach((v, k) => { |
16 | if (v !== undefined && v !== "") { |
17 | url.searchParams.append(k, v); |
18 | } |
19 | }); |
20 | const response = await fetch(url, { |
21 | method: "GET", |
22 | headers: { |
23 | "Content-Type": "application/x-www-form-urlencoded", |
24 | Authorization: "Bearer " + auth.token, |
25 | }, |
26 | body: undefined, |
27 | }); |
28 | if (!response.ok) { |
29 | const text = await response.text(); |
30 | throw new Error(`${response.status} ${text}`); |
31 | } |
32 | return await response.json(); |
33 | } |
34 |
|
35 | function encodeParams(o: any) { |
36 | function iter(o: any, path: string) { |
37 | if (Array.isArray(o)) { |
38 | o.forEach(function (a) { |
39 | iter(a, path + "[]"); |
40 | }); |
41 | return; |
42 | } |
43 | if (o !== null && typeof o === "object") { |
44 | Object.keys(o).forEach(function (k) { |
45 | iter(o[k], path + "[" + k + "]"); |
46 | }); |
47 | return; |
48 | } |
49 | data.push(path + "=" + o); |
50 | } |
51 | const data: string[] = []; |
52 | Object.keys(o).forEach(function (k) { |
53 | if (o[k] !== undefined) { |
54 | iter(o[k], k); |
55 | } |
56 | }); |
57 | return new URLSearchParams(data.join("&")); |
58 | } |
59 |
|