0

CaptureTransaction

by
Published Oct 17, 2025

Captures a transaction that was created with the [Charge](api-endpoint:Transactions-Charge) endpoint with a `delay_capture` value of `true`. See [Delayed capture transactions](https://developer.squareup.com/docs/payments/transactions/overview#delayed-capture) for more information.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * CaptureTransaction
7
 * Captures a transaction that was created with the [Charge](api-endpoint:Transactions-Charge)
8
endpoint with a `delay_capture` value of `true`.
9

10

11
See [Delayed capture transactions](https://developer.squareup.com/docs/payments/transactions/overview#delayed-capture)
12
for more information.
13
 */
14
export async function main(
15
  auth: Square,
16
  location_id: string,
17
  transaction_id: string,
18
) {
19
  const url = new URL(
20
    `https://connect.squareup.com/v2/locations/${location_id}/transactions/${transaction_id}/capture`,
21
  );
22

23
  const response = await fetch(url, {
24
    method: "POST",
25
    headers: {
26
      Authorization: "Bearer " + auth.token,
27
    },
28
    body: undefined,
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36