1 | type Stripe = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Post identity verification sessions session |
6 | * Updates a VerificationSession object. |
7 |
|
8 | When the session status is requires_input, you can use this method to update the |
9 | verification check and options. |
10 | */ |
11 | export async function main( |
12 | auth: Stripe, |
13 | session: string, |
14 | body: { |
15 | expand?: string[]; |
16 | metadata?: { [k: string]: string }; |
17 | options?: { |
18 | document?: |
19 | | { |
20 | allowed_types?: ("driving_license" | "id_card" | "passport")[]; |
21 | require_id_number?: boolean; |
22 | require_live_capture?: boolean; |
23 | require_matching_selfie?: boolean; |
24 | [k: string]: unknown; |
25 | } |
26 | | ""; |
27 | [k: string]: unknown; |
28 | }; |
29 | type?: "document" | "id_number"; |
30 | } |
31 | ) { |
32 | const url = new URL( |
33 | `https://api.stripe.com/v1/identity/verification_sessions/${session}` |
34 | ); |
35 |
|
36 | const response = await fetch(url, { |
37 | method: "POST", |
38 | headers: { |
39 | "Content-Type": "application/x-www-form-urlencoded", |
40 | Authorization: "Bearer " + auth.token, |
41 | }, |
42 | body: encodeParams(body), |
43 | }); |
44 | if (!response.ok) { |
45 | const text = await response.text(); |
46 | throw new Error(`${response.status} ${text}`); |
47 | } |
48 | return await response.json(); |
49 | } |
50 |
|
51 | function encodeParams(o: any) { |
52 | function iter(o: any, path: string) { |
53 | if (Array.isArray(o)) { |
54 | o.forEach(function (a) { |
55 | iter(a, path + "[]"); |
56 | }); |
57 | return; |
58 | } |
59 | if (o !== null && typeof o === "object") { |
60 | Object.keys(o).forEach(function (k) { |
61 | iter(o[k], path + "[" + k + "]"); |
62 | }); |
63 | return; |
64 | } |
65 | data.push(path + "=" + o); |
66 | } |
67 | const data: string[] = []; |
68 | Object.keys(o).forEach(function (k) { |
69 | if (o[k] !== undefined) { |
70 | iter(o[k], k); |
71 | } |
72 | }); |
73 | return new URLSearchParams(data.join("&")); |
74 | } |
75 |
|