//native
type Square = {
token: string;
};
/**
* ListPaymentRefunds
* Retrieves a list of refunds for the account making the request.
Results are eventually consistent, and new refunds or changes to refunds 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,
status: string | undefined,
source_type: string | undefined,
limit: string | undefined,
) {
const url = new URL(`https://connect.squareup.com/v2/refunds`);
for (const [k, v] of [
["begin_time", begin_time],
["end_time", end_time],
["sort_order", sort_order],
["cursor", cursor],
["location_id", location_id],
["status", status],
["source_type", source_type],
["limit", limit],
]) {
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