Delete customers customer

Permanently deletes a customer. It cannot be undone. Also immediately cancels any active subscriptions on the customer.

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 customers customer
6
 * Permanently deletes a customer. It cannot be undone. Also immediately cancels any active subscriptions on the customer.
7
 */
8
export async function main(auth: Stripe, customer: string) {
9
  const url = new URL(`https://api.stripe.com/v1/customers/${customer}`);
10

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