fix: make invoice payment activation idempotent

This commit is contained in:
sirily
2026-03-10 16:22:16 +03:00
parent 431a60f9c8
commit f575e2395d
4 changed files with 330 additions and 14 deletions

View File

@@ -5,6 +5,7 @@ import {
} from "node:http";
import { loadConfig } from "@nproxy/config";
import {
BillingError,
createPrismaAccountStore,
createPrismaAuthStore,
createPrismaBillingStore,
@@ -211,7 +212,13 @@ const server = createServer(async (request, response) => {
}
const invoiceId = decodeURIComponent(invoiceMarkPaidMatch[1] ?? "");
const invoice = await billingStore.markInvoicePaid({ invoiceId });
const invoice = await billingStore.markInvoicePaid({
invoiceId,
actor: {
type: "web_admin",
ref: authenticatedSession.user.id,
},
});
sendJson(response, 200, {
invoice: serializeBillingInvoice(invoice),
});
@@ -672,6 +679,23 @@ function handleRequestError(
return;
}
if (error instanceof BillingError) {
const statusCode =
error.code === "invoice_not_found"
? 404
: error.code === "invoice_transition_not_allowed"
? 409
: 400;
sendJson(response, statusCode, {
error: {
code: error.code,
message: error.message,
},
});
return;
}
if (error instanceof GenerationRequestError) {
const statusCode =
error.code === "missing_active_subscription"