Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Money Correctness
Status: In Progress — A, A2, B and C merged in spree/spree#14852; D (money preferences) and E (Admin and Seller APIs without display_*) built, awaiting review
Target: Spree 6.0
Depends on: 5.5-client-side-money-normalization.md (canonical decimal-string contract), 6.0-6.1-split-adjustments.md (typed spree_tax_lines / spree_discounts / spree_fees — landed, so they are in scope), 6.0-json-preferences.md (decimal preferences are exact strings), 6.0-payment-gateways-monorepo.md (Stripe lives in the monorepo; Adyen and PayPal Checkout are separate gems patched in the same release)
Author: Damian + Claude
Last updated: 2026-10-09
Tracking: Linear V-3738 · GitHub spree/spree#14848
Summary
Spree stores money in decimal columns, but four things still make amounts wrong or ambiguous before 6.0. Some money paths pass through floats (.to_f in Ruby, parseFloat in the dashboard), which cannot hold most decimal amounts exactly and are only rescued by a rounding step that happens to follow. The API does not agree with itself on what a money field looks like: most fields are strings, a few are JSON numbers, and the strings are not normalized ("10.0", never "10.00"). Payment gateways receive a bare integer in hundredths of the currency, which is the right unit only for two-decimal currencies, while Stripe sessions use ISO minor units — and Stripe's own units are neither (ISK, HUF, TWD carry special rules). And the columns are decimal(10, 2), which cannot hold a Kuwaiti dinar's third decimal, a sub-cent B2B unit price, or a large Vietnamese dong order. This plan removes floats from money paths in Ruby and TypeScript and writes the rule into CLAUDE.md, hands gateways an amount with its currency and lets each adapter convert to its provider's unit, makes every money field on the wire a decimal string written to a published per-currency exponent, and widens the money columns to decimal(19, 4). It ships as four pull requests: A (floats out), A2 (gateway amounts), B (wire contract), C (precision).
Key Decisions (do not deviate without discussion)
All decided 2026-10-08; the ones marked review were changed or added after the design review that day.
Decimal strings, not integer minor units. Money stays a canonical decimal string on the wire (
5.5-client-side-money-normalization.md). No integer minor-unit field appears in the API; the integeramount_in_cents/compare_at_amount_in_centsfields leave the Price and PriceHistory serializers.BigDecimal end to end, Ruby and TypeScript. Money is never a
Float/ JSnumberbetween parsing and persisting or between reading and comparing. Stated as a rule inCLAUDE.md("Money").The currency exponent is ISO 4217, from one Spree-owned file (review).
spree/core/config/currency_exponents.jsonholds the ISO 4217 minor-unit table, pinned to a dated list. Ruby registers it over the Money gem at boot, soSpree::Money::Rounding.precision,Money#centsandMoney#formatagree;@spree/sdk-coreimports the same file;CurrencySerializerexposes it asdecimal_places. Where the Money gem differs today (HUF 0 → 2, MGA and MRU 1 → 2) Spree follows ISO. Why: the exponent is now part of the contract ("100.5"JPY is a 422), so a client must be able to read it, and the TypeScript side must use exactly the same table. Accepted trade-off: Spree stops rounding HUF to whole forints; stored HUF values are already at two decimals and do not change. Upgrade-guide entry.Gateways receive a
Spree::Money, not an integer (review; supersedes "gateways receive true minor units" from the first pass). Core passes amount and currency; each adapter converts to its provider's unit. Stripe's adapter owns Stripe's rules (zero-decimal list, ISK sent in a two-decimal representation divisible by 100, HUF and TWD whole-amount rules). Why: no single integer unit is right for every provider, and this gives the TypeScript rewrite a gateway interface whose unit does not depend on the currency.Old gateways keep today's behaviour for one release (review). A gateway opts in with
self.accepts_money_amounts = true. Core keeps passing the integer in hundredths, exactly as today, to any gateway that has not opted in, with a deprecation warning; the bridge is removed in 6.1. Stripe (monorepo),spree_adyenandspree_paypal_checkoutopt in in the same release. Shipped alone as PR A2, so reverting it restores today's behaviour.Two precisions on write (review). Unit-price fields —
priceandcompare_at_amounton prices (base and price-list prices, which carry price breaks),priceon line items,cost_price,unit_cost— accept up to 4 decimals ("0.0125"USD). Every other money field — totals, payments, refunds, captures, adjustments, discounts, fees, tax lines, gift cards, store credit, payouts — accepts at most the currency's exponent. Line amounts areprice × quantityrounded to the exponent when persisted. Why: B2B unit pricing and price breaks ship in 6.0 and need sub-cent unit prices; money that changes hands never has sub-minor-unit amounts.Writes are strict strings. The Admin and Seller APIs parse money with
BigDecimal(str)and reject a JSON number, a non-canonical string ("1,99","1e3"," 5","+5"), or an over-precise string (by the rule above) with 422invalid_money_format, naming the field. Top-level fields and the money keys insidepreferences. Supersedes "JSON numbers are also accepted" inmonetary-amounts.mdxand the 5.5 plan's "lenient now" leaning. Accepted trade-off: breaking for integrators sending numbers.Canonical read format. A money field is a string matching
^-?\d+(\.\d+)?$. Exponent fields carry exactly the currency's decimal places ("10.00","1.500","100"). Unit-price fields carry at least the exponent and at most 4, with zeros beyond the exponent stripped ("19.99","0.0125","19.9950"→"19.995").display_*companions are unchanged.Rates and percentages are canonical decimal strings (review: canonical form and naming rule added). No fixed exponent, trailing zeros and a trailing
.stripped (decimal(8,5)0.23000→"0.23",23.00→"23"), top-level and insidepreferences. Naming rule, enforced by the contract spec: a name ending_percentor_percentageis 0–100; a name that israteor ends_rateis a fraction (0.23). A field may not be named like money (amount,value) when it holds a rate. So the Admin tax rate'samount(fraction) becomesrateandamount_percentagebecomesrate_percent, with model aliases per the read/write-symmetry rule. Discountvalueis the one documented exception: money or percent by itsvalue_type.Round only at boundaries; the rounding mode is a parameter (review). Intermediate math keeps full precision.
Spree::Money::Rounding.to_currency(amount, currency, mode: :half_up)is called when a total or line amount is persisted, when a gateway adapter converts, and when an amount is serialized. Tax providers own their rounding (per line or per invoice, and the mode); the internal provider keeps per-line half-up.Columns become
decimal(19, 4). Every money column, including the typed adjustment tables. Rate and percentage columns keep their current scale. Widening changes no stored value.The column migration is idempotent and has a documented online path (review). It skips a column already at
(19, 4), so an install that widened large tables ahead of the upgrade (shadow column plus backfill) runs it as a no-op for those. Default path: one migration in the 6.0 upgrade window, accepting the table rewrite under lock.Wrong capture events are reported, not repaired.
spree:money:audit_capture_eventslists payments in non-two-decimal currencies whose capture events disagree with the corrected value, and writes nothing. Spree never rewrites money on completed orders.The rule lives in
CLAUDE.md, not in a lint tool (decided 2026-10-09; supersedes the first pass's RuboCop cop and Biome twin). A cop was built and then dropped: the repository runs no RuboCop, and a name-matching rule needs an allowlist that is mostly noise.CLAUDE.md"Money" states it for people and agents alike.Open carts in zero- and three-decimal currencies change on their next recalculation. Accepted trade-off: a yen total can move by under one yen mid-checkout. Completed orders are frozen and do not change.
The strict write check lives in one concern (decided 2026-10-09).
Spree::Api::V3::StrictMoneyParams, included in the Admin and Seller base and resource controllers, walks the request body and refuses a JSON number, malformed text or too many decimals for every money and rate key,preferencesincluded, before anything is written. A money field checks its currency's decimals when the payload names the currency beside it, and allows four otherwise, so a store in one currency never wrongly refuses an amount in another; the model setters (Spree::CanonicalDecimals) still refuse anything malformed. Discount and commissionvalueand custom fieldvalueare not covered by key name, because the same key holds unrelated data elsewhere.Store API money fields are gated and nullable (decided 2026-10-09). Declaring them through
money_attributeshides them from gated (prices-hidden) guests, so delivery rates, claims, returns, exchanges, store credit, refunds, payment sessions, order groups and gift card batches now answernullthere, and their Store SDK types becomestring | null. Admin and Seller subclasses re-declare them non-null.The migration rewrites each table once (decided 2026-10-09, after a review against strong_migrations). All of a table's columns change in one
ALTER TABLE;nullanddefaultare not passed on PostgreSQL or MySQL, which keep them through a type change (passingnull: falseadded aSET NOT NULLthat scans every row); SQLite, which rebuilds the table, is given both. The rewrite is wrapped insafety_assuredwhen strong_migrations is installed.Spree stops parsing numbers by locale (decided 2026-10-09; supersedes the 5.5 plan's "
LocalizedNumberis not removed" and this plan's first-pass "out of scope"). The model setters that re-parsed strings withSpree::LocalizedNumberunder the request locale are replaced by strict ones (Spree::CanonicalDecimals): a number or canonical decimal text is stored exactly, and any other text raisesSpree::Money::InvalidFormat(422invalid_money_formatfrom the API) instead of Rails' lenient cast reading"1,599.99"as 1. Why: the legacy admin they served is gone, and under a store whose language writes a comma decimal they misread the dashboard's canonical"49.50"as 4950 and grew an untouched"99.0"tenfold on every save (a reported bug).Spree::LocalizedNumber.parsestays one release as a deprecated method nothing in Spree calls, and is removed in 6.1. The variant'scost_price/weight/width/height/depthwriters keep ignoring a blank value. Ships in PR A.The dashboard shows and reads money in the admin's own number format (decided 2026-10-09, following Shopify; supersedes the 5.5 plan's "currency's market locale").
useMoneyLocale()returns the dashboard language; every money field formats and normalizes through it, whatever the currency or market. Why: a store can have several markets with one currency and different conventions (EUR in Germany and Ireland), so the market-based format depended on which market loaded first; the person typing knows their own convention, and the old reason against it, server re-parsing, is gone. Accepted trade-off: a German-speaking admin of a US store sees1234,56for dollars. Ships in PR A.All four parts ship on one pull request (decided 2026-10-09; supersedes "four pull requests"). A2, B and C land as their own commit series on spree/spree#14852, so nothing ships half-done; A2 is still revertible by its commits.
spree_adyenandspree_paypal_checkoutare not patched in their Spree 5 repositories (decided 2026-10-09; amends "patch the gems you own in the same release"). Theirmainbranches still target Spree 5 (spree_admin), where this API does not exist. Adyen takes money amounts when it is ported intospree/providers(constraint added to6.0-payment-gateways-monorepo.md); PayPal and third-party gateways keep working through the hundredths bridge until 6.1.PR A applies the ISO table to Spree's own rounding only; registering it over the Money gem moves to A2 (decided 2026-10-09). Registering changes
Money#centsfor HUF, which Stripe payment sessions read, and A2 is the only PR that may change what a gateway receives.Money preferences have their own type (decided 2026-10-09, after spree/spree#14852). A preference is declared
:moneyfor an amount and:decimalfor a rate or a measure.:moneyis stored like a decimal, reportsmoneyinpreference_schema, and is written on the API with at least the decimals of the record'scurrencypreference and up to four, like a unit price; with no currency it keeps its exact decimal. Why: with one:decimaltype the server and the dashboard could only guess money from a preference's name, so calculator amounts went out as"12.5"while every other amount was"12.50". Both types refuse text such as"1,599.99", which the old lenient cast read as 1. Ships in PR D.The Admin API drops
display_*fields (decided 2026-10-09). Every amount is an exact decimal string with its currency, so the dashboard and seller panel format money themselves, in the admin's own language (useMoneyLocale); the server's strings were formatted in the request's language and could disagree with the editable fields beside them. The Store API keeps them for storefronts, webhooks and email templates. Ships in PR E, after the dashboards stop reading them.Email templates format money with the
moneyfilter (decided 2026-10-10). The default templates print raw amounts throughmoneyinstead of the serializers'display_*fields, which gives the same output and leaves one way to format money in a template. Thedisplay_*fields stay in email data, so a template a merchant customized before 6.0 keeps rendering; whether to remove them later is a separate decision, since customized templates live in the database.Money preferences are checked by their type (decided 2026-10-11). Preferences assigned through the API are validated against the JSON Schema built from their declarations, which already refuses a
:moneyvalue that is not a decimal string;assign_preferencesnow also refuses one with more decimals than its currency, read from the payload's or the record'scurrencypreference or from the source acurrency:option names. The name-based Admin and Seller check skipspreferences, so an extension's money preference is checked whatever it is called and a text preference named like money (rate) is no longer refused.
Design Details
Inventory: every .to_f and Float( outside specs (58 sites at 4ca24b8)
Verdict money means it is fixed in PR A. Not money sites stay as they are. Boundary means a third party requires a JSON number; the value is computed in BigDecimal and converted once, on the line that hands it over, with a comment saying why.
| Site | What it is | Verdict |
|---|---|---|
api/…/admin/orders/payments_controller.rb:55 |
capture amount: (params[:amount].to_f * 100).round — float, and hard-coded hundredths |
money |
core/…/workflows/spree/payments/capture.rb:89 |
capture event: ::Money.new(@amount, currency).to_f — float, and reads hundredths as true minor units (see "Gateway unit") |
money |
core/…/models/spree/refund.rb:124 |
refund credit cents via amount.to_f |
money |
core/lib/spree/money.rb:106 |
amount_in_cents: cents / subunit_to_unit.to_f * 100 |
money |
core/…/models/spree/tax_rate.rb:69 |
amount_percentage=: value.to_f / 100 |
money (rate) |
core/…/concerns/spree/vat_price_calculation.rb:69 |
included VAT rate .to_f, multiplied into a price |
money (rate) |
core/…/models/spree/order.rb:420 |
analytics_subtotal returns a Float |
money |
core/…/models/spree/order.rb:1277 |
attributes[:amount].to_f.zero? |
money |
core/…/purchase/payment_processing.rb:49 |
total.to_f > 0.0 |
money |
core/…/calculator/shipping/flat_percent_item_total.rb:16 |
(value * 100).round.to_f / 100 |
money |
core/…/services/spree/stores/provision_defaults.rb:263 |
preferences[:amount].to_f.zero? |
money |
core/…/csv/order_line_item_presenter.rb:99,100,101,108 |
item/delivery/tax/grand total in CSV | money |
core/…/csv/order_line_item_presenter.rb:110 |
total weight | not money |
core/…/csv/product_variant_presenter.rb:101,102,178,179 |
price / compare-at in CSV | money |
core/lib/spree/reporting/adapters/base.rb:25 |
:money/:decimal/:percent metrics cast to_f.round(2) |
money |
core/lib/spree/reporting/adapters/base.rb:38 |
derived ratio (average order value is money ÷ count) | money |
core/lib/spree/reporting/adapters/base.rb:66 |
period-over-period growth percentage | not money |
api/…/v3/cart_serializer.rb:109,113 |
order_minimum_amount, order_minimum_shortfall emitted as numbers |
money |
api/…/v3/admin/store_serializer.rb:129 |
preferred_default_minimum_payout_amount as number |
money |
api/…/v3/admin/store_serializer.rb:133 |
preferred_default_commission_tax_rate as number |
money (rate) |
api/…/v3/admin/tax_rate_serializer.rb:30 |
amount_percentage as number |
money (rate) |
api/…/services/spree/api/v3/filters_aggregator.rb:66,67 |
price-range filter min/max as numbers |
money |
providers/easypost/lib/spree_easypost.rb:179,198 |
customs declared value: item.price.to_f * quantity |
money (boundary at the EasyPost call) |
providers/meilisearch/…/product_presenter.rb:67,68 |
indexed price / compare_at_price |
boundary — Meilisearch numeric filters and sort need numbers |
providers/meilisearch/…/search_provider.rb:389,391,443 |
price filter value parsed with to_f / Float( |
money (parse with parse_canonical, emit at boundary) |
providers/meilisearch/…/search_provider.rb:584,585 |
price facet min/max read back from the index | money (become strings on the wire with the filters aggregator) |
providers/meilisearch/…/product_presenter.rb:109 |
number custom field | not money |
core/…/models/spree/variant.rb:1077, freight_summary/line.rb:171 |
carton counts | not money |
core/…/models/spree/package_type.rb:128,130, providers/easypost/lib/spree_easypost.rb:27,39 |
dimensions and weights | not money |
api/…/v3/variant_serializer.rb:44,48,52,56 |
weight / height / width / depth | not money |
api/…/v3/admin/address_serializer.rb:20,24, api/…/store/delivery_methods_controller.rb:32,33 |
latitude / longitude | not money |
core/…/concerns/spree/stores/setup.rb:52 |
setup percent complete | not money |
core/…/services/spree/generate_token.rb:17 |
timestamp | not money |
core/lib/spree/translations.rb:84 |
translation coverage ratio | not money |
core/…/serializers/spree/emails/store_serializer.rb:22 |
logo height | not money |
Hard-coded hundredths (not .to_f, same class of bug — fixed in PR A because the float fix touches the same lines):
| Site | Code |
|---|---|
core/…/adjusters/promotion.rb:152,157 |
promotion distribution in * 100 cents |
core/…/services/spree/orders/discounts/create.rb:55,60,66 |
manual discount distribution in * 100 cents; percent .round(2) |
core/…/payment_method/store_credit.rb:29,41,52,79 |
amount_in_cents / 100.0.to_d |
core/…/calculator/tiered_percent.rb:18, flat_percent_item_total.rb:10, percent_on_line_item.rb:14 |
.round(2) |
core/…/tax_provider/internal.rb:178,180, delivery_rate.rb:83,85 |
tax .round(2) |
core/…/stock/estimator.rb:124 |
markup .round(2) |
The store credit gateway's amount_in_cents / 100.0.to_d (payment_method/store_credit.rb:29,41,52,79) is fixed in PR A2, where it opts into Spree::Money amounts. The rest of the hard-coded hundredths (promotion and manual discount distribution, .round(2) in calculators, tax and markup) are fixed in PR A.
TypeScript inventory
About 50–65 Number(...) / parseFloat(...) calls in packages/dashboard, dashboard-core, dashboard-ui and seller-dashboard touch money, depending on how they are counted (64 by a name filter on amount|price|total|cost|fee|discount|tax|refund|balance). Representative: orders/order-adjustments-cards.tsx:436 sums parseFloats of discounted_amount; orders/fulfillment-edit-dialog.tsx:61 compares parseFloat(rate.cost) === 0. Both monetary-amounts.mdx pages tell integrators to parseFloat(order.total). Every money site is fixed in PR B.
Gateway amounts
Today payment_method.authorize/purchase/capture/credit receive Spree::Money#amount_in_cents, the amount in hundredths for every currency (1000 JPY → 100000; 1.505 KWD → 151), while Stripe sessions use Money#cents, the ISO minor unit (1000 JPY → 1000). The capture event then reads the hundredths value back as minor units: a 1000 JPY capture records 100,000 JPY, a 1.500 KWD capture records 0.150 KWD. Payment#captured_amount sums those events and the capture flow resizes the payment from that sum, so the error can reach the payment's own amount.
The two capture callers do not even agree with each other: an admin capture passes hundredths, a capture on dispatch passes the currency's minor unit, and the workflow records both the same way. No fix to the recording alone is right for both, so PR A only removes the float and keeps every unit as it was; PR A2 fixes the recording with the interface, when the workflow receives a Spree::Money:
class Spree::Gateway
class_attribute :accepts_money_amounts, default: false
end
# core, one place (Spree::Payment#gateway_amount):
amount = payment_method.accepts_money_amounts ? money : legacy_hundredths(money)
class SpreeStripe::Gateway < Spree::Gateway
self.accepts_money_amounts = true
def capture(money, payment_intent_id, options = {})
Stripe::PaymentIntent.capture(payment_intent_id, { amount_to_capture: stripe_units(money) }, opts)
end
end
stripe_units lives in the Stripe gem and is also what payment sessions use, so a session and its capture always agree. spree_adyen (Adyen minor units, its own currency table) and spree_paypal_checkout (PayPal decimal strings) opt in in releases cut alongside 6.0. The store credit gateway opts in and reads money.amount directly.
Strict parsing at the API boundary
Spree::Money::Rounding.parse_canonical(value, currency, unit_price: false) returns a BigDecimal for a String matching ^-?\d+(\.\d+)?$ with at most the currency's decimal places (4 with unit_price: true), and nil for nil. Anything else raises Spree::Money::InvalidFormat, which the v3 base controller renders as 422 with code invalid_money_format and the field in details. Rates use parse_canonical_decimal(value): same shape, no decimal limit beyond the column's. Admin and Seller controllers validate every declared money and rate field, including the money and percentage keys of preferences, before assignment, so a model setter only ever sees a canonical string. The Store API takes no client amounts (5.5 audit) and is unchanged.
Wire contract
BaseSerializer.money_attributes is the only way to declare a money field, with the currency read from the record:
money_attributes :total, :item_total # currency from object.currency
money_attributes :amount, :compare_at_amount, unit_price: true
money_attributes :cost_price, currency: :cost_currency, unit_price: true
money_attributes :minimum_payout_amount, currency: ->(store) { store.default_currency }
rate_attributes :rate, :rate_percent # canonical decimal, zeros stripped
Both format through Spree::Money::Rounding.format(amount, currency, unit_price:) / format_decimal, keep hide_prices, and type the field string | null. CurrencySerializer gains decimal_places.
The contract spec loads every v3 serializer (Store, Admin, Seller), builds each resource from its factory in USD, KWD and JPY, and asserts: every money_attributes field matches ^-?\d+(\.\d+)?$ with exactly the currency's decimal places (or within exponent..4 for unit prices); every rate_attributes field has no trailing zeros; no attribute whose name matches the money pattern is declared any other way; no rate is named like money; _percent/_percentage fields fall in 0–100 and rate/_rate fields in 0–1 on the factory data.
Known non-conforming fields today: cart.order_minimum_amount / order_minimum_shortfall (numbers), admin store preferred_default_minimum_payout_amount / preferred_default_commission_tax_rate (numbers), admin tax rate amount (fraction named like money) and amount_percentage (number), product filter price range min/max (numbers), report money metrics (numbers), price.amount_in_cents / compare_at_amount_in_cents / price_history.amount_in_cents (removed). Every other money field is already a string, but unnormalized.
TypeScript money
@spree/sdk-core gains a small decimal helper over strings, built on the same currency_exponents.json: compareMoney(a, b), sumMoney(values, currency), isZeroMoney(value), decimalPlaces(currency). It works on scaled bigints internally and returns canonical strings, so no money value passes through a JS number. The dashboard's money sites move onto it; display keeps Intl.NumberFormat on the display_* fields or on the string. Both monetary-amounts.mdx pages replace parseFloat with the helper.
Precision migration
One migration, ChangeMoneyColumnsToDecimal194, changes every money column below to decimal(19, 4), keeping each column's null and default, and skips any column already at (19, 4). Its down restores each original type. Values do not change: every stored decimal(10,2) / (8,2) / (12,4) value is exactly representable.
Columns (from server/db/schema.rb at 4ca24b8): spree_adjustments.amount; all *_total, cost, price, cost_price, pre_tax_amount, amount*, refund_amount, tax_amount, unit_cost, revenue, settled_amount, minimum_payout_amount, min_amount/max_amount, markup_flat columns on carts, orders, line items, fulfillments, payments, payment splits, payment sessions, payment capture events, refunds, reimbursements and reimbursement credits, return / claim / exchange line items, return items, prices and price histories, gift cards and batches, store credits and events (today 8,2), tax lines, discounts (amount; value is percent-or-amount and widens with it), fees, commission lines and rate values, seller payouts and transfers, sellers, catalog order minimums, delivery methods and their services, delivery rates (today 8,2), shipping labels, purchase order items, stock movements, variants (cost_price), products and products-stores (revenue), Stripe payment intents. Extension tables (spree_paypal_checkout_orders) are listed in the upgrade guide for their gem to follow. Not changed: tax_rates.amount, tax_lines.rate, commission_*.rate/tax_rate/commission_tax_rate/value, price_adjustment_*percentage, markup_percent, dimensions, weights, coordinates, focal points.
Cost: a scale change rewrites the table under an exclusive lock on PostgreSQL, and every ALTER rewrites on MySQL. The upgrade guide documents the default (run it in the upgrade window) and an online path for large installs: add a (19,4) shadow column, backfill in batches, swap names in one short transaction for spree_orders, spree_line_items and spree_adjustments; the migration then finds those columns already widened and skips them.
Value-changing cases
None changes a stored value of an existing two-decimal order.
- Capture events in zero- and three-decimal currencies are recorded correctly from PR A2. Old rows are reported by
spree:money:audit_capture_events, never rewritten. - What opted-in gateways receive changes for every currency's representation (a
Spree::Moneyinstead of an integer); the amount charged changes only where it was wrong (JPY captures at Stripe). Un-opted gateways see no change until 6.1. - Open carts in zero- and three-decimal currencies recalculate with exponent rounding (
123.40JPY →123). Accepted. - Promotion and manual discount distribution in JPY/KWD splits in whole yen / thousandths of a dinar on new orders.
- HUF stops rounding to whole forints (ISO 4217 says two decimals).
- CSV exports and reports print canonical strings instead of floats.
- Every money string on the wire is written to its exponent (
"10.0"→"10.00", JPY"1000.0"→"1000"); rates lose trailing zeros; the tax rate fields are renamed.
Migration Path
PR A — floats out. No wire, schema or gateway-interface change.
- Add
currency_exponents.jsonand read it inSpree::Money::Rounding; addparse_canonical,parse_canonical_decimal,format,format_decimal, and amode:parameter onto_currency. - Fix every money row of the Ruby inventory and the hard-coded hundredths. Capture events and dispatch captures keep their units (fixed in A2), without the float.
- Remove the locale-parsing model setters and deprecate
Spree::LocalizedNumber; the dashboard formats money in the admin's own language (useMoneyLocale), with end-to-end tests for English and German admins and for a store whose market writes a comma decimal. - Add
spree:money:audit_capture_events(report only). - Add the "Money" rule to
CLAUDE.md. - Rounding conformance specs that do not depend on column width.
- Upgrade guide: HUF exponent, open-cart rounding, the audit task,
LocalizedNumberdeprecation.
PR A2 — gateway amounts. Revertible on its own.
- Register
currency_exponents.jsonover the Money gem;Spree::Gateway.accepts_money_amounts, the hundredths bridge with its deprecation warning,Spree::Payment#gateway_amount. - The capture workflow takes a
Spree::Moneyfrom every caller and records it as is, which fixes yen and dinar capture records. - Stripe adapter opts in with
stripe_units(zero-decimal list, ISK, HUF, TWD rules), used by sessions and by capture/refund; store credit gateway opts in. - Patch and release
spree_adyenandspree_paypal_checkoutalongside 6.0. - Upgrade guide and changelog: the extension API change and the 6.1 removal of the bridge.
PR B — wire contract (breaking).
money_attributes(exponent and unit-price formats) andrate_attributes; convert the non-conforming fields; rename the tax rate fields with model aliases; remove the*_in_centsfields;decimal_placeson currencies.- Strict
invalid_money_formatparsing on Admin and Seller writes, includingpreferences. - Contract spec over every v3 serializer.
- Regenerate Typelizer types and Zod schemas for
sdk,admin-sdk,seller-sdk; regeneratedocs/api-reference/*.yamlthrough rswag. @spree/sdk-coredecimal helper; move the dashboard and seller panel money sites onto it.- Both
monetary-amounts.mdxpages (remove "JSON numbers are also accepted", "percentage keys stay numbers" andparseFloat; documentinvalid_money_format,decimal_places, unit-price precision and the rate naming rule),docs/developer/upgrades/5.6-to-6.0.mdx,docs/changelog.mdx, a changeset for the SDKs.
PR C — precision.
- The idempotent column migration;
pnpm wt:template. - Remove the "money columns are
decimal(_, 2)" caveat fromSpree::Money::Rounding.precision. - Specs that only pass after widening: KWD three-decimal order, VND order above 100,000,000, a
"0.0125"USD unit price. - Upgrade guide: the migration window, the online path, extension tables to widen (
spree_paypal_checkout_orders).
PR D — money preferences.
- The
:moneypreference type, strict reading for:decimaland:money, and currency-aware serialization of preferences. - Every amount among the built-in calculator, rule and store preferences declared
:money; rates, weights and volumes stay:decimal. - The settings form shows a money preference with its currency's symbol, and calculator summaries format it as money instead of guessing from the key.
- Model preferences docs, upgrade guide, changeset; regenerate
docs/api-reference/*.yaml.
PR E — Admin and Seller APIs without display_*.
- Move every
display_*read in the dashboard, the shared packages and the seller panel ontoformatMoney(amount, currency, useMoneyLocale()). - Remove the admin-only
display_*attributes and drop the ones Admin and Seller serializers inherit from the Store serializers. - Regenerate types, Zod schemas and the API reference; upgrade guide entry.
Rounding conformance specs (each states the exact expected BigDecimal): tax-inclusive VAT pricing; split payments summing exactly to the order total; partial refunds leaving the exact residual; largest-remainder promotion distribution summing to the promotion amount; captures of "0.29", "1.15", "1234567.89"; a KWD three-decimal order end to end; a JPY zero-decimal order end to end; a VND order above 100,000,000; a sub-cent unit price whose line total rounds to the exponent.
Verification per PR: the changed specs locally, then pnpm test:rspec core and pnpm test:rspec api one at a time; for A2 also pnpm test:rspec stripe; for B pnpm typecheck and pnpm test in packages/sdk-core, sdk, admin-sdk, seller-sdk, and pnpm exec tsc -b in the dashboard.
Constraints on Current Work
- No float on a money path, in Ruby or TypeScript. Parse with
parse_canonical, compute inBigDecimal(or the sdk-core helper), never* 100, never.round(2)— round withto_currency(amount, currency). - Exponents come from
currency_exponents.json, never from a hard-coded 2 or straight from the Money gem's defaults. - Declare money fields with
money_attributes(withunit_price: truefor unit prices) and rates withrate_attributes. Never a plainattribute, never.to_f, never typed:number. - Name rates by the rule:
_percent/_percentageis 0–100,rate/_rateis a fraction, and a rate is never named like money. - New gateways set
accepts_money_amounts = trueand convertSpree::Moneyto their provider's unit in the adapter. - New money columns are
decimal(19, 4),null: false, default: 0where required. Rates aredecimal(8, 5). - Do not round in intermediate math — only when persisting, in a gateway adapter, or when serializing. Tax providers choose their own rounding.
- Money writes are strict. A new Admin or Seller endpoint taking an amount parses it with
parse_canonical(value, currency); never.to_d,BigDecimal(x.to_s)on a raw param, orLocalizedNumber. - No locale parsing on the server. A model setter never re-parses a number by locale; localized input is normalized by the client.
Open Questions
None. Everything raised by the draft and by the review was settled on 2026-10-08 and is recorded in Key Decisions.
References
docs/plans/5.5-client-side-money-normalization.mddocs/plans/6.0-6.1-split-adjustments.mddocs/plans/6.0-payment-gateways-monorepo.mddocs/plans/6.0-multi-vendor-marketplace.md— commission rounding already specified as half-up to the currency exponentdocs/plans/6.0-json-preferences.md— decimal preferences stored as exact stringsdocs/api-reference/admin-api/monetary-amounts.mdx,docs/api-reference/store-api/monetary-amounts.mdxspree/core/lib/spree/money.rb—Spree::Money::Rounding- ISO 4217 minor units; Stripe's currency rules (zero-decimal and special cases)