carlos / platform Public

cli: zero-decimal amounts, rate clause on MRR, move the BDC-37 note

Review round 1 (findings 1, 2 layout, 3):
- formatMinor prints Stripe's zero-decimal currencies (jpy, krw and the
  rest) with no decimals; every other currency keeps two.
- The ECB rate clause follows MRR as well as ARR, and on both only when
  the total converts a currency other than euros. Its words (BDC-6) are
  unchanged until the reworded copy lands.
- The BDC-37 paragraph in plans.md moves after "If any of them is wrong",
  so it no longer reads as a start-up check; the copy record's placement
  note follows.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 90dc56bbfb0bf84cdd02fa822330a0aa5003e306 parent 9d54222
4 files changed, +58 −17
  • billing_cli.go +35 −13
  • billing_cli_test.go +20 −1
  • docs/site/plans.md +2 −2
  • docs/superpowers/plans/2026-11-09-billing-dashboard-1-copy.md +1 −1
diff --git a/billing_cli.go b/billing_cli.go
index 08c58cfa7..1d0478152 100644
--- a/billing_cli.go
+++ b/billing_cli.go
@@ -309,18 +309,24 @@ func printBillingRevenue(w io.Writer, rev billingRevenueReply) {
}
fmt.Fprintln(w, label+" "+v)
}
+ // The rate day's clause follows ARR and MRR only when the total
+ // converts a currency other than euros: an all-euro total is exact.
+ rateClause := ""
+ for c := range rev.ARR.ByCurrency {
+ if c != "eur" && rev.ARR.RateDay != "" {
+ rateClause = fmt.Sprintf(cliBillingCopyRateDay, rev.ARR.RateDay)
+ }
+ }
line(cliBillingCopyLabelARR, rev.ARR, func() string {
var parts []string
for _, c := range slices.Sorted(maps.Keys(rev.ARR.ByCurrency)) {
parts = append(parts, formatMinor(rev.ARR.ByCurrency[c], c))
}
- v := fmt.Sprintf(cliBillingCopyARR, formatMinor(rev.ARR.EUR, "eur"), strings.Join(parts, " + "))
- if rev.ARR.RateDay != "" {
- v += fmt.Sprintf(cliBillingCopyRateDay, rev.ARR.RateDay)
- }
- return v
+ return fmt.Sprintf(cliBillingCopyARR, formatMinor(rev.ARR.EUR, "eur"), strings.Join(parts, " + ")) + rateClause
+ })
+ line(cliBillingCopyLabelMRR, rev.MRR, func() string {
+ return fmt.Sprintf(cliBillingCopyMRR, formatMinor(rev.MRR.EUR, "eur")) + rateClause
})
- line(cliBillingCopyLabelMRR, rev.MRR, func() string { return fmt.Sprintf(cliBillingCopyMRR, formatMinor(rev.MRR.EUR, "eur")) })
line(cliBillingCopyLabelPaying, rev.Paying, func() string { return fmt.Sprintf(cliBillingCopyPaying, rev.Paying.Count, rev.Accounts) })
line(cliBillingCopyLabelAttention, rev.Attention, func() string { return fmt.Sprintf(cliBillingCopyAttention, rev.Attention.Count) })
line(cliBillingCopyLabelGroups, rev.Groups, func() string {
@@ -391,25 +397,41 @@ func printBillingPayments(w io.Writer, list []billingPaymentReply) {
// currency; any other prints its code in capitals and a space.
var currencySymbols = map[string]string{"eur": "€", "usd": "$", "gbp": "£"}
-// formatMinor formats minor units of a two-decimal currency, with a comma
-// between thousands: €2,400.00, -$12.00.
+// zeroDecimalCurrencies are the currencies whose minor unit is the whole
+// unit (Stripe's zero-decimal list): 1200 jpy is ¥1,200, not 12.00.
+var zeroDecimalCurrencies = map[string]bool{
+ "bif": true, "clp": true, "djf": true, "gnf": true, "jpy": true, "kmf": true, "krw": true, "mga": true,
+ "pyg": true, "rwf": true, "ugx": true, "vnd": true, "vuv": true, "xaf": true, "xof": true, "xpf": true,
+}
+
+// formatMinor formats minor units of currency, with a comma between
+// thousands: two decimals (€2,400.00, -$12.00), or none for a
+// zero-decimal currency (JPY 1,200).
func formatMinor(minor int64, currency string) string {
sign := ""
u := uint64(minor)
if minor < 0 {
sign, u = "-", uint64(-(minor+1))+1
}
- whole := strconv.FormatUint(u/100, 10)
+ cur := strings.ToLower(currency)
+ whole, cents := u, uint64(0)
+ if !zeroDecimalCurrencies[cur] {
+ whole, cents = u/100, u%100
+ }
+ digits := strconv.FormatUint(whole, 10)
var b strings.Builder
- for i, d := range whole {
- if i > 0 && (len(whole)-i)%3 == 0 {
+ for i, d := range digits {
+ if i > 0 && (len(digits)-i)%3 == 0 {
b.WriteByte(',')
}
b.WriteRune(d)
}
- symbol, ok := currencySymbols[strings.ToLower(currency)]
+ symbol, ok := currencySymbols[cur]
if !ok {
symbol = strings.ToUpper(currency) + " "
}
- return fmt.Sprintf("%s%s%s.%02d", sign, symbol, b.String(), u%100)
+ if zeroDecimalCurrencies[cur] {
+ return sign + symbol + b.String()
+ }
+ return fmt.Sprintf("%s%s%s.%02d", sign, symbol, b.String(), cents)
}
diff --git a/billing_cli_test.go b/billing_cli_test.go
index 3fd3938ba..36109018c 100644
--- a/billing_cli_test.go
+++ b/billing_cli_test.go
@@ -150,7 +150,7 @@ func TestBillingRevenueCLI(t *testing.T) {
}
want := []string{
"arr " + fmt.Sprintf(cliBillingCopyARR, "€4,900.00", "€2,400.00 + $2,800.00") + fmt.Sprintf(cliBillingCopyRateDay, "2026-11-06"),
- "mrr " + fmt.Sprintf(cliBillingCopyMRR, "€408.33"),
+ "mrr " + fmt.Sprintf(cliBillingCopyMRR, "€408.33") + fmt.Sprintf(cliBillingCopyRateDay, "2026-11-06"),
"paying " + fmt.Sprintf(cliBillingCopyPaying, 2, 38),
"needs attention " + fmt.Sprintf(cliBillingCopyAttention, 1),
"groups " + fmt.Sprintf(cliBillingCopyGroups, 2, 30, 3, 2, 1),
@@ -182,6 +182,21 @@ func TestBillingRevenueCLI(t *testing.T) {
if got := strings.TrimRight(out.String(), "\n"); got != strings.Join(want, "\n") {
t.Fatalf("refused:\n%s\nwant\n%s", got, strings.Join(want, "\n"))
}
+ // An all-euro total converts nothing: no rate clause on ARR or MRR.
+ reply = `{"arr":{"available":true,"by_currency":{"eur":240000},"eur":240000,"rate_day":"2026-11-06"},` +
+ `"mrr":{"available":true,"eur":20000},"paying":{"available":true,"count":1},"attention":{"available":true,"count":0},` +
+ `"groups":{"available":true,"counts":{"free":36,"house":0,"ours":1,"paying":1,"sponsored":0}},"accounts":38,"test_mode":false}`
+ out.Reset()
+ if err := runBillingWithSession(context.Background(), s, []string{"revenue"}, &out); err != nil {
+ t.Fatal(err)
+ }
+ got := strings.Split(out.String(), "\n")
+ if want := "arr " + fmt.Sprintf(cliBillingCopyARR, "€2,400.00", "€2,400.00"); got[0] != want {
+ t.Errorf("all-euro arr = %q, want %q", got[0], want)
+ }
+ if want := "mrr " + fmt.Sprintf(cliBillingCopyMRR, "€200.00"); got[1] != want {
+ t.Errorf("all-euro mrr = %q, want %q", got[1], want)
+ }
if err := runBillingWithSession(context.Background(), s, []string{"revenue", "extra"}, io.Discard); err == nil {
t.Fatal("an extra argument was accepted")
}
@@ -270,6 +285,10 @@ func TestFormatMinor(t *testing.T) {
{-1071, "eur", "-€10.71"},
{1200, "gbp", "£12.00"},
{1200, "chf", "CHF 12.00"},
+ {1200, "jpy", "JPY 1,200"},
+ {-1234567, "krw", "-KRW 1,234,567"},
+ {5, "xof", "XOF 5"},
+ {0, "clp", "CLP 0"},
} {
if got := formatMinor(c.minor, c.currency); got != c.want {
t.Errorf("formatMinor(%d, %s) = %q, want %q", c.minor, c.currency, got, c.want)
diff --git a/docs/site/plans.md b/docs/site/plans.md
index 60a1d4cc2..adf32abd9 100644
--- a/docs/site/plans.md
+++ b/docs/site/plans.md
@@ -155,10 +155,10 @@ Every billing setting lives in the console's EnvironmentFile. None of them is a
| `CARLOS_STRIPE_PORTAL_CONFIGURATION` | Required with billing on. The id (`bpc_`) of a Stripe customer portal configuration that allows cards and invoice history and nothing else. |
| `CARLOS_STRIPE_HOUSE_COUPON` | Optional. The id of the coupon that makes a house account's checkout free. |
-The restricted key also needs read access to Balance, Charges and Refunds, and the webhook also needs `charge.succeeded`, `charge.captured` and `charge.refunded`, so the console can record the money it receives.
-
If any of them is wrong, the console refuses to start and names the variable, never its value.
+The restricted key also needs read access to Balance, Charges and Refunds, and the webhook also needs `charge.succeeded`, `charge.captured` and `charge.refunded`, so the console can record the money it receives.
+
Point Stripe's webhook at `https://<console>/billing/webhook`. When the console starts, it checks the account, every price in the book, the portal configuration and the house coupon (if you set one) against Stripe before it accepts a webhook. Until that check passes, the webhook answers 503 and Stripe tries again later, so a console that starts while Stripe is unreachable catches up by itself.
### The portal and the house coupon
diff --git a/docs/superpowers/plans/2026-11-09-billing-dashboard-1-copy.md b/docs/superpowers/plans/2026-11-09-billing-dashboard-1-copy.md
index 899ffc4e2..a8253638e 100644
--- a/docs/superpowers/plans/2026-11-09-billing-dashboard-1-copy.md
+++ b/docs/superpowers/plans/2026-11-09-billing-dashboard-1-copy.md
@@ -82,7 +82,7 @@ BDC-32 to BDC-34 are new lines in the section's `sh` block, after `carlos billin
|---|---|---|---|
| BDC-37 | docs/site/plans.md | The restricted key also needs read access to Balance, Charges and Refunds, and the webhook also needs `charge.succeeded`, `charge.captured` and `charge.refunded`, so the console can record the money it receives. | approved |
-BDC-37 goes straight after the variables table.
+BDC-37 goes straight after the paragraph that starts "If any of them is wrong", which follows the variables table.
## Script: stripe-setup.sh