feat(billing): sell to the countries in BILLING_SELL_COUNTRIES #168

Sammanfogat
supernaut sammanfogade 6 incheckningar från feat/sell-abroad in i main 2026-10-12 19:27:51 +00:00
Ägare

What

Billing can sell outside Sweden, behind one allowlist. Four commits, in order:

  1. fix(vat): standard rates for all EU-27 countries (Finland was 25.6, is 25.5). A Norwegian business without a validated VAT number pays VOEC like a consumer.
  2. feat(billing): charge.billing_country and charge.card_country (migration 0011). The Mollie adapter reads details.cardCountryCode.
  3. feat(billing): BILLING_SELL_COUNTRIES enforcement in startCheckout. Contract 0.11.0.
  4. feat(cli): cli.js sales <YYYY-Qn | YYYY> [--eur-rate N], README, ten-year retention for records that support an OSS return.

How the flag works

BILLING_SELL_COUNTRIES is a comma-separated list of ISO alpha-2 codes. Unset or empty means SE. It is parsed per call and every listed code must have a VAT rate, or the service does not start.

startCheckout takes an optional country (^[A-Z]{2}$). It uses that, else the stored customer.country, else SE only while the list is exactly {SE}. Then:

  • Not listed: BAD_REQUEST country_not_sold.
  • No country and no stored one, with more than SE listed: country_required.
  • One-time (Swish) payment outside Sweden: one_time_sweden_only.
  • A non-Swedish checkout offers cards only (no Apple Pay) and sends restrictPaymentMethodsToCountry.
  • A paid first payment for a non-Swedish checkout whose card country differs or is missing is refunded (card country mismatch) and not activated. A Swedish checkout accepts any card. Renewals are not checked.

The price stays the same gross. VAT is backed out at the destination rate.

How it was tested

  • vat.test.ts: all 27 codes as consumer (oss) and validated business (reverse-charge), FI 2550, NO business without a number is voec, unknown code throws.
  • mollie.test.ts: card country read or omitted, restriction and card-only methods sent only with restrictCountry.
  • billing.test.ts (Postgres): with the variable unset a Swedish checkout is unchanged (25 % domestic, 150000 gross, no restriction argument); refusals; listed country at 1900 oss with restriction; stored-country fallback; match activates; mismatch and missing card country refund and stay inactive; Swedish checkout with a foreign card activates; evidence columns on first payment and renewal; sales report query.
  • config.test.ts, env.test.ts, contract index.test.ts.
  • sales.test.ts: Stockholm quarter bounds, grouping and section order, EUR rounding, refund VAT split, non-SEK rows, empty period, bad period and rate.
  • pnpm test (594 tests, with Postgres 17), pnpm typecheck, pnpm lint, pnpm drizzle-kit check.

Closes #117.

Version 0.12.0.

## What Billing can sell outside Sweden, behind one allowlist. Four commits, in order: 1. `fix(vat)`: standard rates for all EU-27 countries (Finland was 25.6, is 25.5). A Norwegian business without a validated VAT number pays VOEC like a consumer. 2. `feat(billing)`: `charge.billing_country` and `charge.card_country` (migration 0011). The Mollie adapter reads `details.cardCountryCode`. 3. `feat(billing)`: `BILLING_SELL_COUNTRIES` enforcement in `startCheckout`. Contract 0.11.0. 4. `feat(cli)`: `cli.js sales <YYYY-Qn | YYYY> [--eur-rate N]`, README, ten-year retention for records that support an OSS return. ## How the flag works `BILLING_SELL_COUNTRIES` is a comma-separated list of ISO alpha-2 codes. Unset or empty means `SE`. It is parsed per call and every listed code must have a VAT rate, or the service does not start. `startCheckout` takes an optional `country` (`^[A-Z]{2}$`). It uses that, else the stored `customer.country`, else `SE` only while the list is exactly `{SE}`. Then: - Not listed: `BAD_REQUEST` `country_not_sold`. - No country and no stored one, with more than `SE` listed: `country_required`. - One-time (Swish) payment outside Sweden: `one_time_sweden_only`. - A non-Swedish checkout offers cards only (no Apple Pay) and sends `restrictPaymentMethodsToCountry`. - A paid first payment for a non-Swedish checkout whose card country differs or is missing is refunded (`card country mismatch`) and not activated. A Swedish checkout accepts any card. Renewals are not checked. The price stays the same gross. VAT is backed out at the destination rate. ## How it was tested - `vat.test.ts`: all 27 codes as consumer (`oss`) and validated business (`reverse-charge`), FI 2550, NO business without a number is `voec`, unknown code throws. - `mollie.test.ts`: card country read or omitted, restriction and card-only methods sent only with `restrictCountry`. - `billing.test.ts` (Postgres): with the variable unset a Swedish checkout is unchanged (25 % domestic, 150000 gross, no restriction argument); refusals; listed country at 1900 `oss` with restriction; stored-country fallback; match activates; mismatch and missing card country refund and stay inactive; Swedish checkout with a foreign card activates; evidence columns on first payment and renewal; sales report query. - `config.test.ts`, `env.test.ts`, contract `index.test.ts`. - `sales.test.ts`: Stockholm quarter bounds, grouping and section order, EUR rounding, refund VAT split, non-SEK rows, empty period, bad period and rate. - `pnpm test` (594 tests, with Postgres 17), `pnpm typecheck`, `pnpm lint`, `pnpm drizzle-kit check`. Closes #117. Version 0.12.0.
supernaut lade till 6 incheckningar 2026-10-12 19:25:07 +00:00
Finland is 25.5 percent, not 25.6. A Norwegian business without a validated number pays VOEC like a consumer. Fixes #117.
Adds charge.billing_country and charge.card_country. The Mollie adapter reads details.cardCountryCode. Older rows stay null.
An allowlist of ISO country codes, Sweden only when unset. startCheckout takes an optional country, refuses unlisted countries and one-time payments outside Sweden, and restricts non-Swedish checkouts to cards from that country. A paid first checkout whose card country differs from the declared one is refunded and not activated. The service refuses to start when a listed country has no VAT rate. Contract 0.11.0.
cli.js sales prints invoices issued in a quarter or year by country, basis, rate and currency, with refunds and optional EUR conversion. README documents the allowlist, the report and ten-year retention for records that support an OSS return.
A later or abandoned checkout overwrote customer.country, which the invoice and renewals read. The charge now fixes the country: the invoice uses it, renewals copy the previous charge, and activation sets the customer row from it.
chore(release): 0.12.0
Alla kontroller lyckades
ci / ci (pull_request) Successful in 2m5s
5be6967eca
supernaut sammanfogade incheckning 0a604239d4 till main 2026-10-12 19:27:51 +00:00
supernaut tog bort grenen feat/sell-abroad 2026-10-12 19:27:51 +00:00
Logga in för att delta i denna konversation.
Inga granskare
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Förfallodatumet är ogiltigt eller utanför gränserna. Använd formatet "åååå-mm-dd".

Inget förfallodatum satt.

Beroenden

Inga beroenden satta

Referens
bitborg/bitborg-payment!168
Ingen beskrivning angiven.