1 | |
2 | type Square = { |
3 | token: string; |
4 | }; |
5 | |
6 | * ListPaymentRefunds |
7 | * Retrieves a list of refunds for the account making the request. |
8 |
|
9 | Results are eventually consistent, and new refunds or changes to refunds might take several |
10 | seconds to appear. |
11 |
|
12 | The maximum results per page is 100. |
13 | */ |
14 | export async function main( |
15 | auth: Square, |
16 | begin_time: string | undefined, |
17 | end_time: string | undefined, |
18 | sort_order: string | undefined, |
19 | cursor: string | undefined, |
20 | location_id: string | undefined, |
21 | status: string | undefined, |
22 | source_type: string | undefined, |
23 | limit: string | undefined, |
24 | ) { |
25 | const url = new URL(`https://connect.squareup.com/v2/refunds`); |
26 | for (const [k, v] of [ |
27 | ["begin_time", begin_time], |
28 | ["end_time", end_time], |
29 | ["sort_order", sort_order], |
30 | ["cursor", cursor], |
31 | ["location_id", location_id], |
32 | ["status", status], |
33 | ["source_type", source_type], |
34 | ["limit", limit], |
35 | ]) { |
36 | if (v !== undefined && v !== "" && k !== undefined) { |
37 | url.searchParams.append(k, v); |
38 | } |
39 | } |
40 | const response = await fetch(url, { |
41 | method: "GET", |
42 | headers: { |
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 |
|