//native
type Square = {
token: string;
};
/**
* ListPayments
* 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.
*/
export async function main(
auth: Square,
begin_time: string | undefined,
end_time: string | undefined,
sort_order: string | undefined,
cursor: string | undefined,
location_id: string | undefined,
total: string | undefined,
last_4: string | undefined,
card_brand: string | undefined,
limit: string | undefined,
is_offline_payment: string | undefined,
offline_begin_time: string | undefined,
offline_end_time: string | undefined,
updated_at_begin_time: string | undefined,
updated_at_end_time: string | undefined,
sort_field: "CREATED_AT" | "OFFLINE_CREATED_AT" | "UPDATED_AT" | undefined,
) {
const url = new URL(`https://connect.squareup.com/v2/payments`);
for (const [k, v] of [
["begin_time", begin_time],
["end_time", end_time],
["sort_order", sort_order],
["cursor", cursor],
["location_id", location_id],
["total", total],
["last_4", last_4],
["card_brand", card_brand],
["limit", limit],
["is_offline_payment", is_offline_payment],
["offline_begin_time", offline_begin_time],
["offline_end_time", offline_end_time],
["updated_at_begin_time", updated_at_begin_time],
["updated_at_end_time", updated_at_end_time],
["sort_field", sort_field],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago