0

Delete coupons coupon

by
Published Oct 30, 2023

You can delete coupons via the coupon management page of the Stripe dashboard. However, deleting a coupon does not affect any customers who have already applied the coupon; it means that new customers can’t redeem the coupon. You can also delete coupons via the API.

Script stripe
  • Submitted by hugo697 Typescript (fetch-only)
    Created 547 days ago
    1
    type Stripe = {
    2
      token: string;
    3
    };
    4
    /**
    5
     * Delete coupons coupon
    6
     * You can delete coupons via the coupon management page of the Stripe dashboard. However, deleting a coupon does not affect any customers who have already applied the coupon; it means that new customers can’t redeem the coupon. You can also delete coupons via the API.
    7
     */
    8
    export async function main(auth: Stripe, coupon: string) {
    9
      const url = new URL(`https://api.stripe.com/v1/coupons/${coupon}`);
    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