Skip to content

Commit 69aaa22

Browse files
committed
zen: void invoice of cancelled subscription
1 parent 322e2b9 commit 69aaa22

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎packages/console/app/src/routes/stripe/webhook.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ export async function POST(input: APIEvent) {
205205
} else if (productID === BlackData.productID()) {
206206
await Billing.unsubscribeBlack({ subscriptionID })
207207
}
208+
209+
const latestInvoice = body.data.object.latest_invoice
210+
const invoiceID = typeof latestInvoice === "string" ? latestInvoice : latestInvoice?.id
211+
if (invoiceID) {
212+
const invoice = await Billing.stripe().invoices.retrieve(invoiceID)
213+
if (invoice.status === "open") await Billing.stripe().invoices.voidInvoice(invoiceID)
214+
}
208215
}
209216
if (body.type === "invoice.payment_succeeded") {
210217
if (

0 commit comments

Comments
 (0)