//native
type Square = {
token: string;
};
/**
* PayOrder
* Pay for an [order]($m/Order) using one or more approved [payments]($m/Payment)
or settle an order with a total of `0`.
*/
export async function main(
auth: Square,
order_id: string,
body: {
idempotency_key: string;
order_version?: number;
payment_ids?: string[];
},
) {
const url = new URL(`https://connect.squareup.com/v2/orders/${order_id}/pay`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago