Delete accounts account

With Connect, you can delete accounts you manage. Accounts created using test-mode keys can be deleted at any time. Standard accounts created using live-mode keys cannot be deleted. Custom or Express accounts created using live-mode keys can only be deleted once all balances are zero. If you want to delete your own account, use the account information tab in your account settings instead.

Script stripe Verified

by hugo697 ยท 10/30/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 368 days ago
1
type Stripe = {
2
  token: string;
3
};
4
/**
5
 * Delete accounts account
6
 * With Connect, you can delete accounts you manage.
7

8
Accounts created using test-mode keys can be deleted at any time. Standard accounts created using live-mode keys cannot be deleted. Custom or Express accounts created using live-mode keys can only be deleted once all balances are zero.
9

10
If you want to delete your own account, use the account information tab in your account settings instead.
11
 */
12
export async function main(auth: Stripe, account: string) {
13
  const url = new URL(`https://api.stripe.com/v1/accounts/${account}`);
14

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