@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
@@ -0,0 +1,115 @@
1
+ /** @jest-environment jsdom */
2
+
3
+ import * as React from 'react'
4
+ import { render, screen } from '@testing-library/react'
5
+ import { formatPayPageAmount } from '../../lib/payPageAmount'
6
+
7
+ jest.mock('@open-mercato/shared/lib/i18n/context', () => ({
8
+ useT: () => (key: string, fallback?: string) => fallback ?? key,
9
+ useLocale: () => 'en-US',
10
+ useSupportedLocales: () => ['en-US'],
11
+ }))
12
+
13
+ jest.mock('@open-mercato/ui/backend/markdown/MarkdownContent', () => ({ MarkdownContent: () => null }))
14
+
15
+ import { PayPagePricing, PayPageSummary, type PayPagePricingProps, type PayLinkPayload } from '../PayPage'
16
+
17
+ const themeTokens = {
18
+ mode: 'light',
19
+ accent: '#000000',
20
+ accentSecondary: '#000000',
21
+ accentContrast: '#ffffff',
22
+ text: '#000000',
23
+ mutedText: '#000000',
24
+ pageBackground: '#ffffff',
25
+ shellBackground: '#ffffff',
26
+ surface: '#ffffff',
27
+ surfaceMuted: '#ffffff',
28
+ surfaceStrong: '#ffffff',
29
+ border: '#000000',
30
+ borderStrong: '#000000',
31
+ shadow: 'none',
32
+ accentShadow: 'none',
33
+ heroBackground: '#ffffff',
34
+ errorText: '#000000',
35
+ errorBorder: '#000000',
36
+ errorSurface: '#ffffff',
37
+ errorSurfaceStrong: '#ffffff',
38
+ errorRing: '#000000',
39
+ } satisfies PayPagePricingProps['themeTokens']
40
+
41
+ const formatAmount: PayPagePricingProps['formatAmount'] = (value, code, exact) => formatPayPageAmount(value, code, 'en-US', exact)
42
+
43
+ function renderPricing(payload: PayLinkPayload, amountExact?: string) {
44
+ return render(<PayPagePricing
45
+ payload={payload}
46
+ amount={amountExact ? Number(amountExact) : null}
47
+ amountExact={amountExact}
48
+ selectedPriceItemId={null}
49
+ fieldErrors={{}}
50
+ inputsLocked={false}
51
+ formatAmount={formatAmount}
52
+ onAmountChange={() => {}}
53
+ onPriceItemSelect={() => {}}
54
+ translateValidationMessage={(message) => message ?? ''}
55
+ themeTokens={themeTokens}
56
+ />)
57
+ }
58
+
59
+ describe('pay page exact amount display', () => {
60
+ it('renders the exact fixed price and original price', () => {
61
+ renderPricing({
62
+ id: 'eth-link',
63
+ name: 'ETH payment',
64
+ slug: 'eth',
65
+ pricingMode: 'fixed',
66
+ fixedPriceCurrencyCode: 'ETH',
67
+ fixedPriceAmount: 1.1234567890123457,
68
+ fixedPriceAmountExact: '1.123456789012345678',
69
+ fixedPriceOriginalAmount: 2.9876543210987654,
70
+ fixedPriceOriginalAmountExact: '2.987654321098765432',
71
+ })
72
+
73
+ expect(screen.getByText('ETH 1.123456789012345678')).toBeTruthy()
74
+ expect(screen.getByText('ETH 2.987654321098765432')).toBeTruthy()
75
+ })
76
+
77
+ it('renders the exact custom amount bounds', () => {
78
+ renderPricing({
79
+ id: 'eth-link',
80
+ name: 'ETH payment',
81
+ slug: 'eth',
82
+ pricingMode: 'custom_amount',
83
+ customAmountCurrencyCode: 'ETH',
84
+ customAmountMin: 1e-18,
85
+ customAmountMinExact: '0.000000000000000001',
86
+ customAmountMax: 10,
87
+ customAmountMaxExact: '9.999999999999999999',
88
+ }, '1.000000000000000001')
89
+
90
+ expect(screen.getByPlaceholderText('ETH 0.000000000000000001 - ETH 9.999999999999999999')).toBeTruthy()
91
+ expect((screen.getByRole('spinbutton') as HTMLInputElement).value).toBe('1.000000000000000001')
92
+ })
93
+
94
+ it('renders an exact price-list item and selected summary', () => {
95
+ const payload: PayLinkPayload = {
96
+ id: 'eth-link',
97
+ name: 'ETH payment',
98
+ slug: 'eth',
99
+ pricingMode: 'price_list',
100
+ priceListItems: [{ id: 'wei', description: 'One wei', currencyCode: 'ETH', amount: 1e-18, amountExact: '0.000000000000000001' }],
101
+ }
102
+ renderPricing(payload)
103
+ expect(screen.getByText('ETH 0.000000000000000001')).toBeTruthy()
104
+ render(<PayPageSummary
105
+ payload={payload}
106
+ selectedAmount={1e-18}
107
+ selectedAmountExact="0.000000000000000001"
108
+ currencyCode="ETH"
109
+ formatAmount={formatAmount}
110
+ preview={false}
111
+ themeTokens={themeTokens}
112
+ />)
113
+ expect(screen.getAllByText('ETH 0.000000000000000001')).toHaveLength(2)
114
+ })
115
+ })
@@ -0,0 +1,98 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+
5
+ jest.mock('lucide-react', () => {
6
+ const IconStub = () => null
7
+ return new Proxy(
8
+ { __esModule: true },
9
+ { get: (target, prop) => (prop in target ? (target as Record<string | symbol, unknown>)[prop] : IconStub) },
10
+ )
11
+ })
12
+
13
+ jest.mock('next/navigation', () => ({
14
+ useParams: () => ({}),
15
+ useRouter: () => ({ push: jest.fn() }),
16
+ useSearchParams: () => new URLSearchParams(),
17
+ }))
18
+
19
+ jest.mock('@open-mercato/shared/lib/i18n/context', () => ({
20
+ useT: () => (key: string, fallback?: unknown) => (typeof fallback === 'string' ? fallback : key),
21
+ useLocale: () => 'en-US',
22
+ useSupportedLocales: () => ['en'],
23
+ }))
24
+
25
+ jest.mock('@open-mercato/ui/backend/injection/InjectionSpot', () => ({
26
+ InjectionSpot: () => null,
27
+ useInjectionSpotEvents: () => ({ triggerEvent: jest.fn() }),
28
+ useInjectionWidgets: () => ({ widgets: [] }),
29
+ }))
30
+
31
+ jest.mock('@open-mercato/ui/backend/markdown/MarkdownContent', () => ({
32
+ MarkdownContent: () => null,
33
+ }))
34
+
35
+ import * as React from 'react'
36
+ import { render } from '@testing-library/react'
37
+ import { PayPagePricing, type PayLinkPayload, type PayPageThemeTokens } from '../PayPage'
38
+ import { formatPayPageAmount } from '../../lib/payPageAmount'
39
+
40
+ const ETH_AMOUNT = '1.123456789012345678'
41
+ const ONE_WEI = '0.000000000000000001'
42
+
43
+ const themeTokens = new Proxy({} as PayPageThemeTokens, {
44
+ get: (_target, prop) => (prop === 'mode' ? 'light' : '#000000'),
45
+ })
46
+
47
+ function renderPricing(payload: PayLinkPayload) {
48
+ return render(
49
+ <PayPagePricing
50
+ payload={payload}
51
+ amount={null}
52
+ selectedPriceItemId={null}
53
+ fieldErrors={{}}
54
+ inputsLocked={false}
55
+ formatAmount={(value, currencyCode, exact) => formatPayPageAmount(value, currencyCode, 'en-US', exact)}
56
+ onAmountChange={() => undefined}
57
+ onPriceItemSelect={() => undefined}
58
+ translateValidationMessage={(message) => message ?? ''}
59
+ themeTokens={themeTokens}
60
+ />,
61
+ )
62
+ }
63
+
64
+ function amountTexts(selector: string): Array<string | null> {
65
+ return Array.from(document.querySelectorAll(selector)).map((node) => node.textContent)
66
+ }
67
+
68
+ describe('PayPagePricing amount display', () => {
69
+ it('shows every charged digit of a fixed price', () => {
70
+ renderPricing({
71
+ id: 'link-1',
72
+ name: 'Token sale',
73
+ pricingMode: 'fixed',
74
+ fixedPriceAmount: Number(ETH_AMOUNT),
75
+ fixedPriceAmountExact: ETH_AMOUNT,
76
+ fixedPriceCurrencyCode: 'ETH',
77
+ })
78
+
79
+ expect(amountTexts('.text-4xl')).toEqual([`ETH\u00a0${ETH_AMOUNT}`])
80
+ })
81
+
82
+ it('shows every charged digit of the price-list items', () => {
83
+ renderPricing({
84
+ id: 'link-2',
85
+ name: 'Token tiers',
86
+ pricingMode: 'price_list',
87
+ priceListItems: [
88
+ { id: 'tier-1', description: 'Tier one', amount: Number(ETH_AMOUNT), amountExact: ETH_AMOUNT, currencyCode: 'ETH' },
89
+ { id: 'tier-2', description: 'One wei', amount: Number(ONE_WEI), amountExact: ONE_WEI, currencyCode: 'ETH' },
90
+ ],
91
+ })
92
+
93
+ expect(amountTexts('label > span.whitespace-nowrap')).toEqual([
94
+ `ETH\u00a0${ETH_AMOUNT}`,
95
+ `ETH\u00a0${ONE_WEI}`,
96
+ ])
97
+ })
98
+ })
@@ -0,0 +1,13 @@
1
+ import { toSubmittedAmount } from '../../LinkTemplateForm'
2
+ import type { PayPagePricingProps, PayPageSummaryProps } from '../../PayPage'
3
+
4
+ export function legacySubmittedAmountPlusFee(value: string, locale: string): number {
5
+ const amount: number | null = toSubmittedAmount(value, locale)
6
+ return (amount ?? 0) + 1
7
+ }
8
+
9
+ const legacyFormatter = (value: number | null | undefined, currencyCode?: string | null): string =>
10
+ `${currencyCode ?? ''} ${(value ?? 0).toFixed(2)}`
11
+
12
+ export const legacyPricingFormatter: PayPagePricingProps['formatAmount'] = legacyFormatter
13
+ export const legacySummaryFormatter: PayPageSummaryProps['formatAmount'] = legacyFormatter
@@ -0,0 +1,32 @@
1
+ /** @jest-environment node */
2
+ import * as path from 'node:path'
3
+ import * as ts from 'typescript'
4
+ import { legacyPricingFormatter, legacySubmittedAmountPlusFee } from './__fixtures__/legacyPayPageContracts'
5
+
6
+ const FIXTURE = path.join(__dirname, '__fixtures__', 'legacyPayPageContracts.ts')
7
+ const TSCONFIG = path.join(__dirname, '..', '..', '..', '..', '..', 'tsconfig.json')
8
+
9
+ function fixtureDiagnostics(): string[] {
10
+ const config = ts.readConfigFile(TSCONFIG, ts.sys.readFile)
11
+ const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, path.dirname(TSCONFIG))
12
+ const program = ts.createProgram([FIXTURE], { ...parsed.options, noEmit: true })
13
+ const source = program.getSourceFile(FIXTURE)
14
+ if (!source) throw new Error('[internal] fixture not found')
15
+ return [...program.getSyntacticDiagnostics(source), ...program.getSemanticDiagnostics(source)].map((diagnostic) =>
16
+ ts.flattenDiagnosticMessageText(diagnostic.messageText, ' '),
17
+ )
18
+ }
19
+
20
+ describe('checkout amount contracts stay backward compatible (spec D7)', () => {
21
+ it('compiles the numeric toSubmittedAmount return and number-only amount formatters', () => {
22
+ expect(fixtureDiagnostics()).toEqual([])
23
+ }, 120000)
24
+
25
+ it('returns a number from toSubmittedAmount', () => {
26
+ expect(legacySubmittedAmountPlusFee('110,70', 'pl-PL')).toBeCloseTo(111.7)
27
+ })
28
+
29
+ it('accepts a formatter that only understands numbers', () => {
30
+ expect(legacyPricingFormatter(12.5, 'USD')).toBe('USD 12.50')
31
+ })
32
+ })
@@ -1,6 +1,10 @@
1
+ import { z } from 'zod'
1
2
  import {
3
+ assertExactCustomAmountRange,
2
4
  createLinkSchema,
3
5
  createTemplateSchema,
6
+ priceListItemSchema,
7
+ publicSubmitSchema,
4
8
  updateLinkSchema,
5
9
  updateTemplateSchema,
6
10
  } from '../validators'
@@ -127,4 +131,91 @@ describe('checkout validators', () => {
127
131
  }),
128
132
  ).toThrow()
129
133
  })
134
+
135
+ test('assertExactCustomAmountRange rejects a min above max that differs only beyond float precision', () => {
136
+ let caught: unknown = null
137
+ try {
138
+ assertExactCustomAmountRange({
139
+ pricingMode: 'custom_amount',
140
+ customAmountMinExact: '1.000000000000000002',
141
+ customAmountMaxExact: '1.000000000000000001',
142
+ })
143
+ } catch (error) {
144
+ caught = error
145
+ }
146
+
147
+ expect(caught).toBeInstanceOf(z.ZodError)
148
+ expect((caught as z.ZodError).issues).toEqual([
149
+ expect.objectContaining({
150
+ code: 'custom',
151
+ message: 'checkout.validation.customAmount.range',
152
+ path: ['customAmountMax'],
153
+ }),
154
+ ])
155
+ })
156
+
157
+ test('assertExactCustomAmountRange accepts ordered, equal, partial or non custom amount ranges', () => {
158
+ expect(() => assertExactCustomAmountRange({
159
+ pricingMode: 'custom_amount',
160
+ customAmountMinExact: '1.000000000000000001',
161
+ customAmountMaxExact: '1.000000000000000002',
162
+ })).not.toThrow()
163
+ expect(() => assertExactCustomAmountRange({
164
+ pricingMode: 'custom_amount',
165
+ customAmountMinExact: '1.000000000000000001',
166
+ customAmountMaxExact: '1.0000000000000000010',
167
+ })).not.toThrow()
168
+ expect(() => assertExactCustomAmountRange({
169
+ pricingMode: 'custom_amount',
170
+ customAmountMinExact: '1.000000000000000002',
171
+ })).not.toThrow()
172
+ expect(() => assertExactCustomAmountRange({
173
+ pricingMode: 'fixed',
174
+ customAmountMinExact: '1.000000000000000002',
175
+ customAmountMaxExact: '1.000000000000000001',
176
+ })).not.toThrow()
177
+ })
178
+
179
+ describe('money fields beyond the decimal size caps', () => {
180
+ const oversizedValues = [1e305, '1e305', `0.${'1'.repeat(1001)}`]
181
+ const fixedTemplate = {
182
+ name: 'QA template',
183
+ pricingMode: 'fixed' as const,
184
+ fixedPriceCurrencyCode: 'USD',
185
+ gatewayProviderKey: 'mock',
186
+ }
187
+
188
+ test.each(['fixedPriceAmount', 'fixedPriceOriginalAmount', 'customAmountMin', 'customAmountMax'] as const)(
189
+ 'createTemplateSchema rejects an oversized %s instead of storing 0',
190
+ (field) => {
191
+ for (const value of oversizedValues) {
192
+ const result = createTemplateSchema.safeParse({ ...fixedTemplate, fixedPriceAmount: 10, [field]: value })
193
+ expect(result.success).toBe(false)
194
+ if (!result.success) {
195
+ expect(result.error.issues).toEqual(expect.arrayContaining([
196
+ expect.objectContaining({ path: [field], message: 'checkout.validation.common.invalidNumber' }),
197
+ ]))
198
+ }
199
+ }
200
+ },
201
+ )
202
+
203
+ test('priceListItemSchema rejects an oversized amount and keeps coercing in-range values', () => {
204
+ const item = { id: 'general', description: 'General admission', currencyCode: 'USD' }
205
+ for (const value of oversizedValues) {
206
+ expect(priceListItemSchema.safeParse({ ...item, amount: value }).success).toBe(false)
207
+ }
208
+ expect(priceListItemSchema.parse({ ...item, amount: '25.125' }).amount).toBe(25.125)
209
+ expect(priceListItemSchema.parse({ ...item, amount: null }).amount).toBe(0)
210
+ })
211
+
212
+ test('publicSubmitSchema rejects an oversized amount and keeps a null amount for fixed pricing', () => {
213
+ for (const value of oversizedValues) {
214
+ expect(publicSubmitSchema.safeParse({ customerData: {}, amount: value }).success).toBe(false)
215
+ }
216
+ expect(publicSubmitSchema.parse({ customerData: {}, amount: '12.5' }).amount).toBe(12.5)
217
+ expect(publicSubmitSchema.parse({ customerData: {}, amount: null }).amount).toBe(0)
218
+ expect(publicSubmitSchema.parse({ customerData: {} }).amount).toBeUndefined()
219
+ })
220
+ })
130
221
  })
@@ -1,5 +1,6 @@
1
1
  import { OptionalProps } from '@mikro-orm/core'
2
2
  import { Entity, Index, PrimaryKey, Property } from '@mikro-orm/decorators/legacy'
3
+ import { ExactDecimalType } from '@open-mercato/shared/lib/db/exactDecimalType'
3
4
 
4
5
  @Entity({ tableName: 'checkout_link_templates' })
5
6
  @Index({ properties: ['organizationId', 'tenantId', 'deletedAt'] })
@@ -94,7 +95,7 @@ export class CheckoutLinkTemplate {
94
95
  @Property({ name: 'pricing_mode', type: 'text' })
95
96
  pricingMode!: 'fixed' | 'custom_amount' | 'price_list'
96
97
 
97
- @Property({ name: 'fixed_price_amount', type: 'numeric', precision: 12, scale: 2, nullable: true })
98
+ @Property({ name: 'fixed_price_amount', type: ExactDecimalType, columnType: 'numeric', nullable: true })
98
99
  fixedPriceAmount?: string | null
99
100
 
100
101
  @Property({ name: 'fixed_price_currency_code', type: 'text', nullable: true })
@@ -103,20 +104,20 @@ export class CheckoutLinkTemplate {
103
104
  @Property({ name: 'fixed_price_includes_tax', type: 'boolean', default: true })
104
105
  fixedPriceIncludesTax: boolean = true
105
106
 
106
- @Property({ name: 'fixed_price_original_amount', type: 'numeric', precision: 12, scale: 2, nullable: true })
107
+ @Property({ name: 'fixed_price_original_amount', type: ExactDecimalType, columnType: 'numeric', nullable: true })
107
108
  fixedPriceOriginalAmount?: string | null
108
109
 
109
- @Property({ name: 'custom_amount_min', type: 'numeric', precision: 12, scale: 2, nullable: true })
110
+ @Property({ name: 'custom_amount_min', type: ExactDecimalType, columnType: 'numeric', nullable: true })
110
111
  customAmountMin?: string | null
111
112
 
112
- @Property({ name: 'custom_amount_max', type: 'numeric', precision: 12, scale: 2, nullable: true })
113
+ @Property({ name: 'custom_amount_max', type: ExactDecimalType, columnType: 'numeric', nullable: true })
113
114
  customAmountMax?: string | null
114
115
 
115
116
  @Property({ name: 'custom_amount_currency_code', type: 'text', nullable: true })
116
117
  customAmountCurrencyCode?: string | null
117
118
 
118
119
  @Property({ name: 'price_list_items', type: 'jsonb', nullable: true })
119
- priceListItems?: Array<{ id: string; description: string; amount: number; currencyCode: string }> | null
120
+ priceListItems?: Array<{ id: string; description: string; amount: number; amountExact?: string | null; currencyCode: string }> | null
120
121
 
121
122
  @Property({ name: 'gateway_provider_key', type: 'text', nullable: true })
122
123
  gatewayProviderKey?: string | null
@@ -266,7 +267,7 @@ export class CheckoutTransaction {
266
267
  @Property({ type: 'text' })
267
268
  status!: 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled' | 'expired'
268
269
 
269
- @Property({ type: 'numeric', precision: 12, scale: 2 })
270
+ @Property({ type: ExactDecimalType, columnType: 'numeric' })
270
271
  amount!: string
271
272
 
272
273
  @Property({ name: 'currency_code', type: 'text' })
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod'
2
2
  import { fieldsetCodeRegex } from '@open-mercato/shared/modules/entities/validators'
3
+ import { compareDecimals, withDecimalCaps, parseDecimal } from '@open-mercato/shared/lib/decimal'
3
4
  import { DEFAULT_CHECKOUT_CUSTOMER_FIELDS } from '../lib/defaults'
4
5
  import { CHECKOUT_LINK_STATUSES } from '../lib/constants'
5
6
 
@@ -43,7 +44,11 @@ const optionalFieldsetCodeSchema = z.preprocess(
43
44
  message: 'checkout.validation.common.invalidFieldsetCode',
44
45
  }).optional().nullable(),
45
46
  )
46
- const positiveMoneySchema = z.coerce.number().finite('checkout.validation.common.invalidNumber').nonnegative('checkout.validation.common.nonNegativeNumber')
47
+ const moneyInputSchema = <T extends z.ZodType>(schema: T) => withDecimalCaps(schema, 'checkout.validation.common.invalidNumber')
48
+
49
+ const positiveMoneySchema = moneyInputSchema(
50
+ z.coerce.number().finite('checkout.validation.common.invalidNumber').nonnegative('checkout.validation.common.nonNegativeNumber'),
51
+ )
47
52
  const linkStatusSchema = z.enum(CHECKOUT_LINK_STATUSES)
48
53
  const themeModeSchema = z.enum(['light', 'dark', 'auto'])
49
54
  const checkoutTypeSchema = z.enum(['pay_link', 'simple_checkout'])
@@ -189,6 +194,25 @@ function validatePricingConsistency<T extends z.infer<typeof checkoutContentSche
189
194
  }
190
195
  }
191
196
 
197
+ export type ExactCustomAmountRangeInput = {
198
+ pricingMode?: unknown
199
+ customAmountMinExact?: string | null
200
+ customAmountMaxExact?: string | null
201
+ }
202
+
203
+ export function assertExactCustomAmountRange(value: ExactCustomAmountRangeInput): void {
204
+ if (value.pricingMode !== 'custom_amount') return
205
+ const minimum = parseDecimal(value.customAmountMinExact)
206
+ const maximum = parseDecimal(value.customAmountMaxExact)
207
+ if (!minimum || !maximum || compareDecimals(minimum, maximum) <= 0) return
208
+ throw new z.ZodError([{
209
+ code: 'custom',
210
+ message: 'checkout.validation.customAmount.range',
211
+ path: ['customAmountMax'],
212
+ input: value.customAmountMaxExact,
213
+ }])
214
+ }
215
+
192
216
  export const createTemplateSchema = checkoutContentSchema.superRefine((value, ctx) => {
193
217
  validatePricingConsistency(value, ctx)
194
218
  if (!value.gatewayProviderKey) {
@@ -280,7 +304,7 @@ export const publicSubmitSchema = z.object({
280
304
  terms: z.boolean().optional(),
281
305
  privacyPolicy: z.boolean().optional(),
282
306
  }).default({}),
283
- amount: z.coerce.number().finite().nonnegative().optional(),
307
+ amount: moneyInputSchema(z.coerce.number().finite().nonnegative()).optional(),
284
308
  selectedPriceItemId: optionalTrimmedString,
285
309
  })
286
310
 
@@ -168,6 +168,7 @@
168
168
  "checkout.defaultCustomerFields.lastName.placeholder": "Doe",
169
169
  "checkout.defaultCustomerFields.phone.label": "Phone",
170
170
  "checkout.defaultCustomerFields.phone.placeholder": "+1 555 123 4567",
171
+ "checkout.errors.amountPrecisionExceeded": "Der Betrag {amount} hat mehr Nachkommastellen, als {currencyCode} unterstützt ({decimalPlaces})",
171
172
  "checkout.errors.links.lockedEdit": "Dieser Zahlungslink hat aktive Transaktionen und kann nicht bearbeitet werden",
172
173
  "checkout.errors.links.notFound": "Zahlungslink nicht gefunden",
173
174
  "checkout.gatewaySettings.notices.chooseProvider": "Choose a gateway provider to configure checkout session settings.",
@@ -168,6 +168,7 @@
168
168
  "checkout.defaultCustomerFields.lastName.placeholder": "Doe",
169
169
  "checkout.defaultCustomerFields.phone.label": "Phone",
170
170
  "checkout.defaultCustomerFields.phone.placeholder": "+1 555 123 4567",
171
+ "checkout.errors.amountPrecisionExceeded": "Amount {amount} has more decimal places than {currencyCode} supports ({decimalPlaces})",
171
172
  "checkout.errors.links.lockedEdit": "This link has active transactions and cannot be edited",
172
173
  "checkout.errors.links.notFound": "Payment link not found",
173
174
  "checkout.gatewaySettings.notices.chooseProvider": "Choose a gateway provider to configure checkout session settings.",
@@ -168,6 +168,7 @@
168
168
  "checkout.defaultCustomerFields.lastName.placeholder": "Doe",
169
169
  "checkout.defaultCustomerFields.phone.label": "Phone",
170
170
  "checkout.defaultCustomerFields.phone.placeholder": "+1 555 123 4567",
171
+ "checkout.errors.amountPrecisionExceeded": "El importe {amount} tiene más decimales de los que admite {currencyCode} ({decimalPlaces})",
171
172
  "checkout.errors.links.lockedEdit": "Este enlace de pago tiene transacciones activas y no se puede editar",
172
173
  "checkout.errors.links.notFound": "No se encontro el enlace de pago",
173
174
  "checkout.gatewaySettings.notices.chooseProvider": "Choose a gateway provider to configure checkout session settings.",
@@ -168,6 +168,7 @@
168
168
  "checkout.defaultCustomerFields.lastName.placeholder": "Doe",
169
169
  "checkout.defaultCustomerFields.phone.label": "전화번호",
170
170
  "checkout.defaultCustomerFields.phone.placeholder": "+1 555 123 4567",
171
+ "checkout.errors.amountPrecisionExceeded": "금액 {amount}의 소수 자릿수가 {currencyCode}에서 지원하는 자릿수({decimalPlaces})보다 많습니다",
171
172
  "checkout.errors.links.lockedEdit": "이 결제 링크에는 활성 거래가 있어 편집할 수 없습니다",
172
173
  "checkout.errors.links.notFound": "결제 링크를 찾을 수 없습니다",
173
174
  "checkout.gatewaySettings.notices.chooseProvider": "체크아웃 세션 설정을 구성하려면 게이트웨이 제공업체를 선택하세요.",
@@ -168,6 +168,7 @@
168
168
  "checkout.defaultCustomerFields.lastName.placeholder": "Kowalski",
169
169
  "checkout.defaultCustomerFields.phone.label": "Telefon",
170
170
  "checkout.defaultCustomerFields.phone.placeholder": "+48 500 123 456",
171
+ "checkout.errors.amountPrecisionExceeded": "Kwota {amount} ma więcej miejsc po przecinku, niż obsługuje waluta {currencyCode} ({decimalPlaces})",
171
172
  "checkout.errors.links.lockedEdit": "Ten link płatności ma aktywne transakcje i nie można go edytować",
172
173
  "checkout.errors.links.notFound": "Nie znaleziono linku płatności",
173
174
  "checkout.gatewaySettings.notices.chooseProvider": "Wybierz dostawcę bramki, aby skonfigurować ustawienia sesji checkout.",