@open-mercato/checkout 0.10.1-develop.8289.1.9a25111d49 → 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
@@ -38,7 +38,16 @@ import {
38
38
  getCheckoutCustomerFieldSemanticType,
39
39
  validateCheckoutCustomerData,
40
40
  } from '../lib/customerDataValidation'
41
+ import {
42
+ applyPayPageAmountValue,
43
+ buildPayPageSubmitBody,
44
+ formatPayPageAmount,
45
+ parsePayPageAmountInput,
46
+ toPayPageAmount,
47
+ validatePayPageCustomAmount,
48
+ } from '../lib/payPageAmount'
41
49
  import { createLogger } from '@open-mercato/shared/lib/logger'
50
+ import { resolveExactDecimal } from '@open-mercato/shared/lib/decimal'
42
51
 
43
52
  const logger = createLogger('checkout').child({ component: 'PayPage' })
44
53
 
@@ -60,6 +69,7 @@ type PriceListItem = {
60
69
  id: string
61
70
  description: string
62
71
  amount: number
72
+ amountExact?: string | null
63
73
  currencyCode: string
64
74
  }
65
75
 
@@ -81,10 +91,14 @@ export type PayLinkPayload = {
81
91
  status?: 'draft' | 'active' | 'inactive'
82
92
  pricingMode: 'fixed' | 'custom_amount' | 'price_list'
83
93
  fixedPriceAmount?: number | null
94
+ fixedPriceAmountExact?: string | null
84
95
  fixedPriceCurrencyCode?: string | null
85
96
  fixedPriceOriginalAmount?: number | null
97
+ fixedPriceOriginalAmountExact?: string | null
86
98
  customAmountMin?: number | null
99
+ customAmountMinExact?: string | null
87
100
  customAmountMax?: number | null
101
+ customAmountMaxExact?: string | null
88
102
  customAmountCurrencyCode?: string | null
89
103
  priceListItems?: PriceListItem[]
90
104
  collectCustomerDetails?: boolean
@@ -122,6 +136,7 @@ type PayPageSubmitData = {
122
136
  customerData: Record<string, unknown>
123
137
  acceptedLegalConsents: Record<string, boolean>
124
138
  amount: number | null
139
+ amountExact: string | null
125
140
  selectedPriceItemId: string | null
126
141
  }
127
142
 
@@ -207,10 +222,11 @@ export type PayPageCustomerFormProps = {
207
222
  export type PayPagePricingProps = {
208
223
  payload: PayLinkPayload
209
224
  amount: number | null
225
+ amountExact?: string | null
210
226
  selectedPriceItemId: string | null
211
227
  fieldErrors: FieldErrors
212
228
  inputsLocked: boolean
213
- formatAmount: (value: number | null | undefined, currencyCode?: string | null) => string
229
+ formatAmount: (value: number | null | undefined, currencyCode?: string | null, exact?: string | null) => string
214
230
  onAmountChange: (value: string) => void
215
231
  onPriceItemSelect: (item: PriceListItem) => void
216
232
  translateValidationMessage: (message: string | null | undefined, fieldPath?: string) => string
@@ -220,8 +236,9 @@ export type PayPagePricingProps = {
220
236
  export type PayPageSummaryProps = {
221
237
  payload: PayLinkPayload
222
238
  selectedAmount: number | null
239
+ selectedAmountExact?: string | null
223
240
  currencyCode: string | null
224
- formatAmount: (value: number | null | undefined, currencyCode?: string | null) => string
241
+ formatAmount: (value: number | null | undefined, currencyCode?: string | null, exact?: string | null) => string
225
242
  preview: boolean
226
243
  themeTokens: PayPageThemeTokens
227
244
  }
@@ -320,13 +337,6 @@ function readTranslatedErrorMessage(
320
337
  return translate(readErrorMessage(error, fallback), fallback)
321
338
  }
322
339
 
323
- function parseNumericInput(value: string): number | null {
324
- const trimmed = value.trim()
325
- if (!trimmed) return null
326
- const parsed = Number(trimmed)
327
- return Number.isFinite(parsed) ? parsed : null
328
- }
329
-
330
340
  function setSubmitDataFieldValue(
331
341
  data: PayPageSubmitData,
332
342
  fieldPath: string,
@@ -358,7 +368,7 @@ function setSubmitDataFieldValue(
358
368
  if (fieldPath === 'amount') {
359
369
  return {
360
370
  ...data,
361
- amount: typeof value === 'number' && Number.isFinite(value) ? value : null,
371
+ ...applyPayPageAmountValue(data, value),
362
372
  }
363
373
  }
364
374
  if (fieldPath === 'selectedPriceItemId') {
@@ -920,6 +930,7 @@ export function PayPageCustomerForm({
920
930
  export function PayPagePricing({
921
931
  payload,
922
932
  amount,
933
+ amountExact,
923
934
  selectedPriceItemId,
924
935
  fieldErrors,
925
936
  inputsLocked,
@@ -944,11 +955,11 @@ export function PayPagePricing({
944
955
  <div className="rounded-xl border p-5" style={buildPanelStyle(themeTokens, 'default')}>
945
956
  {typeof payload.fixedPriceOriginalAmount === 'number' ? (
946
957
  <div className="text-sm line-through" style={{ color: themeTokens.mutedText }}>
947
- {formatAmount(payload.fixedPriceOriginalAmount, payload.fixedPriceCurrencyCode)}
958
+ {formatAmount(payload.fixedPriceOriginalAmount, payload.fixedPriceCurrencyCode, resolveExactDecimal(payload.fixedPriceOriginalAmountExact, payload.fixedPriceOriginalAmount))}
948
959
  </div>
949
960
  ) : null}
950
961
  <div className="mt-1 text-4xl font-semibold">
951
- {formatAmount(payload.fixedPriceAmount, payload.fixedPriceCurrencyCode)}
962
+ {formatAmount(payload.fixedPriceAmount, payload.fixedPriceCurrencyCode, resolveExactDecimal(payload.fixedPriceAmountExact, payload.fixedPriceAmount))}
952
963
  </div>
953
964
  </div>
954
965
  ) : null}
@@ -959,12 +970,16 @@ export function PayPagePricing({
959
970
  <Input
960
971
  className={READABLE_INPUT_CLASSNAME}
961
972
  type="number"
962
- value={amount ?? ''}
973
+ value={amountExact ?? amount ?? ''}
963
974
  disabled={inputsLocked}
964
975
  onChange={(event) => onAmountChange(event.target.value)}
965
976
  placeholder={[
966
- payload.customAmountMin != null ? formatAmount(payload.customAmountMin, payload.customAmountCurrencyCode) : null,
967
- payload.customAmountMax != null ? formatAmount(payload.customAmountMax, payload.customAmountCurrencyCode) : null,
977
+ payload.customAmountMin != null
978
+ ? formatAmount(payload.customAmountMin, payload.customAmountCurrencyCode, resolveExactDecimal(payload.customAmountMinExact, payload.customAmountMin))
979
+ : null,
980
+ payload.customAmountMax != null
981
+ ? formatAmount(payload.customAmountMax, payload.customAmountCurrencyCode, resolveExactDecimal(payload.customAmountMaxExact, payload.customAmountMax))
982
+ : null,
968
983
  ].filter(Boolean).join(' - ')}
969
984
  style={buildReadableInputStyle(themeTokens, Boolean(fieldErrors.amount), inputsLocked)}
970
985
  />
@@ -1007,7 +1022,7 @@ export function PayPagePricing({
1007
1022
  />
1008
1023
  <span className="font-medium">{item.description}</span>
1009
1024
  </span>
1010
- <span className="whitespace-nowrap font-semibold">{formatAmount(item.amount, item.currencyCode)}</span>
1025
+ <span className="whitespace-nowrap font-semibold">{formatAmount(item.amount, item.currencyCode, resolveExactDecimal(item.amountExact, item.amount))}</span>
1011
1026
  </label>
1012
1027
  ))}
1013
1028
  </RadioGroup>
@@ -1025,6 +1040,7 @@ export function PayPagePricing({
1025
1040
  export function PayPageSummary({
1026
1041
  payload,
1027
1042
  selectedAmount,
1043
+ selectedAmountExact,
1028
1044
  currencyCode,
1029
1045
  formatAmount,
1030
1046
  preview,
@@ -1032,7 +1048,7 @@ export function PayPageSummary({
1032
1048
  }: PayPageSummaryProps) {
1033
1049
  const t = useT()
1034
1050
  const amountLabel = selectedAmount != null && currencyCode
1035
- ? formatAmount(selectedAmount, currencyCode)
1051
+ ? formatAmount(selectedAmount, currencyCode, resolveExactDecimal(selectedAmountExact, selectedAmount))
1036
1052
  : t('checkout.payPage.summary.awaitingSelection', 'Select an amount')
1037
1053
 
1038
1054
  return (
@@ -1485,6 +1501,7 @@ export function PayPage({
1485
1501
  const [customerData, setCustomerData] = React.useState<Record<string, unknown>>({})
1486
1502
  const [acceptedLegalConsents, setAcceptedLegalConsents] = React.useState<Record<string, boolean>>({})
1487
1503
  const [amount, setAmount] = React.useState<number | null>(null)
1504
+ const [amountExact, setAmountExact] = React.useState<string | null>(null)
1488
1505
  const [selectedPriceItemId, setSelectedPriceItemId] = React.useState<string | null>(null)
1489
1506
  const [submissionError, setSubmissionError] = React.useState<string | null>(null)
1490
1507
  const [fieldErrors, setFieldErrors] = React.useState<FieldErrors>({})
@@ -1511,7 +1528,9 @@ export function PayPage({
1511
1528
  setPaymentSession(null)
1512
1529
  setActiveTransactionId(null)
1513
1530
  if (result.pricingMode === 'fixed' && typeof result.fixedPriceAmount === 'number') {
1514
- setAmount(result.fixedPriceAmount)
1531
+ const fixedAmount = toPayPageAmount(result.fixedPriceAmount, result.fixedPriceAmountExact)
1532
+ setAmount(fixedAmount.amount)
1533
+ setAmountExact(fixedAmount.amountExact)
1515
1534
  }
1516
1535
  } catch (error) {
1517
1536
  setPayload(null)
@@ -1530,7 +1549,9 @@ export function PayPage({
1530
1549
  React.useEffect(() => {
1531
1550
  if (!payload) return
1532
1551
  if (payload.pricingMode === 'fixed' && typeof payload.fixedPriceAmount === 'number') {
1533
- setAmount(payload.fixedPriceAmount)
1552
+ const fixedAmount = toPayPageAmount(payload.fixedPriceAmount, payload.fixedPriceAmountExact)
1553
+ setAmount(fixedAmount.amount)
1554
+ setAmountExact(fixedAmount.amountExact)
1534
1555
  return
1535
1556
  }
1536
1557
  if (payload.pricingMode !== 'price_list') {
@@ -1538,23 +1559,11 @@ export function PayPage({
1538
1559
  }
1539
1560
  }, [payload])
1540
1561
 
1541
- const formatAmount = React.useCallback((value: number | null | undefined, currencyCode?: string | null) => {
1542
- const normalizedValue = typeof value === 'number' && Number.isFinite(value) ? value : 0
1543
- if (currencyCode) {
1544
- try {
1545
- return new Intl.NumberFormat(locale, {
1546
- style: 'currency',
1547
- currency: currencyCode,
1548
- }).format(normalizedValue)
1549
- } catch {
1550
- return `${normalizedValue.toFixed(2)} ${currencyCode}`
1551
- }
1552
- }
1553
- return new Intl.NumberFormat(locale, {
1554
- minimumFractionDigits: 2,
1555
- maximumFractionDigits: 2,
1556
- }).format(normalizedValue)
1557
- }, [locale])
1562
+ const formatAmount = React.useCallback(
1563
+ (value: number | null | undefined, currencyCode?: string | null, exact?: string | null) =>
1564
+ formatPayPageAmount(value, currencyCode, locale, exact),
1565
+ [locale],
1566
+ )
1558
1567
 
1559
1568
  const isPreview = payload?.preview === true || previewRequested
1560
1569
  const selectedPriceItem = payload?.priceListItems?.find((item) => item.id === selectedPriceItemId) ?? null
@@ -1562,6 +1571,9 @@ export function PayPage({
1562
1571
  && payload.collectCustomerDetails !== false
1563
1572
  && (payload.customerFieldsSchema?.length ?? 0) > 0
1564
1573
  const effectiveAmount = selectedPriceItem?.amount ?? amount
1574
+ const effectiveAmountExact = selectedPriceItem
1575
+ ? toPayPageAmount(selectedPriceItem.amount, selectedPriceItem.amountExact).amountExact
1576
+ : amountExact
1565
1577
  const effectiveCurrencyCode = selectedPriceItem?.currencyCode
1566
1578
  ?? payload?.fixedPriceCurrencyCode
1567
1579
  ?? payload?.customAmountCurrencyCode
@@ -1572,8 +1584,9 @@ export function PayPage({
1572
1584
  customerData,
1573
1585
  acceptedLegalConsents,
1574
1586
  amount: effectiveAmount ?? null,
1587
+ amountExact: effectiveAmountExact ?? null,
1575
1588
  selectedPriceItemId,
1576
- }), [acceptedLegalConsents, customerData, effectiveAmount, selectedPriceItemId])
1589
+ }), [acceptedLegalConsents, customerData, effectiveAmount, effectiveAmountExact, selectedPriceItemId])
1577
1590
 
1578
1591
  const resolveFieldLabel = React.useCallback((fieldPath: string): string => {
1579
1592
  if (!payload) return t('checkout.payPage.validation.thisField', 'this field')
@@ -1627,6 +1640,7 @@ export function PayPage({
1627
1640
  setCustomerData(nextData.customerData)
1628
1641
  setAcceptedLegalConsents(nextData.acceptedLegalConsents)
1629
1642
  setAmount(nextData.amount)
1643
+ setAmountExact(nextData.amountExact ?? null)
1630
1644
  setSelectedPriceItemId(nextData.selectedPriceItemId)
1631
1645
  }, [])
1632
1646
 
@@ -1642,23 +1656,24 @@ export function PayPage({
1642
1656
  }
1643
1657
 
1644
1658
  if (payload.pricingMode === 'custom_amount') {
1645
- if (effectiveAmount == null || !Number.isFinite(effectiveAmount)) {
1659
+ const amountIssue = validatePayPageCustomAmount(payload, {
1660
+ amount: effectiveAmount ?? null,
1661
+ amountExact: effectiveAmountExact ?? null,
1662
+ })
1663
+ if (amountIssue === 'required') {
1646
1664
  nextErrors.amount = 'checkout.payPage.validation.amountRequired'
1647
- } else {
1648
- if (payload.customAmountMin != null && effectiveAmount < payload.customAmountMin) {
1649
- nextErrors.amount = t(
1650
- 'checkout.payPage.validation.amountMin',
1651
- 'Enter at least {amount}.',
1652
- { amount: formatAmount(payload.customAmountMin, payload.customAmountCurrencyCode) },
1653
- )
1654
- }
1655
- if (payload.customAmountMax != null && effectiveAmount > payload.customAmountMax) {
1656
- nextErrors.amount = t(
1657
- 'checkout.payPage.validation.amountMax',
1658
- 'Enter no more than {amount}.',
1659
- { amount: formatAmount(payload.customAmountMax, payload.customAmountCurrencyCode) },
1660
- )
1661
- }
1665
+ } else if (amountIssue === 'min') {
1666
+ nextErrors.amount = t(
1667
+ 'checkout.payPage.validation.amountMin',
1668
+ 'Enter at least {amount}.',
1669
+ { amount: formatAmount(payload.customAmountMin, payload.customAmountCurrencyCode, resolveExactDecimal(payload.customAmountMinExact, payload.customAmountMin)) },
1670
+ )
1671
+ } else if (amountIssue === 'max') {
1672
+ nextErrors.amount = t(
1673
+ 'checkout.payPage.validation.amountMax',
1674
+ 'Enter no more than {amount}.',
1675
+ { amount: formatAmount(payload.customAmountMax, payload.customAmountCurrencyCode, resolveExactDecimal(payload.customAmountMaxExact, payload.customAmountMax)) },
1676
+ )
1662
1677
  }
1663
1678
  }
1664
1679
 
@@ -1678,6 +1693,7 @@ export function PayPage({
1678
1693
  acceptedLegalConsents,
1679
1694
  customerData,
1680
1695
  effectiveAmount,
1696
+ effectiveAmountExact,
1681
1697
  formatAmount,
1682
1698
  payload,
1683
1699
  selectedPriceItemId,
@@ -1934,7 +1950,7 @@ export function PayPage({
1934
1950
  'Idempotency-Key': crypto.randomUUID(),
1935
1951
  'x-om-unauthorized-redirect': '0',
1936
1952
  },
1937
- body: JSON.stringify(nextSubmitData),
1953
+ body: JSON.stringify(buildPayPageSubmitBody(nextSubmitData)),
1938
1954
  },
1939
1955
  )
1940
1956
 
@@ -2183,22 +2199,23 @@ export function PayPage({
2183
2199
  <PricingComponent
2184
2200
  payload={payload}
2185
2201
  amount={amount}
2202
+ amountExact={amountExact}
2186
2203
  selectedPriceItemId={selectedPriceItemId}
2187
2204
  fieldErrors={fieldErrors}
2188
2205
  inputsLocked={inputsLocked}
2189
2206
  formatAmount={formatAmount}
2190
2207
  onAmountChange={(value) => {
2191
- const nextAmount = parseNumericInput(value)
2192
- const nextData = setSubmitDataFieldValue(submitDataRef.current, 'amount', nextAmount)
2208
+ const nextAmount = parsePayPageAmountInput(value)
2209
+ const nextData = { ...submitDataRef.current, ...nextAmount }
2193
2210
  applySubmitDataToState(nextData)
2194
2211
  clearFieldError('amount')
2195
2212
  setSubmissionError(null)
2196
- dispatchFieldChange('amount', nextAmount, nextData)
2213
+ dispatchFieldChange('amount', nextAmount.amount, nextData)
2197
2214
  }}
2198
2215
  onPriceItemSelect={(item) => {
2199
2216
  const nextData = {
2200
2217
  ...submitDataRef.current,
2201
- amount: item.amount,
2218
+ ...toPayPageAmount(item.amount, item.amountExact),
2202
2219
  selectedPriceItemId: item.id,
2203
2220
  }
2204
2221
  applySubmitDataToState(nextData)
@@ -2217,6 +2234,7 @@ export function PayPage({
2217
2234
  <SummaryComponent
2218
2235
  payload={payload}
2219
2236
  selectedAmount={effectiveAmount}
2237
+ selectedAmountExact={effectiveAmountExact}
2220
2238
  currencyCode={effectiveCurrencyCode}
2221
2239
  formatAmount={formatAmount}
2222
2240
  preview={isPreview}
@@ -54,7 +54,7 @@ jest.mock('../LogoUploadField', () => ({
54
54
  LogoUploadField: () => null,
55
55
  }))
56
56
 
57
- import { PricingSection, PriceListEditor, toSubmittedAmount } from '../LinkTemplateForm'
57
+ import { normalizeFormValues, PricingSection, PriceListEditor, toSubmittedAmount, toSubmittedAmountExact } from '../LinkTemplateForm'
58
58
 
59
59
  function renderPricingSection(initialValues: Record<string, unknown>) {
60
60
  const setValue = jest.fn()
@@ -165,6 +165,16 @@ describe('LinkTemplateForm locale decimal separator (issue #5828)', () => {
165
165
  ) as HTMLInputElement
166
166
  expect(amountInput.value).toBe('25,99')
167
167
  })
168
+
169
+ it('shows a loaded exact amount with the locale comma and every digit', () => {
170
+ const values = normalizeFormValues(
171
+ { fixedPriceAmount: 1234.567891234567891234, fixedPriceAmountExact: '1234.567891234567891234' },
172
+ undefined,
173
+ 'pl-PL',
174
+ )
175
+ expect(values.fixedPriceAmount).toBe('1234,567891234567891234')
176
+ expect(toSubmittedAmountExact(values.fixedPriceAmount, 'pl-PL')).toBe('1234.567891234567891234')
177
+ })
168
178
  })
169
179
 
170
180
  describe('toSubmittedAmount (converts the raw typed text to a number at submit time)', () => {
@@ -186,4 +196,28 @@ describe('LinkTemplateForm locale decimal separator (issue #5828)', () => {
186
196
  expect(toSubmittedAmount(null, 'pl-PL')).toBeNull()
187
197
  })
188
198
  })
199
+
200
+ describe('toSubmittedAmountExact (converts the raw typed text to an exact decimal string at submit time)', () => {
201
+ it('parses a comma-decimal value', () => {
202
+ expect(toSubmittedAmountExact('110,70', 'pl-PL')).toBe('110.7')
203
+ })
204
+
205
+ it('still parses a dot-decimal value', () => {
206
+ expect(toSubmittedAmountExact('110.70', 'pl-PL')).toBe('110.7')
207
+ })
208
+
209
+ it('passes an already-numeric value through unchanged', () => {
210
+ expect(toSubmittedAmountExact(150, 'pl-PL')).toBe('150')
211
+ })
212
+
213
+ it('keeps every digit of an amount beyond float precision', () => {
214
+ expect(toSubmittedAmountExact('0,123456789012345678', 'pl-PL')).toBe('0.123456789012345678')
215
+ })
216
+
217
+ it('returns null for unparseable or blank input, never a silent 0 or NaN', () => {
218
+ expect(toSubmittedAmountExact('abc', 'pl-PL')).toBeNull()
219
+ expect(toSubmittedAmountExact('', 'pl-PL')).toBeNull()
220
+ expect(toSubmittedAmountExact(null, 'pl-PL')).toBeNull()
221
+ })
222
+ })
189
223
  })
@@ -0,0 +1,196 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ *
4
+ * Regression test for review finding F3 on PR #7324.
5
+ *
6
+ * The API stores each price-list row as a float `amount` plus an exact `amountExact` sibling.
7
+ * The form used to hydrate rows from the float alone, so an 18-decimal ETH price of
8
+ * `1.123456789012345678` came back as `1.1234567890123457` and a save that only touched the
9
+ * title silently rewrote the stored price. Rows now hydrate from `amountExact` (formatted for the
10
+ * locale, like the scalar fixed/custom amounts) and submit the exact decimal string.
11
+ */
12
+ import * as React from 'react'
13
+ import { render, screen, waitFor, act } from '@testing-library/react'
14
+
15
+ const mockLocale = { current: 'en-US' }
16
+ const capturedCrudFormProps: { current: Record<string, unknown> | null } = { current: null }
17
+ const mockReadApiResultOrThrow = jest.fn()
18
+
19
+ jest.mock('lucide-react', () => {
20
+ const IconStub = () => null
21
+ return new Proxy(
22
+ { __esModule: true },
23
+ { get: (target, prop) => (prop in target ? (target as Record<string | symbol, unknown>)[prop] : IconStub) },
24
+ )
25
+ })
26
+
27
+ jest.mock('next/navigation', () => ({
28
+ useSearchParams: () => new URLSearchParams(),
29
+ }))
30
+
31
+ jest.mock('@open-mercato/ui/backend/detail', () => ({
32
+ RecordNotFoundState: () => null,
33
+ }))
34
+
35
+ const mockTranslate = (key: string, fallback?: unknown) => (typeof fallback === 'string' ? fallback : key)
36
+
37
+ jest.mock('@open-mercato/shared/lib/i18n/context', () => ({
38
+ useT: () => mockTranslate,
39
+ useLocale: () => mockLocale.current,
40
+ }))
41
+
42
+ jest.mock('@open-mercato/ui/backend/CrudForm', () => ({
43
+ CrudForm: (props: Record<string, unknown>) => {
44
+ capturedCrudFormProps.current = props
45
+ return null
46
+ },
47
+ }))
48
+
49
+ jest.mock('@open-mercato/ui/backend/utils/apiCall', () => ({
50
+ apiCall: jest.fn(async () => ({ ok: true, status: 200, result: null })),
51
+ apiCallOrThrow: jest.fn(async () => ({ ok: true, status: 200, result: null })),
52
+ readApiResultOrThrow: (...args: unknown[]) => mockReadApiResultOrThrow(...args),
53
+ withScopedApiRequestHeaders: async (_headers: unknown, run: () => Promise<unknown>) => run(),
54
+ }))
55
+
56
+ jest.mock('../CheckoutCurrencySelect', () => ({
57
+ CheckoutCurrencySelect: () => null,
58
+ }))
59
+
60
+ jest.mock('../CustomerFieldsEditor', () => ({
61
+ CustomerFieldsEditor: () => null,
62
+ }))
63
+
64
+ jest.mock('../GatewaySettingsFields', () => ({
65
+ GatewaySettingsFields: () => null,
66
+ }))
67
+
68
+ jest.mock('../LogoUploadField', () => ({
69
+ LogoUploadField: () => null,
70
+ }))
71
+
72
+ import { LinkTemplateForm, normalizeFormValues, PriceListEditor } from '../LinkTemplateForm'
73
+
74
+ const RECORD_ID = 'record-1'
75
+ const EXACT_AMOUNT = '1.123456789012345678'
76
+ const FLOAT_AMOUNT = 1.1234567890123457
77
+
78
+ function persistedRecord() {
79
+ return {
80
+ id: RECORD_ID,
81
+ name: 'ETH checkout',
82
+ title: 'Original title',
83
+ slug: 'eth-checkout',
84
+ pricingMode: 'price_list',
85
+ updatedAt: '2026-11-01T10:00:00.000Z',
86
+ priceListItems: [
87
+ { id: 'eth', description: 'ETH', amount: FLOAT_AMOUNT, amountExact: EXACT_AMOUNT, currencyCode: 'ETH' },
88
+ ],
89
+ }
90
+ }
91
+
92
+ type SubmitHandler = (values: Record<string, unknown>, context?: unknown) => Promise<void>
93
+
94
+ async function renderPersistedForm(mode: 'link' | 'template') {
95
+ capturedCrudFormProps.current = null
96
+ mockReadApiResultOrThrow.mockReset()
97
+ mockReadApiResultOrThrow.mockImplementation(async (url: string, init?: { method?: string }) => {
98
+ if (init?.method === 'PUT') return { ok: true }
99
+ if (url.startsWith('/api/payment_gateways/providers')) return { items: [] }
100
+ if (url.startsWith(`/api/checkout/${mode === 'link' ? 'links' : 'templates'}/${RECORD_ID}`)) return persistedRecord()
101
+ return { items: [] }
102
+ })
103
+ render(<LinkTemplateForm mode={mode} recordId={RECORD_ID} />)
104
+ await waitFor(() => {
105
+ const initialValues = capturedCrudFormProps.current?.initialValues as Record<string, unknown> | undefined
106
+ expect(initialValues?.title).toBe('Original title')
107
+ })
108
+ const props = capturedCrudFormProps.current as Record<string, unknown>
109
+ return {
110
+ initialValues: props.initialValues as Record<string, unknown>,
111
+ onSubmit: props.onSubmit as SubmitHandler,
112
+ }
113
+ }
114
+
115
+ function readSubmittedBody(): Record<string, unknown> {
116
+ const putCall = mockReadApiResultOrThrow.mock.calls.find(([, init]) => init?.method === 'PUT')
117
+ expect(putCall).toBeDefined()
118
+ return JSON.parse(String(putCall?.[1]?.body)) as Record<string, unknown>
119
+ }
120
+
121
+ describe('LinkTemplateForm price list exact amounts (PR #7324 finding F3)', () => {
122
+ afterEach(() => {
123
+ mockLocale.current = 'en-US'
124
+ })
125
+
126
+ describe('hydration', () => {
127
+ it.each([
128
+ ['en-US', '1.123456789012345678'],
129
+ ['pl-PL', '1,123456789012345678'],
130
+ ])('hydrates a persisted row from amountExact with every digit in %s', (locale, expected) => {
131
+ const values = normalizeFormValues(
132
+ { priceListItems: [{ id: 'eth', description: 'ETH', amount: FLOAT_AMOUNT, amountExact: EXACT_AMOUNT, currencyCode: 'ETH' }] },
133
+ undefined,
134
+ locale,
135
+ )
136
+ const items = values.priceListItems as Array<Record<string, unknown>>
137
+ expect(items[0].amount).toBe(expected)
138
+ expect(items[0]).not.toHaveProperty('amountExact')
139
+ })
140
+
141
+ it('falls back to the float amount when no exact sibling was persisted', () => {
142
+ const values = normalizeFormValues(
143
+ { priceListItems: [{ id: 'usd', description: 'USD', amount: 25.99, currencyCode: 'USD' }] },
144
+ undefined,
145
+ 'pl-PL',
146
+ )
147
+ expect((values.priceListItems as Array<Record<string, unknown>>)[0].amount).toBe('25,99')
148
+ })
149
+
150
+ it.each([
151
+ ['en-US', '1.123456789012345678'],
152
+ ['pl-PL', '1,123456789012345678'],
153
+ ])('shows every digit of the hydrated row in the price list input in %s', (locale, expected) => {
154
+ mockLocale.current = locale
155
+ const values = normalizeFormValues(persistedRecord() as never, undefined, locale)
156
+ render(
157
+ <PriceListEditor
158
+ value={values.priceListItems as React.ComponentProps<typeof PriceListEditor>['value']}
159
+ onChange={jest.fn()}
160
+ />,
161
+ )
162
+ const amountInput = screen.getByLabelText('checkout.linkTemplateForm.priceList.aria.amount') as HTMLInputElement
163
+ expect(amountInput.value).toBe(expected)
164
+ })
165
+ })
166
+
167
+ describe('title-only submit', () => {
168
+ let consoleErrorSpy: jest.SpyInstance
169
+
170
+ beforeEach(() => {
171
+ consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => undefined)
172
+ })
173
+
174
+ afterEach(() => {
175
+ consoleErrorSpy.mockRestore()
176
+ })
177
+
178
+ it.each([
179
+ ['link', 'en-US'],
180
+ ['link', 'pl-PL'],
181
+ ['template', 'en-US'],
182
+ ['template', 'pl-PL'],
183
+ ] as const)('sends the exact price list amount for a %s form in %s', async (mode, locale) => {
184
+ mockLocale.current = locale
185
+ const { initialValues, onSubmit } = await renderPersistedForm(mode)
186
+ await act(async () => {
187
+ await onSubmit({ ...initialValues, title: 'Renamed' })
188
+ })
189
+ const body = readSubmittedBody()
190
+ expect(body.title).toBe('Renamed')
191
+ expect(body.priceListItems).toEqual([
192
+ { id: 'eth', description: 'ETH', amount: EXACT_AMOUNT, currencyCode: 'ETH' },
193
+ ])
194
+ })
195
+ })
196
+ })