0

Delete Invoice

by
Published Oct 30, 2023

Permanently delete a draft invoice. Finalized invoices can only be voided.

Script stripe Verified

The script

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

3
/**
4
 * Delete Invoice
5
 * Permanently delete a draft invoice. Finalized invoices can only be voided.
6
 */
7
export async function main(auth: RT.Stripe, invoice_id: string) {
8
  const response = await fetch(
9
    `https://api.stripe.com/v1/invoices/${invoice_id}`,
10
    {
11
      method: "DELETE",
12
      headers: {
13
        Authorization: `Bearer ${auth.token}`,
14
        Accept: "application/json",
15
        "Stripe-Version": "2025-03-31.basil",
16
      },
17
    }
18
  )
19

20
  if (!response.ok) {
21
    throw new Error(`${response.status} ${await response.text()}`)
22
  }
23

24
  return await response.json()
25
}
26

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 528 days ago
    1
    type Stripe = {
    2
      token: string;
    3
    };
    4
    /**
    5
     * Delete invoices invoice
    6
     * Permanently deletes a one-off invoice draft. This cannot be undone. Attempts to delete invoices that are no longer in a draft state will fail; once an invoice has been finalized or if an invoice is for a subscription, it must be voided.
    7
     */
    8
    export async function main(auth: Stripe, invoice: string) {
    9
      const url = new URL(`https://api.stripe.com/v1/invoices/${invoice}`);
    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