billing: fee rows carry their currency, amount and reason
Final review finding G (Fable P2-2, Ruling 27): FeePayment left Currency, Amount and Reason empty, so carlos billing payments printed a fee line with a blank reason and a currency-less charged column. A fee now records Currency and Amount from the movement and Reason other (tax 0, settled the amount, fee 0). The CLI and payments-door tests build their fee rows from billing.FeePayment instead of a hand-made shape no fee ever had; TestFeePayment checks the new fields.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+36
−3
billing_cli_test.go+19 −1internal/billing/payments.go+5 −1internal/billing/payments_test.go+5 −0internal/console/apibilling_test.go+7 −1
diff --git a/billing_cli_test.go b/billing_cli_test.go| index 36109018c..9d10d8cfe 100644 |
| --- a/billing_cli_test.go |
| +++ b/billing_cli_test.go |
| @@ -10,6 +10,9 @@ import ( |
| "net/http/httptest" |
| "strings" |
| "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/billing" |
| ) |
| func TestBillingCLIProblemsAndClose(t *testing.T) { |
| @@ -202,11 +205,26 @@ func TestBillingRevenueCLI(t *testing.T) { |
| } |
| } |
| +// billingFeeRowJSON is a fee movement's row as the payments door sends |
| +// it: built from billing.FeePayment, the shape the reconcile records. |
| +func billingFeeRowJSON(t *testing.T, m billing.Movement) string { |
| + t.Helper() |
| + p := billing.FeePayment(m, true) |
| + b, err := json.Marshal(billingPaymentReply{Movement: p.Movement, Source: p.Source, At: p.At, Kind: string(p.Kind), |
| + Reason: p.Reason, Amount: p.Amount, Tax: p.Tax, Currency: p.Currency, Settled: p.Settled, Fee: p.Fee, |
| + SettledCurrency: p.SettledCurrency}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return string(b) |
| +} |
| + |
| func TestBillingPaymentsCLI(t *testing.T) { |
| var paths []string |
| reply := `[{"movement":"mv_2","source":"re_1","at":"2026-11-06T09:30:00Z","account":"bab","kind":"refund","reason":"renewal","detail":"","amount":-1200,"tax":-200,"currency":"usd","settled":-1071,"fee":0,"settled_currency":"eur"},` + |
| `{"movement":"mv_1","source":"ch_1","at":"2026-11-02T08:00:00Z","account":"","kind":"once_off","reason":"domain","detail":"shop.example.com","amount":240000,"tax":0,"currency":"eur","settled":240000,"fee":3500,"settled_currency":"eur"},` + |
| - `{"movement":"mv_0","source":"","at":"2026-11-01T00:00:00Z","account":"","kind":"fee","reason":"other","detail":"","amount":-500,"tax":0,"currency":"eur","settled":-500,"fee":0,"settled_currency":"eur"},` + |
| + billingFeeRowJSON(t, billing.Movement{ID: "mv_0", Kind: billing.MovementFee, Amount: -500, Currency: "eur", |
| + At: time.Date(2026, 11, 1, 0, 0, 0, 0, time.UTC)}) + `,` + |
| `{"movement":"mv_s","source":"ch_s","at":"2026-11-01T00:00:00Z","account":"shop","kind":"subscription","reason":"first","detail":"","amount":1200,"tax":200,"currency":"gbp","settled":1150,"fee":40,"settled_currency":"eur"}]` |
| ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| paths = append(paths, r.Method+" "+r.URL.RequestURI()) |
diff --git a/internal/billing/payments.go b/internal/billing/payments.go| index d7098112f..050e54911 100644 |
| --- a/internal/billing/payments.go |
| +++ b/internal/billing/payments.go |
| @@ -111,11 +111,15 @@ func SettledShare(part, whole, settled int64) int64 { |
| } |
| // FeePayment records a fee movement: the provider charging the balance |
| -// directly, with nothing charged to a customer. |
| +// directly, with nothing charged to a customer. What was charged is the |
| +// fee itself, in its own currency, with no tax and reason other. |
| func FeePayment(m Movement, live bool) Payment { |
| return Payment{ |
| Movement: m.ID, |
| Kind: PaymentFee, |
| + Reason: ReasonOther, |
| + Amount: m.Amount, |
| + Currency: m.Currency, |
| Settled: m.Amount, |
| SettledCurrency: m.Currency, |
| At: m.At, |
diff --git a/internal/billing/payments_test.go b/internal/billing/payments_test.go| index 5c5b34aee..1248093e0 100644 |
| --- a/internal/billing/payments_test.go |
| +++ b/internal/billing/payments_test.go |
| @@ -45,4 +45,9 @@ func TestFeePayment(t *testing.T) { |
| if p.SettledCurrency != "eur" || !p.At.Equal(at) || !p.LiveMode { |
| t.Fatalf("FeePayment currency/time/mode = %+v", p) |
| } |
| + // A fee row prints like any other: charged in its own currency (the |
| + // fee, negative), no tax, and a reason. |
| + if p.Currency != "eur" || p.Amount != -45 || p.Tax != 0 || p.SettledTax != 0 || p.Reason != ReasonOther { |
| + t.Fatalf("FeePayment charged/reason = %+v", p) |
| + } |
| } |
diff --git a/internal/console/apibilling_test.go b/internal/console/apibilling_test.go| index fbe00617e..7882efdf9 100644 |
| --- a/internal/console/apibilling_test.go |
| +++ b/internal/console/apibilling_test.go |
| @@ -264,7 +264,7 @@ func TestAPIBillingPayments(t *testing.T) { |
| mk("mv_sep", billing.PaymentSubscription, "cus_1", oct.Add(-time.Hour)), |
| mk("mv_a", billing.PaymentSubscription, "cus_1", oct.Add(time.Hour)), |
| mk("mv_b", billing.PaymentOnceOff, "cus_nobody", oct.Add(48*time.Hour)), |
| - mk("mv_c", billing.PaymentFee, "", oct.Add(72*time.Hour)), |
| + billing.FeePayment(billing.Movement{ID: "mv_c", Kind: billing.MovementFee, Amount: -45, Currency: "eur", At: oct.Add(72 * time.Hour)}, false), |
| mk("mv_nov", billing.PaymentRefund, "cus_1", nov), |
| } { |
| recordPayment(t, bf.st, p) |
| @@ -315,6 +315,12 @@ func TestAPIBillingPayments(t *testing.T) { |
| if rows[0].Account != "" { |
| t.Errorf("unmatched account = %q, want empty", rows[0].Account) |
| } |
| + // A fee row as the reconcile writes it carries its currency and reason. |
| + wantFee := billingPaymentReply{Movement: "mv_c", At: oct.Add(72 * time.Hour), Kind: "fee", Reason: billing.ReasonOther, |
| + Amount: -45, Currency: "eur", Settled: -45, SettledCurrency: "eur"} |
| + if fees := list("?kind=fee"); len(fees) != 1 || fees[0] != wantFee { |
| + t.Errorf("fee rows = %+v\nwant %+v", fees, wantFee) |
| + } |
| for _, c := range []struct{ query, want string }{ |
| {"?month=2026-13", billingCopyMonth}, |
| {"?month=2026-1", billingCopyMonth}, |