Delete customers customer subscriptions subscription exposed id discount

Removes the currently applied discount on a 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 subscriptions subscription exposed id discount
6
 * Removes the currently applied discount on a customer.
7
 */
8
export async function main(
9
  auth: Stripe,
10
  customer: string,
11
  subscription_exposed_id: string
12
) {
13
  const url = new URL(
14
    `https://api.stripe.com/v1/customers/${customer}/subscriptions/${subscription_exposed_id}/discount`
15
  );
16

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