1

Create Payout

by
Published Aug 23, 2022

Send funds from the Stripe balance to the account's default bank account or debit card. `amount` is in the smallest currency unit and must be available in the balance. Set `idempotency_key` to make retries safe: Stripe returns the first result for a repeated key within 24 hours. `extra_params` passes any other documented field through as-is.

Script stripe Verified

The script

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

3
/**
4
 * Create Payout
5
 * Send funds from the Stripe balance to the account's default bank account or debit card. `amount` is in the smallest currency unit and must be available in the balance. Set `idempotency_key` to make retries safe: Stripe returns the first result for a repeated key within 24 hours. `extra_params` passes any other documented field through as-is.
6
 */
7
export async function main(
8
  auth: RT.Stripe,
9
  amount: number,
10
  currency: string,
11
  description: string | undefined,
12
  method: "standard" | "instant" | undefined,
13
  statement_descriptor: string | undefined,
14
  metadata: { [key: string]: string } | undefined,
15
  idempotency_key: string | undefined,
16
  extra_params: { [key: string]: any } | undefined
17
) {
18
  const response = await fetch(`https://api.stripe.com/v1/payouts`, {
19
    method: "POST",
20
    headers: {
21
      Authorization: `Bearer ${auth.token}`,
22
      "Content-Type": "application/x-www-form-urlencoded",
23
      Accept: "application/json",
24
      "Stripe-Version": "2025-03-31.basil",
25
      ...(idempotency_key ? { "Idempotency-Key": idempotency_key } : {}),
26
    },
27
    body: toForm({
28
      amount,
29
      currency,
30
      description,
31
      method,
32
      statement_descriptor,
33
      metadata,
34
      ...extra_params,
35
    }),
36
  })
37

38
  if (!response.ok) {
39
    throw new Error(`${response.status} ${await response.text()}`)
40
  }
41

42
  return await response.json()
43
}
44

45
// Stripe takes form-encoded params with bracketed nesting: metadata[key]=v, items[0][price]=p
46
function toForm(
47
  params: { [key: string]: any },
48
  prefix = "",
49
  out = new URLSearchParams()
50
) {
51
  for (const [key, value] of Object.entries(params)) {
52
    if (value == null || value === "") continue
53
    const name = prefix ? `${prefix}[${key}]` : key
54
    if (typeof value === "object") toForm(value, name, out)
55
    else out.append(name, String(value))
56
  }
57
  return out
58
}
59

Other submissions
  • Submitted by rossmccrann Deno
    Created 528 days ago
    1
    import Stripe from "https://esm.sh/stripe?target=deno";
    2
    
    
    3
    type Stripe = {
    4
      token: string;
    5
    };
    6
    export async function main(
    7
      stripe_con: Stripe,
    8
      amount: number,
    9
      currency: string
    10
    ) {
    11
      const token = stripe_con["token"];
    12
      const stripe = Stripe(`${token}`, {
    13
        httpClient: Stripe.createFetchHttpClient(),
    14
      });
    15
    
    
    16
      const payout = await stripe.payouts.create({
    17
        amount: amount,
    18
        currency: `${currency}`,
    19
      });
    20
    
    
    21
      return await payout.json();
    22
    }
    23
    
    
  • Submitted by hugo989 Bun
    Created 136 days ago
    1
    import StripeClient from "stripe@11";
    2
    
    
    3
    type Stripe = {
    4
      token: string;
    5
    };
    6
    export async function main(
    7
      stripe_con: Stripe,
    8
      amount: number,
    9
      currency: string
    10
    ) {
    11
      const token = stripe_con["token"];
    12
      const stripe = StripeClient(`${token}`, {
    13
        httpClient: StripeClient.createFetchHttpClient(),
    14
      });
    15
    
    
    16
      const payout = await stripe.payouts.create({
    17
        amount: amount,
    18
        currency: `${currency}`,
    19
      });
    20
    
    
    21
      return await payout.json();
    22
    }
    23