0

ListPayments

by
Published Oct 17, 2025

Retrieves a list of payments taken by the account making the request. Results are eventually consistent, and new payments or changes to payments might take several seconds to appear. The maximum results per page is 100.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * ListPayments
7
 * Retrieves a list of payments taken by the account making the request.
8

9
Results are eventually consistent, and new payments or changes to payments 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
  total: string | undefined,
22
  last_4: string | undefined,
23
  card_brand: string | undefined,
24
  limit: string | undefined,
25
  is_offline_payment: string | undefined,
26
  offline_begin_time: string | undefined,
27
  offline_end_time: string | undefined,
28
  updated_at_begin_time: string | undefined,
29
  updated_at_end_time: string | undefined,
30
  sort_field: "CREATED_AT" | "OFFLINE_CREATED_AT" | "UPDATED_AT" | undefined,
31
) {
32
  const url = new URL(`https://connect.squareup.com/v2/payments`);
33
  for (const [k, v] of [
34
    ["begin_time", begin_time],
35
    ["end_time", end_time],
36
    ["sort_order", sort_order],
37
    ["cursor", cursor],
38
    ["location_id", location_id],
39
    ["total", total],
40
    ["last_4", last_4],
41
    ["card_brand", card_brand],
42
    ["limit", limit],
43
    ["is_offline_payment", is_offline_payment],
44
    ["offline_begin_time", offline_begin_time],
45
    ["offline_end_time", offline_end_time],
46
    ["updated_at_begin_time", updated_at_begin_time],
47
    ["updated_at_end_time", updated_at_end_time],
48
    ["sort_field", sort_field],
49
  ]) {
50
    if (v !== undefined && v !== "" && k !== undefined) {
51
      url.searchParams.append(k, v);
52
    }
53
  }
54
  const response = await fetch(url, {
55
    method: "GET",
56
    headers: {
57
      Authorization: "Bearer " + auth.token,
58
    },
59
    body: undefined,
60
  });
61
  if (!response.ok) {
62
    const text = await response.text();
63
    throw new Error(`${response.status} ${text}`);
64
  }
65
  return await response.json();
66
}
67