billingstripe: Checkout collects a VAT number (tax_id_collection) so Stripe Tax applies reverse charge to qualifying EU business sales
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Squashed from checkout-tax-id into main.
4 files changed,
+97
−4
docs/site/plans.md+1 −1docs/superpowers/reviews/CODEX-REVIEW-BRIEF-checkout-tax-id.md+23 −0internal/billingstripe/prepared.go+12 −2internal/billingstripe/prepared_test.go+61 −1
CI passed — run details
diff --git a/docs/site/plans.md b/docs/site/plans.md| index c91feb5d8..05715b662 100644 |
| --- a/docs/site/plans.md |
| +++ b/docs/site/plans.md |
| @@ -211,7 +211,7 @@ Where billing is on, an account's owners buy and change their plan on the accoun |
| ### Buying a plan |
| -Under **Choose a plan**, pick a currency (`usd`, `eur` or `gbp`), a plan, and any packs, then press **Continue to payment**. You go to Stripe to pay. When you come back, the page shows your new plan as soon as the payment is confirmed. Prices are for a year, and tax is added where it applies. |
| +Under **Choose a plan**, pick a currency (`usd`, `eur` or `gbp`), a plan, and any packs, then press **Continue to payment**. You go to Stripe to pay. When you come back, the page shows your new plan as soon as the payment is confirmed. Prices are for a year, and tax is added where it applies. Business customers can add a VAT number at checkout. Stripe then applies reverse charge where the sale qualifies. |
| The currency is fixed by the first purchase. After that the page says which currency the account pays in, and changing it means asking an operator. |
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-checkout-tax-id.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-checkout-tax-id.md| new file mode 100644 |
| index 000000000..a97dabc37 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-checkout-tax-id.md |
| @@ -0,0 +1,23 @@ |
| +# Review brief: branch checkout-tax-id, round 1 of 3 |
| + |
| +Repo carlos/platform, branch `checkout-tax-id`, the commit that adds this brief (named in your prompt). |
| +Under review: the diff `origin/main...HEAD`: PrepareCheckout adds `tax_id_collection[enabled]=true` and `customer_update[name]=auto` so EU business customers can enter a VAT number and Stripe Tax applies reverse charge (Paul's tax setup, 2026-10-31). Confirmed against the Stripe sandbox: a session with these parameters opens with tax_id_collection {enabled: true, required: never}. |
| + |
| +## What to check |
| + |
| +1. Prepared requests stay byte-stable: only newly prepared Checkout requests carry the new fields; a stored request is resent verbatim (Plan 6b Invariant: prepared bytes never change under a key). |
| +2. `customer_update[name]=auto` does not overwrite anything the console relies on (the customer name the console set, if any) in a way that breaks billing. |
| +3. The house-coupon path, the expiry path and every other Prepare* are unchanged. |
| +4. Docs sentence accuracy. |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not compile, a test fails, or it would not work. Blocks merge. |
| +- **P2**: wrong or missing. Fixed without reopening this review. |
| +- **P3**: clarity or polish. Goes on a follow-up list; never a reason for another round. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3 with file:line, failure scenario and fix. End with exactly one verdict: **READY**, **READY AFTER FIXES**, or **NOT READY**. |
| + |
| +Do not edit files. Do not spawn Anthropic-model reviewers or subagents of your own. Do not run the full test suites. |
diff --git a/internal/billingstripe/prepared.go b/internal/billingstripe/prepared.go| index 5ecce0d52..00c1ec7bc 100644 |
| --- a/internal/billingstripe/prepared.go |
| +++ b/internal/billingstripe/prepared.go |
| @@ -41,8 +41,9 @@ func (p *Provider) PrepareCustomer(accountSqid, key string) (billing.Prepared, e |
| // PrepareCheckout encodes a Checkout Session create: subscription mode in |
| // the request's currency, its line items by price id, Adaptive Pricing |
| -// off, the billing address required and saved on the customer, automatic |
| -// tax, the provider-time expiry, the success and cancel URLs, the purchase |
| +// off, the billing address required and saved on the customer, the |
| +// customer's name saved and an optional tax id collected (so Stripe Tax can |
| +// reverse charge an EU business), automatic tax, the provider-time expiry, the success and cancel URLs, the purchase |
| // metadata on the session and on the subscription it makes, and either the |
| // resolved coupon (req.Coupon) or promotion codes. |
| func (p *Provider) PrepareCheckout(req billing.CheckoutRequest) (billing.Prepared, error) { |
| @@ -68,6 +69,15 @@ func (p *Provider) PrepareCheckout(req billing.CheckoutRequest) (billing.Prepare |
| } |
| form.Set("billing_address_collection", "required") |
| form.Set("customer_update[address]", "auto") |
| + // Optional VAT number: Stripe Tax applies reverse charge when an EU |
| + // business that gives one is eligible for it (never for a domestic sale, |
| + // which keeps VAT). tax_id_collection[required] stays unset (it |
| + // defaults to never). Stripe requires customer_update[name]=auto beside |
| + // tax_id_collection when the session has a customer, as ours always |
| + // does. These ride only on a newly prepared request: Send resends a |
| + // stored Prepared's bytes as they are. |
| + form.Set("customer_update[name]", "auto") |
| + form.Set("tax_id_collection[enabled]", "true") |
| form.Set("expires_at", strconv.FormatInt(req.ExpiresAt.Unix(), 10)) |
| return prepared(billing.PreparedCheckout, "/v1/checkout/sessions", form, req.IdempotencyKey) |
| } |
diff --git a/internal/billingstripe/prepared_test.go b/internal/billingstripe/prepared_test.go| index 4270b6c1a..47a46ea92 100644 |
| --- a/internal/billingstripe/prepared_test.go |
| +++ b/internal/billingstripe/prepared_test.go |
| @@ -259,7 +259,8 @@ func TestPrepareCheckoutCarriesResolvedCoupon(t *testing.T) { |
| "line_items[0][price]": {"price_p"}, "line_items[0][quantity]": {"1"}, |
| "line_items[1][price]": {"price_a"}, "line_items[1][quantity]": {"2"}, |
| "adaptive_pricing[enabled]": {"false"}, "billing_address_collection": {"required"}, |
| - "customer_update[address]": {"auto"}, "automatic_tax[enabled]": {"true"}, |
| + "customer_update[address]": {"auto"}, "customer_update[name]": {"auto"}, |
| + "tax_id_collection[enabled]": {"true"}, "automatic_tax[enabled]": {"true"}, |
| "expires_at": {strconv.FormatInt(providerDate.Add(time.Hour).Unix(), 10)}, |
| "success_url": {req.SuccessURL}, "cancel_url": {req.CancelURL}, |
| "allow_promotion_codes": {"true"}, |
| @@ -292,6 +293,65 @@ func TestPrepareCheckoutCarriesResolvedCoupon(t *testing.T) { |
| } |
| } |
| +// A Checkout create prepared before tax_id_collection existed is stored |
| +// with its bytes and resent as they are: Send never re-encodes a Prepared, |
| +// so the new fields reach only newly prepared requests. |
| +func TestSendStoredCheckoutWithoutTaxIDFieldsIsUnchanged(t *testing.T) { |
| + var c capture |
| + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + got := c.add(r) |
| + fmt.Fprint(w, okBody(got.path)) |
| + })) |
| + defer srv.Close() |
| + p := prepProvider(t, srv.URL, nil) |
| + |
| + // The body PrepareCheckout produced before this change, frozen. |
| + stored := billing.Prepared{ |
| + Kind: billing.PreparedCheckout, Method: http.MethodPost, Path: "/v1/checkout/sessions", Key: "key-checkout-1", |
| + Body: []byte("adaptive_pricing%5Benabled%5D=false&allow_promotion_codes=true&automatic_tax%5Benabled%5D=true" + |
| + "&billing_address_collection=required&cancel_url=https%3A%2F%2Fconsole.example.com%2Fbilling" + |
| + "¤cy=usd&customer=cus_1&customer_update%5Baddress%5D=auto&expires_at=1792933200" + |
| + "&line_items%5B0%5D%5Bprice%5D=price_p&line_items%5B0%5D%5Bquantity%5D=1" + |
| + "&line_items%5B1%5D%5Bprice%5D=price_a&line_items%5B1%5D%5Bquantity%5D=2" + |
| + "&metadata%5Baccount_sqid%5D=bab&metadata%5Bcheckout_intent%5D=ci_1&metadata%5Bcurrency%5D=usd" + |
| + "&metadata%5Bprice_book%5D=example-v1&mode=subscription" + |
| + "&subscription_data%5Bmetadata%5D%5Baccount_sqid%5D=bab&subscription_data%5Bmetadata%5D%5Bcheckout_intent%5D=ci_1" + |
| + "&subscription_data%5Bmetadata%5D%5Bcurrency%5D=usd&subscription_data%5Bmetadata%5D%5Bprice_book%5D=example-v1" + |
| + "&success_url=https%3A%2F%2Fconsole.example.com%2Fbilling%3Fdone%3D1"), |
| + } |
| + want := string(stored.Body) |
| + if _, err := p.Send(context.Background(), stored); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := c.last(); string(got.body) != want || got.key != "key-checkout-1" { |
| + t.Errorf("stored create was altered:\n got %q\nwant %q", got.body, want) |
| + } |
| + if string(stored.Body) != want { |
| + t.Errorf("Send changed the stored body") |
| + } |
| + |
| + // A newly prepared request carries the new fields, and differs from the |
| + // stored one by exactly those two. |
| + fresh, err := p.PrepareCheckout(checkoutRequest()) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + fv, _ := url.ParseQuery(string(fresh.Body)) |
| + sv, _ := url.ParseQuery(want) |
| + for _, k := range []string{"customer_update[name]", "tax_id_collection[enabled]"} { |
| + if fv.Get(k) == "" || sv.Has(k) { |
| + t.Errorf("%s: fresh %q, stored %q", k, fv.Get(k), sv.Get(k)) |
| + } |
| + fv.Del(k) |
| + } |
| + if fv.Encode() != sv.Encode() { |
| + t.Errorf("fresh and stored differ by more than the new fields:\n %s\n %s", fv.Encode(), sv.Encode()) |
| + } |
| + if fv.Has("tax_id_collection[required]") { |
| + t.Errorf("tax id collection must stay optional") |
| + } |
| +} |
| + |
| func TestSendVerbatimOneRequest(t *testing.T) { |
| var c capture |
| var mode atomic.Value |