Metrics: total spend from Stripe's charges, as Stripe counts it

Customers who paid without an invoice (one-off Checkout payments) were
missed, and the Stripe card counted every customer record, deleted ones
too. The sync now reads charges (and follows their events); a customer's
total spend is their successful charges, captured less refunded. A
database synced before reads everything once (sync state version 2).
Until charges are in, paid invoices less refunds stand in.

The Stripe card's Customers now counts those who spent more than $0, "of
N in Stripe", and a Payments count is added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 12:35:00 -07:00
co-authored by Claude Opus 5.5
parent 6f2fbdf63a
commit 739f85fde1
7 changed files with 103 additions and 23 deletions
+6
View File
@@ -37,10 +37,16 @@ func (s *Server) renderMetrics(w http.ResponseWriter, r *http.Request, errMsg st
s.serverError(w, err)
return
}
spenders, err := metrics.Spenders(s.DB)
if err != nil {
s.serverError(w, err)
return
}
s.render(w, r, "metrics", page{Title: "Metrics", Nav: "metrics/overview", Error: errMsg, Data: map[string]any{
"Stripe": s.stripe() != nil,
"Last": metrics.LastSync(s.DB),
"Counts": counts,
"Spenders": len(spenders),
"Products": products,
"Margins": metrics.LoadMargins(s.DB),
"Model": model,