refactor billing endpoints to separate reads from reconciliation requests

This commit is contained in:
Jon Staab
2026-06-02 14:30:50 -07:00
parent 5e7aa7df10
commit 6b693e11d3
14 changed files with 217 additions and 124 deletions
+6
View File
@@ -20,6 +20,7 @@ import {
listTenantInvoices,
listTenantRelays,
listTenants,
reconcileTenant,
updateRelay,
updateTenant,
type Activity,
@@ -208,6 +209,11 @@ export async function getLatestOpenInvoice(): Promise<Invoice | null> {
// none is available). Shared by RelayNew, Home's signup-and-create path, and the
// plan-upgrade toggle so the post-paid ladder stays identical across all three.
export async function resolvePostPaidFlow(): Promise<PaidFlowDecision> {
const pubkey = account()!.pubkey
// The reads below are pure GETs now, so explicitly materialize the just-created
// invoice and pick up any portal-added card before deciding the post-paid ladder.
await reconcileTenant(pubkey)
const needsSetup = await tenantNeedsPaymentSetup()
const invoice = needsSetup ? await getLatestOpenInvoice() : null
return decidePostPaidFlow({ needsSetup, invoice })