DrillsPaid, but the event never left
Paid, but the event never left
What happened
When Stripe confirms a payment, Harbor's webhook calls markPaid. It marks the invoice paid, then publishes InvoicePaid, which lifts the team's overdue lock and sends the receipt. During Thursday's deploy at 10:14, web-3 was killed mid-request. Three teams who paid in that minute have invoices marked Paid, but they are still locked out of uploads and got no receipt.
Priya, engineering managerThree tickets from Thursday: paid, the invoice says Paid, the red overdue banner is still there and uploads are blocked. Stripe shows the payments and retried the webhook. Billing looks fine. What happened to the event?
The MagisterRun it first and read what comes back. Then change the code if you like: your edits go to the review too.
Run it: Stripe sends the webhook, a deploy kills the server right after the commit, the server starts again, and Stripe retries.
// Stripe's webhook calls this when the payment for an invoice succeeds.
// Billing owns invoices. Accounts (lifts the overdue lock) and notifications
// (sends the receipt) react to InvoicePaid.
async function markPaid(invoiceId, paymentId) {
const [current] = await db.select("invoices", (r) => r.id === invoiceId);
// Stripe retries webhooks, so this can run twice for one payment.
if (current.status === "paid") return current;
const invoice = await db.update("invoices", invoiceId, { status: "paid", paymentId, paidAt: NOW });
await queue.publish({
id: newId("evt"),
type: "InvoicePaid",
invoiceId: invoice.id,
teamId: invoice.teamId,
total: invoice.total,
});
return invoice;
}
// ---- Simulation, not part of Harbor. db, queue, server, NOW and newId are test
// doubles. Stripe sends the webhook, and a deploy kills the server right after
// the database commit. The server starts again, then Stripe retries the webhook.
await server.handle(() => markPaid("inv_2291", "pi_DEMO_8812"));
await server.restart();
await server.handle(() => markPaid("inv_2291", "pi_DEMO_8812"));
console.log("invoice:", invoices[0].status);
console.log("InvoicePaid events published:", published.filter((e) => e.type === "InvoicePaid").length);
The code runs in your browser against stand-in data. Nothing is sent anywhere.
Your answer
Reviewed by AI against what a good fix needs. About 10 seconds.Sign in to get your answer reviewed
It's free. Anything you've typed here stays in this browser and is waiting when you come back.
Sign in with email