//native
type Square = {
token: string;
};
/**
* DeleteInvoice
* Deletes the specified invoice. When an invoice is deleted, the
associated order status changes to CANCELED. You can only delete a draft
invoice (you cannot delete a published invoice, including one that is scheduled for processing).
*/
export async function main(
auth: Square,
invoice_id: string,
version: string | undefined,
) {
const url = new URL(`https://connect.squareup.com/v2/invoices/${invoice_id}`);
for (const [k, v] of [["version", version]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "DELETE",
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