@open-mercato/checkout 0.10.1-develop.8287.1.7313a0fe67 → 0.10.1-develop.8291.1.6ec3aee41c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/modules/checkout/__integration__/TC-CHK-CRUDFORM-001.spec.js +3 -3
  3. package/dist/modules/checkout/__integration__/TC-CHK-CRUDFORM-001.spec.js.map +2 -2
  4. package/dist/modules/checkout/__integration__/TC-CHKT-037-template-sync.spec.js +3 -1
  5. package/dist/modules/checkout/__integration__/TC-CHKT-037-template-sync.spec.js.map +2 -2
  6. package/dist/modules/checkout/__integration__/TC-CHKT-PRECISION-001.spec.js +259 -0
  7. package/dist/modules/checkout/__integration__/TC-CHKT-PRECISION-001.spec.js.map +7 -0
  8. package/dist/modules/checkout/__integration__/TC-CHKT-PRECISION-002-admin-round-trip.spec.js +85 -0
  9. package/dist/modules/checkout/__integration__/TC-CHKT-PRECISION-002-admin-round-trip.spec.js.map +7 -0
  10. package/dist/modules/checkout/api/pay/[slug]/submit/route.js +17 -2
  11. package/dist/modules/checkout/api/pay/[slug]/submit/route.js.map +2 -2
  12. package/dist/modules/checkout/backend/checkout/pay-links/page.js +9 -3
  13. package/dist/modules/checkout/backend/checkout/pay-links/page.js.map +2 -2
  14. package/dist/modules/checkout/commands/links.js +7 -10
  15. package/dist/modules/checkout/commands/links.js.map +2 -2
  16. package/dist/modules/checkout/commands/shared.js +43 -7
  17. package/dist/modules/checkout/commands/shared.js.map +2 -2
  18. package/dist/modules/checkout/commands/templates.js +12 -10
  19. package/dist/modules/checkout/commands/templates.js.map +2 -2
  20. package/dist/modules/checkout/commands/transactions.js +13 -1
  21. package/dist/modules/checkout/commands/transactions.js.map +2 -2
  22. package/dist/modules/checkout/components/LinkTemplateForm.js +47 -20
  23. package/dist/modules/checkout/components/LinkTemplateForm.js.map +2 -2
  24. package/dist/modules/checkout/components/PayPage.js +59 -55
  25. package/dist/modules/checkout/components/PayPage.js.map +2 -2
  26. package/dist/modules/checkout/data/entities.js +6 -5
  27. package/dist/modules/checkout/data/entities.js.map +2 -2
  28. package/dist/modules/checkout/data/validators.js +19 -2
  29. package/dist/modules/checkout/data/validators.js.map +2 -2
  30. package/dist/modules/checkout/i18n/de.json +1 -0
  31. package/dist/modules/checkout/i18n/en.json +1 -0
  32. package/dist/modules/checkout/i18n/es.json +1 -0
  33. package/dist/modules/checkout/i18n/ko.json +1 -0
  34. package/dist/modules/checkout/i18n/pl.json +1 -0
  35. package/dist/modules/checkout/lib/amountPrecision.js +98 -0
  36. package/dist/modules/checkout/lib/amountPrecision.js.map +7 -0
  37. package/dist/modules/checkout/lib/payPageAmount.js +56 -0
  38. package/dist/modules/checkout/lib/payPageAmount.js.map +7 -0
  39. package/dist/modules/checkout/lib/utils.js +63 -20
  40. package/dist/modules/checkout/lib/utils.js.map +2 -2
  41. package/dist/modules/checkout/migrations/Migration20261014082519_checkout.js +33 -0
  42. package/dist/modules/checkout/migrations/Migration20261014082519_checkout.js.map +7 -0
  43. package/dist/modules/checkout/workers/send-email.worker.js +8 -1
  44. package/dist/modules/checkout/workers/send-email.worker.js.map +2 -2
  45. package/package.json +10 -7
  46. package/src/modules/checkout/__integration__/TC-CHK-CRUDFORM-001.spec.ts +3 -3
  47. package/src/modules/checkout/__integration__/TC-CHKT-037-template-sync.spec.ts +2 -0
  48. package/src/modules/checkout/__integration__/TC-CHKT-PRECISION-001.spec.ts +320 -0
  49. package/src/modules/checkout/__integration__/TC-CHKT-PRECISION-002-admin-round-trip.spec.ts +112 -0
  50. package/src/modules/checkout/api/pay/[slug]/__tests__/route.test.ts +4 -0
  51. package/src/modules/checkout/api/pay/[slug]/submit/__tests__/route.test.ts +145 -0
  52. package/src/modules/checkout/api/pay/[slug]/submit/route.ts +19 -2
  53. package/src/modules/checkout/backend/checkout/pay-links/page.tsx +13 -3
  54. package/src/modules/checkout/commands/__tests__/configured-amount-precision.test.ts +180 -0
  55. package/src/modules/checkout/commands/__tests__/create-transaction-amount.test.ts +77 -0
  56. package/src/modules/checkout/commands/__tests__/template-sync.test.ts +145 -0
  57. package/src/modules/checkout/commands/links.ts +7 -10
  58. package/src/modules/checkout/commands/shared.ts +56 -7
  59. package/src/modules/checkout/commands/templates.ts +12 -10
  60. package/src/modules/checkout/commands/transactions.ts +15 -1
  61. package/src/modules/checkout/components/LinkTemplateForm.tsx +52 -21
  62. package/src/modules/checkout/components/PayPage.tsx +76 -58
  63. package/src/modules/checkout/components/__tests__/LinkTemplateForm.localeDecimalSeparator.test.tsx +35 -1
  64. package/src/modules/checkout/components/__tests__/LinkTemplateForm.priceListExactAmount.test.tsx +196 -0
  65. package/src/modules/checkout/components/__tests__/PayPage.amountPrecision.test.tsx +115 -0
  66. package/src/modules/checkout/components/__tests__/PayPagePricing.amountDisplay.test.tsx +98 -0
  67. package/src/modules/checkout/components/__tests__/__fixtures__/legacyPayPageContracts.ts +13 -0
  68. package/src/modules/checkout/components/__tests__/payPageContracts.backwardCompat.test.ts +32 -0
  69. package/src/modules/checkout/data/__tests__/validators.test.ts +91 -0
  70. package/src/modules/checkout/data/entities.ts +7 -6
  71. package/src/modules/checkout/data/validators.ts +26 -2
  72. package/src/modules/checkout/i18n/de.json +1 -0
  73. package/src/modules/checkout/i18n/en.json +1 -0
  74. package/src/modules/checkout/i18n/es.json +1 -0
  75. package/src/modules/checkout/i18n/ko.json +1 -0
  76. package/src/modules/checkout/i18n/pl.json +1 -0
  77. package/src/modules/checkout/lib/__tests__/amountPrecision.test.ts +169 -0
  78. package/src/modules/checkout/lib/__tests__/payPageAmount.test.ts +127 -0
  79. package/src/modules/checkout/lib/__tests__/utils.test.ts +72 -0
  80. package/src/modules/checkout/lib/amountPrecision.ts +152 -0
  81. package/src/modules/checkout/lib/payPageAmount.ts +99 -0
  82. package/src/modules/checkout/lib/utils.ts +85 -28
  83. package/src/modules/checkout/migrations/.snapshot-open-mercato.json +158 -27
  84. package/src/modules/checkout/migrations/Migration20261014082519_checkout.ts +35 -0
  85. package/src/modules/checkout/migrations/__tests__/Migration20261014082519_checkout.integration.test.ts +6 -0
  86. package/src/modules/checkout/workers/__tests__/send-email.worker.test.ts +43 -0
  87. package/src/modules/checkout/workers/send-email.worker.ts +8 -1
@@ -3,9 +3,10 @@ import { ensureOrganizationScope, ensureTenantScope } from '@open-mercato/shared
3
3
  import { extractUndoPayload } from '@open-mercato/shared/lib/commands/undo'
4
4
  import { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'
5
5
  import type { CustomFieldSnapshot } from '@open-mercato/shared/lib/commands/customFieldSnapshots'
6
+ import { resolveExactDecimal } from '@open-mercato/shared/lib/decimal'
6
7
  import { CheckoutLink, CheckoutLinkTemplate } from '../data/entities'
7
8
  import { requireCheckoutScope, type CheckoutScope } from '../lib/utils'
8
- import { serializeTemplateOrLink, toMoneyString } from '../lib/utils'
9
+ import { serializeTemplateOrLink } from '../lib/utils'
9
10
 
10
11
  function isRecord(value: unknown): value is Record<string, unknown> {
11
12
  return !!value && typeof value === 'object' && !Array.isArray(value)
@@ -96,6 +97,44 @@ const PROPAGATED_TEMPLATE_FIELD_KEYS = [
96
97
 
97
98
  type PropagatedTemplateFieldKey = (typeof PROPAGATED_TEMPLATE_FIELD_KEYS)[number]
98
99
 
100
+ const PROPAGATED_TEMPLATE_MONEY_FIELD_KEYS = [
101
+ 'fixedPriceAmount',
102
+ 'fixedPriceOriginalAmount',
103
+ 'customAmountMin',
104
+ 'customAmountMax',
105
+ ] as const satisfies ReadonlyArray<PropagatedTemplateFieldKey>
106
+
107
+ type PropagatedTemplateMoneyFieldKey = (typeof PROPAGATED_TEMPLATE_MONEY_FIELD_KEYS)[number]
108
+
109
+ const PROPAGATED_TEMPLATE_EXACT_FIELD_KEYS = {
110
+ fixedPriceAmount: 'fixedPriceAmountExact',
111
+ fixedPriceOriginalAmount: 'fixedPriceOriginalAmountExact',
112
+ customAmountMin: 'customAmountMinExact',
113
+ customAmountMax: 'customAmountMaxExact',
114
+ } as const satisfies Record<PropagatedTemplateMoneyFieldKey, keyof CheckoutTemplateSnapshot>
115
+
116
+ function isPropagatedTemplateMoneyField(key: PropagatedTemplateFieldKey): key is PropagatedTemplateMoneyFieldKey {
117
+ return (PROPAGATED_TEMPLATE_MONEY_FIELD_KEYS as ReadonlyArray<PropagatedTemplateFieldKey>).includes(key)
118
+ }
119
+
120
+ function readExactMoneyField(snapshot: CheckoutTemplateSnapshot, key: PropagatedTemplateMoneyFieldKey): string | null {
121
+ return resolveExactDecimal(snapshot[PROPAGATED_TEMPLATE_EXACT_FIELD_KEYS[key]], snapshot[key])
122
+ }
123
+
124
+ function normalizePriceListItemsForComparison(items: unknown): unknown {
125
+ if (!Array.isArray(items)) return items
126
+ return items.map((item) => {
127
+ if (!isRecord(item)) return item
128
+ const { amountExact, ...rest } = item
129
+ return { ...rest, amount: resolveExactDecimal(amountExact, rest.amount) }
130
+ })
131
+ }
132
+
133
+ function readPropagatedTemplateField(snapshot: CheckoutTemplateSnapshot, key: PropagatedTemplateFieldKey): unknown {
134
+ if (key === 'priceListItems') return normalizePriceListItemsForComparison(snapshot.priceListItems)
135
+ return isPropagatedTemplateMoneyField(key) ? readExactMoneyField(snapshot, key) : snapshot[key]
136
+ }
137
+
99
138
  function cloneJson<T>(value: T): T {
100
139
  if (value == null) return value
101
140
  return JSON.parse(JSON.stringify(value)) as T
@@ -133,6 +172,14 @@ function copyPropagatedTemplateField<K extends PropagatedTemplateFieldKey>(
133
172
  snapshot[key] = cloneJson(nextTemplate[key]) as CheckoutLinkSnapshot[K]
134
173
  }
135
174
 
175
+ function copyPropagatedExactMoneyField(
176
+ snapshot: CheckoutLinkSnapshot,
177
+ nextTemplate: CheckoutTemplateSnapshot,
178
+ key: PropagatedTemplateMoneyFieldKey,
179
+ ): void {
180
+ snapshot[PROPAGATED_TEMPLATE_EXACT_FIELD_KEYS[key]] = readExactMoneyField(nextTemplate, key)
181
+ }
182
+
136
183
  export function captureTemplateSnapshot(
137
184
  record: CheckoutLinkTemplate,
138
185
  custom?: CustomFieldSnapshot,
@@ -169,9 +216,11 @@ export function buildSelectiveLinkedLinkSnapshot(
169
216
  const snapshot = cloneJson(current)
170
217
 
171
218
  for (const key of PROPAGATED_TEMPLATE_FIELD_KEYS) {
172
- if (!valuesEqual(current[key], previousTemplate[key])) continue
173
- if (valuesEqual(current[key], nextTemplate[key])) continue
219
+ const currentValue = readPropagatedTemplateField(current, key)
220
+ if (!valuesEqual(currentValue, readPropagatedTemplateField(previousTemplate, key))) continue
221
+ if (valuesEqual(currentValue, readPropagatedTemplateField(nextTemplate, key))) continue
174
222
  copyPropagatedTemplateField(snapshot, nextTemplate, key)
223
+ if (isPropagatedTemplateMoneyField(key)) copyPropagatedExactMoneyField(snapshot, nextTemplate, key)
175
224
  changed = true
176
225
  }
177
226
 
@@ -221,12 +270,12 @@ function buildTemplateSnapshotData(snapshot: CheckoutTemplateSnapshot) {
221
270
  backgroundColor: snapshot.backgroundColor ?? null,
222
271
  themeMode: snapshot.themeMode,
223
272
  pricingMode: snapshot.pricingMode,
224
- fixedPriceAmount: toMoneyString(snapshot.fixedPriceAmount),
273
+ fixedPriceAmount: resolveExactDecimal(snapshot.fixedPriceAmountExact, snapshot.fixedPriceAmount),
225
274
  fixedPriceCurrencyCode: snapshot.fixedPriceCurrencyCode ?? null,
226
275
  fixedPriceIncludesTax: snapshot.fixedPriceIncludesTax,
227
- fixedPriceOriginalAmount: toMoneyString(snapshot.fixedPriceOriginalAmount),
228
- customAmountMin: toMoneyString(snapshot.customAmountMin),
229
- customAmountMax: toMoneyString(snapshot.customAmountMax),
276
+ fixedPriceOriginalAmount: resolveExactDecimal(snapshot.fixedPriceOriginalAmountExact, snapshot.fixedPriceOriginalAmount),
277
+ customAmountMin: resolveExactDecimal(snapshot.customAmountMinExact, snapshot.customAmountMin),
278
+ customAmountMax: resolveExactDecimal(snapshot.customAmountMaxExact, snapshot.customAmountMax),
230
279
  customAmountCurrencyCode: snapshot.customAmountCurrencyCode ?? null,
231
280
  priceListItems: cloneJson(snapshot.priceListItems ?? []),
232
281
  gatewayProviderKey: snapshot.gatewayProviderKey ?? null,
@@ -23,9 +23,10 @@ import {
23
23
  hashCheckoutPassword,
24
24
  parseCheckoutInput,
25
25
  serializeTemplateOrLink,
26
- toMoneyString,
26
+ toTemplateOrLinkMutationInput,
27
27
  validateDescriptorCurrencies,
28
28
  } from '../lib/utils'
29
+ import { roundCheckoutConfiguredAmounts, toStoredCheckoutAmounts } from '../lib/amountPrecision'
29
30
  import {
30
31
  buildSelectiveLinkedCustomFieldUpdates,
31
32
  buildSelectiveLinkedLinkSnapshot,
@@ -115,14 +116,12 @@ const createTemplateCommand: CommandHandler<Record<string, unknown>, { id: strin
115
116
  ensurePayerFieldsCollected(parsed)
116
117
  const em = ctx.container.resolve('em') as EntityManager
117
118
  const dataEngine = ctx.container.resolve('dataEngine') as DataEngine
119
+ const roundedInput = await roundCheckoutConfiguredAmounts(ctx.container, scope, parsed)
118
120
  const template = em.create(CheckoutLinkTemplate, {
119
121
  organizationId: scope.organizationId,
120
122
  tenantId: scope.tenantId,
121
- ...parsed,
122
- fixedPriceAmount: toMoneyString(parsed.fixedPriceAmount),
123
- fixedPriceOriginalAmount: toMoneyString(parsed.fixedPriceOriginalAmount),
124
- customAmountMin: toMoneyString(parsed.customAmountMin),
125
- customAmountMax: toMoneyString(parsed.customAmountMax),
123
+ ...roundedInput,
124
+ ...toStoredCheckoutAmounts(roundedInput),
126
125
  passwordHash: await hashCheckoutPassword(parsed.password),
127
126
  } as any)
128
127
  em.persist(template)
@@ -297,12 +296,15 @@ const updateTemplateCommand: CommandHandler<Record<string, unknown>, { ok: true
297
296
  const passwordHash = parsed.password !== undefined
298
297
  ? await hashCheckoutPassword(parsed.password)
299
298
  : template.passwordHash
299
+ const roundedValues = await roundCheckoutConfiguredAmounts(
300
+ ctx.container,
301
+ scope,
302
+ toTemplateOrLinkMutationInput(template, parsed),
303
+ )
300
304
  Object.assign(template, {
301
305
  ...parsed,
302
- fixedPriceAmount: parsed.fixedPriceAmount !== undefined ? toMoneyString(parsed.fixedPriceAmount) : template.fixedPriceAmount,
303
- fixedPriceOriginalAmount: parsed.fixedPriceOriginalAmount !== undefined ? toMoneyString(parsed.fixedPriceOriginalAmount) : template.fixedPriceOriginalAmount,
304
- customAmountMin: parsed.customAmountMin !== undefined ? toMoneyString(parsed.customAmountMin) : template.customAmountMin,
305
- customAmountMax: parsed.customAmountMax !== undefined ? toMoneyString(parsed.customAmountMax) : template.customAmountMax,
306
+ ...toStoredCheckoutAmounts(roundedValues),
307
+ priceListItems: roundedValues.priceListItems,
306
308
  passwordHash,
307
309
  })
308
310
  await em.flush()
@@ -13,6 +13,9 @@ import {
13
13
  toMoneyString,
14
14
  } from '../lib/utils'
15
15
  import { assertValidCheckoutStatusTransition } from '../lib/transaction-status-machine'
16
+ import { decimalToString, roundDecimal } from '@open-mercato/shared/lib/decimal'
17
+ import { resolveCurrencyDecimalPlaces } from '@open-mercato/shared/lib/currencyPrecision'
18
+ import { DEFAULT_CHECKOUT_DECIMAL_PLACES } from '../lib/amountPrecision'
16
19
 
17
20
  function resolveTransactionScope(input: { tenantId?: string | null; organizationId?: string | null }) {
18
21
  if (!input.organizationId || !input.tenantId) {
@@ -32,6 +35,7 @@ type CheckoutTerminalEventPayload = {
32
35
  status: CheckoutTransaction['status']
33
36
  paymentStatus: string | null
34
37
  amount: number
38
+ amountExact?: string | null
35
39
  currency: string
36
40
  gatewayProvider: string | null
37
41
  gatewayTransactionId: string | null
@@ -46,6 +50,13 @@ const createTransactionCommand: CommandHandler<Record<string, unknown>, { id: st
46
50
  const { parsed } = parseCheckoutInput(rawInput, transactionCreateSchema.parse)
47
51
  const scope = resolveTransactionScope(parsed)
48
52
  const em = ctx.container.resolve('em') as EntityManager
53
+ const currencyDecimalPlaces =
54
+ (await resolveCurrencyDecimalPlaces(ctx.container, {
55
+ code: parsed.currencyCode,
56
+ tenantId: scope.tenantId,
57
+ organizationId: scope.organizationId,
58
+ })) ?? DEFAULT_CHECKOUT_DECIMAL_PLACES
59
+ const chargedAmount = roundDecimal(parsed.amountExact ?? parsed.amount, currencyDecimalPlaces)
49
60
  let lockedLinkId: string | null = null
50
61
  let lockedLinkSlug: string | null = null
51
62
  let lockedLinkTemplateId: string | null = null
@@ -68,7 +79,7 @@ const createTransactionCommand: CommandHandler<Record<string, unknown>, { id: st
68
79
  ...parsed,
69
80
  organizationId: scope.organizationId,
70
81
  tenantId: scope.tenantId,
71
- amount: toMoneyString(parsed.amount) ?? '0.00',
82
+ amount: decimalToString(chargedAmount),
72
83
  status: 'processing',
73
84
  })
74
85
  tx.persist(transaction)
@@ -115,6 +126,7 @@ const createTransactionCommand: CommandHandler<Record<string, unknown>, { id: st
115
126
  linkId: transaction.linkId,
116
127
  status: transaction.status,
117
128
  amount: Number(transaction.amount),
129
+ amountExact: toMoneyString(transaction.amount),
118
130
  currency: transaction.currencyCode,
119
131
  tenantId: scope.tenantId,
120
132
  organizationId: scope.organizationId,
@@ -127,6 +139,7 @@ const createTransactionCommand: CommandHandler<Record<string, unknown>, { id: st
127
139
  status: transaction.status,
128
140
  paymentStatus: transaction.paymentStatus ?? null,
129
141
  amount: Number(transaction.amount),
142
+ amountExact: toMoneyString(transaction.amount),
130
143
  currency: transaction.currencyCode,
131
144
  gatewayProvider: lockedLinkGatewayProvider,
132
145
  gatewayTransactionId: transaction.gatewayTransactionId ?? null,
@@ -268,6 +281,7 @@ const updateTransactionStatusCommand: CommandHandler<Record<string, unknown>, {
268
281
  status: transaction.status,
269
282
  paymentStatus: transaction.paymentStatus ?? null,
270
283
  amount: Number(transaction.amount),
284
+ amountExact: toMoneyString(transaction.amount),
271
285
  currency: transaction.currencyCode,
272
286
  gatewayProvider: link.gatewayProviderKey ?? null,
273
287
  gatewayTransactionId: transaction.gatewayTransactionId ?? null,
@@ -3,7 +3,8 @@
3
3
  import * as React from 'react'
4
4
  import { useSearchParams } from 'next/navigation'
5
5
  import { useT, useLocale, type TranslateFn } from '@open-mercato/shared/lib/i18n/context'
6
- import { formatLocaleNumberInput, parseLocaleNumber } from '@open-mercato/shared/lib/number'
6
+ import { formatLocaleDecimalInput, formatLocaleNumberInput, parseLocaleDecimal } from '@open-mercato/shared/lib/number'
7
+ import { decimalToNumber, decimalToString, resolveExactDecimal } from '@open-mercato/shared/lib/decimal'
7
8
  import {
8
9
  AlertTriangle,
9
10
  BadgeCheck,
@@ -88,7 +89,7 @@ type LegalDocumentsValue = {
88
89
 
89
90
  type PriceListItem = PriceListItemInput
90
91
  // `amount` stays a raw locale-typed string while a row is being edited (issue #5828) —
91
- // converted to a number only at submit time.
92
+ // converted to an exact decimal string only at submit time.
92
93
  type PriceListEditorItem = Omit<PriceListItem, 'amount'> & { amount: number | string }
93
94
 
94
95
  const DEFAULT_COLORS = {
@@ -116,16 +117,24 @@ function readNumberInputValue(value: unknown, locale?: string): string {
116
117
 
117
118
  // Money fields stay a raw locale-typed string while being edited (issue #5828) so an
118
119
  // in-progress decimal separator is never dropped mid-keystroke; this converts to the
119
- // canonical number the API expects right before submission.
120
- export function toSubmittedAmount(value: unknown, locale?: string): number | null {
121
- if (typeof value === 'number') return Number.isFinite(value) ? value : null
120
+ // canonical exact decimal string the API accepts right before submission, so no digit is
121
+ // lost to a float.
122
+ export function toSubmittedAmountExact(value: unknown, locale?: string): string | null {
123
+ if (typeof value === 'number') return Number.isFinite(value) ? decimalToString(value) : null
122
124
  if (typeof value !== 'string') return null
123
125
  if (!value.trim()) return null
124
- return parseLocaleNumber(value, locale)
126
+ return parseLocaleDecimal(value, locale)
127
+ }
128
+
129
+ /** Float copy of {@link toSubmittedAmountExact}. */
130
+ export function toSubmittedAmount(value: unknown, locale?: string): number | null {
131
+ const exact = toSubmittedAmountExact(value, locale)
132
+ return exact === null ? null : decimalToNumber(exact)
125
133
  }
126
134
 
135
+
127
136
  function isUnparseableAmount(value: unknown, locale?: string): boolean {
128
- return typeof value === 'string' && value.trim().length > 0 && toSubmittedAmount(value, locale) === null
137
+ return typeof value === 'string' && value.trim().length > 0 && toSubmittedAmountExact(value, locale) === null
129
138
  }
130
139
 
131
140
  // `toSubmittedAmount` turns unparseable text into `null`, which the API then reads as "no
@@ -231,6 +240,17 @@ function normalizePriceListItems(value: unknown): PriceListEditorItem[] {
231
240
  .filter((item): item is PriceListEditorItem => item !== null)
232
241
  }
233
242
 
243
+ function hydratePriceListItems(value: unknown, locale?: string): PriceListEditorItem[] {
244
+ if (!Array.isArray(value)) return []
245
+ return normalizePriceListItems(
246
+ value.map((item) => {
247
+ if (!isRecord(item)) return item
248
+ const amount = toAmountInputValue(resolveExactDecimal(item.amountExact, item.amount), locale)
249
+ return amount === null ? item : { ...item, amount }
250
+ }),
251
+ )
252
+ }
253
+
234
254
  function normalizeCustomerFields(value: unknown, t?: TranslateFn): CustomerFieldDefinitionInput[] {
235
255
  if (!Array.isArray(value)) return cloneDefaultCustomerFields(t)
236
256
  return value.reduce<CustomerFieldDefinitionInput[]>((result, field, index) => {
@@ -285,7 +305,11 @@ function normalizeLegalDocuments(value: unknown): LegalDocumentsValue {
285
305
  }
286
306
  }
287
307
 
288
- function normalizeFormValues(value: FormValues | null | undefined, t?: TranslateFn): FormValues {
308
+ function toAmountInputValue(exact: string | null, locale?: string): string | null {
309
+ return exact === null ? null : formatLocaleDecimalInput(exact, locale)
310
+ }
311
+
312
+ export function normalizeFormValues(value: FormValues | null | undefined, t?: TranslateFn, locale?: string): FormValues {
289
313
  const defaults = createDefaultValues(t)
290
314
  const source = isRecord(value) ? value : {}
291
315
  const customFields = isRecord(source.customFields) ? source.customFields : {}
@@ -309,7 +333,14 @@ function normalizeFormValues(value: FormValues | null | undefined, t?: Translate
309
333
  collectCustomerDetails: readBoolean(source.collectCustomerDetails, true),
310
334
  customerFieldsSchema: normalizeCustomerFields(source.customerFieldsSchema, t),
311
335
  legalDocuments: normalizeLegalDocuments(source.legalDocuments),
312
- priceListItems: normalizePriceListItems(source.priceListItems),
336
+ priceListItems: hydratePriceListItems(source.priceListItems, locale),
337
+ fixedPriceAmount: toAmountInputValue(resolveExactDecimal(source.fixedPriceAmountExact, source.fixedPriceAmount), locale),
338
+ fixedPriceOriginalAmount: toAmountInputValue(
339
+ resolveExactDecimal(source.fixedPriceOriginalAmountExact, source.fixedPriceOriginalAmount),
340
+ locale,
341
+ ),
342
+ customAmountMin: toAmountInputValue(resolveExactDecimal(source.customAmountMinExact, source.customAmountMin), locale),
343
+ customAmountMax: toAmountInputValue(resolveExactDecimal(source.customAmountMaxExact, source.customAmountMax), locale),
313
344
  fixedPriceCurrencyCode: readString(source.fixedPriceCurrencyCode).trim().toUpperCase() || 'USD',
314
345
  customAmountCurrencyCode: readString(source.customAmountCurrencyCode).trim().toUpperCase() || 'USD',
315
346
  sendStartEmail: readBoolean(source.sendStartEmail, true),
@@ -1403,7 +1434,7 @@ export function LinkTemplateForm({ mode, recordId }: Props) {
1403
1434
  const [isApplyingTemplate, setIsApplyingTemplate] = React.useState(false)
1404
1435
  const [formInstanceKey, setFormInstanceKey] = React.useState(0)
1405
1436
  const [initialValues, setInitialValues] = React.useState<FormValues | null>(
1406
- recordId ? null : normalizeFormValues(createDefaultValues(t), t),
1437
+ recordId ? null : normalizeFormValues(createDefaultValues(t), t, locale),
1407
1438
  )
1408
1439
  const [notFound, setNotFound] = React.useState(false)
1409
1440
 
@@ -1465,7 +1496,7 @@ export function LinkTemplateForm({ mode, recordId }: Props) {
1465
1496
  const applyTemplate = React.useCallback(async (nextTemplateId: string | null) => {
1466
1497
  if (recordId || mode !== 'link') return
1467
1498
  if (!nextTemplateId) {
1468
- replaceInitialValues(normalizeFormValues(createDefaultValues(t), t))
1499
+ replaceInitialValues(normalizeFormValues(createDefaultValues(t), t, locale))
1469
1500
  return
1470
1501
  }
1471
1502
  setIsApplyingTemplate(true)
@@ -1483,12 +1514,12 @@ export function LinkTemplateForm({ mode, recordId }: Props) {
1483
1514
  ...result,
1484
1515
  slug: '',
1485
1516
  templateId: nextTemplateId,
1486
- }, t),
1517
+ }, t, locale),
1487
1518
  )
1488
1519
  } finally {
1489
1520
  setIsApplyingTemplate(false)
1490
1521
  }
1491
- }, [mode, recordId, rememberTemplateOptions, replaceInitialValues, t])
1522
+ }, [locale, mode, recordId, rememberTemplateOptions, replaceInitialValues, t])
1492
1523
 
1493
1524
  React.useEffect(() => {
1494
1525
  if (mode !== 'link' || recordId) return
@@ -1503,7 +1534,7 @@ export function LinkTemplateForm({ mode, recordId }: Props) {
1503
1534
  void readApiResultOrThrow<FormValues>(`/api/checkout/${mode === 'link' ? 'links' : 'templates'}/${encodeURIComponent(recordId)}`)
1504
1535
  .then((result) => {
1505
1536
  if (!active) return
1506
- replaceInitialValues(normalizeFormValues(result, t))
1537
+ replaceInitialValues(normalizeFormValues(result, t, locale))
1507
1538
  })
1508
1539
  .catch((error) => {
1509
1540
  if (!active) return
@@ -1511,12 +1542,12 @@ export function LinkTemplateForm({ mode, recordId }: Props) {
1511
1542
  setNotFound(true)
1512
1543
  return
1513
1544
  }
1514
- replaceInitialValues(normalizeFormValues({}, t))
1545
+ replaceInitialValues(normalizeFormValues({}, t, locale))
1515
1546
  })
1516
1547
  return () => {
1517
1548
  active = false
1518
1549
  }
1519
- }, [mode, recordId, replaceInitialValues, t])
1550
+ }, [locale, mode, recordId, replaceInitialValues, t])
1520
1551
 
1521
1552
  React.useEffect(() => {
1522
1553
  if (recordId || mode !== 'link' || !templateId) return
@@ -1748,13 +1779,13 @@ export function LinkTemplateForm({ mode, recordId }: Props) {
1748
1779
  const payload = {
1749
1780
  ...values,
1750
1781
  status: submitIntent === 'publish' ? 'active' : values.status,
1751
- fixedPriceAmount: toSubmittedAmount(values.fixedPriceAmount, locale),
1752
- fixedPriceOriginalAmount: toSubmittedAmount(values.fixedPriceOriginalAmount, locale),
1753
- customAmountMin: toSubmittedAmount(values.customAmountMin, locale),
1754
- customAmountMax: toSubmittedAmount(values.customAmountMax, locale),
1782
+ fixedPriceAmount: toSubmittedAmountExact(values.fixedPriceAmount, locale),
1783
+ fixedPriceOriginalAmount: toSubmittedAmountExact(values.fixedPriceOriginalAmount, locale),
1784
+ customAmountMin: toSubmittedAmountExact(values.customAmountMin, locale),
1785
+ customAmountMax: toSubmittedAmountExact(values.customAmountMax, locale),
1755
1786
  priceListItems: normalizePriceListItems(values.priceListItems).map((item) => ({
1756
1787
  ...item,
1757
- amount: toSubmittedAmount(item.amount, locale) ?? Number.NaN,
1788
+ amount: toSubmittedAmountExact(item.amount, locale) ?? Number.NaN,
1758
1789
  })),
1759
1790
  customFields: collectCustomFieldValues(values),
1760
1791
  }