0

CancelPaymentByIdempotencyKey

by
Published Oct 17, 2025

Cancels (voids) a payment identified by the idempotency key that is specified in the request.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * CancelPaymentByIdempotencyKey
7
 * Cancels (voids) a payment identified by the idempotency key that is specified in the
8
request.
9
 */
10
export async function main(auth: Square, body: { idempotency_key: string }) {
11
  const url = new URL(`https://connect.squareup.com/v2/payments/cancel`);
12

13
  const response = await fetch(url, {
14
    method: "POST",
15
    headers: {
16
      "Content-Type": "application/json",
17
      Authorization: "Bearer " + auth.token,
18
    },
19
    body: JSON.stringify(body),
20
  });
21
  if (!response.ok) {
22
    const text = await response.text();
23
    throw new Error(`${response.status} ${text}`);
24
  }
25
  return await response.json();
26
}
27