//native
type Square = {
token: string;
};
/**
* CompletePayment
* Completes (captures) a payment.
By default, payments are set to complete immediately after they are created.
You can use this endpoint to complete a payment with the APPROVED `status`.
*/
export async function main(
auth: Square,
payment_id: string,
body: { version_token?: string },
) {
const url = new URL(
`https://connect.squareup.com/v2/payments/${payment_id}/complete`,
);
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