1

Cancel or Reverse Payout

by
Published Aug 23, 2022

Cancel a pending payout, or reverse a paid one; either way the funds go back to the available balance. Payouts in transit, failed or already canceled are rejected.

Script stripe Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 2 hours ago
1
//native
2

3
/**
4
 * Cancel or Reverse Payout
5
 * Cancel a pending payout, or reverse a paid one; either way the funds go back to the available balance. Payouts in transit, failed or already canceled are rejected.
6
 */
7
export async function main(auth: RT.Stripe, payout_id: string) {
8
  const headers = {
9
    Authorization: `Bearer ${auth.token}`,
10
    Accept: "application/json",
11
    "Stripe-Version": "2025-03-31.basil",
12
  }
13
  const current = await fetch(
14
    `https://api.stripe.com/v1/payouts/${payout_id}`,
15
    { headers }
16
  )
17
  if (!current.ok) {
18
    throw new Error(`${current.status} ${await current.text()}`)
19
  }
20
  const { status } = (await current.json()) as { status: string }
21
  if (status !== "pending" && status !== "paid") {
22
    throw new Error(
23
      `Payout ${payout_id} is ${status}: only pending or paid payouts can be canceled or reversed`
24
    )
25
  }
26

27
  const response = await fetch(
28
    `https://api.stripe.com/v1/payouts/${payout_id}/${status === "paid" ? "reverse" : "cancel"}`,
29
    { method: "POST", headers }
30
  )
31

32
  if (!response.ok) {
33
    throw new Error(`${response.status} ${await response.text()}`)
34
  }
35

36
  return await response.json()
37
}
38

Other submissions
  • Submitted by rossmccrann Deno
    Created 528 days ago
    1
    type Stripe = {
    2
      token: string;
    3
    };
    4
    export async function main(stripe_con: Stripe, payout_id: string) {
    5
      const STRIPE_REVERSE_PAYOUT_URL = `https://api.stripe.com/v1/payouts/:${payout_id}/reverse`;
    6
    
    
    7
      const token = stripe_con["token"];
    8
    
    
    9
      const response = await fetch(STRIPE_REVERSE_PAYOUT_URL, {
    10
        method: "POST",
    11
        headers: {
    12
          Authorization: "Bearer " + token,
    13
          "Content-Type": "application/json",
    14
        },
    15
      });
    16
    
    
    17
      return await response.json();
    18
    }
    19