Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Deprecated display_* money fields in the Store API (#14885)

Damian Legawiec34b80f0db561
diff --git a/.changeset/deprecate-store-display-money.md b/.changeset/deprecate-store-display-money.md
new file mode 100644
index 0000000000..8d3f13aea8
--- /dev/null
+++ b/.changeset/deprecate-store-display-money.md
@@ -0,0 +1,5 @@
+---
+"@spree/sdk": patch
+---
+
+Marked the Store API's `display_*` money fields as deprecated. Format the amount beside each one with its currency instead (`total` for `display_total`); the fields are removed in 6.1.
diff --git a/.changeset/format-money-helper.md b/.changeset/format-money-helper.md
new file mode 100644
index 0000000000..474afb8eae
--- /dev/null
+++ b/.changeset/format-money-helper.md
@@ -0,0 +1,8 @@
+---
+"@spree/sdk": minor
+"@spree/admin-sdk": minor
+"@spree/seller-sdk": minor
+"@spree/dashboard": patch
+---
+
+Added `formatMoney(amount, currency, locale?, { unitPrice? })`, which formats a decimal-string amount in its currency and the reader's language with the currency's own decimal places, without passing it through a JavaScript number. The dashboard now uses the SDK's copy.
diff --git a/docs/api-reference/admin-api/monetary-amounts.mdx b/docs/api-reference/admin-api/monetary-amounts.mdx
index ceea92d4b0..3ca6614cd1 100644
--- a/docs/api-reference/admin-api/monetary-amounts.mdx
+++ b/docs/api-reference/admin-api/monetary-amounts.mdx
@@ -18,7 +18,46 @@ Every monetary field is returned as a decimal string, with its currency on the r
}
```
-The Admin and Seller APIs return amounts only, with no `display_*` formatted copies: format them for the person reading them, in their own language. In JavaScript, pass the string to `Intl.NumberFormat` (`new Intl.NumberFormat('de', { style: 'currency', currency: 'EUR' }).format('1234.5')` gives `1.234,50 €`), which reads a numeric string exactly. Calculate with a decimal library rather than `parseFloat`: the SDK exports `sumMoney`, `subtractMoney`, `multiplyMoney`, `compareMoney` and `isZeroMoney`, which work on the strings exactly. The [Store API](/api-reference/store-api/monetary-amounts) keeps `display_*` fields for storefronts, and webhook payloads and email templates carry them too.
+The Admin and Seller APIs return amounts only, with no `display_*` formatted copies: format them for the person reading them, in their own language. Format and calculate with the SDK's [money helpers](#money-helpers); without the SDK, pass the string to `Intl.NumberFormat`, which reads a numeric string exactly, and calculate with a decimal library rather than `parseFloat`. The [Store API](/api-reference/store-api/monetary-amounts) and webhook payloads still carry `display_*` fields, deprecated and removed in 6.1; email templates format amounts with the `money` filter.
+
+## Money helpers
+
+`@spree/admin-sdk` and `@spree/seller-sdk` export helpers that work on the decimal strings directly. None of them turns an amount into a JavaScript number, so a sum or a comparison is exact.
+
+```typescript
+import {
+ compareMoney, decimalPlaces, formatMoney, isDecimalString, isZeroMoney,
+ multiplyMoney, negateMoney, subtractMoney, sumMoney,
+} from '@spree/admin-sdk'
+```
+
+### Displaying
+
+| Helper | What it does | Example |
+| --- | --- | --- |
+| `formatMoney(amount, currency, locale?, { unitPrice? })` | Formats an amount in a currency and language, with the currency's own decimal places. Pass `{ unitPrice: true }` for a unit price, which keeps up to four decimals. A missing or malformed amount gives an empty string. | `formatMoney('1234.5', 'EUR', 'de')` → `"1.234,50 €"`<br/>`formatMoney('1000', 'JPY', 'en')` → `"¥1,000"`<br/>`formatMoney('0.0125', 'USD', 'en', { unitPrice: true })` → `"$0.0125"` |
+| `decimalPlaces(currency)` | The number of decimals a currency's amounts are written with, from ISO 4217. An unknown code gives `2`. | `decimalPlaces('USD')` → `2`<br/>`decimalPlaces('JPY')` → `0`<br/>`decimalPlaces('KWD')` → `3` |
+
+### Calculating
+
+Pass a currency to write the result with that currency's decimal places. Without one, the result keeps only the decimals it needs.
+
+| Helper | What it does | Example |
+| --- | --- | --- |
+| `sumMoney(amounts, currency?)` | Adds amounts. Blank values (`null`, `undefined`, `""`) count as zero. | `sumMoney(['19.99', '10.01'], 'USD')` → `"30.00"`<br/>`sumMoney(['19.99', '10.01'])` → `"30"`<br/>`sumMoney(['0.1', '0.2'])` → `"0.3"` |
+| `subtractMoney(a, b, currency?)` | `a` minus `b`. | `subtractMoney('100.00', '29.99', 'USD')` → `"70.01"` |
+| `multiplyMoney(amount, quantity, currency?)` | An amount times a whole quantity, such as a unit price times the units. A quantity that is not a whole number throws. | `multiplyMoney('19.99', 3, 'USD')` → `"59.97"` |
+| `negateMoney(amount)` | The amount with its sign flipped. | `negateMoney('5.00')` → `"-5.00"` |
+
+### Comparing and checking
+
+| Helper | What it does | Example |
+| --- | --- | --- |
+| `compareMoney(a, b)` | `1` when `a` is larger, `-1` when it is smaller, `0` when they are equal, whatever their decimal places. | `compareMoney('10.00', '9.99')` → `1`<br/>`compareMoney('10', '10.00')` → `0` |
+| `isZeroMoney(amount)` | Whether an amount is zero. Blank counts as zero. | `isZeroMoney('0.00')` → `true`<br/>`isZeroMoney(null)` → `true`<br/>`isZeroMoney('0.01')` → `false` |
+| `isDecimalString(value)` | Whether a value is a canonical decimal string. | `isDecimalString('19.99')` → `true`<br/>`isDecimalString('1,99')` → `false`<br/>`isDecimalString(19.99)` → `false` |
+
+The calculating and comparing helpers throw on a value that is not a canonical decimal string, such as `"1,99"` or `"1e3"`, rather than guess what it means. Check input you did not get from the API with `isDecimalString` first.
## Writing
diff --git a/docs/api-reference/admin.yaml b/docs/api-reference/admin.yaml
index 1877f4867a..3a7e7b4eb4 100644
--- a/docs/api-reference/admin.yaml
+++ b/docs/api-reference/admin.yaml
@@ -52639,41 +52639,57 @@ components:
item_total:
type: string
nullable: true
+ description: 'The line items: each price times its quantity, before discounts,
+ fees and delivery.'
discount_total:
type: string
nullable: true
+ description: What promotions take off, as a negative amount. Manual discounts
+ are not included.
tax_total:
type: string
nullable: true
+ description: All tax, both included in prices and added on top.
included_tax_total:
type: string
nullable: true
+ description: Tax already included in the prices, as in a store whose prices
+ are tax-inclusive.
additional_tax_total:
type: string
nullable: true
+ description: Tax added on top of the prices.
delivery_total:
type: string
nullable: true
+ description: What delivery costs, before delivery discounts.
fee_total:
type: string
nullable: true
+ description: Every fee charged, such as handling or a customs duty.
gift_card_total:
type: string
nullable: true
+ description: What a gift card pays.
store_credit_total:
type: string
nullable: true
+ description: What store credit pays, apart from gift cards.
total:
type: string
nullable: true
+ description: 'What the customer pays in all: items, delivery, fees and added
+ tax, less discounts.'
amount_due:
type: string
nullable: true
+ description: What is left to pay after payments and store credit.
covered_by_store_credit:
type: boolean
adjustment_total:
type: string
nullable: true
+ description: Every discount, fee and added tax together, as one amount.
current_step:
type: string
completed_steps:
@@ -57828,23 +57844,34 @@ components:
type: string
price:
type: string
+ description: The price of one unit.
total:
type: string
+ description: 'What this line costs: price times quantity, with its discounts,
+ fees and added tax.'
adjustment_total:
type: string
+ description: This line's discounts, fees and added tax together.
additional_tax_total:
type: string
+ description: Tax added on top of the price.
included_tax_total:
type: string
+ description: Tax already included in the price.
discount_total:
type: string
+ description: What promotions take off this line, as a negative amount.
pre_tax_amount:
type: string
+ description: This line after discounts, without tax.
discounted_amount:
type: string
+ description: Price times quantity, after discounts.
compare_at_amount:
type: string
nullable: true
+ description: The compare-at price times quantity, or null when the variant
+ has none.
thumbnail_url:
type: string
nullable: true
@@ -58881,36 +58908,51 @@ components:
item_total:
type: string
nullable: true
+ description: 'The line items: each price times its quantity, before discounts,
+ fees and delivery.'
discount_total:
type: string
nullable: true
+ description: What promotions take off, as a negative amount. Manual discounts
+ are not included.
tax_total:
type: string
nullable: true
+ description: All tax, both included in prices and added on top.
included_tax_total:
type: string
nullable: true
+ description: Tax already included in the prices, as in a store whose prices
+ are tax-inclusive.
additional_tax_total:
type: string
nullable: true
+ description: Tax added on top of the prices.
delivery_total:
type: string
nullable: true
+ description: What delivery costs, before delivery discounts.
fee_total:
type: string
nullable: true
+ description: Every fee charged, such as handling or a customs duty.
gift_card_total:
type: string
nullable: true
+ description: What a gift card pays.
store_credit_total:
type: string
nullable: true
+ description: What store credit pays, apart from gift cards.
total:
type: string
nullable: true
+ description: 'What the customer pays in all: items, delivery, fees and added
+ tax, less discounts.'
amount_due:
type: string
nullable: true
+ description: What is left to pay after payments and store credit.
covered_by_store_credit:
type: boolean
payments:
@@ -59299,26 +59341,41 @@ components:
nullable: true
item_total:
type: string
+ description: 'The line items: each price times its quantity, before discounts,
+ fees and delivery.'
discount_total:
type: string
+ description: What promotions take off, as a negative amount. Manual discounts
+ are not included.
tax_total:
type: string
+ description: All tax, both included in prices and added on top.
included_tax_total:
type: string
+ description: Tax already included in the prices, as in a store whose prices
+ are tax-inclusive.
additional_tax_total:
type: string
+ description: Tax added on top of the prices.
delivery_total:
type: string
+ description: What delivery costs, before delivery discounts.
fee_total:
type: string
+ description: Every fee charged, such as handling or a customs duty.
gift_card_total:
type: string
+ description: What a gift card pays.
store_credit_total:
type: string
+ description: What store credit pays, apart from gift cards.
total:
type: string
+ description: 'What the customer pays in all: items, delivery, fees and added
+ tax, less discounts.'
amount_due:
type: string
+ description: What is left to pay after payments and store credit.
covered_by_store_credit:
type: boolean
payments:
@@ -59327,6 +59384,7 @@ components:
"$ref": "#/components/schemas/Payment"
adjustment_total:
type: string
+ description: Every discount, fee and added tax together, as one amount.
items:
type: array
items:
diff --git a/docs/api-reference/store-api/monetary-amounts.mdx b/docs/api-reference/store-api/monetary-amounts.mdx
index bb43d7dbb3..a180bcad96 100644
--- a/docs/api-reference/store-api/monetary-amounts.mdx
+++ b/docs/api-reference/store-api/monetary-amounts.mdx
@@ -8,21 +8,24 @@ All monetary values in the Store API are returned as **decimal strings**, never
## Response Format
-Every monetary field has a corresponding `display_` field that includes currency formatting:
+Every monetary field is a decimal string, with its currency on the record or on the record it belongs to (an order's line items, payments and fulfillments are in the order's currency):
```json
{
+ "currency": "USD",
"total": "129.99",
- "display_total": "$129.99",
"item_total": "99.99",
- "display_item_total": "$99.99",
"delivery_total": "10.00",
- "display_delivery_total": "$10.00",
- "tax_total": "20.00",
- "display_tax_total": "$20.00"
+ "tax_total": "20.00"
}
```
+Format each amount for the customer reading it, in their language and in the currency the amount is in. An order or cart carries both (`currency`, `locale`); before checkout, use the current market's (`currency`, `default_locale`) or the price's own `currency`. See [Working with Amounts](#working-with-amounts) for examples.
+
+<Warning>
+**The `display_*` fields are deprecated and will be removed in Spree 6.1.** Each monetary field still has a pre-formatted copy (`display_total` beside `total`), formatted in the request's language. Format the amount beside it instead. The API reference marks these fields as deprecated, and the SDK types strike them through. Labels such as `display_name` are not affected.
+</Warning>
+
## Affected Types
This convention applies to all monetary fields across all resources:
@@ -41,20 +44,64 @@ Rates, such as a tax line's `rate`, are decimal strings too, without trailing ze
## Currency decimal places
-Each currency the store sells in (`GET /api/v3/store/currencies`) carries `decimal_places`, from ISO 4217: `2` for USD and EUR, `0` for JPY, `3` for KWD. Every amount in that currency is written with that many decimals.
+Each currency the store sells in (`GET /api/v3/store/currencies`) carries `decimal_places`, from ISO 4217: `2` for USD and EUR, `0` for JPY, `3` for KWD. Every amount in that currency is written with that many decimals. The SDK knows the same table, so `decimalPlaces(currency)` answers without a request.
+
+## Money helpers
+
+`@spree/sdk` exports helpers that work on the decimal strings directly. None of them turns an amount into a JavaScript number, so a sum or a comparison is exact.
+
+```typescript
+import {
+ compareMoney, decimalPlaces, formatMoney, isDecimalString, isZeroMoney,
+ multiplyMoney, negateMoney, subtractMoney, sumMoney,
+} from '@spree/sdk'
+```
+
+### Displaying
+
+| Helper | What it does | Example |
+| --- | --- | --- |
+| `formatMoney(amount, currency, locale?, { unitPrice? })` | Formats an amount in a currency and language, with the currency's own decimal places. Pass `{ unitPrice: true }` for a unit price, which keeps up to four decimals. A missing or malformed amount gives an empty string. | `formatMoney('1234.5', 'EUR', 'de')` → `"1.234,50 €"`<br/>`formatMoney('1000', 'JPY', 'en')` → `"¥1,000"`<br/>`formatMoney('0.0125', 'USD', 'en', { unitPrice: true })` → `"$0.0125"` |
+| `decimalPlaces(currency)` | The number of decimals a currency's amounts are written with, from ISO 4217. An unknown code gives `2`. | `decimalPlaces('USD')` → `2`<br/>`decimalPlaces('JPY')` → `0`<br/>`decimalPlaces('KWD')` → `3` |
+
+### Calculating
+
+Pass a currency to write the result with that currency's decimal places. Without one, the result keeps only the decimals it needs.
+
+| Helper | What it does | Example |
+| --- | --- | --- |
+| `sumMoney(amounts, currency?)` | Adds amounts. Blank values (`null`, `undefined`, `""`) count as zero. | `sumMoney(['19.99', '10.01'], 'USD')` → `"30.00"`<br/>`sumMoney(['19.99', '10.01'])` → `"30"`<br/>`sumMoney(['0.1', '0.2'])` → `"0.3"` |
+| `subtractMoney(a, b, currency?)` | `a` minus `b`. | `subtractMoney('100.00', '29.99', 'USD')` → `"70.01"` |
+| `multiplyMoney(amount, quantity, currency?)` | An amount times a whole quantity, such as a unit price times the units. A quantity that is not a whole number throws. | `multiplyMoney('19.99', 3, 'USD')` → `"59.97"` |
+| `negateMoney(amount)` | The amount with its sign flipped. | `negateMoney('5.00')` → `"-5.00"` |
+
+### Comparing and checking
+
+| Helper | What it does | Example |
+| --- | --- | --- |
+| `compareMoney(a, b)` | `1` when `a` is larger, `-1` when it is smaller, `0` when they are equal, whatever their decimal places. | `compareMoney('10.00', '9.99')` → `1`<br/>`compareMoney('10', '10.00')` → `0` |
+| `isZeroMoney(amount)` | Whether an amount is zero. Blank counts as zero. | `isZeroMoney('0.00')` → `true`<br/>`isZeroMoney(null)` → `true`<br/>`isZeroMoney('0.01')` → `false` |
+| `isDecimalString(value)` | Whether a value is a canonical decimal string. | `isDecimalString('19.99')` → `true`<br/>`isDecimalString('1,99')` → `false`<br/>`isDecimalString(19.99)` → `false` |
+
+The calculating and comparing helpers throw on a value that is not a canonical decimal string, such as `"1,99"` or `"1e3"`, rather than guess what it means. Check input you did not get from the API with `isDecimalString` first.
## Working with Amounts
+Format an amount with the SDK's [`formatMoney`](#money-helpers). It writes the currency's own decimal places (none for yen, three for dinar) and never turns the amount into a JavaScript number. Without the SDK, pass the decimal string straight to `Intl.NumberFormat`, which reads it exactly.
+
+### Order and cart totals
+
+An order carries its own `currency` and the `locale` the customer shopped in, so its receipt reads the same however the store changes later.
+
<CodeGroup>
```typescript SDK
-const order = await client.orders.get('or_abc123', {}, { token });
+import { compareMoney, formatMoney, sumMoney } from '@spree/sdk'
-import { compareMoney, sumMoney } from '@spree/sdk'
+const order = await client.orders.get('or_abc123', {}, { token });
-// Raw string values
-order.total; // "129.99"
-order.display_total; // "$129.99"
+formatMoney(order.total, order.currency, order.locale); // "€129.99" for an order in euros, read in English; "" when null
+formatMoney(order.delivery_total, order.currency, order.locale); // "€10.00"
// Calculate on the strings, exactly
const subtotal = sumMoney(order.items.map((item) => item.total), order.currency); // "129.99"
@@ -62,10 +109,11 @@ const isFree = compareMoney(order.total, '0') === 0;
```
```javascript JavaScript
-const data = await response.json();
+const order = await response.json();
-// Use display fields for rendering
-element.textContent = data.display_total; // "$129.99"
+const money = new Intl.NumberFormat(order.locale ?? 'en', { style: 'currency', currency: order.currency });
+// An amount is null when prices are hidden from the shopper; Intl would show it as zero
+element.textContent = order.total === null ? '' : money.format(order.total); // "€129.99"
// Calculate on the raw strings with a decimal library, never parseFloat:
// 0.1 + 0.2 is 0.30000000000000004 as a JSON number.
@@ -73,6 +121,37 @@ element.textContent = data.display_total; // "$129.99"
</CodeGroup>
+### Product prices
+
+Before there is a cart, prices are in the customer's market. Resolve the market once and format every price with it; each price also carries its own `currency`.
+
+<CodeGroup>
+
+```typescript SDK
+import { formatMoney } from '@spree/sdk'
+
+const market = await client.markets.resolve('DE');
+const product = await client.products.get('spree-tote', {}, { currency: market.currency, locale: market.default_locale });
+
+// A price is a unit price, which may carry a fraction of a cent
+formatMoney(product.price.amount, market.currency, market.default_locale, { unitPrice: true }); // "29,99 €"
+formatMoney(product.price.compare_at_amount, market.currency, market.default_locale, { unitPrice: true }); // "39,99 €", or "" when there is none
+```
+
+```javascript JavaScript
+const headers = { 'X-Spree-API-Key': 'pk_xxx' };
+const market = await (await fetch('/api/v3/store/markets/resolve?country=DE', { headers })).json();
+const product = await (await fetch('/api/v3/store/products/spree-tote', {
+ headers: { ...headers, 'X-Spree-Currency': market.currency, 'X-Spree-Locale': market.default_locale },
+})).json();
+
+// A unit price may carry a fraction of a cent, so allow up to four decimals
+const money = new Intl.NumberFormat(market.default_locale, { style: 'currency', currency: market.currency, maximumFractionDigits: 4 });
+element.textContent = product.price.amount === null ? '' : money.format(product.price.amount); // "29,99 €"
+```
+
+</CodeGroup>
+
<Tip>
-Use `display_*` fields for rendering prices in the UI — they are pre-formatted with the correct currency symbol and decimal places based on the order's currency. Calculate on the raw strings with the SDK's `sumMoney`, `subtractMoney`, `multiplyMoney` and `compareMoney`, which work on decimal strings exactly.
+Never convert an amount to a JavaScript number: `0.1 + 0.2` is `0.30000000000000004`. Calculate and display with the [money helpers](#money-helpers) instead.
</Tip>
diff --git a/docs/api-reference/store.yaml b/docs/api-reference/store.yaml
index a5b496849a..dc7d6ff780 100644
--- a/docs/api-reference/store.yaml
+++ b/docs/api-reference/store.yaml
@@ -13821,6 +13821,9 @@ components:
display_amount:
type: string
nullable: true
+ description: "`amount` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
required:
- id
- promotion_id
@@ -14076,69 +14079,117 @@ components:
item_total:
type: string
nullable: true
+ description: 'The line items: each price times its quantity, before discounts,
+ fees and delivery.'
display_item_total:
type: string
nullable: true
+ description: "`item_total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
discount_total:
type: string
nullable: true
+ description: What promotions take off, as a negative amount. Manual discounts
+ are not included.
display_discount_total:
type: string
nullable: true
+ description: "`discount_total` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
tax_total:
type: string
nullable: true
+ description: All tax, both included in prices and added on top.
display_tax_total:
type: string
nullable: true
+ description: "`tax_total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
included_tax_total:
type: string
nullable: true
+ description: Tax already included in the prices, as in a store whose prices
+ are tax-inclusive.
display_included_tax_total:
type: string
nullable: true
+ description: "`included_tax_total` formatted with its currency symbol in
+ the request's language."
+ deprecated: true
additional_tax_total:
type: string
nullable: true
+ description: Tax added on top of the prices.
display_additional_tax_total:
type: string
nullable: true
+ description: "`additional_tax_total` formatted with its currency symbol
+ in the request's language."
+ deprecated: true
delivery_total:
type: string
nullable: true
+ description: What delivery costs, before delivery discounts.
display_delivery_total:
type: string
nullable: true
+ description: "`delivery_total` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
fee_total:
type: string
nullable: true
+ description: Every fee charged, such as handling or a customs duty.
display_fee_total:
type: string
nullable: true
+ description: "`fee_total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
gift_card_total:
type: string
nullable: true
+ description: What a gift card pays.
display_gift_card_total:
type: string
nullable: true
+ description: "`gift_card_total` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
store_credit_total:
type: string
nullable: true
+ description: What store credit pays, apart from gift cards.
display_store_credit_total:
type: string
nullable: true
+ description: "`store_credit_total` formatted with its currency symbol in
+ the request's language."
+ deprecated: true
total:
type: string
nullable: true
+ description: 'What the customer pays in all: items, delivery, fees and added
+ tax, less discounts.'
display_total:
type: string
nullable: true
+ description: "`total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
amount_due:
type: string
nullable: true
+ description: What is left to pay after payments and store credit.
display_amount_due:
type: string
nullable: true
+ description: "`amount_due` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
covered_by_store_credit:
type: boolean
payments:
@@ -14148,9 +14199,13 @@ components:
adjustment_total:
type: string
nullable: true
+ description: Every discount, fee and added tax together, as one amount.
display_adjustment_total:
type: string
nullable: true
+ description: "`adjustment_total` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
current_step:
type: string
completed_steps:
@@ -14411,6 +14466,9 @@ components:
display_refund_amount:
type: string
nullable: true
+ description: "`refund_amount` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
variant_id:
type: string
nullable: true
@@ -14486,6 +14544,9 @@ components:
display_refund_total:
type: string
nullable: true
+ description: "`refund_total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
approved_at:
type: string
nullable: true
@@ -15204,6 +15265,9 @@ components:
type: string
display_available_store_credit_total:
type: string
+ description: "`available_store_credit_total` formatted with its currency
+ symbol in the request's language."
+ deprecated: true
addresses:
type: array
items:
@@ -15399,18 +15463,33 @@ components:
display_cost:
type: string
nullable: true
+ description: "`cost` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
display_total:
type: string
nullable: true
+ description: "`total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
display_additional_tax_total:
type: string
nullable: true
+ description: "`additional_tax_total` formatted with its currency symbol
+ in the request's language."
+ deprecated: true
display_included_tax_total:
type: string
nullable: true
+ description: "`included_tax_total` formatted with its currency symbol in
+ the request's language."
+ deprecated: true
display_tax_total:
type: string
nullable: true
+ description: "`tax_total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
delivery_method:
"$ref": "#/components/schemas/DeliveryMethod"
required:
@@ -15875,6 +15954,9 @@ components:
display_amount:
type: string
nullable: true
+ description: "`amount` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
required:
- id
- label
@@ -15976,6 +16058,9 @@ components:
display_price_difference:
type: string
nullable: true
+ description: "`price_difference` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
approved_at:
type: string
nullable: true
@@ -16070,6 +16155,9 @@ components:
display_amount:
type: string
nullable: true
+ description: "`amount` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
required:
- id
- label
@@ -16175,36 +16263,54 @@ components:
display_cost:
type: string
nullable: true
+ description: "`cost` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
total:
type: string
nullable: true
display_total:
type: string
nullable: true
+ description: "`total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
discount_total:
type: string
nullable: true
display_discount_total:
type: string
nullable: true
+ description: "`discount_total` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
additional_tax_total:
type: string
nullable: true
display_additional_tax_total:
type: string
nullable: true
+ description: "`additional_tax_total` formatted with its currency symbol
+ in the request's language."
+ deprecated: true
included_tax_total:
type: string
nullable: true
display_included_tax_total:
type: string
nullable: true
+ description: "`included_tax_total` formatted with its currency symbol in
+ the request's language."
+ deprecated: true
tax_total:
type: string
nullable: true
display_tax_total:
type: string
nullable: true
+ description: "`tax_total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
status:
anyOf:
- type: string
@@ -16710,12 +16816,21 @@ components:
display_amount:
type: string
nullable: true
+ description: "`amount` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
display_amount_used:
type: string
nullable: true
+ description: "`amount_used` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
display_amount_remaining:
type: string
nullable: true
+ description: "`amount_remaining` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
expires_at:
type: string
nullable: true
@@ -17110,57 +17225,95 @@ components:
price:
type: string
nullable: true
+ description: The price of one unit.
display_price:
type: string
nullable: true
+ description: "`price` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
total:
type: string
nullable: true
+ description: 'What this line costs: price times quantity, with its discounts,
+ fees and added tax.'
display_total:
type: string
nullable: true
+ description: "`total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
adjustment_total:
type: string
nullable: true
+ description: This line's discounts, fees and added tax together.
display_adjustment_total:
type: string
nullable: true
+ description: "`adjustment_total` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
additional_tax_total:
type: string
nullable: true
+ description: Tax added on top of the price.
display_additional_tax_total:
type: string
nullable: true
+ description: "`additional_tax_total` formatted with its currency symbol
+ in the request's language."
+ deprecated: true
included_tax_total:
type: string
nullable: true
+ description: Tax already included in the price.
display_included_tax_total:
type: string
nullable: true
+ description: "`included_tax_total` formatted with its currency symbol in
+ the request's language."
+ deprecated: true
discount_total:
type: string
nullable: true
+ description: What promotions take off this line, as a negative amount.
display_discount_total:
type: string
nullable: true
+ description: "`discount_total` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
pre_tax_amount:
type: string
nullable: true
+ description: This line after discounts, without tax.
display_pre_tax_amount:
type: string
nullable: true
+ description: "`pre_tax_amount` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
discounted_amount:
type: string
nullable: true
+ description: Price times quantity, after discounts.
display_discounted_amount:
type: string
nullable: true
+ description: "`discounted_amount` formatted with its currency symbol in
+ the request's language."
+ deprecated: true
display_compare_at_amount:
type: string
nullable: true
+ description: "`compare_at_amount` formatted with its currency symbol in
+ the request's language."
+ deprecated: true
compare_at_amount:
type: string
nullable: true
+ description: The compare-at price times quantity, or null when the variant
+ has none.
thumbnail_url:
type: string
nullable: true
@@ -18118,69 +18271,117 @@ components:
item_total:
type: string
nullable: true
+ description: 'The line items: each price times its quantity, before discounts,
+ fees and delivery.'
display_item_total:
type: string
nullable: true
+ description: "`item_total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
discount_total:
type: string
nullable: true
+ description: What promotions take off, as a negative amount. Manual discounts
+ are not included.
display_discount_total:
type: string
nullable: true
+ description: "`discount_total` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
tax_total:
type: string
nullable: true
+ description: All tax, both included in prices and added on top.
display_tax_total:
type: string
nullable: true
+ description: "`tax_total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
included_tax_total:
type: string
nullable: true
+ description: Tax already included in the prices, as in a store whose prices
+ are tax-inclusive.
display_included_tax_total:
type: string
nullable: true
+ description: "`included_tax_total` formatted with its currency symbol in
+ the request's language."
+ deprecated: true
additional_tax_total:
type: string
nullable: true
+ description: Tax added on top of the prices.
display_additional_tax_total:
type: string
nullable: true
+ description: "`additional_tax_total` formatted with its currency symbol
+ in the request's language."
+ deprecated: true
delivery_total:
type: string
nullable: true
+ description: What delivery costs, before delivery discounts.
display_delivery_total:
type: string
nullable: true
+ description: "`delivery_total` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
fee_total:
type: string
nullable: true
+ description: Every fee charged, such as handling or a customs duty.
display_fee_total:
type: string
nullable: true
+ description: "`fee_total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
gift_card_total:
type: string
nullable: true
+ description: What a gift card pays.
display_gift_card_total:
type: string
nullable: true
+ description: "`gift_card_total` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
store_credit_total:
type: string
nullable: true
+ description: What store credit pays, apart from gift cards.
display_store_credit_total:
type: string
nullable: true
+ description: "`store_credit_total` formatted with its currency symbol in
+ the request's language."
+ deprecated: true
total:
type: string
nullable: true
+ description: 'What the customer pays in all: items, delivery, fees and added
+ tax, less discounts.'
display_total:
type: string
nullable: true
+ description: "`total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
amount_due:
type: string
nullable: true
+ description: What is left to pay after payments and store credit.
display_amount_due:
type: string
nullable: true
+ description: "`amount_due` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
covered_by_store_credit:
type: boolean
payments:
@@ -18524,69 +18725,117 @@ components:
item_total:
type: string
nullable: true
+ description: 'The line items: each price times its quantity, before discounts,
+ fees and delivery.'
display_item_total:
type: string
nullable: true
+ description: "`item_total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
discount_total:
type: string
nullable: true
+ description: What promotions take off, as a negative amount. Manual discounts
+ are not included.
display_discount_total:
type: string
nullable: true
+ description: "`discount_total` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
tax_total:
type: string
nullable: true
+ description: All tax, both included in prices and added on top.
display_tax_total:
type: string
nullable: true
+ description: "`tax_total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
included_tax_total:
type: string
nullable: true
+ description: Tax already included in the prices, as in a store whose prices
+ are tax-inclusive.
display_included_tax_total:
type: string
nullable: true
+ description: "`included_tax_total` formatted with its currency symbol in
+ the request's language."
+ deprecated: true
additional_tax_total:
type: string
nullable: true
+ description: Tax added on top of the prices.
display_additional_tax_total:
type: string
nullable: true
+ description: "`additional_tax_total` formatted with its currency symbol
+ in the request's language."
+ deprecated: true
delivery_total:
type: string
nullable: true
+ description: What delivery costs, before delivery discounts.
display_delivery_total:
type: string
nullable: true
+ description: "`delivery_total` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
fee_total:
type: string
nullable: true
+ description: Every fee charged, such as handling or a customs duty.
display_fee_total:
type: string
nullable: true
+ description: "`fee_total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
gift_card_total:
type: string
nullable: true
+ description: What a gift card pays.
display_gift_card_total:
type: string
nullable: true
+ description: "`gift_card_total` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
store_credit_total:
type: string
nullable: true
+ description: What store credit pays, apart from gift cards.
display_store_credit_total:
type: string
nullable: true
+ description: "`store_credit_total` formatted with its currency symbol in
+ the request's language."
+ deprecated: true
total:
type: string
nullable: true
+ description: 'What the customer pays in all: items, delivery, fees and added
+ tax, less discounts.'
display_total:
type: string
nullable: true
+ description: "`total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
amount_due:
type: string
nullable: true
+ description: What is left to pay after payments and store credit.
display_amount_due:
type: string
nullable: true
+ description: "`amount_due` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
covered_by_store_credit:
type: boolean
payments:
@@ -18596,9 +18845,13 @@ components:
adjustment_total:
type: string
nullable: true
+ description: Every discount, fee and added tax together, as one amount.
display_adjustment_total:
type: string
nullable: true
+ description: "`adjustment_total` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
discounts:
type: array
items:
@@ -18767,6 +19020,9 @@ components:
display_amount:
type: string
nullable: true
+ description: "`amount` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
source_type:
type: string
nullable: true
@@ -19316,6 +19572,9 @@ components:
nullable: true
display_amount:
type: string
+ description: "`amount` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
recorded_at:
type: string
required:
@@ -19521,9 +19780,15 @@ components:
display_amount:
type: string
nullable: true
+ description: "`amount` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
display_compare_at_amount:
type: string
nullable: true
+ description: "`compare_at_amount` formatted with its currency symbol in
+ the request's language."
+ deprecated: true
price_list_id:
type: string
nullable: true
@@ -20201,6 +20466,9 @@ components:
display_pre_tax_amount:
type: string
nullable: true
+ description: "`pre_tax_amount` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
included_tax_total:
type: string
nullable: true
@@ -20213,12 +20481,18 @@ components:
display_tax_total:
type: string
nullable: true
+ description: "`tax_total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
refund_amount:
type: string
nullable: true
display_refund_amount:
type: string
nullable: true
+ description: "`refund_amount` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
variant_id:
type: string
nullable: true
@@ -20292,12 +20566,18 @@ components:
display_refund_total:
type: string
nullable: true
+ description: "`refund_total` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
refund_tax_total:
type: string
nullable: true
display_refund_tax_total:
type: string
nullable: true
+ description: "`refund_tax_total` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
approved_at:
type: string
nullable: true
@@ -20903,6 +21183,9 @@ components:
display_amount:
type: string
nullable: true
+ description: "`amount` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
created_at:
type: string
required:
@@ -20931,12 +21214,21 @@ components:
display_amount:
type: string
nullable: true
+ description: "`amount` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
display_amount_used:
type: string
nullable: true
+ description: "`amount_used` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
display_amount_remaining:
type: string
nullable: true
+ description: "`amount_remaining` formatted with its currency symbol in the
+ request's language."
+ deprecated: true
currency:
type: string
enum:
@@ -21202,6 +21494,9 @@ components:
display_amount:
type: string
nullable: true
+ description: "`amount` formatted with its currency symbol in the request's
+ language."
+ deprecated: true
required:
- id
- label
diff --git a/docs/developer/upgrades/5.6-to-6.0.mdx b/docs/developer/upgrades/5.6-to-6.0.mdx
index ae3c375189..f94f2663ed 100644
--- a/docs/developer/upgrades/5.6-to-6.0.mdx
+++ b/docs/developer/upgrades/5.6-to-6.0.mdx
@@ -912,7 +912,7 @@ Other changes that come with it:
- **Money on the API is written to each currency's decimals.** Every amount in the Store, Admin and Seller APIs, and so in webhook payloads and email variables, is a decimal string with exactly its currency's decimal places: `"10.00"` (was `"10.0"`), `"1000"` in yen (was `"1000.0"`), `"1.500"` in dinar. Unit prices keep up to four decimals. Fields that were JSON numbers are now strings: `cart.order_minimum` and `order_minimum_shortfall`, the product filter price range `min`/`max`, report money metrics and percentages, and the store's `default_minimum_payout_amount` and `default_commission_tax_rate`. Clients comparing these strings, or parsing them as numbers, should switch to exact decimal arithmetic; the SDKs export `sumMoney`, `subtractMoney`, `multiplyMoney`, `compareMoney` and `isZeroMoney`.
- **Admin and Seller writes refuse JSON numbers for money.** Amounts and rates, including those inside `preferences`, must be canonical decimal strings (`"19.99"`). A number, a localized or grouped string, or more decimals than the field holds is answered with `422` and `invalid_money_format`, naming the field.
- **Amounts may not carry more decimals than they can keep.** Now that the columns hold four decimals, the database no longer rounds away a fraction of a cent, so a payment, refund, store credit, gift card, fee or discount with more decimals than its currency has (`10.0049` dollars) fails validation with `too_many_decimals`. Unit prices and cost prices allow four, tax rates five decimals of the fraction (`rate_percent` `"7.125"`, not `"7.1255"`), and price list percentages three. Round in your own code before saving. A manual order discount's `value` and a commission rate's `value` are read as strictly as other money fields.
-- **The Admin and Seller APIs no longer return `display_*` money fields.** Responses carry the amount (`"29.99"`) with its currency, and the client formats it in the reader's own language. Before 6.0 the server formatted a copy in the request's language, which could disagree with the editable amount beside it. Format with `Intl.NumberFormat` or your platform's equivalent. The Store API and webhook payloads keep their `display_*` fields, and labels such as `display_name` are unchanged.
+- **The Admin and Seller APIs no longer return `display_*` money fields.** Responses carry the amount (`"29.99"`) with its currency, and the client formats it in the reader's own language. Before 6.0 the server formatted a copy in the request's language, which could disagree with the editable amount beside it. Format with `Intl.NumberFormat` or your platform's equivalent. The Store API and webhook payloads keep their `display_*` money fields until 6.1, marked deprecated in the API reference and the SDK types; format the amount beside each one instead (`total` for `display_total`). Labels such as `display_name` are unchanged.
- **Money preferences have their own type.** Calculator, rule and store preferences holding an amount (`amount`, `first_item`, `minimal_amount`, `amount_min`, `min_amount`, `default_minimum_payout_amount` and the like) are declared `:money` instead of `:decimal`, report `money` in `preference_schema`, and are written with the decimals of the calculator's currency (`"12.50"` rather than `"12.5"`). Declare your own extensions' amounts with `:money` so the dashboard shows their currency. A `:decimal` or `:money` preference now refuses text such as `"1,599.99"` instead of reading it as 1. Money preferences are checked by their type on write: a value that is not a decimal string, or has more decimals than its currency, is refused with `invalid_preferences` and a pointer to the field (`/calculator/preferences/amount`), rather than `invalid_money_format`.
- **Rates are decimal strings, and tax rates are renamed.** Rates and percentages read and write as strings without trailing zeros. A tax rate's `amount` (a fraction) is now `rate`, and `amount_percentage` is `rate_percent`; `Spree::TaxRate#amount_percentage` keeps working with a warning until 6.1.
- **`amount_in_cents` and `compare_at_amount_in_cents` are removed** from prices and price history. Read `amount`, and each currency's `decimal_places` (new on `GET /api/v3/store/currencies`) if you need minor units.
diff --git a/packages/admin-sdk/src/index.ts b/packages/admin-sdk/src/index.ts
index c790bc2a28..4968668245 100644
--- a/packages/admin-sdk/src/index.ts
+++ b/packages/admin-sdk/src/index.ts
@@ -13,6 +13,7 @@ export type {
export {
compareMoney,
decimalPlaces,
+ formatMoney,
isDecimalString,
isZeroMoney,
multiplyMoney,
diff --git a/packages/admin-sdk/src/types/generated/Cart.ts b/packages/admin-sdk/src/types/generated/Cart.ts
index d14e2e3baf..c23697e214 100644
--- a/packages/admin-sdk/src/types/generated/Cart.ts
+++ b/packages/admin-sdk/src/types/generated/Cart.ts
@@ -1,4 +1,4 @@
-// Typelizer digest f2ee3f8658c4b99835c5e58bcf4a3ae0
+// Typelizer digest 4deba7885d7549b2d8f1f505d4ced15c
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {FreightSummary, LineItem, Address, Market, AppliedPromotion, CurrencyCode} from '@/types'
@@ -22,18 +22,30 @@ interface Cart {
total_quantity: number;
warnings: Array<{code: string, message: string, line_item_id?: string, variant_id?: string, item_index?: number}>;
coupon_code: string | null;
+ /** The line items: each price times its quantity, before discounts, fees and delivery. */
item_total: string | null;
+ /** What promotions take off, as a negative amount. Manual discounts are not included. */
discount_total: string | null;
+ /** All tax, both included in prices and added on top. */
tax_total: string | null;
+ /** Tax already included in the prices, as in a store whose prices are tax-inclusive. */
included_tax_total: string | null;
+ /** Tax added on top of the prices. */
additional_tax_total: string | null;
+ /** What delivery costs, before delivery discounts. */
delivery_total: string | null;
+ /** Every fee charged, such as handling or a customs duty. */
fee_total: string | null;
+ /** What a gift card pays. */
gift_card_total: string | null;
+ /** What store credit pays, apart from gift cards. */
store_credit_total: string | null;
+ /** What the customer pays in all: items, delivery, fees and added tax, less discounts. */
total: string | null;
+ /** What is left to pay after payments and store credit. */
amount_due: string | null;
covered_by_store_credit: boolean;
+ /** Every discount, fee and added tax together, as one amount. */
adjustment_total: string | null;
current_step: string;
completed_steps: Array<string>;
diff --git a/packages/admin-sdk/src/types/generated/LineItem.ts b/packages/admin-sdk/src/types/generated/LineItem.ts
index 8273a1a461..61c93eba88 100644
--- a/packages/admin-sdk/src/types/generated/LineItem.ts
+++ b/packages/admin-sdk/src/types/generated/LineItem.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 39fd90f012cce17b02063c674dcbe4fc
+// Typelizer digest 6e665e645658d7f90c5396732af1c8b3
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Seller, OptionValue, DigitalLink, TaxLine, Variant, TaxCategory, CurrencyCode} from '@/types'
@@ -14,14 +14,23 @@ interface LineItem {
name: string;
slug: string;
options_text: string;
+ /** The price of one unit. */
price: string;
+ /** What this line costs: price times quantity, with its discounts, fees and added tax. */
total: string;
+ /** This line's discounts, fees and added tax together. */
adjustment_total: string;
+ /** Tax added on top of the price. */
additional_tax_total: string;
+ /** Tax already included in the price. */
included_tax_total: string;
+ /** What promotions take off this line, as a negative amount. */
discount_total: string;
+ /** This line after discounts, without tax. */
pre_tax_amount: string;
+ /** Price times quantity, after discounts. */
discounted_amount: string;
+ /** The compare-at price times quantity, or null when the variant has none. */
compare_at_amount: string | null;
thumbnail_url: string | null;
seller?: Seller;
diff --git a/packages/admin-sdk/src/types/generated/Order.ts b/packages/admin-sdk/src/types/generated/Order.ts
index 512047517b..404231ed59 100644
--- a/packages/admin-sdk/src/types/generated/Order.ts
+++ b/packages/admin-sdk/src/types/generated/Order.ts
@@ -1,4 +1,4 @@
-// Typelizer digest a832c07d5def234561478a7a2f1880aa
+// Typelizer digest 2387609bdf23f7610c38d10587e00c0d
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {FreightSummary, Payment, LineItem, Fulfillment, Address, GiftCard, Market, Seller, Actor, AppliedPromotion, PaymentSplit, Cart, Channel, StockLocation, PaymentMethod, Customer, OrderCancellationReason, Return, Exchange, Claim, CurrencyCode, ActorKind} from '@/types'
@@ -25,19 +25,31 @@ interface Order {
fulfillment_status: 'backorder' | 'canceled' | 'partial' | 'unfulfilled' | 'fulfilled' | 'delivered' | 'pending' | 'ready' | 'shipped' | null;
payment_status: 'none' | 'authorized' | 'partially_paid' | 'paid' | 'partially_refunded' | 'refunded' | 'overcharged' | 'voided' | null;
completed_at: string | null;
+ /** The line items: each price times its quantity, before discounts, fees and delivery. */
item_total: string;
+ /** What promotions take off, as a negative amount. Manual discounts are not included. */
discount_total: string;
+ /** All tax, both included in prices and added on top. */
tax_total: string;
+ /** Tax already included in the prices, as in a store whose prices are tax-inclusive. */
included_tax_total: string;
+ /** Tax added on top of the prices. */
additional_tax_total: string;
+ /** What delivery costs, before delivery discounts. */
delivery_total: string;
+ /** Every fee charged, such as handling or a customs duty. */
fee_total: string;
+ /** What a gift card pays. */
gift_card_total: string;
+ /** What store credit pays, apart from gift cards. */
store_credit_total: string;
+ /** What the customer pays in all: items, delivery, fees and added tax, less discounts. */
total: string;
+ /** What is left to pay after payments and store credit. */
amount_due: string;
covered_by_store_credit: boolean;
payments?: Array<Payment>;
+ /** Every discount, fee and added tax together, as one amount. */
adjustment_total: string;
items?: Array<LineItem>;
fulfillments?: Array<Fulfillment>;
diff --git a/packages/admin-sdk/src/types/generated/OrderGroup.ts b/packages/admin-sdk/src/types/generated/OrderGroup.ts
index 665348e044..6b98e8c934 100644
--- a/packages/admin-sdk/src/types/generated/OrderGroup.ts
+++ b/packages/admin-sdk/src/types/generated/OrderGroup.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 3414cbff12fc8b677003fddff72727a5
+// Typelizer digest b0b39f2ce721f4a87d3d110b0b579ff7
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Payment, Address, Order, CurrencyCode} from '@/types'
@@ -8,16 +8,27 @@ interface OrderGroup {
number: string;
email: string | null;
currency: CurrencyCode;
+ /** The line items: each price times its quantity, before discounts, fees and delivery. */
item_total: string | null;
+ /** What promotions take off, as a negative amount. Manual discounts are not included. */
discount_total: string | null;
+ /** All tax, both included in prices and added on top. */
tax_total: string | null;
+ /** Tax already included in the prices, as in a store whose prices are tax-inclusive. */
included_tax_total: string | null;
+ /** Tax added on top of the prices. */
additional_tax_total: string | null;
+ /** What delivery costs, before delivery discounts. */
delivery_total: string | null;
+ /** Every fee charged, such as handling or a customs duty. */
fee_total: string | null;
+ /** What a gift card pays. */
gift_card_total: string | null;
+ /** What store credit pays, apart from gift cards. */
store_credit_total: string | null;
+ /** What the customer pays in all: items, delivery, fees and added tax, less discounts. */
total: string | null;
+ /** What is left to pay after payments and store credit. */
amount_due: string | null;
covered_by_store_credit: boolean;
payments: Array<Payment>;
diff --git a/packages/admin-sdk/src/types/generated/emails/EmailLineItem.ts b/packages/admin-sdk/src/types/generated/emails/EmailLineItem.ts
index 00635a356e..8ba707b743 100644
--- a/packages/admin-sdk/src/types/generated/emails/EmailLineItem.ts
+++ b/packages/admin-sdk/src/types/generated/emails/EmailLineItem.ts
@@ -1,4 +1,4 @@
-// Typelizer digest b7be38df7dcedd69294d779533aa4d0f
+// Typelizer digest bf4ff356c0d6b8554dfef53605f3542e
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {EmailOptionValue, CurrencyCode} from '.'
@@ -14,14 +14,23 @@ interface EmailLineItem {
name: string;
slug: string;
options_text: string;
+ /** The price of one unit. */
price: string | null;
+ /** What this line costs: price times quantity, with its discounts, fees and added tax. */
total: string | null;
+ /** This line's discounts, fees and added tax together. */
adjustment_total: string | null;
+ /** Tax added on top of the price. */
additional_tax_total: string | null;
+ /** Tax already included in the price. */
included_tax_total: string | null;
+ /** What promotions take off this line, as a negative amount. */
discount_total: string | null;
+ /** This line after discounts, without tax. */
pre_tax_amount: string | null;
+ /** Price times quantity, after discounts. */
discounted_amount: string | null;
+ /** The compare-at price times quantity, or null when the variant has none. */
compare_at_amount: string | null;
option_values: Array<EmailOptionValue>;
url: string | null;
diff --git a/packages/admin-sdk/src/types/generated/emails/EmailOrder.ts b/packages/admin-sdk/src/types/generated/emails/EmailOrder.ts
index 108d13e947..55119ef800 100644
--- a/packages/admin-sdk/src/types/generated/emails/EmailOrder.ts
+++ b/packages/admin-sdk/src/types/generated/emails/EmailOrder.ts
@@ -1,4 +1,4 @@
-// Typelizer digest c0cc8d5f705c4953cc3ebbb22c173998
+// Typelizer digest f0337bcb7d0ecd69798be9baef6ab90c
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {EmailPayment, EmailAppliedPromotion, EmailFee, EmailLineItem, EmailFulfillment, EmailAddress, EmailGiftCard, EmailMarket, EmailAmountLine, CurrencyCode} from '.'
@@ -25,19 +25,31 @@ interface EmailOrder {
fulfillment_status: 'backorder' | 'canceled' | 'partial' | 'unfulfilled' | 'fulfilled' | 'delivered' | 'pending' | 'ready' | 'shipped' | null;
payment_status: 'none' | 'authorized' | 'partially_paid' | 'paid' | 'partially_refunded' | 'refunded' | 'overcharged' | 'voided' | null;
completed_at: string | null;
+ /** The line items: each price times its quantity, before discounts, fees and delivery. */
item_total: string | null;
+ /** What promotions take off, as a negative amount. Manual discounts are not included. */
discount_total: string | null;
+ /** All tax, both included in prices and added on top. */
tax_total: string | null;
+ /** Tax already included in the prices, as in a store whose prices are tax-inclusive. */
included_tax_total: string | null;
+ /** Tax added on top of the prices. */
additional_tax_total: string | null;
+ /** What delivery costs, before delivery discounts. */
delivery_total: string | null;
+ /** Every fee charged, such as handling or a customs duty. */
fee_total: string | null;
+ /** What a gift card pays. */
gift_card_total: string | null;
+ /** What store credit pays, apart from gift cards. */
store_credit_total: string | null;
+ /** What the customer pays in all: items, delivery, fees and added tax, less discounts. */
total: string | null;
+ /** What is left to pay after payments and store credit. */
amount_due: string | null;
covered_by_store_credit: boolean;
payments: Array<EmailPayment>;
+ /** Every discount, fee and added tax together, as one amount. */
adjustment_total: string | null;
discounts: Array<EmailAppliedPromotion>;
fees: Array<EmailFee>;
diff --git a/packages/admin-sdk/src/types/generated/emails/EmailOrderGroup.ts b/packages/admin-sdk/src/types/generated/emails/EmailOrderGroup.ts
index 98fb9da91f..cc5ff55069 100644
--- a/packages/admin-sdk/src/types/generated/emails/EmailOrderGroup.ts
+++ b/packages/admin-sdk/src/types/generated/emails/EmailOrderGroup.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 458576791161ac4a1dbc9eaf2c5d3fbf
+// Typelizer digest 648672c5ce1f526b326a3ced9f0a7782
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {EmailPayment, EmailAddress, EmailLineItem, EmailAmountLine, EmailFulfillmentGroup, CurrencyCode} from '.'
@@ -8,16 +8,27 @@ interface EmailOrderGroup {
number: string;
email: string | null;
currency: CurrencyCode;
+ /** The line items: each price times its quantity, before discounts, fees and delivery. */
item_total: string | null;
+ /** What promotions take off, as a negative amount. Manual discounts are not included. */
discount_total: string | null;
+ /** All tax, both included in prices and added on top. */
tax_total: string | null;
+ /** Tax already included in the prices, as in a store whose prices are tax-inclusive. */
included_tax_total: string | null;
+ /** Tax added on top of the prices. */
additional_tax_total: string | null;
+ /** What delivery costs, before delivery discounts. */
delivery_total: string | null;
+ /** Every fee charged, such as handling or a customs duty. */
fee_total: string | null;
+ /** What a gift card pays. */
gift_card_total: string | null;
+ /** What store credit pays, apart from gift cards. */
store_credit_total: string | null;
+ /** What the customer pays in all: items, delivery, fees and added tax, less discounts. */
total: string | null;
+ /** What is left to pay after payments and store credit. */
amount_due: string | null;
covered_by_store_credit: boolean;
payments: Array<EmailPayment>;
diff --git a/packages/admin-sdk/tests/money.test.ts b/packages/admin-sdk/tests/money.test.ts
index 6158cd9b8a..c6ed2084a8 100644
--- a/packages/admin-sdk/tests/money.test.ts
+++ b/packages/admin-sdk/tests/money.test.ts
@@ -5,6 +5,7 @@ import { CURRENCY_EXPONENTS } from '../../sdk-core/src/currency-exponents'
import {
compareMoney,
decimalPlaces,
+ formatMoney,
isDecimalString,
isZeroMoney,
multiplyMoney,
@@ -67,4 +68,14 @@ describe('money helpers', () => {
]).toEqual([true, false, false, false])
expect(() => sumMoney(['1,99'])).toThrow()
})
+
+ it('formats an amount in its currency and the reader’s language', () => {
+ expect(formatMoney('1234.5', 'USD', 'en')).toBe('$1,234.50')
+ expect(formatMoney('1234.5', 'EUR', 'de')).toBe('1.234,50\u00a0€')
+ expect(formatMoney('1000', 'JPY', 'en')).toBe('¥1,000')
+ expect(formatMoney('1.5', 'KWD', 'en')).toBe('KWD\u00a01.500')
+ expect(formatMoney('0.0125', 'USD', 'en', { unitPrice: true })).toBe('$0.0125')
+ expect(formatMoney('99999999999999999.99', 'USD', 'en')).toBe('$99,999,999,999,999,999.99')
+ expect([formatMoney(null, 'USD'), formatMoney('1,99', 'USD')]).toEqual(['', ''])
+ })
})
diff --git a/packages/dashboard-core/src/lib/formatters.ts b/packages/dashboard-core/src/lib/formatters.ts
index 828758292e..d92871669f 100644
--- a/packages/dashboard-core/src/lib/formatters.ts
+++ b/packages/dashboard-core/src/lib/formatters.ts
@@ -1,8 +1,10 @@
-import { decimalPlaces, isDecimalString, type Price } from '@spree/admin-sdk'
+import { formatMoney, type Price } from '@spree/admin-sdk'
import { parseISO } from 'date-fns'
import { formatInTimeZone } from 'date-fns-tz'
import i18n from 'i18next'
+export { formatMoney }
+
/**
* A price's amount in its currency, in the admin's own number format. A unit
* price keeps a fraction of a cent. `display_amount` is accepted and ignored
@@ -16,32 +18,6 @@ export function formatPrice(
return formatMoney(price.amount, price.currency, locale, { unitPrice: true })
}
-/**
- * Formats a decimal-string amount ("1234.50") in a currency and locale. The
- * string goes to `Intl` as it is — `Intl` reads numeric strings exactly — so
- * the amount never passes through a JavaScript number. A missing or malformed
- * amount formats as an empty string.
- */
-export function formatMoney(
- amount: string | null | undefined,
- currency: string,
- locale?: string,
- options: { unitPrice?: boolean } = {},
-): string {
- if (!isDecimalString(amount)) return ''
-
- // The decimals come from the same ISO 4217 table the API writes amounts
- // with, so a dinar shows three and a yen none; a unit price keeps up to four.
- const places = decimalPlaces(currency)
- // ES2023's Intl typings accept a numeric string; this package targets ES2022.
- return new Intl.NumberFormat(locale, {
- style: 'currency',
- currency,
- minimumFractionDigits: places,
- maximumFractionDigits: options.unitPrice ? Math.max(places, 4) : places,
- }).format(amount as unknown as number)
-}
-
/**
* Formats an API amount (a decimal string) in its currency, falling back to
* the bare number for a currency `Intl` does not know, and to `fallback` when
diff --git a/packages/sdk-core/src/index.ts b/packages/sdk-core/src/index.ts
index ef6e6b2ccb..ecae84f728 100644
--- a/packages/sdk-core/src/index.ts
+++ b/packages/sdk-core/src/index.ts
@@ -20,6 +20,7 @@ export { getParams, resolveRetryConfig } from './helpers'
export {
compareMoney,
decimalPlaces,
+ formatMoney,
isDecimalString,
isZeroMoney,
multiplyMoney,
diff --git a/packages/sdk-core/src/money.ts b/packages/sdk-core/src/money.ts
index dd20a5bd3b..7aa61ae345 100644
--- a/packages/sdk-core/src/money.ts
+++ b/packages/sdk-core/src/money.ts
@@ -97,3 +97,31 @@ export function multiplyMoney(value: string, quantity: number, currency?: string
const { units, scale } = parse(value)
return write(units * BigInt(quantity), scale, currency ? decimalPlaces(currency) : scale)
}
+
+/**
+ * Formats a decimal-string amount ("1234.50") in a currency and locale. The
+ * string goes to `Intl` as it is — `Intl` reads numeric strings exactly — so
+ * the amount never passes through a JavaScript number. A missing or malformed
+ * amount formats as an empty string.
+ *
+ * @example formatMoney(order.total, order.currency, order.locale) // "€129.99"
+ */
+export function formatMoney(
+ amount: string | null | undefined,
+ currency: string,
+ locale?: string | null,
+ options: { unitPrice?: boolean } = {},
+): string {
+ if (!isDecimalString(amount)) return ''
+
+ // The decimals come from the same ISO 4217 table the API writes amounts
+ // with, so a dinar shows three and a yen none; a unit price keeps up to four.
+ const places = decimalPlaces(currency)
+ // ES2023's Intl typings accept a numeric string; this package targets ES2022.
+ return new Intl.NumberFormat(locale ?? undefined, {
+ style: 'currency',
+ currency,
+ minimumFractionDigits: places,
+ maximumFractionDigits: options.unitPrice ? Math.max(places, 4) : places,
+ }).format(amount as unknown as number)
+}
diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts
index b8659d8b20..708ed9c7af 100644
--- a/packages/sdk/src/index.ts
+++ b/packages/sdk/src/index.ts
@@ -5,6 +5,7 @@ export type { RequestFn, RequestOptions, RetryConfig } from '@spree/sdk-core'
export {
compareMoney,
decimalPlaces,
+ formatMoney,
isDecimalString,
isZeroMoney,
multiplyMoney,
diff --git a/packages/sdk/src/types/generated/AppliedPromotion.ts b/packages/sdk/src/types/generated/AppliedPromotion.ts
index 83cd1845b1..18f95cc05e 100644
--- a/packages/sdk/src/types/generated/AppliedPromotion.ts
+++ b/packages/sdk/src/types/generated/AppliedPromotion.ts
@@ -1,4 +1,4 @@
-// Typelizer digest e4784c1dfe28a79bb174fbbd802587d1
+// Typelizer digest 34da3831ace9ea4cea1e32f322a4adbd
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
@@ -9,6 +9,8 @@ interface AppliedPromotion {
description: string | null;
code: string | null;
amount: string | null;
+ /** `amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount` with its currency instead. Removed in 6.1. */
display_amount: string | null;
}
diff --git a/packages/sdk/src/types/generated/Cart.ts b/packages/sdk/src/types/generated/Cart.ts
index 757c710b40..abad4aced1 100644
--- a/packages/sdk/src/types/generated/Cart.ts
+++ b/packages/sdk/src/types/generated/Cart.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 622e59e73af914c7672ec39b7cd24481
+// Typelizer digest 936d2dad44ce54fc5a6454c7069c6151
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {FreightSummary, Payment, AppliedPromotion, Fee, LineItem, Fulfillment, Address, PaymentMethod, GiftCard, Market, CurrencyCode} from '@/types'
@@ -24,31 +24,67 @@ interface Cart {
total_quantity: number;
warnings: Array<{code: string, message: string, line_item_id?: string, variant_id?: string, item_index?: number}>;
coupon_code: string | null;
+ /** The line items: each price times its quantity, before discounts, fees and delivery. */
item_total: string | null;
+ /** `item_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `item_total` with its currency instead. Removed in 6.1. */
display_item_total: string | null;
+ /** What promotions take off, as a negative amount. Manual discounts are not included. */
discount_total: string | null;
+ /** `discount_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `discount_total` with its currency instead. Removed in 6.1. */
display_discount_total: string | null;
+ /** All tax, both included in prices and added on top. */
tax_total: string | null;
+ /** `tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `tax_total` with its currency instead. Removed in 6.1. */
display_tax_total: string | null;
+ /** Tax already included in the prices, as in a store whose prices are tax-inclusive. */
included_tax_total: string | null;
+ /** `included_tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `included_tax_total` with its currency instead. Removed in 6.1. */
display_included_tax_total: string | null;
+ /** Tax added on top of the prices. */
additional_tax_total: string | null;
+ /** `additional_tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `additional_tax_total` with its currency instead. Removed in 6.1. */
display_additional_tax_total: string | null;
+ /** What delivery costs, before delivery discounts. */
delivery_total: string | null;
+ /** `delivery_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `delivery_total` with its currency instead. Removed in 6.1. */
display_delivery_total: string | null;
+ /** Every fee charged, such as handling or a customs duty. */
fee_total: string | null;
+ /** `fee_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `fee_total` with its currency instead. Removed in 6.1. */
display_fee_total: string | null;
+ /** What a gift card pays. */
gift_card_total: string | null;
+ /** `gift_card_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `gift_card_total` with its currency instead. Removed in 6.1. */
display_gift_card_total: string | null;
+ /** What store credit pays, apart from gift cards. */
store_credit_total: string | null;
+ /** `store_credit_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `store_credit_total` with its currency instead. Removed in 6.1. */
display_store_credit_total: string | null;
+ /** What the customer pays in all: items, delivery, fees and added tax, less discounts. */
total: string | null;
+ /** `total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `total` with its currency instead. Removed in 6.1. */
display_total: string | null;
+ /** What is left to pay after payments and store credit. */
amount_due: string | null;
+ /** `amount_due` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount_due` with its currency instead. Removed in 6.1. */
display_amount_due: string | null;
covered_by_store_credit: boolean;
payments: Array<Payment>;
+ /** Every discount, fee and added tax together, as one amount. */
adjustment_total: string | null;
+ /** `adjustment_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `adjustment_total` with its currency instead. Removed in 6.1. */
display_adjustment_total: string | null;
current_step: string;
completed_steps: Array<string>;
diff --git a/packages/sdk/src/types/generated/Claim.ts b/packages/sdk/src/types/generated/Claim.ts
index 9d9fbecd25..afbedc3ac0 100644
--- a/packages/sdk/src/types/generated/Claim.ts
+++ b/packages/sdk/src/types/generated/Claim.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 758cba4d74ea400f8baa68702380a774
+// Typelizer digest ef87731277e11830c562eee0219e802d
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {ClaimReason, ClaimLineItem, ClaimStatus} from '@/types'
@@ -11,6 +11,8 @@ interface Claim {
order_id: string | null;
reason_id: string | null;
refund_total: string | null;
+ /** `refund_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `refund_total` with its currency instead. Removed in 6.1. */
display_refund_total: string | null;
approved_at: string | null;
resolved_at: string | null;
diff --git a/packages/sdk/src/types/generated/ClaimLineItem.ts b/packages/sdk/src/types/generated/ClaimLineItem.ts
index 7c1ca0a33b..d5f697ea3b 100644
--- a/packages/sdk/src/types/generated/ClaimLineItem.ts
+++ b/packages/sdk/src/types/generated/ClaimLineItem.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 080a40c6b7549a5f37cc3f2b8ea18974
+// Typelizer digest fe6492840ce42de7afffbf8e3c75d730
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Variant} from '@/types'
@@ -14,6 +14,8 @@ interface ClaimLineItem {
included_tax_total: string | null;
additional_tax_total: string | null;
tax_total: string | null;
+ /** `refund_amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `refund_amount` with its currency instead. Removed in 6.1. */
display_refund_amount: string | null;
variant_id: string | null;
replacement_variant_id: string | null;
diff --git a/packages/sdk/src/types/generated/Customer.ts b/packages/sdk/src/types/generated/Customer.ts
index 74b1fed584..e69006ccd8 100644
--- a/packages/sdk/src/types/generated/Customer.ts
+++ b/packages/sdk/src/types/generated/Customer.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 895310c4c36c1f7179a9f62f486c5136
+// Typelizer digest 37aa4adb646ef180da9ed0f60351ce30
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Address, NewsletterSubscriber, CustomerGroup} from '@/types'
@@ -13,6 +13,8 @@ interface Customer {
email_marketing_consent_updated_at: string | null;
full_name: string;
available_store_credit_total: string;
+ /** `available_store_credit_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `available_store_credit_total` with its currency instead. Removed in 6.1. */
display_available_store_credit_total: string;
addresses: Array<Address>;
default_billing_address: Address | null;
diff --git a/packages/sdk/src/types/generated/DeliveryRate.ts b/packages/sdk/src/types/generated/DeliveryRate.ts
index a913a46975..697180b262 100644
--- a/packages/sdk/src/types/generated/DeliveryRate.ts
+++ b/packages/sdk/src/types/generated/DeliveryRate.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 18b6a19b4956210ad3039ed8f4d99f34
+// Typelizer digest c83f4f9d07a30375b93270924a7adf72
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {FreightSummary, DeliveryMethod} from '@/types'
@@ -18,10 +18,20 @@ interface DeliveryRate {
estimated_delivery_date: string | null;
unpriced: boolean;
freight_summary: FreightSummary | null;
+ /** `cost` formatted with its currency symbol in the request's language.
+ * @deprecated Format `cost` with its currency instead. Removed in 6.1. */
display_cost: string | null;
+ /** `total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `total` with its currency instead. Removed in 6.1. */
display_total: string | null;
+ /** `additional_tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `additional_tax_total` with its currency instead. Removed in 6.1. */
display_additional_tax_total: string | null;
+ /** `included_tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `included_tax_total` with its currency instead. Removed in 6.1. */
display_included_tax_total: string | null;
+ /** `tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `tax_total` with its currency instead. Removed in 6.1. */
display_tax_total: string | null;
delivery_method: DeliveryMethod;
}
diff --git a/packages/sdk/src/types/generated/Discount.ts b/packages/sdk/src/types/generated/Discount.ts
index d858f316ff..6b795d45ad 100644
--- a/packages/sdk/src/types/generated/Discount.ts
+++ b/packages/sdk/src/types/generated/Discount.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 74191b0a1e009bdd9c8704d278c59256
+// Typelizer digest df83b754c48138153f2677ca7d877ef4
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
@@ -13,6 +13,8 @@ interface Discount {
line_item_id: string | null;
fulfillment_id: string | null;
amount: string | null;
+ /** `amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount` with its currency instead. Removed in 6.1. */
display_amount: string | null;
}
diff --git a/packages/sdk/src/types/generated/Exchange.ts b/packages/sdk/src/types/generated/Exchange.ts
index 0e60475b17..c6b787c318 100644
--- a/packages/sdk/src/types/generated/Exchange.ts
+++ b/packages/sdk/src/types/generated/Exchange.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 9f5051c2c8bd138a33c82a1b1e1fbad3
+// Typelizer digest 3cbfdc942cc197194c2021c453c79338
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {ReturnReason, ExchangeLineItem, ExchangeStatus} from '@/types'
@@ -10,6 +10,8 @@ interface Exchange {
order_id: string | null;
reason_id: string | null;
price_difference: string | null;
+ /** `price_difference` formatted with its currency symbol in the request's language.
+ * @deprecated Format `price_difference` with its currency instead. Removed in 6.1. */
display_price_difference: string | null;
approved_at: string | null;
received_at: string | null;
diff --git a/packages/sdk/src/types/generated/Fee.ts b/packages/sdk/src/types/generated/Fee.ts
index 3ccb873315..3f04243ff0 100644
--- a/packages/sdk/src/types/generated/Fee.ts
+++ b/packages/sdk/src/types/generated/Fee.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 6e629d17c410635b3b0ff06d916dc04b
+// Typelizer digest e68a896e1cb69e579a19cd9d48dbffd6
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {FeeKind} from '@/types'
@@ -11,6 +11,8 @@ interface Fee {
line_item_id: string | null;
fulfillment_id: string | null;
amount: string | null;
+ /** `amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount` with its currency instead. Removed in 6.1. */
display_amount: string | null;
}
diff --git a/packages/sdk/src/types/generated/Fulfillment.ts b/packages/sdk/src/types/generated/Fulfillment.ts
index 64ef5d297e..524c847a83 100644
--- a/packages/sdk/src/types/generated/Fulfillment.ts
+++ b/packages/sdk/src/types/generated/Fulfillment.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 079221153c1a721d945e7116d683ae06
+// Typelizer digest 9faf3738ce1482d6a2efea52774a3604
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Delivery, DeliveryMethod, StockLocation, DeliveryRate, TaxLine, FulfillmentStatus} from '@/types'
@@ -12,16 +12,28 @@ interface Fulfillment {
selected_delivery_rate_id: string | null;
unpriced: boolean;
cost: string | null;
+ /** `cost` formatted with its currency symbol in the request's language.
+ * @deprecated Format `cost` with its currency instead. Removed in 6.1. */
display_cost: string | null;
total: string | null;
+ /** `total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `total` with its currency instead. Removed in 6.1. */
display_total: string | null;
discount_total: string | null;
+ /** `discount_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `discount_total` with its currency instead. Removed in 6.1. */
display_discount_total: string | null;
additional_tax_total: string | null;
+ /** `additional_tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `additional_tax_total` with its currency instead. Removed in 6.1. */
display_additional_tax_total: string | null;
included_tax_total: string | null;
+ /** `included_tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `included_tax_total` with its currency instead. Removed in 6.1. */
display_included_tax_total: string | null;
tax_total: string | null;
+ /** `tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `tax_total` with its currency instead. Removed in 6.1. */
display_tax_total: string | null;
status: FulfillmentStatus;
fulfillment_type: 'shipping' | 'digital' | 'pickup' | 'pickup_point';
diff --git a/packages/sdk/src/types/generated/GiftCard.ts b/packages/sdk/src/types/generated/GiftCard.ts
index 1a2ca125b2..66a2a86da0 100644
--- a/packages/sdk/src/types/generated/GiftCard.ts
+++ b/packages/sdk/src/types/generated/GiftCard.ts
@@ -1,4 +1,4 @@
-// Typelizer digest b8216ce884a74f5aac69a40c70861969
+// Typelizer digest 8c37a32d858152d37ab3f1f66477f354
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {GiftCardStatus, CurrencyCode} from '@/types'
@@ -12,8 +12,14 @@ interface GiftCard {
amount_used: string | null;
amount_authorized: string | null;
amount_remaining: string | null;
+ /** `amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount` with its currency instead. Removed in 6.1. */
display_amount: string | null;
+ /** `amount_used` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount_used` with its currency instead. Removed in 6.1. */
display_amount_used: string | null;
+ /** `amount_remaining` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount_remaining` with its currency instead. Removed in 6.1. */
display_amount_remaining: string | null;
expires_at: string | null;
redeemed_at: string | null;
diff --git a/packages/sdk/src/types/generated/LineItem.ts b/packages/sdk/src/types/generated/LineItem.ts
index 2eb43cb9b9..f43408002a 100644
--- a/packages/sdk/src/types/generated/LineItem.ts
+++ b/packages/sdk/src/types/generated/LineItem.ts
@@ -1,4 +1,4 @@
-// Typelizer digest e5780d5c48fcd785f454412d9b87ebfc
+// Typelizer digest c54e5cd5b6b1c5476a714c8259a12969
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Seller, OptionValue, DigitalLink, TaxLine, CurrencyCode} from '@/types'
@@ -14,23 +14,50 @@ interface LineItem {
name: string;
slug: string;
options_text: string;
+ /** The price of one unit. */
price: string | null;
+ /** `price` formatted with its currency symbol in the request's language.
+ * @deprecated Format `price` with its currency instead. Removed in 6.1. */
display_price: string | null;
+ /** What this line costs: price times quantity, with its discounts, fees and added tax. */
total: string | null;
+ /** `total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `total` with its currency instead. Removed in 6.1. */
display_total: string | null;
+ /** This line's discounts, fees and added tax together. */
adjustment_total: string | null;
+ /** `adjustment_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `adjustment_total` with its currency instead. Removed in 6.1. */
display_adjustment_total: string | null;
+ /** Tax added on top of the price. */
additional_tax_total: string | null;
+ /** `additional_tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `additional_tax_total` with its currency instead. Removed in 6.1. */
display_additional_tax_total: string | null;
+ /** Tax already included in the price. */
included_tax_total: string | null;
+ /** `included_tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `included_tax_total` with its currency instead. Removed in 6.1. */
display_included_tax_total: string | null;
+ /** What promotions take off this line, as a negative amount. */
discount_total: string | null;
+ /** `discount_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `discount_total` with its currency instead. Removed in 6.1. */
display_discount_total: string | null;
+ /** This line after discounts, without tax. */
pre_tax_amount: string | null;
+ /** `pre_tax_amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `pre_tax_amount` with its currency instead. Removed in 6.1. */
display_pre_tax_amount: string | null;
+ /** Price times quantity, after discounts. */
discounted_amount: string | null;
+ /** `discounted_amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `discounted_amount` with its currency instead. Removed in 6.1. */
display_discounted_amount: string | null;
+ /** `compare_at_amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `compare_at_amount` with its currency instead. Removed in 6.1. */
display_compare_at_amount: string | null;
+ /** The compare-at price times quantity, or null when the variant has none. */
compare_at_amount: string | null;
thumbnail_url: string | null;
seller?: Seller;
diff --git a/packages/sdk/src/types/generated/Order.ts b/packages/sdk/src/types/generated/Order.ts
index 4113fcc7d4..3a30e8fc44 100644
--- a/packages/sdk/src/types/generated/Order.ts
+++ b/packages/sdk/src/types/generated/Order.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 3591f6fa021bb07bfff31c9b20dc9bdf
+// Typelizer digest 117f1e5d5d744c0d6b8b03ccaa0a8da5
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Payment, AppliedPromotion, Fee, LineItem, Fulfillment, Address, GiftCard, Market, CurrencyCode} from '@/types'
@@ -25,31 +25,67 @@ interface Order {
fulfillment_status: 'backorder' | 'canceled' | 'partial' | 'unfulfilled' | 'fulfilled' | 'delivered' | 'pending' | 'ready' | 'shipped' | null;
payment_status: 'none' | 'authorized' | 'partially_paid' | 'paid' | 'partially_refunded' | 'refunded' | 'overcharged' | 'voided' | null;
completed_at: string | null;
+ /** The line items: each price times its quantity, before discounts, fees and delivery. */
item_total: string | null;
+ /** `item_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `item_total` with its currency instead. Removed in 6.1. */
display_item_total: string | null;
+ /** What promotions take off, as a negative amount. Manual discounts are not included. */
discount_total: string | null;
+ /** `discount_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `discount_total` with its currency instead. Removed in 6.1. */
display_discount_total: string | null;
+ /** All tax, both included in prices and added on top. */
tax_total: string | null;
+ /** `tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `tax_total` with its currency instead. Removed in 6.1. */
display_tax_total: string | null;
+ /** Tax already included in the prices, as in a store whose prices are tax-inclusive. */
included_tax_total: string | null;
+ /** `included_tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `included_tax_total` with its currency instead. Removed in 6.1. */
display_included_tax_total: string | null;
+ /** Tax added on top of the prices. */
additional_tax_total: string | null;
+ /** `additional_tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `additional_tax_total` with its currency instead. Removed in 6.1. */
display_additional_tax_total: string | null;
+ /** What delivery costs, before delivery discounts. */
delivery_total: string | null;
+ /** `delivery_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `delivery_total` with its currency instead. Removed in 6.1. */
display_delivery_total: string | null;
+ /** Every fee charged, such as handling or a customs duty. */
fee_total: string | null;
+ /** `fee_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `fee_total` with its currency instead. Removed in 6.1. */
display_fee_total: string | null;
+ /** What a gift card pays. */
gift_card_total: string | null;
+ /** `gift_card_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `gift_card_total` with its currency instead. Removed in 6.1. */
display_gift_card_total: string | null;
+ /** What store credit pays, apart from gift cards. */
store_credit_total: string | null;
+ /** `store_credit_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `store_credit_total` with its currency instead. Removed in 6.1. */
display_store_credit_total: string | null;
+ /** What the customer pays in all: items, delivery, fees and added tax, less discounts. */
total: string | null;
+ /** `total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `total` with its currency instead. Removed in 6.1. */
display_total: string | null;
+ /** What is left to pay after payments and store credit. */
amount_due: string | null;
+ /** `amount_due` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount_due` with its currency instead. Removed in 6.1. */
display_amount_due: string | null;
covered_by_store_credit: boolean;
payments: Array<Payment>;
+ /** Every discount, fee and added tax together, as one amount. */
adjustment_total: string | null;
+ /** `adjustment_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `adjustment_total` with its currency instead. Removed in 6.1. */
display_adjustment_total: string | null;
discounts: Array<AppliedPromotion>;
fees: Array<Fee>;
diff --git a/packages/sdk/src/types/generated/OrderGroup.ts b/packages/sdk/src/types/generated/OrderGroup.ts
index 11001b2ac5..3079682268 100644
--- a/packages/sdk/src/types/generated/OrderGroup.ts
+++ b/packages/sdk/src/types/generated/OrderGroup.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 832e29db012712d0637162ae388b9a89
+// Typelizer digest 12a644fc42b128fc71c537ac886dfd18
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Payment, Address, Order, CurrencyCode} from '@/types'
@@ -8,27 +8,60 @@ interface OrderGroup {
number: string;
email: string | null;
currency: CurrencyCode;
+ /** The line items: each price times its quantity, before discounts, fees and delivery. */
item_total: string | null;
+ /** `item_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `item_total` with its currency instead. Removed in 6.1. */
display_item_total: string | null;
+ /** What promotions take off, as a negative amount. Manual discounts are not included. */
discount_total: string | null;
+ /** `discount_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `discount_total` with its currency instead. Removed in 6.1. */
display_discount_total: string | null;
+ /** All tax, both included in prices and added on top. */
tax_total: string | null;
+ /** `tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `tax_total` with its currency instead. Removed in 6.1. */
display_tax_total: string | null;
+ /** Tax already included in the prices, as in a store whose prices are tax-inclusive. */
included_tax_total: string | null;
+ /** `included_tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `included_tax_total` with its currency instead. Removed in 6.1. */
display_included_tax_total: string | null;
+ /** Tax added on top of the prices. */
additional_tax_total: string | null;
+ /** `additional_tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `additional_tax_total` with its currency instead. Removed in 6.1. */
display_additional_tax_total: string | null;
+ /** What delivery costs, before delivery discounts. */
delivery_total: string | null;
+ /** `delivery_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `delivery_total` with its currency instead. Removed in 6.1. */
display_delivery_total: string | null;
+ /** Every fee charged, such as handling or a customs duty. */
fee_total: string | null;
+ /** `fee_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `fee_total` with its currency instead. Removed in 6.1. */
display_fee_total: string | null;
+ /** What a gift card pays. */
gift_card_total: string | null;
+ /** `gift_card_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `gift_card_total` with its currency instead. Removed in 6.1. */
display_gift_card_total: string | null;
+ /** What store credit pays, apart from gift cards. */
store_credit_total: string | null;
+ /** `store_credit_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `store_credit_total` with its currency instead. Removed in 6.1. */
display_store_credit_total: string | null;
+ /** What the customer pays in all: items, delivery, fees and added tax, less discounts. */
total: string | null;
+ /** `total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `total` with its currency instead. Removed in 6.1. */
display_total: string | null;
+ /** What is left to pay after payments and store credit. */
amount_due: string | null;
+ /** `amount_due` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount_due` with its currency instead. Removed in 6.1. */
display_amount_due: string | null;
covered_by_store_credit: boolean;
payments: Array<Payment>;
diff --git a/packages/sdk/src/types/generated/Payment.ts b/packages/sdk/src/types/generated/Payment.ts
index c55efa7194..e3f8933dc4 100644
--- a/packages/sdk/src/types/generated/Payment.ts
+++ b/packages/sdk/src/types/generated/Payment.ts
@@ -1,4 +1,4 @@
-// Typelizer digest beabfc8e5734fc40c76e12408d80851f
+// Typelizer digest d95a4d6d93c59aa450be14d060c73f41
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {CreditCard, StoreCredit, PaymentSource, PaymentMethod, PaymentStatus} from '@/types'
@@ -10,6 +10,8 @@ interface Payment {
number: string;
status: PaymentStatus;
amount: string | null;
+ /** `amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount` with its currency instead. Removed in 6.1. */
display_amount: string | null;
source_type: 'credit_card' | 'store_credit' | 'payment_source' | null;
source_id: string | null;
diff --git a/packages/sdk/src/types/generated/Price.ts b/packages/sdk/src/types/generated/Price.ts
index 66f7edc9a1..2edeab96f2 100644
--- a/packages/sdk/src/types/generated/Price.ts
+++ b/packages/sdk/src/types/generated/Price.ts
@@ -1,4 +1,4 @@
-// Typelizer digest ca70fe414df158856b4a5a5bed77a9ca
+// Typelizer digest d1d8ab56607bdd49dec39815b987d525
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {CurrencyCode} from '@/types'
@@ -8,7 +8,11 @@ interface Price {
currency: CurrencyCode | null;
amount: string | null;
compare_at_amount: string | null;
+ /** `amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount` with its currency instead. Removed in 6.1. */
display_amount: string | null;
+ /** `compare_at_amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `compare_at_amount` with its currency instead. Removed in 6.1. */
display_compare_at_amount: string | null;
price_list_id: string | null;
}
diff --git a/packages/sdk/src/types/generated/PriceHistory.ts b/packages/sdk/src/types/generated/PriceHistory.ts
index 7dcca49ebd..2d2acc5942 100644
--- a/packages/sdk/src/types/generated/PriceHistory.ts
+++ b/packages/sdk/src/types/generated/PriceHistory.ts
@@ -1,4 +1,4 @@
-// Typelizer digest ad87dcafc61af2c9f2b3f9fa2e73beac
+// Typelizer digest c43732b1c5554a88dff19569bba598dc
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {CurrencyCode} from '@/types'
@@ -7,6 +7,8 @@ interface PriceHistory {
id: string;
currency: CurrencyCode;
amount: string | null;
+ /** `amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount` with its currency instead. Removed in 6.1. */
display_amount: string;
recorded_at: string;
}
diff --git a/packages/sdk/src/types/generated/Return.ts b/packages/sdk/src/types/generated/Return.ts
index ee12d8fb9c..d3d30b3420 100644
--- a/packages/sdk/src/types/generated/Return.ts
+++ b/packages/sdk/src/types/generated/Return.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 629e0b8ed448a349cd291939e5a51b69
+// Typelizer digest b18e0146b31024777365e5185b7f1ce1
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {ReturnReason, ReturnLineItem, ReturnStatus} from '@/types'
@@ -10,8 +10,12 @@ interface Return {
order_id: string | null;
reason_id: string | null;
refund_total: string | null;
+ /** `refund_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `refund_total` with its currency instead. Removed in 6.1. */
display_refund_total: string | null;
refund_tax_total: string | null;
+ /** `refund_tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `refund_tax_total` with its currency instead. Removed in 6.1. */
display_refund_tax_total: string | null;
approved_at: string | null;
received_at: string | null;
diff --git a/packages/sdk/src/types/generated/ReturnLineItem.ts b/packages/sdk/src/types/generated/ReturnLineItem.ts
index 45c0c82570..ce97768987 100644
--- a/packages/sdk/src/types/generated/ReturnLineItem.ts
+++ b/packages/sdk/src/types/generated/ReturnLineItem.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 714e4f5c56fafb4983c96cdfc04aa471
+// Typelizer digest be347ce17b562a95b6f4a3be8f1647a6
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {Variant} from '@/types'
@@ -9,12 +9,18 @@ interface ReturnLineItem {
received_quantity: number;
resellable: boolean;
pre_tax_amount: string | null;
+ /** `pre_tax_amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `pre_tax_amount` with its currency instead. Removed in 6.1. */
display_pre_tax_amount: string | null;
included_tax_total: string | null;
additional_tax_total: string | null;
tax_total: string | null;
+ /** `tax_total` formatted with its currency symbol in the request's language.
+ * @deprecated Format `tax_total` with its currency instead. Removed in 6.1. */
display_tax_total: string | null;
refund_amount: string | null;
+ /** `refund_amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `refund_amount` with its currency instead. Removed in 6.1. */
display_refund_amount: string | null;
variant_id: string | null;
line_item_id: string | null;
diff --git a/packages/sdk/src/types/generated/StoreCredit.ts b/packages/sdk/src/types/generated/StoreCredit.ts
index 5057aee7a1..a1f0ca00b7 100644
--- a/packages/sdk/src/types/generated/StoreCredit.ts
+++ b/packages/sdk/src/types/generated/StoreCredit.ts
@@ -1,4 +1,4 @@
-// Typelizer digest 97d4a98a16dd189897a339512788c177
+// Typelizer digest 00138617ee4ba750323b015134e4837e
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
import type {CurrencyCode} from '@/types'
@@ -8,8 +8,14 @@ interface StoreCredit {
amount: string | null;
amount_used: string | null;
amount_remaining: string | null;
+ /** `amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount` with its currency instead. Removed in 6.1. */
display_amount: string | null;
+ /** `amount_used` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount_used` with its currency instead. Removed in 6.1. */
display_amount_used: string | null;
+ /** `amount_remaining` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount_remaining` with its currency instead. Removed in 6.1. */
display_amount_remaining: string | null;
currency: CurrencyCode;
}
diff --git a/packages/sdk/src/types/generated/StoreCreditEvent.ts b/packages/sdk/src/types/generated/StoreCreditEvent.ts
index baa4f262ec..38a83de861 100644
--- a/packages/sdk/src/types/generated/StoreCreditEvent.ts
+++ b/packages/sdk/src/types/generated/StoreCreditEvent.ts
@@ -1,4 +1,4 @@
-// Typelizer digest b78f2e36d2c39d8870c913dbba1c7f60
+// Typelizer digest 649e3a531c9151d879ade1ef19a9cb84
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
@@ -8,6 +8,8 @@ interface StoreCreditEvent {
authorization_code: string | null;
display_action: string | null;
amount: string | null;
+ /** `amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount` with its currency instead. Removed in 6.1. */
display_amount: string | null;
created_at: string;
}
diff --git a/packages/sdk/src/types/generated/TaxLine.ts b/packages/sdk/src/types/generated/TaxLine.ts
index 0e8d8e381a..a09e56b5c4 100644
--- a/packages/sdk/src/types/generated/TaxLine.ts
+++ b/packages/sdk/src/types/generated/TaxLine.ts
@@ -1,4 +1,4 @@
-// Typelizer digest e62f5f22e0ed73c0ae9ad1087303d82b
+// Typelizer digest ef0c2eed3e5f7cb3c8d5366eb32e7f0e
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
@@ -16,6 +16,8 @@ interface TaxLine {
claim_line_item_id: string | null;
exchange_line_item_id: string | null;
amount: string | null;
+ /** `amount` formatted with its currency symbol in the request's language.
+ * @deprecated Format `amount` with its currency instead. Removed in 6.1. */
display_amount: string | null;
}
diff --git a/packages/seller-sdk/src/index.ts b/packages/seller-sdk/src/index.ts
index 5db290aafe..9114a7f574 100644
--- a/packages/seller-sdk/src/index.ts
+++ b/packages/seller-sdk/src/index.ts
@@ -10,6 +10,7 @@ export type {
export {
compareMoney,
decimalPlaces,
+ formatMoney,
isDecimalString,
isZeroMoney,
multiplyMoney,
diff --git a/spree/api/app/serializers/concerns/spree/api/v3/purchase_summary.rb b/spree/api/app/serializers/concerns/spree/api/v3/purchase_summary.rb
index c65c33e90a..f558efb10b 100644
--- a/spree/api/app/serializers/concerns/spree/api/v3/purchase_summary.rb
+++ b/spree/api/app/serializers/concerns/spree/api/v3/purchase_summary.rb
@@ -23,7 +23,20 @@ module Spree
:gift_card_total, :display_gift_card_total,
:store_credit_total, :display_store_credit_total,
:total, :display_total,
- :amount_due, :display_amount_due
+ :amount_due, :display_amount_due,
+ descriptions: {
+ item_total: 'The line items: each price times its quantity, before discounts, fees and delivery.',
+ discount_total: 'What promotions take off, as a negative amount. Manual discounts are not included.',
+ tax_total: 'All tax, both included in prices and added on top.',
+ included_tax_total: 'Tax already included in the prices, as in a store whose prices are tax-inclusive.',
+ additional_tax_total: 'Tax added on top of the prices.',
+ delivery_total: 'What delivery costs, before delivery discounts.',
+ fee_total: 'Every fee charged, such as handling or a customs duty.',
+ gift_card_total: 'What a gift card pays.',
+ store_credit_total: 'What store credit pays, apart from gift cards.',
+ total: 'What the customer pays in all: items, delivery, fees and added tax, less discounts.',
+ amount_due: 'What is left to pay after payments and store credit.'
+ }
attribute :covered_by_store_credit, &:covered_by_store_credit?
diff --git a/spree/api/app/serializers/spree/api/v3/base_serializer.rb b/spree/api/app/serializers/spree/api/v3/base_serializer.rb
index 59c7a6dccd..1f306d2137 100644
--- a/spree/api/app/serializers/spree/api/v3/base_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/base_serializer.rb
@@ -35,7 +35,7 @@ module Spree
# Emails use it alone: their templates format amounts with the `money`
# Liquid filter.
def self.without_display_money
- _attributes.delete_if { |key, _| key.to_s.start_with?('display_') && !FORMATTED_LABELS.include?(key.to_sym) }
+ _attributes.delete_if { |key, _| display_money?(key) }
end
# Declares money attributes, written as decimal strings with exactly
@@ -48,15 +48,22 @@ module Spree
# @param currency [Symbol, Proc] the record's reader for its currency,
# or a block taking the record
# @param unit_price [Boolean]
- def self.money_attributes(*names, currency: :currency, unit_price: false)
- typelize(**names.index_with { [:string, nullable: true] })
+ # @param descriptions [Hash{Symbol => String}] what each amount is, for
+ # the API reference and the SDK types
+ def self.money_attributes(*names, currency: :currency, unit_price: false, descriptions: {})
+ typelize(**names.index_with do |name|
+ next display_money_type(name) if display_money?(name)
+
+ descriptions[name] ? [:string, nullable: true, comment: descriptions[name]] : [:string, nullable: true]
+ end)
names.each do |name|
+ formatted = display_money?(name)
attribute(name) do |object|
next if params[:hide_prices]
value = object.public_send(name)
- next value if name.to_s.start_with?('display_') || value.nil?
+ next value if formatted || value.nil?
code = currency.is_a?(Proc) ? currency.call(object) : object.public_send(currency)
Spree::Money::Rounding.format(value, code, unit_price: unit_price)
@@ -64,6 +71,20 @@ module Spree
end
end
+ # A formatted money copy, as opposed to a label such as +display_name+.
+ def self.display_money?(name)
+ name.to_s.start_with?('display_') && !FORMATTED_LABELS.include?(name.to_sym)
+ end
+
+ # The type of a formatted money copy: deprecated in favour of the
+ # amount it formats, which clients format in the reader's language.
+ def self.display_money_type(name, nullable: true)
+ amount = name.to_s.delete_prefix('display_')
+ [:string, nullable: nullable,
+ comment: "`#{amount}` formatted with its currency symbol in the request's language.",
+ deprecated: "Format `#{amount}` with its currency instead. Removed in 6.1."]
+ end
+
# Declares rates and percentages, written as decimal strings without
# trailing zeros ("0.23", "7.25", "10"). A name ending +_percent+ or
# +_percentage+ holds 0-100; +rate+ or a name ending +_rate+ holds a
diff --git a/spree/api/app/serializers/spree/api/v3/cart_serializer.rb b/spree/api/app/serializers/spree/api/v3/cart_serializer.rb
index c54723a65d..2c8366fcd2 100644
--- a/spree/api/app/serializers/spree/api/v3/cart_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/cart_serializer.rb
@@ -59,7 +59,8 @@ module Spree
# Nulled for gated (prices_hidden) guests so the cart can't leak the
# prices that product/variant serializers already withhold.
include Spree::Api::V3::PurchaseSummary
- money_attributes :adjustment_total, :display_adjustment_total
+ money_attributes :adjustment_total, :display_adjustment_total,
+ descriptions: { adjustment_total: 'Every discount, fee and added tax together, as one amount.' }
attribute :current_step do |order|
order.current_checkout_step
diff --git a/spree/api/app/serializers/spree/api/v3/customer_serializer.rb b/spree/api/app/serializers/spree/api/v3/customer_serializer.rb
index f2738da03f..ed0da0ba70 100644
--- a/spree/api/app/serializers/spree/api/v3/customer_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/customer_serializer.rb
@@ -7,7 +7,8 @@ module Spree
typelize email: :string, first_name: [:string, nullable: true], last_name: [:string, nullable: true],
full_name: :string,
phone: [:string, nullable: true], accepts_email_marketing: :boolean,
- available_store_credit_total: :string, display_available_store_credit_total: :string,
+ available_store_credit_total: :string,
+ display_available_store_credit_total: display_money_type(:display_available_store_credit_total, nullable: false),
default_billing_address: { nullable: true }, default_shipping_address: { nullable: true },
newsletter_subscriber: { nullable: true },
email_marketing_consent_updated_at: [:string, nullable: true]
diff --git a/spree/api/app/serializers/spree/api/v3/gift_card_serializer.rb b/spree/api/app/serializers/spree/api/v3/gift_card_serializer.rb
index 2c3fec16e5..d6b349221f 100644
--- a/spree/api/app/serializers/spree/api/v3/gift_card_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/gift_card_serializer.rb
@@ -4,8 +4,10 @@ module Spree
class GiftCardSerializer < BaseSerializer
typelize code: :string,
status: [:string, enum: Spree::GiftCard::DISPLAY_STATUSES, enum_type_name: 'GiftCardStatus'],
- display_amount: [:string, nullable: true], display_amount_used: [:string, nullable: true],
- display_amount_remaining: [:string, nullable: true], currency: [:string, enum: Spree::Money::Rounding::CURRENCY_CODES, enum_type_name: 'CurrencyCode'],
+ display_amount: display_money_type(:display_amount),
+ display_amount_used: display_money_type(:display_amount_used),
+ display_amount_remaining: display_money_type(:display_amount_remaining),
+ currency: [:string, enum: Spree::Money::Rounding::CURRENCY_CODES, enum_type_name: 'CurrencyCode'],
expires_at: [:string, nullable: true], redeemed_at: [:string, nullable: true], expired: :boolean,
active: :boolean
diff --git a/spree/api/app/serializers/spree/api/v3/line_item_serializer.rb b/spree/api/app/serializers/spree/api/v3/line_item_serializer.rb
index e12de914a8..de3b78fbe5 100644
--- a/spree/api/app/serializers/spree/api/v3/line_item_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/line_item_serializer.rb
@@ -3,7 +3,7 @@ module Spree
module V3
class LineItemSerializer < BaseSerializer
typelize variant_id: :string, quantity: :number, currency: [:string, enum: Spree::Money::Rounding::CURRENCY_CODES, enum_type_name: 'CurrencyCode'], name: :string, slug: :string,
- options_text: :string, compare_at_amount: [:string, nullable: true],
+ options_text: :string, compare_at_amount: [:string, nullable: true, comment: 'The compare-at price times quantity, or null when the variant has none.'],
thumbnail_url: [:string, nullable: true], preorder: :boolean,
preorder_ships_at: [:string, nullable: true], seller_id: [:string, nullable: true]
@@ -30,7 +30,7 @@ module Spree
# Nulled for gated (prices_hidden) guests so the cart's line items can't
# leak the prices that product/variant serializers already withhold.
- money_attributes :price, :display_price, unit_price: true
+ money_attributes :price, :display_price, unit_price: true, descriptions: { price: 'The price of one unit.' }
money_attributes :total, :display_total,
:adjustment_total, :display_adjustment_total,
:additional_tax_total, :display_additional_tax_total,
@@ -38,7 +38,16 @@ module Spree
:discount_total, :display_discount_total,
:pre_tax_amount, :display_pre_tax_amount,
:discounted_amount, :display_discounted_amount,
- :display_compare_at_amount
+ :display_compare_at_amount,
+ descriptions: {
+ total: 'What this line costs: price times quantity, with its discounts, fees and added tax.',
+ adjustment_total: "This line's discounts, fees and added tax together.",
+ additional_tax_total: 'Tax added on top of the price.',
+ included_tax_total: 'Tax already included in the price.',
+ discount_total: 'What promotions take off this line, as a negative amount.',
+ pre_tax_amount: 'This line after discounts, without tax.',
+ discounted_amount: 'Price times quantity, after discounts.'
+ }
# Return compare_at_amount as string, nil if zero
attribute :compare_at_amount do |line_item|
diff --git a/spree/api/app/serializers/spree/api/v3/order_serializer.rb b/spree/api/app/serializers/spree/api/v3/order_serializer.rb
index 1b4dc617d2..db221a0bfc 100644
--- a/spree/api/app/serializers/spree/api/v3/order_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/order_serializer.rb
@@ -64,7 +64,8 @@ module Spree
# Nulled for gated (prices_hidden) guests, consistent with cart and
# catalog price hiding.
include Spree::Api::V3::PurchaseSummary
- money_attributes :adjustment_total, :display_adjustment_total
+ money_attributes :adjustment_total, :display_adjustment_total,
+ descriptions: { adjustment_total: 'Every discount, fee and added tax together, as one amount.' }
many :order_promotions, key: :discounts, resource: proc { Spree.api.applied_promotion_serializer }
# Itemized charges (duties, surcharges, COD, handling) — see the cart
diff --git a/spree/api/app/serializers/spree/api/v3/price_history_serializer.rb b/spree/api/app/serializers/spree/api/v3/price_history_serializer.rb
index 83922dd90e..2271d59959 100644
--- a/spree/api/app/serializers/spree/api/v3/price_history_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/price_history_serializer.rb
@@ -4,7 +4,7 @@ module Spree
module Api
module V3
class PriceHistorySerializer < BaseSerializer
- typelize display_amount: :string,
+ typelize display_amount: display_money_type(:display_amount, nullable: false),
currency: [:string, enum: Spree::Money::Rounding::CURRENCY_CODES, enum_type_name: 'CurrencyCode'],
recorded_at: :string
diff --git a/spree/api/app/serializers/spree/api/v3/price_serializer.rb b/spree/api/app/serializers/spree/api/v3/price_serializer.rb
index b4da48b358..6b918e9bfa 100644
--- a/spree/api/app/serializers/spree/api/v3/price_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/price_serializer.rb
@@ -5,8 +5,8 @@ module Spree
# Represents a resolved/calculated price for storefront display
# Can represent either a calculated price (with price list resolution) or a base price
class PriceSerializer < BaseSerializer
- typelize display_amount: [:string, nullable: true],
- display_compare_at_amount: [:string, nullable: true],
+ typelize display_amount: display_money_type(:display_amount),
+ display_compare_at_amount: display_money_type(:display_compare_at_amount),
currency: [:string, nullable: true, enum: Spree::Money::Rounding::CURRENCY_CODES, enum_type_name: 'CurrencyCode'],
price_list_id: [:string, nullable: true]