@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
@@ -83,8 +83,8 @@ test.describe('TC-CHK-CRUDFORM-001: pay-link template CrudForm persists scalars,
83
83
  description: 'Original template description',
84
84
  pricingMode: 'price_list',
85
85
  priceListItems: [
86
- { id: 'tier-basic', description: 'Basic tier', amount: 19.99, currencyCode: 'USD' },
87
- { id: 'tier-pro', description: 'Pro tier', amount: 49.99, currencyCode: 'USD' },
86
+ { id: 'tier-basic', description: 'Basic tier', amount: 19.99, amountExact: '19.99', currencyCode: 'USD' },
87
+ { id: 'tier-pro', description: 'Pro tier', amount: 49.99, amountExact: '49.99', currencyCode: 'USD' },
88
88
  ],
89
89
  collectCustomerDetails: true,
90
90
  displayCustomFieldsOnPage: true,
@@ -136,7 +136,7 @@ test.describe('TC-CHK-CRUDFORM-001: pay-link template CrudForm persists scalars,
136
136
  description: 'Updated template description',
137
137
  pricingMode: 'price_list',
138
138
  priceListItems: [
139
- { id: 'tier-solo', description: 'Solo tier', amount: 99, currencyCode: 'USD' },
139
+ { id: 'tier-solo', description: 'Solo tier', amount: 99, amountExact: '99', currencyCode: 'USD' },
140
140
  ],
141
141
  collectCustomerDetails: false,
142
142
  displayCustomFieldsOnPage: false,
@@ -38,12 +38,14 @@ test.describe('TC-CHKT-037: Template updates sync unchanged fields to existing l
38
38
  const updateResponse = await updateTemplate(request, token, templateId, {
39
39
  title: 'Template title v2',
40
40
  subtitle: 'Template subtitle v2',
41
+ fixedPriceAmount: 59.99,
41
42
  })
42
43
  expect(updateResponse.ok(), `Template update failed: ${updateResponse.status()}`).toBeTruthy()
43
44
 
44
45
  const stored = await readLink(request, token, link.id)
45
46
  expect(stored.title).toBe('Manual link title')
46
47
  expect(stored.subtitle).toBe('Template subtitle v2')
48
+ expect(stored.fixedPriceAmount).toBe(59.99)
47
49
  } finally {
48
50
  await deleteCheckoutEntityIfExists(request, token, 'links', linkId)
49
51
  await deleteCheckoutEntityIfExists(request, token, 'templates', templateId)
@@ -0,0 +1,320 @@
1
+ import { expect, test, type APIRequestContext, type APIResponse } from '@playwright/test'
2
+ import { apiRequest, getAuthToken } from '@open-mercato/core/helpers/integration/api'
3
+ import {
4
+ createRandomCurrencyFixture,
5
+ deleteCurrenciesEntityIfExists,
6
+ } from '@open-mercato/core/helpers/integration/currenciesFixtures'
7
+ import {
8
+ createCheckoutClientHeaders,
9
+ createCustomAmountTemplateInput,
10
+ createCustomerData,
11
+ createFixedTemplateInput,
12
+ createPriceListTemplateInput,
13
+ deleteCheckoutEntityIfExists,
14
+ readPublicPayLink,
15
+ updateTemplate,
16
+ } from './helpers/fixtures'
17
+ import {
18
+ buildPayPageSubmitBody,
19
+ parsePayPageAmountInput,
20
+ toPayPageAmount,
21
+ type PayPageAmount,
22
+ } from '../lib/payPageAmount'
23
+
24
+ /**
25
+ * TC-CHKT-PRECISION-001: checkout amounts in an 18-decimal currency keep every digit.
26
+ * Source: .ai/specs/2026-10-08-arbitrary-precision-money-and-fx.md
27
+ */
28
+
29
+ type JsonRecord = Record<string, unknown>
30
+
31
+ const FIXED_PRICE = '1.123456789012345678'
32
+ const FIXED_ORIGINAL_PRICE = '2.987654321098765432'
33
+ const OVERRIDDEN_FIXED_PRICE = '3.000000000000000007'
34
+ const UPDATED_FIXED_PRICE = '1.123456789012345679'
35
+ const UPDATED_FIXED_ORIGINAL_PRICE = '2.987654321098765433'
36
+ const CUSTOM_MIN = '0.000000000000000001'
37
+ const CUSTOM_MAX = '9.999999999999999999'
38
+ const SUBMITTED_AMOUNT = '1.1234567890123456785'
39
+ const CHARGED_AMOUNT = '1.123456789012345679'
40
+ const PAY_PAGE_FIXED_PRICE = '1234.567890123456789012'
41
+ const PAY_PAGE_PRICE_ITEM = '0.123456789012345678'
42
+ const PAY_PAGE_CUSTOM_MIN = '1.000000000000000001'
43
+
44
+ async function readJson(response: APIResponse): Promise<JsonRecord> {
45
+ const raw = await response.text()
46
+ if (!raw) return {}
47
+ try {
48
+ return JSON.parse(raw) as JsonRecord
49
+ } catch {
50
+ return {}
51
+ }
52
+ }
53
+
54
+ async function createCheckoutEntity(
55
+ request: APIRequestContext,
56
+ token: string,
57
+ kind: 'templates' | 'links',
58
+ data: JsonRecord,
59
+ ): Promise<JsonRecord> {
60
+ const response = await apiRequest(request, 'POST', `/api/checkout/${kind}`, { token, data })
61
+ const body = await readJson(response)
62
+ expect(response.status(), `POST /api/checkout/${kind} failed: ${JSON.stringify(body)}`).toBe(201)
63
+ expect(typeof body.id === 'string' && body.id.length > 0, `${kind} create should return id`).toBeTruthy()
64
+ return body
65
+ }
66
+
67
+ async function readCheckoutEntity(
68
+ request: APIRequestContext,
69
+ token: string,
70
+ kind: 'templates' | 'links' | 'transactions',
71
+ id: string,
72
+ ): Promise<JsonRecord> {
73
+ const response = await apiRequest(request, 'GET', `/api/checkout/${kind}/${encodeURIComponent(id)}`, { token })
74
+ expect(response.status(), `GET /api/checkout/${kind}/${id} should be 200`).toBe(200)
75
+ return readJson(response)
76
+ }
77
+
78
+ async function submitPayload(
79
+ request: APIRequestContext,
80
+ slug: string,
81
+ data: JsonRecord,
82
+ ): Promise<APIResponse> {
83
+ const baseUrl = process.env.BASE_URL || 'http://localhost:3000'
84
+ return request.fetch(`${baseUrl}/api/checkout/pay/${encodeURIComponent(slug)}/submit`, {
85
+ method: 'POST',
86
+ headers: createCheckoutClientHeaders({
87
+ 'Content-Type': 'application/json',
88
+ 'Idempotency-Key': `precision-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`,
89
+ }),
90
+ data,
91
+ })
92
+ }
93
+
94
+ async function submitExactAmount(
95
+ request: APIRequestContext,
96
+ slug: string,
97
+ amount: string,
98
+ ): Promise<APIResponse> {
99
+ return submitPayload(request, slug, { customerData: createCustomerData(), acceptedLegalConsents: {}, amount })
100
+ }
101
+
102
+ async function readPublicPayload(request: APIRequestContext, slug: string): Promise<JsonRecord> {
103
+ const response = await readPublicPayLink(request, slug)
104
+ expect(response.status(), `GET /api/checkout/pay/${slug} should be 200`).toBe(200)
105
+ return readJson(response)
106
+ }
107
+
108
+ async function submitLikePayPage(
109
+ request: APIRequestContext,
110
+ token: string,
111
+ slug: string,
112
+ amount: PayPageAmount,
113
+ selectedPriceItemId: string | null = null,
114
+ ): Promise<JsonRecord> {
115
+ const body = buildPayPageSubmitBody({
116
+ customerData: createCustomerData(),
117
+ acceptedLegalConsents: {},
118
+ ...amount,
119
+ selectedPriceItemId,
120
+ })
121
+ expect(typeof body.amount, 'the pay page submits the amount as an exact string').toBe('string')
122
+ const response = await submitPayload(request, slug, body)
123
+ const responseBody = await readJson(response)
124
+ expect(response.status(), `pay page submit for ${slug} failed: ${JSON.stringify(responseBody)}`).toBe(201)
125
+ const transactionId = responseBody.transactionId as string
126
+ expect(transactionId, 'submit should return transactionId').toBeTruthy()
127
+ const transactionBody = await readCheckoutEntity(request, token, 'transactions', transactionId)
128
+ return (transactionBody.transaction ?? {}) as JsonRecord
129
+ }
130
+
131
+ test.describe('TC-CHKT-PRECISION-001: 18-decimal currency checkout amounts', () => {
132
+ test('template, link and transaction amounts stay exact beyond float precision, including template-to-link sync', async ({ request }) => {
133
+ test.slow()
134
+ const token = await getAuthToken(request, 'admin')
135
+ let currencyId: string | null = null
136
+ let templateId: string | null = null
137
+ const linkIds: string[] = []
138
+
139
+ try {
140
+ const currency = await createRandomCurrencyFixture(request, token, {
141
+ name: 'QA TC-CHKT-PRECISION-001',
142
+ decimalPlaces: 18,
143
+ })
144
+ currencyId = currency.id
145
+
146
+ const template = await createCheckoutEntity(request, token, 'templates', {
147
+ ...createFixedTemplateInput({ fixedPriceCurrencyCode: currency.code }),
148
+ fixedPriceAmount: FIXED_PRICE,
149
+ fixedPriceOriginalAmount: FIXED_ORIGINAL_PRICE,
150
+ })
151
+ templateId = template.id as string
152
+
153
+ const storedTemplate = await readCheckoutEntity(request, token, 'templates', templateId)
154
+ expect(storedTemplate.fixedPriceAmountExact).toBe(FIXED_PRICE)
155
+ expect(storedTemplate.fixedPriceOriginalAmountExact).toBe(FIXED_ORIGINAL_PRICE)
156
+ expect(storedTemplate.fixedPriceAmount).toBe(Number(FIXED_PRICE))
157
+
158
+ const customLink = await createCheckoutEntity(request, token, 'links', {
159
+ ...createCustomAmountTemplateInput({ customAmountCurrencyCode: currency.code }),
160
+ customAmountMin: CUSTOM_MIN,
161
+ customAmountMax: CUSTOM_MAX,
162
+ })
163
+ const customLinkId = customLink.id as string
164
+ const customLinkSlug = customLink.slug as string
165
+ linkIds.push(customLinkId)
166
+ const storedCustomLink = await readCheckoutEntity(request, token, 'links', customLinkId)
167
+ expect(storedCustomLink.customAmountMinExact).toBe(CUSTOM_MIN)
168
+ expect(storedCustomLink.customAmountMaxExact).toBe(CUSTOM_MAX)
169
+
170
+ const publicResponse = await readPublicPayLink(request, customLinkSlug)
171
+ expect(publicResponse.status(), 'GET /api/checkout/pay/:slug should be 200').toBe(200)
172
+ const publicLink = await readJson(publicResponse)
173
+ expect(publicLink.customAmountMinExact).toBe(CUSTOM_MIN)
174
+ expect(publicLink.customAmountMaxExact).toBe(CUSTOM_MAX)
175
+
176
+ const submitResponse = await submitExactAmount(request, customLinkSlug, SUBMITTED_AMOUNT)
177
+ const submitBody = await readJson(submitResponse)
178
+ expect(submitResponse.status(), `submit failed: ${JSON.stringify(submitBody)}`).toBe(201)
179
+ const transactionId = submitBody.transactionId as string
180
+ expect(transactionId, 'submit should return transactionId').toBeTruthy()
181
+
182
+ const transactionBody = await readCheckoutEntity(request, token, 'transactions', transactionId)
183
+ const transaction = (transactionBody.transaction ?? {}) as JsonRecord
184
+ expect(transaction.currencyCode).toBe(currency.code)
185
+ expect(transaction.amountExact).toBe(CHARGED_AMOUNT)
186
+ expect(transaction.amount).toBe(Number(CHARGED_AMOUNT))
187
+
188
+ const templateLink = await createCheckoutEntity(request, token, 'links', {
189
+ templateId,
190
+ name: `QA precision template link ${Date.now()}`,
191
+ pricingMode: 'fixed',
192
+ fixedPriceAmount: OVERRIDDEN_FIXED_PRICE,
193
+ fixedPriceCurrencyCode: currency.code,
194
+ gatewayProviderKey: 'mock',
195
+ })
196
+ linkIds.push(templateLink.id as string)
197
+ const storedTemplateLink = await readCheckoutEntity(request, token, 'links', templateLink.id as string)
198
+ expect(storedTemplateLink.templateId).toBe(templateId)
199
+ expect(storedTemplateLink.fixedPriceAmountExact).toBe(OVERRIDDEN_FIXED_PRICE)
200
+ expect(storedTemplateLink.fixedPriceOriginalAmountExact).toBe(FIXED_ORIGINAL_PRICE)
201
+
202
+ const inheritingLink = await createCheckoutEntity(request, token, 'links', {
203
+ templateId,
204
+ name: `QA precision inheriting link ${Date.now()}`,
205
+ pricingMode: 'fixed',
206
+ fixedPriceAmount: FIXED_PRICE,
207
+ fixedPriceCurrencyCode: currency.code,
208
+ gatewayProviderKey: 'mock',
209
+ })
210
+ const inheritingLinkId = inheritingLink.id as string
211
+ linkIds.push(inheritingLinkId)
212
+
213
+ const templateUpdateResponse = await updateTemplate(request, token, templateId, {
214
+ fixedPriceAmount: UPDATED_FIXED_PRICE,
215
+ fixedPriceOriginalAmount: UPDATED_FIXED_ORIGINAL_PRICE,
216
+ })
217
+ expect(
218
+ templateUpdateResponse.ok(),
219
+ `PUT /api/checkout/templates/${templateId} failed: ${JSON.stringify(await readJson(templateUpdateResponse))}`,
220
+ ).toBeTruthy()
221
+ const updatedTemplate = await readCheckoutEntity(request, token, 'templates', templateId)
222
+ expect(updatedTemplate.fixedPriceAmountExact).toBe(UPDATED_FIXED_PRICE)
223
+
224
+ const syncedInheritingLink = await readCheckoutEntity(request, token, 'links', inheritingLinkId)
225
+ expect(syncedInheritingLink.fixedPriceAmountExact).toBe(UPDATED_FIXED_PRICE)
226
+ expect(syncedInheritingLink.fixedPriceOriginalAmountExact).toBe(UPDATED_FIXED_ORIGINAL_PRICE)
227
+
228
+ const syncedOverrideLink = await readCheckoutEntity(request, token, 'links', templateLink.id as string)
229
+ expect(syncedOverrideLink.fixedPriceAmountExact).toBe(OVERRIDDEN_FIXED_PRICE)
230
+ expect(syncedOverrideLink.fixedPriceOriginalAmountExact).toBe(UPDATED_FIXED_ORIGINAL_PRICE)
231
+ } finally {
232
+ for (const linkId of linkIds) {
233
+ await deleteCheckoutEntityIfExists(request, token, 'links', linkId)
234
+ }
235
+ await deleteCheckoutEntityIfExists(request, token, 'templates', templateId)
236
+ await deleteCurrenciesEntityIfExists(request, token, '/api/currencies/currencies', currencyId)
237
+ }
238
+ })
239
+
240
+ test('pay page payloads pay a high-precision fixed price, price-list item and the exact custom minimum', async ({ request }) => {
241
+ test.slow()
242
+ const token = await getAuthToken(request, 'admin')
243
+ let currencyId: string | null = null
244
+ const linkIds: string[] = []
245
+
246
+ try {
247
+ const currency = await createRandomCurrencyFixture(request, token, {
248
+ name: 'QA TC-CHKT-PRECISION-001 pay page',
249
+ decimalPlaces: 18,
250
+ })
251
+ currencyId = currency.id
252
+
253
+ const fixedLink = await createCheckoutEntity(request, token, 'links', {
254
+ ...createFixedTemplateInput({ fixedPriceCurrencyCode: currency.code, status: 'active' }),
255
+ fixedPriceAmount: PAY_PAGE_FIXED_PRICE,
256
+ fixedPriceOriginalAmount: null,
257
+ })
258
+ linkIds.push(fixedLink.id as string)
259
+ const fixedPayload = await readPublicPayload(request, fixedLink.slug as string)
260
+ expect(fixedPayload.fixedPriceAmountExact).toBe(PAY_PAGE_FIXED_PRICE)
261
+
262
+ const floatSubmit = await submitPayload(request, fixedLink.slug as string, {
263
+ customerData: createCustomerData(),
264
+ acceptedLegalConsents: {},
265
+ amount: fixedPayload.fixedPriceAmount,
266
+ })
267
+ expect(floatSubmit.status(), 'a float fixed price no longer matches the exact configuration').toBe(422)
268
+
269
+ const fixedTransaction = await submitLikePayPage(
270
+ request,
271
+ token,
272
+ fixedLink.slug as string,
273
+ toPayPageAmount(fixedPayload.fixedPriceAmount, fixedPayload.fixedPriceAmountExact),
274
+ )
275
+ expect(fixedTransaction.amountExact).toBe(PAY_PAGE_FIXED_PRICE)
276
+
277
+ const priceListLink = await createCheckoutEntity(request, token, 'links', {
278
+ ...createPriceListTemplateInput(),
279
+ priceListItems: [{ id: 'precise', description: 'Precise', amount: PAY_PAGE_PRICE_ITEM, currencyCode: currency.code }],
280
+ })
281
+ linkIds.push(priceListLink.id as string)
282
+ const priceListPayload = await readPublicPayload(request, priceListLink.slug as string)
283
+ const priceItems = (priceListPayload.priceListItems ?? []) as Array<{ id: string; amount: number; amountExact?: string | null }>
284
+ const preciseItem = priceItems.find((item) => item.id === 'precise')
285
+ expect(preciseItem?.amountExact).toBe(PAY_PAGE_PRICE_ITEM)
286
+
287
+ const priceListTransaction = await submitLikePayPage(
288
+ request,
289
+ token,
290
+ priceListLink.slug as string,
291
+ toPayPageAmount(preciseItem?.amount, preciseItem?.amountExact),
292
+ 'precise',
293
+ )
294
+ expect(priceListTransaction.amountExact).toBe(PAY_PAGE_PRICE_ITEM)
295
+ expect(priceListTransaction.selectedPriceItemId).toBe('precise')
296
+
297
+ const customLink = await createCheckoutEntity(request, token, 'links', {
298
+ ...createCustomAmountTemplateInput({ customAmountCurrencyCode: currency.code }),
299
+ customAmountMin: PAY_PAGE_CUSTOM_MIN,
300
+ customAmountMax: CUSTOM_MAX,
301
+ })
302
+ linkIds.push(customLink.id as string)
303
+ const customPayload = await readPublicPayload(request, customLink.slug as string)
304
+ expect(customPayload.customAmountMinExact).toBe(PAY_PAGE_CUSTOM_MIN)
305
+
306
+ const customTransaction = await submitLikePayPage(
307
+ request,
308
+ token,
309
+ customLink.slug as string,
310
+ parsePayPageAmountInput(customPayload.customAmountMinExact as string),
311
+ )
312
+ expect(customTransaction.amountExact).toBe(PAY_PAGE_CUSTOM_MIN)
313
+ } finally {
314
+ for (const linkId of linkIds) {
315
+ await deleteCheckoutEntityIfExists(request, token, 'links', linkId)
316
+ }
317
+ await deleteCurrenciesEntityIfExists(request, token, '/api/currencies/currencies', currencyId)
318
+ }
319
+ })
320
+ })
@@ -0,0 +1,112 @@
1
+ import { expect, test, type APIRequestContext, type Page } from '@playwright/test'
2
+ import { login } from '@open-mercato/core/helpers/integration/auth'
3
+ import { getAuthToken } from '@open-mercato/core/helpers/integration/api'
4
+ import {
5
+ createRandomCurrencyFixture,
6
+ deleteCurrenciesEntityIfExists,
7
+ } from '@open-mercato/core/helpers/integration/currenciesFixtures'
8
+ import {
9
+ createLinkFixture,
10
+ createPriceListTemplateInput,
11
+ createTemplateFixture,
12
+ deleteCheckoutEntityIfExists,
13
+ readLink,
14
+ readTemplate,
15
+ } from './helpers/fixtures'
16
+
17
+ /**
18
+ * TC-CHKT-PRECISION-002: saving only the title of a template or pay link keeps
19
+ * every digit of its price-list amounts, in dot- and comma-decimal locales.
20
+ * Source: .ai/specs/2026-10-08-arbitrary-precision-money-and-fx.md
21
+ */
22
+
23
+ const PRICE = '1.123456789012345678'
24
+
25
+ const LOCALES = [
26
+ { locale: 'en', titlePlaceholder: 'Consulting session payment', amountLabel: 'Amount 1', displayedPrice: PRICE },
27
+ { locale: 'pl', titlePlaceholder: 'Płatność za sesję konsultingową', amountLabel: 'Kwota 1', displayedPrice: PRICE.replace('.', ',') },
28
+ ] as const
29
+
30
+ const EDITORS = [
31
+ { kind: 'templates' as const, path: 'templates' },
32
+ { kind: 'links' as const, path: 'pay-links' },
33
+ ]
34
+
35
+ type PriceListItem = { id: string; amount: number; amountExact?: string | null }
36
+
37
+ async function useLocale(page: Page, locale: string) {
38
+ const baseUrl = process.env.BASE_URL || 'http://localhost:3000'
39
+ await page.context().addCookies([
40
+ { name: 'locale', value: locale, url: baseUrl, sameSite: 'Lax' },
41
+ { name: 'om_demo_notice_ack', value: 'ack', url: baseUrl, sameSite: 'Lax' },
42
+ { name: 'om_cookie_notice_ack', value: 'ack', url: baseUrl, sameSite: 'Lax' },
43
+ ])
44
+ }
45
+
46
+ async function readPriceListItems(
47
+ request: APIRequestContext,
48
+ token: string,
49
+ kind: 'templates' | 'links',
50
+ id: string,
51
+ ): Promise<PriceListItem[]> {
52
+ const record = kind === 'templates' ? await readTemplate(request, token, id) : await readLink(request, token, id)
53
+ return ((record as { priceListItems?: PriceListItem[] }).priceListItems ?? []) as PriceListItem[]
54
+ }
55
+
56
+ test.describe('TC-CHKT-PRECISION-002: exact price-list amounts survive an admin title edit', () => {
57
+ for (const { locale, titlePlaceholder, amountLabel, displayedPrice } of LOCALES) {
58
+ for (const { kind, path } of EDITORS) {
59
+ test(`${kind} editor in ${locale} keeps ${PRICE} after a title-only save`, async ({ page, request }) => {
60
+ test.setTimeout(150_000)
61
+ const token = await getAuthToken(request, 'admin')
62
+ let currencyId: string | null = null
63
+ let entityId: string | null = null
64
+
65
+ try {
66
+ const currency = await createRandomCurrencyFixture(request, token, {
67
+ name: `QA TC-CHKT-PRECISION-002 ${kind} ${locale}`,
68
+ decimalPlaces: 18,
69
+ })
70
+ currencyId = currency.id
71
+ const input = createPriceListTemplateInput({
72
+ priceListItems: [{ id: 'precise', description: 'Precise', amount: PRICE as unknown as number, currencyCode: currency.code }],
73
+ status: 'draft',
74
+ })
75
+ entityId = kind === 'templates'
76
+ ? await createTemplateFixture(request, token, input)
77
+ : (await createLinkFixture(request, token, input)).id
78
+ const [created] = await readPriceListItems(request, token, kind, entityId)
79
+ expect(created?.amountExact).toBe(PRICE)
80
+
81
+ await login(page, 'admin')
82
+ await useLocale(page, locale)
83
+ await page.goto(`/backend/checkout/${path}/${encodeURIComponent(entityId)}`, { waitUntil: 'domcontentloaded' })
84
+ const amountInput = page.getByRole('textbox', { name: amountLabel, exact: true })
85
+ await expect(amountInput).toHaveValue(displayedPrice, { timeout: 30_000 })
86
+
87
+ await page.getByPlaceholder(titlePlaceholder).fill(`QA title only ${Date.now()}`)
88
+ const saved = page.waitForResponse((response) =>
89
+ response.request().method() === 'PUT'
90
+ && new URL(response.url()).pathname === `/api/checkout/${kind}/${entityId}`,
91
+ )
92
+ await page.locator('form button[type="submit"]').first().click()
93
+ expect((await saved).status()).toBe(200)
94
+
95
+ const [afterSave] = await readPriceListItems(request, token, kind, entityId)
96
+ expect(afterSave?.amountExact).toBe(PRICE)
97
+
98
+ await page.goto(`/backend/checkout/${path}/${encodeURIComponent(entityId)}`, { waitUntil: 'domcontentloaded' })
99
+ await expect(amountInput).toHaveValue(displayedPrice, { timeout: 30_000 })
100
+
101
+ await page.setViewportSize({ width: 390, height: 844 })
102
+ await expect(amountInput).toBeVisible()
103
+ const overflow = await page.evaluate(() => document.documentElement.scrollWidth - window.innerWidth)
104
+ expect(overflow).toBeLessThanOrEqual(0)
105
+ } finally {
106
+ await deleteCheckoutEntityIfExists(request, token, kind, entityId)
107
+ await deleteCurrenciesEntityIfExists(request, token, '/api/currencies/currencies', currencyId)
108
+ }
109
+ })
110
+ }
111
+ }
112
+ })
@@ -97,11 +97,15 @@ function expectedPublicResponse(link: CheckoutLink) {
97
97
  themeMode: 'auto',
98
98
  pricingMode: 'fixed',
99
99
  fixedPriceAmount: 49.99,
100
+ fixedPriceAmountExact: '49.99',
100
101
  fixedPriceCurrencyCode: 'USD',
101
102
  fixedPriceIncludesTax: true,
102
103
  fixedPriceOriginalAmount: 69.99,
104
+ fixedPriceOriginalAmountExact: '69.99',
103
105
  customAmountMin: 10,
106
+ customAmountMinExact: '10',
104
107
  customAmountMax: 100,
108
+ customAmountMaxExact: '100',
105
109
  customAmountCurrencyCode: 'EUR',
106
110
  priceListItems: link.priceListItems,
107
111
  gatewayProviderKey: 'mock',
@@ -13,6 +13,7 @@ const TENANT_ID = '55555555-5555-4555-8555-555555555555'
13
13
  const mockCreatePaymentSession = jest.fn()
14
14
  const mockCommandExecute = jest.fn()
15
15
  const mockEmFindOne = jest.fn()
16
+ const mockCurrencyDecimalPlaces = jest.fn()
16
17
 
17
18
  jest.mock('@open-mercato/shared/lib/di/container', () => ({
18
19
  createRequestContainer: jest.fn(),
@@ -83,6 +84,7 @@ describe('POST /api/checkout/pay/[slug]/submit', () => {
83
84
 
84
85
  beforeEach(() => {
85
86
  jest.clearAllMocks()
87
+ mockCurrencyDecimalPlaces.mockResolvedValue(null)
86
88
  process.env.APP_URL = 'https://merchant.example'
87
89
  delete process.env.NEXT_PUBLIC_APP_URL
88
90
 
@@ -93,6 +95,7 @@ describe('POST /api/checkout/pay/[slug]/submit', () => {
93
95
  if (name === 'rateLimiterService') return { trustProxyDepth: 0 }
94
96
  if (name === 'em') return { findOne: mockEmFindOne }
95
97
  if (name === 'commandBus') return { execute: mockCommandExecute }
98
+ if (name === 'currencyPrecisionService') return { getDecimalPlaces: mockCurrencyDecimalPlaces }
96
99
  if (name === 'paymentGatewayService') {
97
100
  return { createPaymentSession: mockCreatePaymentSession }
98
101
  }
@@ -119,6 +122,67 @@ describe('POST /api/checkout/pay/[slug]/submit', () => {
119
122
  })
120
123
  })
121
124
 
125
+ describe('provider amount precision', () => {
126
+ async function submitAmount(amount: string) {
127
+ return POST(new Request('https://merchant.example/api/checkout/pay/donate/submit', {
128
+ method: 'POST',
129
+ headers: {
130
+ 'content-type': 'application/json',
131
+ 'Idempotency-Key': 'precision-check-key-1234',
132
+ origin: 'https://merchant.example',
133
+ },
134
+ body: JSON.stringify({ customerData: {}, acceptedLegalConsents: {}, amount }),
135
+ }), { params: { slug: 'donate' } })
136
+ }
137
+
138
+ it('rejects configured USD precision above the provider unit before reserving a transaction', async () => {
139
+ mockCurrencyDecimalPlaces.mockResolvedValue(4)
140
+ ;(findOneWithDecryption as jest.Mock)
141
+ .mockResolvedValueOnce({ ...createLink(), pricingMode: 'fixed', fixedPriceAmount: '10.0051', fixedPriceCurrencyCode: 'USD' })
142
+ .mockResolvedValueOnce(null)
143
+
144
+ const response = await submitAmount('10.0051')
145
+
146
+ expect(response.status).toBe(400)
147
+ expect(mockCommandExecute).not.toHaveBeenCalled()
148
+ expect(mockCreatePaymentSession).not.toHaveBeenCalled()
149
+ })
150
+
151
+ it('rejects a replayed stored amount even when the newly submitted amount is valid', async () => {
152
+ mockCurrencyDecimalPlaces.mockResolvedValue(4)
153
+ ;(findOneWithDecryption as jest.Mock)
154
+ .mockResolvedValueOnce(createLink())
155
+ .mockResolvedValueOnce(createTransaction({ amount: '10.0051' }))
156
+
157
+ const response = await submitAmount('10.01')
158
+
159
+ expect(response.status).toBe(400)
160
+ expect(mockCommandExecute).not.toHaveBeenCalled()
161
+ expect(mockCreatePaymentSession).not.toHaveBeenCalled()
162
+ })
163
+
164
+ it.each([
165
+ { currencyCode: 'USD', decimalPlaces: 4, amount: '10.01', storedAmount: '10.01' },
166
+ { currencyCode: 'USD', decimalPlaces: 2, amount: '10.0051', storedAmount: '10.01' },
167
+ { currencyCode: 'ETH', decimalPlaces: 18, amount: '1.123456789012345678', storedAmount: '1.123456789012345678' },
168
+ ])('accepts $currencyCode amount $amount after normal checkout rounding', async ({ currencyCode, decimalPlaces, amount, storedAmount }) => {
169
+ mockCurrencyDecimalPlaces.mockResolvedValue(decimalPlaces)
170
+ const transaction = createTransaction({ currencyCode, amount: storedAmount })
171
+ ;(findOneWithDecryption as jest.Mock)
172
+ .mockResolvedValueOnce({ ...createLink(), customAmountCurrencyCode: currencyCode })
173
+ .mockResolvedValueOnce(null)
174
+ .mockResolvedValueOnce(transaction)
175
+ .mockResolvedValueOnce({ ...transaction, gatewayTransactionId: GATEWAY_TRANSACTION_ID })
176
+ mockCommandExecute.mockResolvedValue({ result: { id: TRANSACTION_ID } })
177
+
178
+ const response = await submitAmount(amount)
179
+
180
+ expect(response.status).toBe(201)
181
+ expect(mockCommandExecute).toHaveBeenCalledWith('checkout.transaction.create', expect.anything())
182
+ expect(mockCreatePaymentSession).toHaveBeenCalledWith(expect.objectContaining({ currencyCode, amountExact: storedAmount }))
183
+ })
184
+ })
185
+
122
186
  it('uses the stored transaction amount when replaying an idempotency key before gateway session creation', async () => {
123
187
  ;(findOneWithDecryption as jest.Mock)
124
188
  .mockResolvedValueOnce(createLink())
@@ -446,6 +510,87 @@ describe('POST /api/checkout/pay/[slug]/submit', () => {
446
510
  expect(payload.transactionId).toBe(TRANSACTION_ID)
447
511
  })
448
512
 
513
+ describe('payment amount precision', () => {
514
+ function useCurrencyDecimalPlaces(decimalPlaces: number) {
515
+ ;(createRequestContainer as jest.Mock).mockResolvedValue({
516
+ resolve: (name: string) => {
517
+ if (name === 'rateLimiterService') return { trustProxyDepth: 0 }
518
+ if (name === 'em') return { findOne: mockEmFindOne }
519
+ if (name === 'commandBus') return { execute: mockCommandExecute }
520
+ if (name === 'paymentGatewayService') return { createPaymentSession: mockCreatePaymentSession }
521
+ if (name === 'currencyPrecisionService') return { getDecimalPlaces: async () => decimalPlaces }
522
+ throw new Error(`Unknown dependency: ${name}`)
523
+ },
524
+ })
525
+ }
526
+
527
+ function submitPrecisionRequest(idempotencyKey: string, body: Record<string, unknown>) {
528
+ return POST(
529
+ new Request('https://merchant.example/api/checkout/pay/donate/submit', {
530
+ method: 'POST',
531
+ headers: {
532
+ 'content-type': 'application/json',
533
+ 'Idempotency-Key': idempotencyKey,
534
+ origin: 'https://merchant.example',
535
+ },
536
+ body: JSON.stringify({ customerData: {}, acceptedLegalConsents: {}, ...body }),
537
+ }),
538
+ { params: { slug: 'donate' } },
539
+ )
540
+ }
541
+
542
+ it('rejects a fixed price the provider cannot charge exactly before reserving the link or calling the provider', async () => {
543
+ useCurrencyDecimalPlaces(4)
544
+ ;(findOneWithDecryption as jest.Mock)
545
+ .mockResolvedValueOnce({
546
+ ...createLink(),
547
+ pricingMode: 'fixed',
548
+ fixedPriceAmount: '10.0051',
549
+ fixedPriceCurrencyCode: 'USD',
550
+ })
551
+ .mockResolvedValueOnce(null)
552
+
553
+ const response = await submitPrecisionRequest('precision-fixed-key-1', {})
554
+
555
+ expect(response.status).toBe(400)
556
+ const payload = await response.json()
557
+ expect(typeof payload.error).toBe('string')
558
+ expect(payload.error).toContain('10.0051')
559
+ expect(mockCommandExecute).not.toHaveBeenCalled()
560
+ expect(mockCreatePaymentSession).not.toHaveBeenCalled()
561
+ })
562
+
563
+ it('rejects a replayed transaction whose stored amount the provider cannot charge exactly', async () => {
564
+ useCurrencyDecimalPlaces(4)
565
+ ;(findOneWithDecryption as jest.Mock)
566
+ .mockResolvedValueOnce(createLink())
567
+ .mockResolvedValueOnce(createTransaction({ amount: '10.0051' }))
568
+
569
+ const response = await submitPrecisionRequest('precision-replay-key-1', { amount: 10 })
570
+
571
+ expect(response.status).toBe(400)
572
+ expect(mockCommandExecute).not.toHaveBeenCalled()
573
+ expect(mockCreatePaymentSession).not.toHaveBeenCalled()
574
+ })
575
+
576
+ it('checks the amount after rounding it to the currency decimals checkout stores', async () => {
577
+ useCurrencyDecimalPlaces(2)
578
+ ;(findOneWithDecryption as jest.Mock)
579
+ .mockResolvedValueOnce(createLink())
580
+ .mockResolvedValueOnce(null)
581
+ .mockResolvedValueOnce(createTransaction({ amount: '10.00' }))
582
+ .mockResolvedValueOnce(createTransaction({ amount: '10.00', gatewayTransactionId: GATEWAY_TRANSACTION_ID }))
583
+ mockCommandExecute.mockResolvedValueOnce({ result: { id: TRANSACTION_ID } })
584
+
585
+ const response = await submitPrecisionRequest('precision-rounded-key-1', { amount: 10.00001 })
586
+
587
+ expect(response.status).toBe(201)
588
+ expect(mockCreatePaymentSession).toHaveBeenCalledWith(
589
+ expect.objectContaining({ amount: 10, currencyCode: 'USD' }),
590
+ )
591
+ })
592
+ })
593
+
449
594
  describe('rate limiting is fail-closed', () => {
450
595
  function submitRequest() {
451
596
  return POST(