@open-mercato/checkout 0.10.1-develop.8287.1.7313a0fe67 → 0.10.1-develop.8291.1.6ec3aee41c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/dist/modules/checkout/__integration__/TC-CHK-CRUDFORM-001.spec.js +3 -3
- package/dist/modules/checkout/__integration__/TC-CHK-CRUDFORM-001.spec.js.map +2 -2
- package/dist/modules/checkout/__integration__/TC-CHKT-037-template-sync.spec.js +3 -1
- package/dist/modules/checkout/__integration__/TC-CHKT-037-template-sync.spec.js.map +2 -2
- package/dist/modules/checkout/__integration__/TC-CHKT-PRECISION-001.spec.js +259 -0
- package/dist/modules/checkout/__integration__/TC-CHKT-PRECISION-001.spec.js.map +7 -0
- package/dist/modules/checkout/__integration__/TC-CHKT-PRECISION-002-admin-round-trip.spec.js +85 -0
- package/dist/modules/checkout/__integration__/TC-CHKT-PRECISION-002-admin-round-trip.spec.js.map +7 -0
- package/dist/modules/checkout/api/pay/[slug]/submit/route.js +17 -2
- package/dist/modules/checkout/api/pay/[slug]/submit/route.js.map +2 -2
- package/dist/modules/checkout/backend/checkout/pay-links/page.js +9 -3
- package/dist/modules/checkout/backend/checkout/pay-links/page.js.map +2 -2
- package/dist/modules/checkout/commands/links.js +7 -10
- package/dist/modules/checkout/commands/links.js.map +2 -2
- package/dist/modules/checkout/commands/shared.js +43 -7
- package/dist/modules/checkout/commands/shared.js.map +2 -2
- package/dist/modules/checkout/commands/templates.js +12 -10
- package/dist/modules/checkout/commands/templates.js.map +2 -2
- package/dist/modules/checkout/commands/transactions.js +13 -1
- package/dist/modules/checkout/commands/transactions.js.map +2 -2
- package/dist/modules/checkout/components/LinkTemplateForm.js +47 -20
- package/dist/modules/checkout/components/LinkTemplateForm.js.map +2 -2
- package/dist/modules/checkout/components/PayPage.js +59 -55
- package/dist/modules/checkout/components/PayPage.js.map +2 -2
- package/dist/modules/checkout/data/entities.js +6 -5
- package/dist/modules/checkout/data/entities.js.map +2 -2
- package/dist/modules/checkout/data/validators.js +19 -2
- package/dist/modules/checkout/data/validators.js.map +2 -2
- package/dist/modules/checkout/i18n/de.json +1 -0
- package/dist/modules/checkout/i18n/en.json +1 -0
- package/dist/modules/checkout/i18n/es.json +1 -0
- package/dist/modules/checkout/i18n/ko.json +1 -0
- package/dist/modules/checkout/i18n/pl.json +1 -0
- package/dist/modules/checkout/lib/amountPrecision.js +98 -0
- package/dist/modules/checkout/lib/amountPrecision.js.map +7 -0
- package/dist/modules/checkout/lib/payPageAmount.js +56 -0
- package/dist/modules/checkout/lib/payPageAmount.js.map +7 -0
- package/dist/modules/checkout/lib/utils.js +63 -20
- package/dist/modules/checkout/lib/utils.js.map +2 -2
- package/dist/modules/checkout/migrations/Migration20261014082519_checkout.js +33 -0
- package/dist/modules/checkout/migrations/Migration20261014082519_checkout.js.map +7 -0
- package/dist/modules/checkout/workers/send-email.worker.js +8 -1
- package/dist/modules/checkout/workers/send-email.worker.js.map +2 -2
- package/package.json +10 -7
- package/src/modules/checkout/__integration__/TC-CHK-CRUDFORM-001.spec.ts +3 -3
- package/src/modules/checkout/__integration__/TC-CHKT-037-template-sync.spec.ts +2 -0
- package/src/modules/checkout/__integration__/TC-CHKT-PRECISION-001.spec.ts +320 -0
- package/src/modules/checkout/__integration__/TC-CHKT-PRECISION-002-admin-round-trip.spec.ts +112 -0
- package/src/modules/checkout/api/pay/[slug]/__tests__/route.test.ts +4 -0
- package/src/modules/checkout/api/pay/[slug]/submit/__tests__/route.test.ts +145 -0
- package/src/modules/checkout/api/pay/[slug]/submit/route.ts +19 -2
- package/src/modules/checkout/backend/checkout/pay-links/page.tsx +13 -3
- package/src/modules/checkout/commands/__tests__/configured-amount-precision.test.ts +180 -0
- package/src/modules/checkout/commands/__tests__/create-transaction-amount.test.ts +77 -0
- package/src/modules/checkout/commands/__tests__/template-sync.test.ts +145 -0
- package/src/modules/checkout/commands/links.ts +7 -10
- package/src/modules/checkout/commands/shared.ts +56 -7
- package/src/modules/checkout/commands/templates.ts +12 -10
- package/src/modules/checkout/commands/transactions.ts +15 -1
- package/src/modules/checkout/components/LinkTemplateForm.tsx +52 -21
- package/src/modules/checkout/components/PayPage.tsx +76 -58
- package/src/modules/checkout/components/__tests__/LinkTemplateForm.localeDecimalSeparator.test.tsx +35 -1
- package/src/modules/checkout/components/__tests__/LinkTemplateForm.priceListExactAmount.test.tsx +196 -0
- package/src/modules/checkout/components/__tests__/PayPage.amountPrecision.test.tsx +115 -0
- package/src/modules/checkout/components/__tests__/PayPagePricing.amountDisplay.test.tsx +98 -0
- package/src/modules/checkout/components/__tests__/__fixtures__/legacyPayPageContracts.ts +13 -0
- package/src/modules/checkout/components/__tests__/payPageContracts.backwardCompat.test.ts +32 -0
- package/src/modules/checkout/data/__tests__/validators.test.ts +91 -0
- package/src/modules/checkout/data/entities.ts +7 -6
- package/src/modules/checkout/data/validators.ts +26 -2
- package/src/modules/checkout/i18n/de.json +1 -0
- package/src/modules/checkout/i18n/en.json +1 -0
- package/src/modules/checkout/i18n/es.json +1 -0
- package/src/modules/checkout/i18n/ko.json +1 -0
- package/src/modules/checkout/i18n/pl.json +1 -0
- package/src/modules/checkout/lib/__tests__/amountPrecision.test.ts +169 -0
- package/src/modules/checkout/lib/__tests__/payPageAmount.test.ts +127 -0
- package/src/modules/checkout/lib/__tests__/utils.test.ts +72 -0
- package/src/modules/checkout/lib/amountPrecision.ts +152 -0
- package/src/modules/checkout/lib/payPageAmount.ts +99 -0
- package/src/modules/checkout/lib/utils.ts +85 -28
- package/src/modules/checkout/migrations/.snapshot-open-mercato.json +158 -27
- package/src/modules/checkout/migrations/Migration20261014082519_checkout.ts +35 -0
- package/src/modules/checkout/migrations/__tests__/Migration20261014082519_checkout.integration.test.ts +6 -0
- package/src/modules/checkout/workers/__tests__/send-email.worker.test.ts +43 -0
- package/src/modules/checkout/workers/send-email.worker.ts +8 -1
|
@@ -10,6 +10,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
10
10
|
};
|
|
11
11
|
import { OptionalProps } from "@mikro-orm/core";
|
|
12
12
|
import { Entity, Index, PrimaryKey, Property } from "@mikro-orm/decorators/legacy";
|
|
13
|
+
import { ExactDecimalType } from "@open-mercato/shared/lib/db/exactDecimalType";
|
|
13
14
|
OptionalProps;
|
|
14
15
|
let CheckoutLinkTemplate = class {
|
|
15
16
|
constructor() {
|
|
@@ -69,7 +70,7 @@ __decorateClass([
|
|
|
69
70
|
Property({ name: "pricing_mode", type: "text" })
|
|
70
71
|
], CheckoutLinkTemplate.prototype, "pricingMode", 2);
|
|
71
72
|
__decorateClass([
|
|
72
|
-
Property({ name: "fixed_price_amount", type:
|
|
73
|
+
Property({ name: "fixed_price_amount", type: ExactDecimalType, columnType: "numeric", nullable: true })
|
|
73
74
|
], CheckoutLinkTemplate.prototype, "fixedPriceAmount", 2);
|
|
74
75
|
__decorateClass([
|
|
75
76
|
Property({ name: "fixed_price_currency_code", type: "text", nullable: true })
|
|
@@ -78,13 +79,13 @@ __decorateClass([
|
|
|
78
79
|
Property({ name: "fixed_price_includes_tax", type: "boolean", default: true })
|
|
79
80
|
], CheckoutLinkTemplate.prototype, "fixedPriceIncludesTax", 2);
|
|
80
81
|
__decorateClass([
|
|
81
|
-
Property({ name: "fixed_price_original_amount", type:
|
|
82
|
+
Property({ name: "fixed_price_original_amount", type: ExactDecimalType, columnType: "numeric", nullable: true })
|
|
82
83
|
], CheckoutLinkTemplate.prototype, "fixedPriceOriginalAmount", 2);
|
|
83
84
|
__decorateClass([
|
|
84
|
-
Property({ name: "custom_amount_min", type:
|
|
85
|
+
Property({ name: "custom_amount_min", type: ExactDecimalType, columnType: "numeric", nullable: true })
|
|
85
86
|
], CheckoutLinkTemplate.prototype, "customAmountMin", 2);
|
|
86
87
|
__decorateClass([
|
|
87
|
-
Property({ name: "custom_amount_max", type:
|
|
88
|
+
Property({ name: "custom_amount_max", type: ExactDecimalType, columnType: "numeric", nullable: true })
|
|
88
89
|
], CheckoutLinkTemplate.prototype, "customAmountMax", 2);
|
|
89
90
|
__decorateClass([
|
|
90
91
|
Property({ name: "custom_amount_currency_code", type: "text", nullable: true })
|
|
@@ -234,7 +235,7 @@ __decorateClass([
|
|
|
234
235
|
Property({ type: "text" })
|
|
235
236
|
], CheckoutTransaction.prototype, "status", 2);
|
|
236
237
|
__decorateClass([
|
|
237
|
-
Property({ type:
|
|
238
|
+
Property({ type: ExactDecimalType, columnType: "numeric" })
|
|
238
239
|
], CheckoutTransaction.prototype, "amount", 2);
|
|
239
240
|
__decorateClass([
|
|
240
241
|
Property({ name: "currency_code", type: "text" })
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/checkout/data/entities.ts"],
|
|
4
|
-
"sourcesContent": ["import { OptionalProps } from '@mikro-orm/core'\nimport { Entity, Index, PrimaryKey, Property } from '@mikro-orm/decorators/legacy'\n\n@Entity({ tableName: 'checkout_link_templates' })\n@Index({ properties: ['organizationId', 'tenantId', 'deletedAt'] })\nexport class CheckoutLinkTemplate {\n [OptionalProps]?:\n | 'title'\n | 'subtitle'\n | 'description'\n | 'logoAttachmentId'\n | 'logoUrl'\n | 'primaryColor'\n | 'secondaryColor'\n | 'backgroundColor'\n | 'themeMode'\n | 'fixedPriceAmount'\n | 'fixedPriceCurrencyCode'\n | 'fixedPriceIncludesTax'\n | 'fixedPriceOriginalAmount'\n | 'customAmountMin'\n | 'customAmountMax'\n | 'customAmountCurrencyCode'\n | 'priceListItems'\n | 'gatewayProviderKey'\n | 'gatewaySettings'\n | 'customFieldsetCode'\n | 'collectCustomerDetails'\n | 'customerFieldsSchema'\n | 'legalDocuments'\n | 'displayCustomFieldsOnPage'\n | 'successTitle'\n | 'successMessage'\n | 'cancelTitle'\n | 'cancelMessage'\n | 'errorTitle'\n | 'errorMessage'\n | 'successEmailSubject'\n | 'successEmailBody'\n | 'sendSuccessEmail'\n | 'errorEmailSubject'\n | 'errorEmailBody'\n | 'sendErrorEmail'\n | 'startEmailSubject'\n | 'startEmailBody'\n | 'sendStartEmail'\n | 'passwordHash'\n | 'maxCompletions'\n | 'status'\n | 'checkoutType'\n | 'createdAt'\n | 'updatedAt'\n | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ type: 'text' })\n name!: string\n\n @Property({ type: 'text', nullable: true })\n title?: string | null\n\n @Property({ type: 'text', nullable: true })\n subtitle?: string | null\n\n @Property({ type: 'text', nullable: true })\n description?: string | null\n\n @Property({ name: 'logo_attachment_id', type: 'uuid', nullable: true })\n logoAttachmentId?: string | null\n\n @Property({ name: 'logo_url', type: 'text', nullable: true })\n logoUrl?: string | null\n\n @Property({ name: 'primary_color', type: 'text', nullable: true })\n primaryColor?: string | null\n\n @Property({ name: 'secondary_color', type: 'text', nullable: true })\n secondaryColor?: string | null\n\n @Property({ name: 'background_color', type: 'text', nullable: true })\n backgroundColor?: string | null\n\n @Property({ name: 'theme_mode', type: 'text', default: 'auto' })\n themeMode: 'light' | 'dark' | 'auto' = 'auto'\n\n @Property({ name: 'pricing_mode', type: 'text' })\n pricingMode!: 'fixed' | 'custom_amount' | 'price_list'\n\n @Property({ name: 'fixed_price_amount', type: 'numeric', precision: 12, scale: 2, nullable: true })\n fixedPriceAmount?: string | null\n\n @Property({ name: 'fixed_price_currency_code', type: 'text', nullable: true })\n fixedPriceCurrencyCode?: string | null\n\n @Property({ name: 'fixed_price_includes_tax', type: 'boolean', default: true })\n fixedPriceIncludesTax: boolean = true\n\n @Property({ name: 'fixed_price_original_amount', type: 'numeric', precision: 12, scale: 2, nullable: true })\n fixedPriceOriginalAmount?: string | null\n\n @Property({ name: 'custom_amount_min', type: 'numeric', precision: 12, scale: 2, nullable: true })\n customAmountMin?: string | null\n\n @Property({ name: 'custom_amount_max', type: 'numeric', precision: 12, scale: 2, nullable: true })\n customAmountMax?: string | null\n\n @Property({ name: 'custom_amount_currency_code', type: 'text', nullable: true })\n customAmountCurrencyCode?: string | null\n\n @Property({ name: 'price_list_items', type: 'jsonb', nullable: true })\n priceListItems?: Array<{ id: string; description: string; amount: number; currencyCode: string }> | null\n\n @Property({ name: 'gateway_provider_key', type: 'text', nullable: true })\n gatewayProviderKey?: string | null\n\n @Property({ name: 'gateway_settings', type: 'jsonb', nullable: true })\n gatewaySettings?: Record<string, unknown> | null\n\n @Property({ name: 'custom_fieldset_code', type: 'text', nullable: true })\n customFieldsetCode?: string | null\n\n @Property({ name: 'collect_customer_details', type: 'boolean', default: true })\n collectCustomerDetails: boolean = true\n\n @Property({ name: 'customer_fields_schema', type: 'jsonb', nullable: true })\n customerFieldsSchema?: Array<Record<string, unknown>> | null\n\n @Property({ name: 'legal_documents', type: 'jsonb', nullable: true })\n legalDocuments?: Record<string, unknown> | null\n\n @Property({ name: 'display_custom_fields_on_page', type: 'boolean', default: false })\n displayCustomFieldsOnPage: boolean = false\n\n @Property({ name: 'success_title', type: 'text', nullable: true })\n successTitle?: string | null\n\n @Property({ name: 'success_message', type: 'text', nullable: true })\n successMessage?: string | null\n\n @Property({ name: 'cancel_title', type: 'text', nullable: true })\n cancelTitle?: string | null\n\n @Property({ name: 'cancel_message', type: 'text', nullable: true })\n cancelMessage?: string | null\n\n @Property({ name: 'error_title', type: 'text', nullable: true })\n errorTitle?: string | null\n\n @Property({ name: 'error_message', type: 'text', nullable: true })\n errorMessage?: string | null\n\n @Property({ name: 'success_email_subject', type: 'text', nullable: true })\n successEmailSubject?: string | null\n\n @Property({ name: 'success_email_body', type: 'text', nullable: true })\n successEmailBody?: string | null\n\n @Property({ name: 'send_success_email', type: 'boolean', default: true })\n sendSuccessEmail: boolean = true\n\n @Property({ name: 'error_email_subject', type: 'text', nullable: true })\n errorEmailSubject?: string | null\n\n @Property({ name: 'error_email_body', type: 'text', nullable: true })\n errorEmailBody?: string | null\n\n @Property({ name: 'send_error_email', type: 'boolean', default: true })\n sendErrorEmail: boolean = true\n\n @Property({ name: 'start_email_subject', type: 'text', nullable: true })\n startEmailSubject?: string | null\n\n @Property({ name: 'start_email_body', type: 'text', nullable: true })\n startEmailBody?: string | null\n\n @Property({ name: 'send_start_email', type: 'boolean', default: true })\n sendStartEmail: boolean = true\n\n @Property({ name: 'password_hash', type: 'text', nullable: true })\n passwordHash?: string | null\n\n @Property({ name: 'max_completions', type: 'integer', nullable: true })\n maxCompletions?: number | null\n\n @Property({ type: 'text', default: 'draft' })\n status: 'draft' | 'active' | 'inactive' = 'draft'\n\n @Property({ name: 'checkout_type', type: 'text', default: 'pay_link' })\n checkoutType: 'pay_link' | 'simple_checkout' = 'pay_link'\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n@Entity({ tableName: 'checkout_links' })\n@Index({ properties: ['organizationId', 'tenantId', 'status', 'deletedAt'] })\n@Index({ properties: ['slug'], options: { unique: true, where: 'deleted_at is null' } })\nexport class CheckoutLink extends CheckoutLinkTemplate {\n @Property({ name: 'template_id', type: 'uuid', nullable: true })\n templateId?: string | null\n\n @Property({ type: 'text' })\n slug!: string\n\n @Property({ name: 'completion_count', type: 'integer', default: 0 })\n completionCount: number = 0\n\n @Property({ name: 'active_reservation_count', type: 'integer', default: 0 })\n activeReservationCount: number = 0\n\n @Property({ name: 'is_locked', type: 'boolean', default: false })\n isLocked: boolean = false\n}\n\n@Entity({ tableName: 'checkout_transactions' })\n@Index({ properties: ['organizationId', 'tenantId', 'linkId', 'status'] })\n@Index({ properties: ['organizationId', 'tenantId', 'createdAt'] })\n@Index({ properties: ['gatewayTransactionId'] })\n@Index({\n properties: ['organizationId', 'tenantId', 'linkId', 'idempotencyKey'],\n options: { unique: true },\n})\nexport class CheckoutTransaction {\n [OptionalProps]?:\n | 'idempotencyKey'\n | 'customerData'\n | 'firstName'\n | 'lastName'\n | 'email'\n | 'phone'\n | 'gatewayTransactionId'\n | 'paymentStatus'\n | 'selectedPriceItemId'\n | 'acceptedLegalConsents'\n | 'ipAddress'\n | 'userAgent'\n | 'createdAt'\n | 'updatedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'link_id', type: 'uuid' })\n linkId!: string\n\n @Property({ type: 'text' })\n status!: 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled' | 'expired'\n\n @Property({ type: 'numeric', precision: 12, scale: 2 })\n amount!: string\n\n @Property({ name: 'currency_code', type: 'text' })\n currencyCode!: string\n\n @Property({ name: 'idempotency_key', type: 'text' })\n idempotencyKey!: string\n\n @Property({ name: 'customer_data', type: 'jsonb', nullable: true })\n customerData?: Record<string, unknown> | null\n\n @Property({ name: 'first_name', type: 'text', nullable: true })\n firstName?: string | null\n\n @Property({ name: 'last_name', type: 'text', nullable: true })\n lastName?: string | null\n\n @Property({ type: 'text', nullable: true })\n email?: string | null\n\n @Property({ type: 'text', nullable: true })\n phone?: string | null\n\n @Property({ name: 'gateway_transaction_id', type: 'uuid', nullable: true })\n gatewayTransactionId?: string | null\n\n @Property({ name: 'payment_status', type: 'text', nullable: true })\n paymentStatus?: string | null\n\n @Property({ name: 'selected_price_item_id', type: 'text', nullable: true })\n selectedPriceItemId?: string | null\n\n @Property({ name: 'accepted_legal_consents', type: 'jsonb', nullable: true })\n acceptedLegalConsents?: Record<string, unknown> | null\n\n @Property({ name: 'ip_address', type: 'text', nullable: true })\n ipAddress?: string | null\n\n @Property({ name: 'user_agent', type: 'text', nullable: true })\n userAgent?: string | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n}\n\nexport default [CheckoutLinkTemplate, CheckoutLink, CheckoutTransaction]\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;AAAA,SAAS,qBAAqB;AAC9B,SAAS,QAAQ,OAAO,YAAY,gBAAgB;
|
|
4
|
+
"sourcesContent": ["import { OptionalProps } from '@mikro-orm/core'\nimport { Entity, Index, PrimaryKey, Property } from '@mikro-orm/decorators/legacy'\nimport { ExactDecimalType } from '@open-mercato/shared/lib/db/exactDecimalType'\n\n@Entity({ tableName: 'checkout_link_templates' })\n@Index({ properties: ['organizationId', 'tenantId', 'deletedAt'] })\nexport class CheckoutLinkTemplate {\n [OptionalProps]?:\n | 'title'\n | 'subtitle'\n | 'description'\n | 'logoAttachmentId'\n | 'logoUrl'\n | 'primaryColor'\n | 'secondaryColor'\n | 'backgroundColor'\n | 'themeMode'\n | 'fixedPriceAmount'\n | 'fixedPriceCurrencyCode'\n | 'fixedPriceIncludesTax'\n | 'fixedPriceOriginalAmount'\n | 'customAmountMin'\n | 'customAmountMax'\n | 'customAmountCurrencyCode'\n | 'priceListItems'\n | 'gatewayProviderKey'\n | 'gatewaySettings'\n | 'customFieldsetCode'\n | 'collectCustomerDetails'\n | 'customerFieldsSchema'\n | 'legalDocuments'\n | 'displayCustomFieldsOnPage'\n | 'successTitle'\n | 'successMessage'\n | 'cancelTitle'\n | 'cancelMessage'\n | 'errorTitle'\n | 'errorMessage'\n | 'successEmailSubject'\n | 'successEmailBody'\n | 'sendSuccessEmail'\n | 'errorEmailSubject'\n | 'errorEmailBody'\n | 'sendErrorEmail'\n | 'startEmailSubject'\n | 'startEmailBody'\n | 'sendStartEmail'\n | 'passwordHash'\n | 'maxCompletions'\n | 'status'\n | 'checkoutType'\n | 'createdAt'\n | 'updatedAt'\n | 'deletedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ type: 'text' })\n name!: string\n\n @Property({ type: 'text', nullable: true })\n title?: string | null\n\n @Property({ type: 'text', nullable: true })\n subtitle?: string | null\n\n @Property({ type: 'text', nullable: true })\n description?: string | null\n\n @Property({ name: 'logo_attachment_id', type: 'uuid', nullable: true })\n logoAttachmentId?: string | null\n\n @Property({ name: 'logo_url', type: 'text', nullable: true })\n logoUrl?: string | null\n\n @Property({ name: 'primary_color', type: 'text', nullable: true })\n primaryColor?: string | null\n\n @Property({ name: 'secondary_color', type: 'text', nullable: true })\n secondaryColor?: string | null\n\n @Property({ name: 'background_color', type: 'text', nullable: true })\n backgroundColor?: string | null\n\n @Property({ name: 'theme_mode', type: 'text', default: 'auto' })\n themeMode: 'light' | 'dark' | 'auto' = 'auto'\n\n @Property({ name: 'pricing_mode', type: 'text' })\n pricingMode!: 'fixed' | 'custom_amount' | 'price_list'\n\n @Property({ name: 'fixed_price_amount', type: ExactDecimalType, columnType: 'numeric', nullable: true })\n fixedPriceAmount?: string | null\n\n @Property({ name: 'fixed_price_currency_code', type: 'text', nullable: true })\n fixedPriceCurrencyCode?: string | null\n\n @Property({ name: 'fixed_price_includes_tax', type: 'boolean', default: true })\n fixedPriceIncludesTax: boolean = true\n\n @Property({ name: 'fixed_price_original_amount', type: ExactDecimalType, columnType: 'numeric', nullable: true })\n fixedPriceOriginalAmount?: string | null\n\n @Property({ name: 'custom_amount_min', type: ExactDecimalType, columnType: 'numeric', nullable: true })\n customAmountMin?: string | null\n\n @Property({ name: 'custom_amount_max', type: ExactDecimalType, columnType: 'numeric', nullable: true })\n customAmountMax?: string | null\n\n @Property({ name: 'custom_amount_currency_code', type: 'text', nullable: true })\n customAmountCurrencyCode?: string | null\n\n @Property({ name: 'price_list_items', type: 'jsonb', nullable: true })\n priceListItems?: Array<{ id: string; description: string; amount: number; amountExact?: string | null; currencyCode: string }> | null\n\n @Property({ name: 'gateway_provider_key', type: 'text', nullable: true })\n gatewayProviderKey?: string | null\n\n @Property({ name: 'gateway_settings', type: 'jsonb', nullable: true })\n gatewaySettings?: Record<string, unknown> | null\n\n @Property({ name: 'custom_fieldset_code', type: 'text', nullable: true })\n customFieldsetCode?: string | null\n\n @Property({ name: 'collect_customer_details', type: 'boolean', default: true })\n collectCustomerDetails: boolean = true\n\n @Property({ name: 'customer_fields_schema', type: 'jsonb', nullable: true })\n customerFieldsSchema?: Array<Record<string, unknown>> | null\n\n @Property({ name: 'legal_documents', type: 'jsonb', nullable: true })\n legalDocuments?: Record<string, unknown> | null\n\n @Property({ name: 'display_custom_fields_on_page', type: 'boolean', default: false })\n displayCustomFieldsOnPage: boolean = false\n\n @Property({ name: 'success_title', type: 'text', nullable: true })\n successTitle?: string | null\n\n @Property({ name: 'success_message', type: 'text', nullable: true })\n successMessage?: string | null\n\n @Property({ name: 'cancel_title', type: 'text', nullable: true })\n cancelTitle?: string | null\n\n @Property({ name: 'cancel_message', type: 'text', nullable: true })\n cancelMessage?: string | null\n\n @Property({ name: 'error_title', type: 'text', nullable: true })\n errorTitle?: string | null\n\n @Property({ name: 'error_message', type: 'text', nullable: true })\n errorMessage?: string | null\n\n @Property({ name: 'success_email_subject', type: 'text', nullable: true })\n successEmailSubject?: string | null\n\n @Property({ name: 'success_email_body', type: 'text', nullable: true })\n successEmailBody?: string | null\n\n @Property({ name: 'send_success_email', type: 'boolean', default: true })\n sendSuccessEmail: boolean = true\n\n @Property({ name: 'error_email_subject', type: 'text', nullable: true })\n errorEmailSubject?: string | null\n\n @Property({ name: 'error_email_body', type: 'text', nullable: true })\n errorEmailBody?: string | null\n\n @Property({ name: 'send_error_email', type: 'boolean', default: true })\n sendErrorEmail: boolean = true\n\n @Property({ name: 'start_email_subject', type: 'text', nullable: true })\n startEmailSubject?: string | null\n\n @Property({ name: 'start_email_body', type: 'text', nullable: true })\n startEmailBody?: string | null\n\n @Property({ name: 'send_start_email', type: 'boolean', default: true })\n sendStartEmail: boolean = true\n\n @Property({ name: 'password_hash', type: 'text', nullable: true })\n passwordHash?: string | null\n\n @Property({ name: 'max_completions', type: 'integer', nullable: true })\n maxCompletions?: number | null\n\n @Property({ type: 'text', default: 'draft' })\n status: 'draft' | 'active' | 'inactive' = 'draft'\n\n @Property({ name: 'checkout_type', type: 'text', default: 'pay_link' })\n checkoutType: 'pay_link' | 'simple_checkout' = 'pay_link'\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n@Entity({ tableName: 'checkout_links' })\n@Index({ properties: ['organizationId', 'tenantId', 'status', 'deletedAt'] })\n@Index({ properties: ['slug'], options: { unique: true, where: 'deleted_at is null' } })\nexport class CheckoutLink extends CheckoutLinkTemplate {\n @Property({ name: 'template_id', type: 'uuid', nullable: true })\n templateId?: string | null\n\n @Property({ type: 'text' })\n slug!: string\n\n @Property({ name: 'completion_count', type: 'integer', default: 0 })\n completionCount: number = 0\n\n @Property({ name: 'active_reservation_count', type: 'integer', default: 0 })\n activeReservationCount: number = 0\n\n @Property({ name: 'is_locked', type: 'boolean', default: false })\n isLocked: boolean = false\n}\n\n@Entity({ tableName: 'checkout_transactions' })\n@Index({ properties: ['organizationId', 'tenantId', 'linkId', 'status'] })\n@Index({ properties: ['organizationId', 'tenantId', 'createdAt'] })\n@Index({ properties: ['gatewayTransactionId'] })\n@Index({\n properties: ['organizationId', 'tenantId', 'linkId', 'idempotencyKey'],\n options: { unique: true },\n})\nexport class CheckoutTransaction {\n [OptionalProps]?:\n | 'idempotencyKey'\n | 'customerData'\n | 'firstName'\n | 'lastName'\n | 'email'\n | 'phone'\n | 'gatewayTransactionId'\n | 'paymentStatus'\n | 'selectedPriceItemId'\n | 'acceptedLegalConsents'\n | 'ipAddress'\n | 'userAgent'\n | 'createdAt'\n | 'updatedAt'\n\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'link_id', type: 'uuid' })\n linkId!: string\n\n @Property({ type: 'text' })\n status!: 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled' | 'expired'\n\n @Property({ type: ExactDecimalType, columnType: 'numeric' })\n amount!: string\n\n @Property({ name: 'currency_code', type: 'text' })\n currencyCode!: string\n\n @Property({ name: 'idempotency_key', type: 'text' })\n idempotencyKey!: string\n\n @Property({ name: 'customer_data', type: 'jsonb', nullable: true })\n customerData?: Record<string, unknown> | null\n\n @Property({ name: 'first_name', type: 'text', nullable: true })\n firstName?: string | null\n\n @Property({ name: 'last_name', type: 'text', nullable: true })\n lastName?: string | null\n\n @Property({ type: 'text', nullable: true })\n email?: string | null\n\n @Property({ type: 'text', nullable: true })\n phone?: string | null\n\n @Property({ name: 'gateway_transaction_id', type: 'uuid', nullable: true })\n gatewayTransactionId?: string | null\n\n @Property({ name: 'payment_status', type: 'text', nullable: true })\n paymentStatus?: string | null\n\n @Property({ name: 'selected_price_item_id', type: 'text', nullable: true })\n selectedPriceItemId?: string | null\n\n @Property({ name: 'accepted_legal_consents', type: 'jsonb', nullable: true })\n acceptedLegalConsents?: Record<string, unknown> | null\n\n @Property({ name: 'ip_address', type: 'text', nullable: true })\n ipAddress?: string | null\n\n @Property({ name: 'user_agent', type: 'text', nullable: true })\n userAgent?: string | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n}\n\nexport default [CheckoutLinkTemplate, CheckoutLink, CheckoutTransaction]\n"],
|
|
5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AAC,sBAAsB,cAAc,mBAAmB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -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.js";
|
|
4
5
|
import { CHECKOUT_LINK_STATUSES } from "../lib/constants.js";
|
|
5
6
|
function normalizeBlankString(value) {
|
|
@@ -39,7 +40,10 @@ const optionalFieldsetCodeSchema = z.preprocess(
|
|
|
39
40
|
message: "checkout.validation.common.invalidFieldsetCode"
|
|
40
41
|
}).optional().nullable()
|
|
41
42
|
);
|
|
42
|
-
const
|
|
43
|
+
const moneyInputSchema = (schema) => withDecimalCaps(schema, "checkout.validation.common.invalidNumber");
|
|
44
|
+
const positiveMoneySchema = moneyInputSchema(
|
|
45
|
+
z.coerce.number().finite("checkout.validation.common.invalidNumber").nonnegative("checkout.validation.common.nonNegativeNumber")
|
|
46
|
+
);
|
|
43
47
|
const linkStatusSchema = z.enum(CHECKOUT_LINK_STATUSES);
|
|
44
48
|
const themeModeSchema = z.enum(["light", "dark", "auto"]);
|
|
45
49
|
const checkoutTypeSchema = z.enum(["pay_link", "simple_checkout"]);
|
|
@@ -173,6 +177,18 @@ function validatePricingConsistency(value, ctx) {
|
|
|
173
177
|
}
|
|
174
178
|
}
|
|
175
179
|
}
|
|
180
|
+
function assertExactCustomAmountRange(value) {
|
|
181
|
+
if (value.pricingMode !== "custom_amount") return;
|
|
182
|
+
const minimum = parseDecimal(value.customAmountMinExact);
|
|
183
|
+
const maximum = parseDecimal(value.customAmountMaxExact);
|
|
184
|
+
if (!minimum || !maximum || compareDecimals(minimum, maximum) <= 0) return;
|
|
185
|
+
throw new z.ZodError([{
|
|
186
|
+
code: "custom",
|
|
187
|
+
message: "checkout.validation.customAmount.range",
|
|
188
|
+
path: ["customAmountMax"],
|
|
189
|
+
input: value.customAmountMaxExact
|
|
190
|
+
}]);
|
|
191
|
+
}
|
|
176
192
|
const createTemplateSchema = checkoutContentSchema.superRefine((value, ctx) => {
|
|
177
193
|
validatePricingConsistency(value, ctx);
|
|
178
194
|
if (!value.gatewayProviderKey) {
|
|
@@ -255,10 +271,11 @@ const publicSubmitSchema = z.object({
|
|
|
255
271
|
terms: z.boolean().optional(),
|
|
256
272
|
privacyPolicy: z.boolean().optional()
|
|
257
273
|
}).default({}),
|
|
258
|
-
amount: z.coerce.number().finite().nonnegative().optional(),
|
|
274
|
+
amount: moneyInputSchema(z.coerce.number().finite().nonnegative()).optional(),
|
|
259
275
|
selectedPriceItemId: optionalTrimmedString
|
|
260
276
|
});
|
|
261
277
|
export {
|
|
278
|
+
assertExactCustomAmountRange,
|
|
262
279
|
createLinkSchema,
|
|
263
280
|
createTemplateSchema,
|
|
264
281
|
customerFieldDefinitionSchema,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/checkout/data/validators.ts"],
|
|
4
|
-
"sourcesContent": ["import { z } from 'zod'\nimport { fieldsetCodeRegex } from '@open-mercato/shared/modules/entities/validators'\nimport { DEFAULT_CHECKOUT_CUSTOMER_FIELDS } from '../lib/defaults'\nimport { CHECKOUT_LINK_STATUSES } from '../lib/constants'\n\nfunction normalizeBlankString(value: unknown): unknown {\n if (typeof value !== 'string') return value\n const trimmed = value.trim()\n return trimmed.length > 0 ? trimmed : null\n}\n\nfunction normalizeOptionalDocument(value: unknown): unknown {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return value\n const source = value as Record<string, unknown>\n const title = typeof source.title === 'string' ? source.title.trim() : ''\n const markdown = typeof source.markdown === 'string' ? source.markdown.trim() : ''\n const required = source.required === true\n if (!title && !markdown && !required) return undefined\n return value\n}\n\nfunction requiredTrimmedString(message: string) {\n return z.string().trim().min(1, { message })\n}\n\nconst hexColorSchema = z.string().regex(/^#([0-9a-fA-F]{6})$/, {\n message: 'checkout.validation.common.invalidColor',\n})\nconst currencyCodeSchema = z.string().trim().toUpperCase().regex(/^[A-Z]{3}$/, {\n message: 'checkout.validation.common.invalidCurrencyCode',\n})\nconst optionalTrimmedString = z.preprocess(\n normalizeBlankString,\n z.string().trim().min(1, { message: 'checkout.validation.common.required' }).optional().nullable(),\n)\nconst optionalUrlSchema = z.preprocess(\n normalizeBlankString,\n z.string().url('checkout.validation.common.invalidUrl').optional().nullable(),\n)\nconst optionalFieldsetCodeSchema = z.preprocess(\n normalizeBlankString,\n z.string().regex(fieldsetCodeRegex, {\n message: 'checkout.validation.common.invalidFieldsetCode',\n }).optional().nullable(),\n)\nconst positiveMoneySchema = z.coerce.number().finite('checkout.validation.common.invalidNumber').nonnegative('checkout.validation.common.nonNegativeNumber')\nconst linkStatusSchema = z.enum(CHECKOUT_LINK_STATUSES)\nconst themeModeSchema = z.enum(['light', 'dark', 'auto'])\nconst checkoutTypeSchema = z.enum(['pay_link', 'simple_checkout'])\n\nexport const customerFieldOptionSchema = z.object({\n value: requiredTrimmedString('checkout.validation.common.required'),\n label: requiredTrimmedString('checkout.validation.common.required'),\n})\n\nexport const customerFieldDefinitionSchema = z.object({\n key: z.string().regex(/^[a-z][A-Za-z0-9]*$/, {\n message: 'checkout.validation.customerFields.key.invalid',\n }),\n label: requiredTrimmedString('checkout.validation.common.required'),\n kind: z.enum(['text', 'multiline', 'boolean', 'select', 'radio']),\n required: z.boolean(),\n fixed: z.boolean(),\n placeholder: optionalTrimmedString,\n options: z.array(customerFieldOptionSchema).optional(),\n sortOrder: z.coerce.number().int('checkout.validation.common.integer').min(0, {\n message: 'checkout.validation.common.nonNegativeInteger',\n }),\n})\n\nexport const legalDocumentSchema = z.preprocess(\n normalizeOptionalDocument,\n z.object({\n title: requiredTrimmedString('checkout.validation.common.required'),\n markdown: requiredTrimmedString('checkout.validation.common.required'),\n required: z.boolean().default(false),\n }).optional(),\n)\n\nexport const legalDocumentsSchema = z.object({\n terms: legalDocumentSchema.optional(),\n privacyPolicy: legalDocumentSchema.optional(),\n}).optional()\n\nexport const priceListItemSchema = z.object({\n id: requiredTrimmedString('checkout.validation.common.required'),\n description: requiredTrimmedString('checkout.validation.common.required'),\n amount: positiveMoneySchema,\n currencyCode: currencyCodeSchema,\n})\n\nexport const gatewaySettingsSchema = z.record(z.string(), z.unknown()).optional()\n\nconst checkoutContentSchema = z.object({\n name: requiredTrimmedString('checkout.validation.name.required'),\n title: optionalTrimmedString,\n subtitle: optionalTrimmedString,\n description: z.string().optional().nullable(),\n logoAttachmentId: z.string().uuid('checkout.validation.common.invalidUuid').optional().nullable(),\n logoUrl: optionalUrlSchema,\n primaryColor: hexColorSchema.optional().nullable(),\n secondaryColor: hexColorSchema.optional().nullable(),\n backgroundColor: hexColorSchema.optional().nullable(),\n themeMode: themeModeSchema.default('auto'),\n pricingMode: z.enum(['fixed', 'custom_amount', 'price_list']),\n fixedPriceAmount: positiveMoneySchema.optional().nullable(),\n fixedPriceCurrencyCode: currencyCodeSchema.optional().nullable(),\n fixedPriceIncludesTax: z.boolean().default(true),\n fixedPriceOriginalAmount: positiveMoneySchema.optional().nullable(),\n customAmountMin: positiveMoneySchema.optional().nullable(),\n customAmountMax: positiveMoneySchema.optional().nullable(),\n customAmountCurrencyCode: currencyCodeSchema.optional().nullable(),\n priceListItems: z.array(priceListItemSchema).optional().nullable(),\n gatewayProviderKey: optionalTrimmedString,\n gatewaySettings: gatewaySettingsSchema,\n customFieldsetCode: optionalFieldsetCodeSchema,\n collectCustomerDetails: z.boolean().default(true),\n customerFieldsSchema: z.array(customerFieldDefinitionSchema).default([...DEFAULT_CHECKOUT_CUSTOMER_FIELDS]),\n legalDocuments: legalDocumentsSchema,\n displayCustomFieldsOnPage: z.boolean().default(false),\n successTitle: optionalTrimmedString,\n successMessage: z.string().optional().nullable(),\n cancelTitle: optionalTrimmedString,\n cancelMessage: z.string().optional().nullable(),\n errorTitle: optionalTrimmedString,\n errorMessage: z.string().optional().nullable(),\n successEmailSubject: optionalTrimmedString,\n successEmailBody: z.string().optional().nullable(),\n sendSuccessEmail: z.boolean().default(true),\n errorEmailSubject: optionalTrimmedString,\n errorEmailBody: z.string().optional().nullable(),\n sendErrorEmail: z.boolean().default(true),\n startEmailSubject: optionalTrimmedString,\n startEmailBody: z.string().optional().nullable(),\n sendStartEmail: z.boolean().default(true),\n password: optionalTrimmedString,\n maxCompletions: z.coerce.number().int('checkout.validation.common.integer').positive('checkout.validation.common.positiveInteger').optional().nullable(),\n status: linkStatusSchema.default('draft'),\n checkoutType: checkoutTypeSchema.default('pay_link'),\n})\n\nconst checkoutContentUpdateSchema = checkoutContentSchema.partial().extend({\n themeMode: themeModeSchema.optional(),\n fixedPriceIncludesTax: z.boolean().optional(),\n collectCustomerDetails: z.boolean().optional(),\n customerFieldsSchema: z.array(customerFieldDefinitionSchema).optional(),\n displayCustomFieldsOnPage: z.boolean().optional(),\n sendSuccessEmail: z.boolean().optional(),\n sendErrorEmail: z.boolean().optional(),\n sendStartEmail: z.boolean().optional(),\n status: linkStatusSchema.optional(),\n checkoutType: checkoutTypeSchema.optional(),\n})\n\nfunction validatePricingConsistency<T extends z.infer<typeof checkoutContentSchema>>(value: T, ctx: z.RefinementCtx) {\n if (value.pricingMode === 'fixed') {\n if (value.fixedPriceAmount == null) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.fixedPriceAmount.required', path: ['fixedPriceAmount'] })\n }\n if (!value.fixedPriceCurrencyCode) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.fixedPriceCurrencyCode.required', path: ['fixedPriceCurrencyCode'] })\n }\n }\n\n if (value.pricingMode === 'custom_amount') {\n if (value.customAmountMin == null) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.customAmountMin.required', path: ['customAmountMin'] })\n }\n if (value.customAmountMax == null) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.customAmountMax.required', path: ['customAmountMax'] })\n }\n if (!value.customAmountCurrencyCode) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.customAmountCurrencyCode.required', path: ['customAmountCurrencyCode'] })\n }\n if (value.customAmountMin != null && value.customAmountMax != null && value.customAmountMin > value.customAmountMax) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.customAmount.range', path: ['customAmountMax'] })\n }\n }\n\n if (value.pricingMode === 'price_list') {\n if (!Array.isArray(value.priceListItems) || value.priceListItems.length === 0) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.priceListItems.required', path: ['priceListItems'] })\n return\n }\n const currencies = new Set(value.priceListItems.map((item) => item.currencyCode))\n if (currencies.size > 1) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.priceListItems.singleCurrency', path: ['priceListItems'] })\n }\n }\n}\n\nexport const createTemplateSchema = checkoutContentSchema.superRefine((value, ctx) => {\n validatePricingConsistency(value, ctx)\n if (!value.gatewayProviderKey) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: 'checkout.validation.gatewayProviderKey.required',\n path: ['gatewayProviderKey'],\n })\n }\n})\n\nfunction applyPartialPricingConsistency(value: Record<string, unknown>, ctx: z.RefinementCtx) {\n if (!value.pricingMode) return\n validatePricingConsistency({\n ...checkoutContentSchema.parse({\n ...value,\n name: value.name ?? 'placeholder',\n pricingMode: value.pricingMode,\n customerFieldsSchema: value.customerFieldsSchema ?? [...DEFAULT_CHECKOUT_CUSTOMER_FIELDS],\n }),\n ...value,\n }, ctx)\n}\n\nexport const updateTemplateSchema = checkoutContentUpdateSchema.extend({\n id: z.string().uuid('checkout.validation.common.invalidUuid'),\n}).superRefine((value, ctx) => {\n applyPartialPricingConsistency(value, ctx)\n if (Object.prototype.hasOwnProperty.call(value, 'gatewayProviderKey') && !value.gatewayProviderKey) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: 'checkout.validation.gatewayProviderKey.required',\n path: ['gatewayProviderKey'],\n })\n }\n})\n\nexport const createLinkSchema = createTemplateSchema.safeExtend({\n templateId: z.string().uuid('checkout.validation.common.invalidUuid').optional().nullable(),\n slug: optionalTrimmedString,\n})\n\nexport const updateLinkSchema = checkoutContentUpdateSchema.safeExtend({\n id: z.string().uuid('checkout.validation.common.invalidUuid'),\n templateId: z.string().uuid('checkout.validation.common.invalidUuid').optional().nullable(),\n slug: optionalTrimmedString,\n}).superRefine((value, ctx) => {\n applyPartialPricingConsistency(value, ctx)\n})\n\nexport const transactionStatusSchema = z.enum(['pending', 'processing', 'completed', 'failed', 'cancelled', 'expired'])\n\nexport const transactionCreateSchema = z.object({\n linkId: z.string().uuid('checkout.validation.common.invalidUuid'),\n amount: positiveMoneySchema,\n currencyCode: currencyCodeSchema,\n idempotencyKey: requiredTrimmedString('checkout.validation.common.required'),\n customerData: z.record(z.string(), z.unknown()).default({}),\n firstName: optionalTrimmedString,\n lastName: optionalTrimmedString,\n email: optionalTrimmedString,\n phone: optionalTrimmedString,\n gatewayTransactionId: z.string().uuid('checkout.validation.common.invalidUuid').optional().nullable(),\n paymentStatus: optionalTrimmedString,\n selectedPriceItemId: optionalTrimmedString,\n acceptedLegalConsents: z.record(z.string(), z.unknown()).optional().nullable(),\n ipAddress: optionalTrimmedString,\n userAgent: z.string().optional().nullable(),\n tenantId: z.string().uuid('checkout.validation.common.invalidUuid'),\n organizationId: z.string().uuid('checkout.validation.common.invalidUuid'),\n})\n\nexport const transactionUpdateStatusSchema = z.object({\n id: z.string().uuid('checkout.validation.common.invalidUuid'),\n status: transactionStatusSchema,\n paymentStatus: optionalTrimmedString,\n gatewayTransactionId: z.string().uuid('checkout.validation.common.invalidUuid').optional().nullable(),\n tenantId: z.string().uuid('checkout.validation.common.invalidUuid'),\n organizationId: z.string().uuid('checkout.validation.common.invalidUuid'),\n})\n\nexport const publicPasswordVerifySchema = z.object({\n password: z.string().min(1, { message: 'checkout.validation.common.required' }),\n})\n\nexport const publicSubmitSchema = z.object({\n customerData: z.record(z.string(), z.unknown()),\n acceptedLegalConsents: z.object({\n terms: z.boolean().optional(),\n privacyPolicy: z.boolean().optional(),\n }).default({}),\n amount: z.coerce.number().finite().nonnegative().optional(),\n selectedPriceItemId: optionalTrimmedString,\n})\n\nexport type CustomerFieldDefinitionInput = z.infer<typeof customerFieldDefinitionSchema>\nexport type PriceListItemInput = z.infer<typeof priceListItemSchema>\nexport type CreateTemplateInput = z.infer<typeof createTemplateSchema>\nexport type UpdateTemplateInput = z.infer<typeof updateTemplateSchema>\nexport type CreateLinkInput = z.infer<typeof createLinkSchema>\nexport type UpdateLinkInput = z.infer<typeof updateLinkSchema>\nexport type CreateTransactionInput = z.infer<typeof transactionCreateSchema>\nexport type UpdateTransactionStatusInput = z.infer<typeof transactionUpdateStatusSchema>\nexport type PublicSubmitInput = z.infer<typeof publicSubmitSchema>\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,SAAS;AAClB,SAAS,yBAAyB;AAClC,SAAS,wCAAwC;AACjD,SAAS,8BAA8B;AAEvC,SAAS,qBAAqB,OAAyB;AACrD,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,QAAM,UAAU,MAAM,KAAK;AAC3B,SAAO,QAAQ,SAAS,IAAI,UAAU;AACxC;AAEA,SAAS,0BAA0B,OAAyB;AAC1D,MAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,EAAG,QAAO;AACxE,QAAM,SAAS;AACf,QAAM,QAAQ,OAAO,OAAO,UAAU,WAAW,OAAO,MAAM,KAAK,IAAI;AACvE,QAAM,WAAW,OAAO,OAAO,aAAa,WAAW,OAAO,SAAS,KAAK,IAAI;AAChF,QAAM,WAAW,OAAO,aAAa;AACrC,MAAI,CAAC,SAAS,CAAC,YAAY,CAAC,SAAU,QAAO;AAC7C,SAAO;AACT;AAEA,SAAS,sBAAsB,SAAiB;AAC9C,SAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,QAAQ,CAAC;AAC7C;AAEA,MAAM,iBAAiB,EAAE,OAAO,EAAE,MAAM,uBAAuB;AAAA,EAC7D,SAAS;AACX,CAAC;AACD,MAAM,qBAAqB,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc;AAAA,EAC7E,SAAS;AACX,CAAC;AACD,MAAM,wBAAwB,EAAE;AAAA,EAC9B;AAAA,EACA,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,SAAS,sCAAsC,CAAC,EAAE,SAAS,EAAE,SAAS;AACnG;AACA,MAAM,oBAAoB,EAAE;AAAA,EAC1B;AAAA,EACA,EAAE,OAAO,EAAE,IAAI,uCAAuC,EAAE,SAAS,EAAE,SAAS;AAC9E;AACA,MAAM,6BAA6B,EAAE;AAAA,EACnC;AAAA,EACA,EAAE,OAAO,EAAE,MAAM,mBAAmB;AAAA,IAClC,SAAS;AAAA,EACX,CAAC,EAAE,SAAS,EAAE,SAAS;AACzB;AACA,MAAM,sBAAsB,EAAE,OAAO,OAAO,EAAE,OAAO,0CAA0C,EAAE,YAAY,8CAA8C;
|
|
4
|
+
"sourcesContent": ["import { z } from 'zod'\nimport { fieldsetCodeRegex } from '@open-mercato/shared/modules/entities/validators'\nimport { compareDecimals, withDecimalCaps, parseDecimal } from '@open-mercato/shared/lib/decimal'\nimport { DEFAULT_CHECKOUT_CUSTOMER_FIELDS } from '../lib/defaults'\nimport { CHECKOUT_LINK_STATUSES } from '../lib/constants'\n\nfunction normalizeBlankString(value: unknown): unknown {\n if (typeof value !== 'string') return value\n const trimmed = value.trim()\n return trimmed.length > 0 ? trimmed : null\n}\n\nfunction normalizeOptionalDocument(value: unknown): unknown {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return value\n const source = value as Record<string, unknown>\n const title = typeof source.title === 'string' ? source.title.trim() : ''\n const markdown = typeof source.markdown === 'string' ? source.markdown.trim() : ''\n const required = source.required === true\n if (!title && !markdown && !required) return undefined\n return value\n}\n\nfunction requiredTrimmedString(message: string) {\n return z.string().trim().min(1, { message })\n}\n\nconst hexColorSchema = z.string().regex(/^#([0-9a-fA-F]{6})$/, {\n message: 'checkout.validation.common.invalidColor',\n})\nconst currencyCodeSchema = z.string().trim().toUpperCase().regex(/^[A-Z]{3}$/, {\n message: 'checkout.validation.common.invalidCurrencyCode',\n})\nconst optionalTrimmedString = z.preprocess(\n normalizeBlankString,\n z.string().trim().min(1, { message: 'checkout.validation.common.required' }).optional().nullable(),\n)\nconst optionalUrlSchema = z.preprocess(\n normalizeBlankString,\n z.string().url('checkout.validation.common.invalidUrl').optional().nullable(),\n)\nconst optionalFieldsetCodeSchema = z.preprocess(\n normalizeBlankString,\n z.string().regex(fieldsetCodeRegex, {\n message: 'checkout.validation.common.invalidFieldsetCode',\n }).optional().nullable(),\n)\nconst moneyInputSchema = <T extends z.ZodType>(schema: T) => withDecimalCaps(schema, 'checkout.validation.common.invalidNumber')\n\nconst positiveMoneySchema = moneyInputSchema(\n z.coerce.number().finite('checkout.validation.common.invalidNumber').nonnegative('checkout.validation.common.nonNegativeNumber'),\n)\nconst linkStatusSchema = z.enum(CHECKOUT_LINK_STATUSES)\nconst themeModeSchema = z.enum(['light', 'dark', 'auto'])\nconst checkoutTypeSchema = z.enum(['pay_link', 'simple_checkout'])\n\nexport const customerFieldOptionSchema = z.object({\n value: requiredTrimmedString('checkout.validation.common.required'),\n label: requiredTrimmedString('checkout.validation.common.required'),\n})\n\nexport const customerFieldDefinitionSchema = z.object({\n key: z.string().regex(/^[a-z][A-Za-z0-9]*$/, {\n message: 'checkout.validation.customerFields.key.invalid',\n }),\n label: requiredTrimmedString('checkout.validation.common.required'),\n kind: z.enum(['text', 'multiline', 'boolean', 'select', 'radio']),\n required: z.boolean(),\n fixed: z.boolean(),\n placeholder: optionalTrimmedString,\n options: z.array(customerFieldOptionSchema).optional(),\n sortOrder: z.coerce.number().int('checkout.validation.common.integer').min(0, {\n message: 'checkout.validation.common.nonNegativeInteger',\n }),\n})\n\nexport const legalDocumentSchema = z.preprocess(\n normalizeOptionalDocument,\n z.object({\n title: requiredTrimmedString('checkout.validation.common.required'),\n markdown: requiredTrimmedString('checkout.validation.common.required'),\n required: z.boolean().default(false),\n }).optional(),\n)\n\nexport const legalDocumentsSchema = z.object({\n terms: legalDocumentSchema.optional(),\n privacyPolicy: legalDocumentSchema.optional(),\n}).optional()\n\nexport const priceListItemSchema = z.object({\n id: requiredTrimmedString('checkout.validation.common.required'),\n description: requiredTrimmedString('checkout.validation.common.required'),\n amount: positiveMoneySchema,\n currencyCode: currencyCodeSchema,\n})\n\nexport const gatewaySettingsSchema = z.record(z.string(), z.unknown()).optional()\n\nconst checkoutContentSchema = z.object({\n name: requiredTrimmedString('checkout.validation.name.required'),\n title: optionalTrimmedString,\n subtitle: optionalTrimmedString,\n description: z.string().optional().nullable(),\n logoAttachmentId: z.string().uuid('checkout.validation.common.invalidUuid').optional().nullable(),\n logoUrl: optionalUrlSchema,\n primaryColor: hexColorSchema.optional().nullable(),\n secondaryColor: hexColorSchema.optional().nullable(),\n backgroundColor: hexColorSchema.optional().nullable(),\n themeMode: themeModeSchema.default('auto'),\n pricingMode: z.enum(['fixed', 'custom_amount', 'price_list']),\n fixedPriceAmount: positiveMoneySchema.optional().nullable(),\n fixedPriceCurrencyCode: currencyCodeSchema.optional().nullable(),\n fixedPriceIncludesTax: z.boolean().default(true),\n fixedPriceOriginalAmount: positiveMoneySchema.optional().nullable(),\n customAmountMin: positiveMoneySchema.optional().nullable(),\n customAmountMax: positiveMoneySchema.optional().nullable(),\n customAmountCurrencyCode: currencyCodeSchema.optional().nullable(),\n priceListItems: z.array(priceListItemSchema).optional().nullable(),\n gatewayProviderKey: optionalTrimmedString,\n gatewaySettings: gatewaySettingsSchema,\n customFieldsetCode: optionalFieldsetCodeSchema,\n collectCustomerDetails: z.boolean().default(true),\n customerFieldsSchema: z.array(customerFieldDefinitionSchema).default([...DEFAULT_CHECKOUT_CUSTOMER_FIELDS]),\n legalDocuments: legalDocumentsSchema,\n displayCustomFieldsOnPage: z.boolean().default(false),\n successTitle: optionalTrimmedString,\n successMessage: z.string().optional().nullable(),\n cancelTitle: optionalTrimmedString,\n cancelMessage: z.string().optional().nullable(),\n errorTitle: optionalTrimmedString,\n errorMessage: z.string().optional().nullable(),\n successEmailSubject: optionalTrimmedString,\n successEmailBody: z.string().optional().nullable(),\n sendSuccessEmail: z.boolean().default(true),\n errorEmailSubject: optionalTrimmedString,\n errorEmailBody: z.string().optional().nullable(),\n sendErrorEmail: z.boolean().default(true),\n startEmailSubject: optionalTrimmedString,\n startEmailBody: z.string().optional().nullable(),\n sendStartEmail: z.boolean().default(true),\n password: optionalTrimmedString,\n maxCompletions: z.coerce.number().int('checkout.validation.common.integer').positive('checkout.validation.common.positiveInteger').optional().nullable(),\n status: linkStatusSchema.default('draft'),\n checkoutType: checkoutTypeSchema.default('pay_link'),\n})\n\nconst checkoutContentUpdateSchema = checkoutContentSchema.partial().extend({\n themeMode: themeModeSchema.optional(),\n fixedPriceIncludesTax: z.boolean().optional(),\n collectCustomerDetails: z.boolean().optional(),\n customerFieldsSchema: z.array(customerFieldDefinitionSchema).optional(),\n displayCustomFieldsOnPage: z.boolean().optional(),\n sendSuccessEmail: z.boolean().optional(),\n sendErrorEmail: z.boolean().optional(),\n sendStartEmail: z.boolean().optional(),\n status: linkStatusSchema.optional(),\n checkoutType: checkoutTypeSchema.optional(),\n})\n\nfunction validatePricingConsistency<T extends z.infer<typeof checkoutContentSchema>>(value: T, ctx: z.RefinementCtx) {\n if (value.pricingMode === 'fixed') {\n if (value.fixedPriceAmount == null) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.fixedPriceAmount.required', path: ['fixedPriceAmount'] })\n }\n if (!value.fixedPriceCurrencyCode) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.fixedPriceCurrencyCode.required', path: ['fixedPriceCurrencyCode'] })\n }\n }\n\n if (value.pricingMode === 'custom_amount') {\n if (value.customAmountMin == null) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.customAmountMin.required', path: ['customAmountMin'] })\n }\n if (value.customAmountMax == null) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.customAmountMax.required', path: ['customAmountMax'] })\n }\n if (!value.customAmountCurrencyCode) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.customAmountCurrencyCode.required', path: ['customAmountCurrencyCode'] })\n }\n if (value.customAmountMin != null && value.customAmountMax != null && value.customAmountMin > value.customAmountMax) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.customAmount.range', path: ['customAmountMax'] })\n }\n }\n\n if (value.pricingMode === 'price_list') {\n if (!Array.isArray(value.priceListItems) || value.priceListItems.length === 0) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.priceListItems.required', path: ['priceListItems'] })\n return\n }\n const currencies = new Set(value.priceListItems.map((item) => item.currencyCode))\n if (currencies.size > 1) {\n ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'checkout.validation.priceListItems.singleCurrency', path: ['priceListItems'] })\n }\n }\n}\n\nexport type ExactCustomAmountRangeInput = {\n pricingMode?: unknown\n customAmountMinExact?: string | null\n customAmountMaxExact?: string | null\n}\n\nexport function assertExactCustomAmountRange(value: ExactCustomAmountRangeInput): void {\n if (value.pricingMode !== 'custom_amount') return\n const minimum = parseDecimal(value.customAmountMinExact)\n const maximum = parseDecimal(value.customAmountMaxExact)\n if (!minimum || !maximum || compareDecimals(minimum, maximum) <= 0) return\n throw new z.ZodError([{\n code: 'custom',\n message: 'checkout.validation.customAmount.range',\n path: ['customAmountMax'],\n input: value.customAmountMaxExact,\n }])\n}\n\nexport const createTemplateSchema = checkoutContentSchema.superRefine((value, ctx) => {\n validatePricingConsistency(value, ctx)\n if (!value.gatewayProviderKey) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: 'checkout.validation.gatewayProviderKey.required',\n path: ['gatewayProviderKey'],\n })\n }\n})\n\nfunction applyPartialPricingConsistency(value: Record<string, unknown>, ctx: z.RefinementCtx) {\n if (!value.pricingMode) return\n validatePricingConsistency({\n ...checkoutContentSchema.parse({\n ...value,\n name: value.name ?? 'placeholder',\n pricingMode: value.pricingMode,\n customerFieldsSchema: value.customerFieldsSchema ?? [...DEFAULT_CHECKOUT_CUSTOMER_FIELDS],\n }),\n ...value,\n }, ctx)\n}\n\nexport const updateTemplateSchema = checkoutContentUpdateSchema.extend({\n id: z.string().uuid('checkout.validation.common.invalidUuid'),\n}).superRefine((value, ctx) => {\n applyPartialPricingConsistency(value, ctx)\n if (Object.prototype.hasOwnProperty.call(value, 'gatewayProviderKey') && !value.gatewayProviderKey) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: 'checkout.validation.gatewayProviderKey.required',\n path: ['gatewayProviderKey'],\n })\n }\n})\n\nexport const createLinkSchema = createTemplateSchema.safeExtend({\n templateId: z.string().uuid('checkout.validation.common.invalidUuid').optional().nullable(),\n slug: optionalTrimmedString,\n})\n\nexport const updateLinkSchema = checkoutContentUpdateSchema.safeExtend({\n id: z.string().uuid('checkout.validation.common.invalidUuid'),\n templateId: z.string().uuid('checkout.validation.common.invalidUuid').optional().nullable(),\n slug: optionalTrimmedString,\n}).superRefine((value, ctx) => {\n applyPartialPricingConsistency(value, ctx)\n})\n\nexport const transactionStatusSchema = z.enum(['pending', 'processing', 'completed', 'failed', 'cancelled', 'expired'])\n\nexport const transactionCreateSchema = z.object({\n linkId: z.string().uuid('checkout.validation.common.invalidUuid'),\n amount: positiveMoneySchema,\n currencyCode: currencyCodeSchema,\n idempotencyKey: requiredTrimmedString('checkout.validation.common.required'),\n customerData: z.record(z.string(), z.unknown()).default({}),\n firstName: optionalTrimmedString,\n lastName: optionalTrimmedString,\n email: optionalTrimmedString,\n phone: optionalTrimmedString,\n gatewayTransactionId: z.string().uuid('checkout.validation.common.invalidUuid').optional().nullable(),\n paymentStatus: optionalTrimmedString,\n selectedPriceItemId: optionalTrimmedString,\n acceptedLegalConsents: z.record(z.string(), z.unknown()).optional().nullable(),\n ipAddress: optionalTrimmedString,\n userAgent: z.string().optional().nullable(),\n tenantId: z.string().uuid('checkout.validation.common.invalidUuid'),\n organizationId: z.string().uuid('checkout.validation.common.invalidUuid'),\n})\n\nexport const transactionUpdateStatusSchema = z.object({\n id: z.string().uuid('checkout.validation.common.invalidUuid'),\n status: transactionStatusSchema,\n paymentStatus: optionalTrimmedString,\n gatewayTransactionId: z.string().uuid('checkout.validation.common.invalidUuid').optional().nullable(),\n tenantId: z.string().uuid('checkout.validation.common.invalidUuid'),\n organizationId: z.string().uuid('checkout.validation.common.invalidUuid'),\n})\n\nexport const publicPasswordVerifySchema = z.object({\n password: z.string().min(1, { message: 'checkout.validation.common.required' }),\n})\n\nexport const publicSubmitSchema = z.object({\n customerData: z.record(z.string(), z.unknown()),\n acceptedLegalConsents: z.object({\n terms: z.boolean().optional(),\n privacyPolicy: z.boolean().optional(),\n }).default({}),\n amount: moneyInputSchema(z.coerce.number().finite().nonnegative()).optional(),\n selectedPriceItemId: optionalTrimmedString,\n})\n\nexport type CustomerFieldDefinitionInput = z.infer<typeof customerFieldDefinitionSchema>\nexport type PriceListItemInput = z.infer<typeof priceListItemSchema>\nexport type CreateTemplateInput = z.infer<typeof createTemplateSchema>\nexport type UpdateTemplateInput = z.infer<typeof updateTemplateSchema>\nexport type CreateLinkInput = z.infer<typeof createLinkSchema>\nexport type UpdateLinkInput = z.infer<typeof updateLinkSchema>\nexport type CreateTransactionInput = z.infer<typeof transactionCreateSchema>\nexport type UpdateTransactionStatusInput = z.infer<typeof transactionUpdateStatusSchema>\nexport type PublicSubmitInput = z.infer<typeof publicSubmitSchema>\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS;AAClB,SAAS,yBAAyB;AAClC,SAAS,iBAAiB,iB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AE,QAAQ,CAAC,CAAC;AAAA,EACb,QAAQ,iBAAiB,EAAE,OAAO,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,SAAS;AAAA,EAC5E,qBAAqB;AACvB,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -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.",
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decimalToNumber,
|
|
3
|
+
decimalToString,
|
|
4
|
+
parseDecimal,
|
|
5
|
+
resolveExactDecimal,
|
|
6
|
+
roundDecimal
|
|
7
|
+
} from "@open-mercato/shared/lib/decimal";
|
|
8
|
+
import { findCurrencyAmountPrecisionError, resolveCurrencyDecimalPlaces } from "@open-mercato/shared/lib/currencyPrecision";
|
|
9
|
+
import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
|
|
10
|
+
import { createFallbackTranslator } from "@open-mercato/shared/lib/i18n/translate";
|
|
11
|
+
import enDictionary from "@open-mercato/checkout/modules/checkout/i18n/en.json";
|
|
12
|
+
const DEFAULT_CHECKOUT_DECIMAL_PLACES = 2;
|
|
13
|
+
const CONFIGURED_MONEY_FIELDS = [
|
|
14
|
+
{ field: "fixedPriceAmount", exactField: "fixedPriceAmountExact", currencyField: "fixedPriceCurrencyCode" },
|
|
15
|
+
{ field: "fixedPriceOriginalAmount", exactField: "fixedPriceOriginalAmountExact", currencyField: "fixedPriceCurrencyCode" },
|
|
16
|
+
{ field: "customAmountMin", exactField: "customAmountMinExact", currencyField: "customAmountCurrencyCode" },
|
|
17
|
+
{ field: "customAmountMax", exactField: "customAmountMaxExact", currencyField: "customAmountCurrencyCode" }
|
|
18
|
+
];
|
|
19
|
+
function roundMoneyPair(legacy, exact, decimalPlaces) {
|
|
20
|
+
const resolved = resolveExactDecimal(exact, legacy);
|
|
21
|
+
if (resolved == null) return null;
|
|
22
|
+
const rounded = roundDecimal(resolved, decimalPlaces);
|
|
23
|
+
return { amount: decimalToNumber(rounded), amountExact: decimalToString(rounded) };
|
|
24
|
+
}
|
|
25
|
+
async function roundCheckoutConfiguredAmounts(container, scope, values) {
|
|
26
|
+
const decimalPlacesByCurrency = {};
|
|
27
|
+
const resolveDecimalPlaces = async (code) => {
|
|
28
|
+
const normalizedCode = code ?? "";
|
|
29
|
+
if (!(normalizedCode in decimalPlacesByCurrency)) {
|
|
30
|
+
const resolved = await resolveCurrencyDecimalPlaces(container, {
|
|
31
|
+
code: normalizedCode,
|
|
32
|
+
tenantId: scope.tenantId,
|
|
33
|
+
organizationId: scope.organizationId
|
|
34
|
+
});
|
|
35
|
+
decimalPlacesByCurrency[normalizedCode] = resolved ?? DEFAULT_CHECKOUT_DECIMAL_PLACES;
|
|
36
|
+
}
|
|
37
|
+
return decimalPlacesByCurrency[normalizedCode];
|
|
38
|
+
};
|
|
39
|
+
const next = { ...values };
|
|
40
|
+
for (const { field, exactField, currencyField } of CONFIGURED_MONEY_FIELDS) {
|
|
41
|
+
if (values[field] === void 0 && values[exactField] === void 0) continue;
|
|
42
|
+
const rounded = roundMoneyPair(values[field], values[exactField], await resolveDecimalPlaces(values[currencyField]));
|
|
43
|
+
next[field] = rounded?.amount ?? null;
|
|
44
|
+
next[exactField] = rounded?.amountExact ?? null;
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(values.priceListItems)) {
|
|
47
|
+
const items = [];
|
|
48
|
+
for (const item of values.priceListItems) {
|
|
49
|
+
const rounded = roundMoneyPair(item.amount, item.amountExact, await resolveDecimalPlaces(item.currencyCode));
|
|
50
|
+
items.push(rounded ? { ...item, amount: rounded.amount, amountExact: rounded.amountExact } : item);
|
|
51
|
+
}
|
|
52
|
+
next.priceListItems = items;
|
|
53
|
+
}
|
|
54
|
+
return next;
|
|
55
|
+
}
|
|
56
|
+
function toStoredCheckoutAmounts(values) {
|
|
57
|
+
return {
|
|
58
|
+
fixedPriceAmount: resolveExactDecimal(values.fixedPriceAmountExact, values.fixedPriceAmount),
|
|
59
|
+
fixedPriceOriginalAmount: resolveExactDecimal(values.fixedPriceOriginalAmountExact, values.fixedPriceOriginalAmount),
|
|
60
|
+
customAmountMin: resolveExactDecimal(values.customAmountMinExact, values.customAmountMin),
|
|
61
|
+
customAmountMax: resolveExactDecimal(values.customAmountMaxExact, values.customAmountMax)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
async function findCheckoutChargePrecisionError(container, scope, input) {
|
|
65
|
+
const resolved = parseDecimal(input.amount);
|
|
66
|
+
if (!resolved || !input.currencyCode) return null;
|
|
67
|
+
const decimalPlaces = await resolveCurrencyDecimalPlaces(container, {
|
|
68
|
+
code: input.currencyCode,
|
|
69
|
+
tenantId: scope.tenantId,
|
|
70
|
+
organizationId: scope.organizationId
|
|
71
|
+
}) ?? DEFAULT_CHECKOUT_DECIMAL_PLACES;
|
|
72
|
+
const precisionError = findCurrencyAmountPrecisionError({
|
|
73
|
+
amount: decimalToString(roundDecimal(resolved, decimalPlaces)),
|
|
74
|
+
currencyCode: input.currencyCode,
|
|
75
|
+
decimalPlaces
|
|
76
|
+
});
|
|
77
|
+
if (!precisionError) return null;
|
|
78
|
+
let translate = createFallbackTranslator(enDictionary);
|
|
79
|
+
try {
|
|
80
|
+
translate = (await resolveTranslations()).translate;
|
|
81
|
+
} catch {
|
|
82
|
+
translate = createFallbackTranslator(enDictionary);
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
error: translate(
|
|
86
|
+
"checkout.errors.amountPrecisionExceeded",
|
|
87
|
+
enDictionary["checkout.errors.amountPrecisionExceeded"],
|
|
88
|
+
precisionError
|
|
89
|
+
)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export {
|
|
93
|
+
DEFAULT_CHECKOUT_DECIMAL_PLACES,
|
|
94
|
+
findCheckoutChargePrecisionError,
|
|
95
|
+
roundCheckoutConfiguredAmounts,
|
|
96
|
+
toStoredCheckoutAmounts
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=amountPrecision.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/checkout/lib/amountPrecision.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n decimalToNumber,\n decimalToString,\n parseDecimal,\n resolveExactDecimal,\n roundDecimal,\n} from '@open-mercato/shared/lib/decimal'\nimport { findCurrencyAmountPrecisionError, resolveCurrencyDecimalPlaces } from '@open-mercato/shared/lib/currencyPrecision'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { createFallbackTranslator } from '@open-mercato/shared/lib/i18n/translate'\nimport enDictionary from '@open-mercato/checkout/modules/checkout/i18n/en.json'\n\nexport const DEFAULT_CHECKOUT_DECIMAL_PLACES = 2\n\ntype CurrencyContainer = Parameters<typeof resolveCurrencyDecimalPlaces>[0]\n\ntype CheckoutAmountScope = {\n tenantId: string\n organizationId: string\n}\n\ntype ConfiguredPriceListItem = {\n amount: number\n amountExact?: string | null\n currencyCode: string\n}\n\nexport type CheckoutConfiguredAmounts = {\n fixedPriceAmount?: number | null\n fixedPriceAmountExact?: string | null\n fixedPriceOriginalAmount?: number | null\n fixedPriceOriginalAmountExact?: string | null\n fixedPriceCurrencyCode?: string | null\n customAmountMin?: number | null\n customAmountMinExact?: string | null\n customAmountMax?: number | null\n customAmountMaxExact?: string | null\n customAmountCurrencyCode?: string | null\n priceListItems?: ReadonlyArray<ConfiguredPriceListItem> | null\n}\n\nconst CONFIGURED_MONEY_FIELDS = [\n { field: 'fixedPriceAmount', exactField: 'fixedPriceAmountExact', currencyField: 'fixedPriceCurrencyCode' },\n { field: 'fixedPriceOriginalAmount', exactField: 'fixedPriceOriginalAmountExact', currencyField: 'fixedPriceCurrencyCode' },\n { field: 'customAmountMin', exactField: 'customAmountMinExact', currencyField: 'customAmountCurrencyCode' },\n { field: 'customAmountMax', exactField: 'customAmountMaxExact', currencyField: 'customAmountCurrencyCode' },\n] as const\n\nfunction roundMoneyPair(\n legacy: unknown,\n exact: unknown,\n decimalPlaces: number,\n): { amount: number; amountExact: string } | null {\n const resolved = resolveExactDecimal(exact, legacy)\n if (resolved == null) return null\n const rounded = roundDecimal(resolved, decimalPlaces)\n return { amount: decimalToNumber(rounded), amountExact: decimalToString(rounded) }\n}\n\n/**\n * Rounds configured checkout amounts (fixed price, original price, custom amount\n * bounds and price-list items) half-up to the currency's own decimals, keeping\n * each `<field>` number and `<field>Exact` string in sync. Fields absent from\n * `values` are left untouched.\n */\nexport async function roundCheckoutConfiguredAmounts<T extends CheckoutConfiguredAmounts>(\n container: CurrencyContainer,\n scope: CheckoutAmountScope,\n values: T,\n): Promise<T> {\n const decimalPlacesByCurrency: Record<string, number> = {}\n const resolveDecimalPlaces = async (code: string | null | undefined): Promise<number> => {\n const normalizedCode = code ?? ''\n if (!(normalizedCode in decimalPlacesByCurrency)) {\n const resolved = await resolveCurrencyDecimalPlaces(container, {\n code: normalizedCode,\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n })\n decimalPlacesByCurrency[normalizedCode] = resolved ?? DEFAULT_CHECKOUT_DECIMAL_PLACES\n }\n return decimalPlacesByCurrency[normalizedCode]\n }\n\n const next: CheckoutConfiguredAmounts = { ...values }\n for (const { field, exactField, currencyField } of CONFIGURED_MONEY_FIELDS) {\n if (values[field] === undefined && values[exactField] === undefined) continue\n const rounded = roundMoneyPair(values[field], values[exactField], await resolveDecimalPlaces(values[currencyField]))\n next[field] = rounded?.amount ?? null\n next[exactField] = rounded?.amountExact ?? null\n }\n\n if (Array.isArray(values.priceListItems)) {\n const items: ConfiguredPriceListItem[] = []\n for (const item of values.priceListItems) {\n const rounded = roundMoneyPair(item.amount, item.amountExact, await resolveDecimalPlaces(item.currencyCode))\n items.push(rounded ? { ...item, amount: rounded.amount, amountExact: rounded.amountExact } : item)\n }\n next.priceListItems = items\n }\n\n return next as T\n}\n\n/** Exact decimal strings for the configured money columns of a template or link. */\nexport function toStoredCheckoutAmounts(values: CheckoutConfiguredAmounts) {\n return {\n fixedPriceAmount: resolveExactDecimal(values.fixedPriceAmountExact, values.fixedPriceAmount),\n fixedPriceOriginalAmount: resolveExactDecimal(values.fixedPriceOriginalAmountExact, values.fixedPriceOriginalAmount),\n customAmountMin: resolveExactDecimal(values.customAmountMinExact, values.customAmountMin),\n customAmountMax: resolveExactDecimal(values.customAmountMaxExact, values.customAmountMax),\n }\n}\n\n/**\n * Rounds a checkout charge to the currency's own decimals (as\n * `checkout.transaction.create` stores it) and checks it against the precision\n * payment providers charge in, so a link amount like `10.0051` USD is rejected\n * before a reservation or provider session instead of being charged as `10.01`.\n */\nexport async function findCheckoutChargePrecisionError(\n container: CurrencyContainer,\n scope: CheckoutAmountScope,\n input: { amount: string | number | null | undefined; currencyCode: string | null | undefined },\n): Promise<{ error: string } | null> {\n const resolved = parseDecimal(input.amount)\n if (!resolved || !input.currencyCode) return null\n const decimalPlaces = (await resolveCurrencyDecimalPlaces(container, {\n code: input.currencyCode,\n tenantId: scope.tenantId,\n organizationId: scope.organizationId,\n })) ?? DEFAULT_CHECKOUT_DECIMAL_PLACES\n const precisionError = findCurrencyAmountPrecisionError({\n amount: decimalToString(roundDecimal(resolved, decimalPlaces)),\n currencyCode: input.currencyCode,\n decimalPlaces,\n })\n if (!precisionError) return null\n let translate = createFallbackTranslator(enDictionary)\n try {\n translate = (await resolveTranslations()).translate\n } catch {\n translate = createFallbackTranslator(enDictionary)\n }\n return {\n error: translate(\n 'checkout.errors.amountPrecisionExceeded',\n enDictionary['checkout.errors.amountPrecisionExceeded'],\n precisionError,\n ),\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kCAAkC,oCAAoC;AAC/E,SAAS,2BAA2B;AACpC,SAAS,gCAAgC;AACzC,OAAO,kBAAkB;AAElB,MAAM,kCAAkC;AA6B/C,MAAM,0BAA0B;AAAA,EAC9B,EAAE,OAAO,oBAAoB,YAAY,yBAAyB,eAAe,yBAAyB;AAAA,EAC1G,EAAE,OAAO,4BAA4B,YAAY,iCAAiC,eAAe,yBAAyB;AAAA,EAC1H,EAAE,OAAO,mBAAmB,YAAY,wBAAwB,eAAe,2BAA2B;AAAA,EAC1G,EAAE,OAAO,mBAAmB,YAAY,wBAAwB,eAAe,2BAA2B;AAC5G;AAEA,SAA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AEA,SAAO;AACT;AAGO,SAAS,wBAAwB,QAAmC;AACzE,SAAO;AAAA,IACL,kBAAkB,oBAAoB,OAAO,uBAAuB,OAAO,gBAAgB;AAAA,IAC3F,0BAA0B,oBAAoB,OAAO,+BAA+B,OAAO,wBAAwB;AAAA,IACnH,iBAAiB,oBAAoB,OAAO,sBAAsB,OAAO,eAAe;AAAA,IACxF,iBAAiB,oBAAoB,OAAO,sBAAsB,OAAO,eAAe;AAAA,EAC1F;AACF;AAQA,eAAsB,iCACpB,WACA,OACA,OACmC;AACnC,QAAM,WAAW,aAAa,MAAM,MAAM;AAC1C,MAAI,CAAC,YAAY,CAAC,MAAM,aAAc,QAAO;AAC7C,QAAM,gBAAiB,MAAM,6BAA6B,WAAW;AAAA,IACnE,MAAM,MAAM;AAAA,IACZ,UAAU,MAAM;AAAA,IAChB,gBAAgB,MAAM;AAAA,EACxB,CAAC,KAAM;AACP,QAAM,iBAAiB,iCAAiC;AAAA,IACtD,QAAQ,gBAAgB,aAAa,UAAU,aAAa,CAAC;AAAA,IAC7D,cAAc,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACD,MAAI,CAAC,eAAgB,QAAO;AAC5B,MAAI,YAAY,yBAAyB,YAAY;AACrD,MAAI;AACF,iBAAa,MAAM,oBAAoB,GAAG;AAAA,EAC5C,QAAQ;AACN,gBAAY,yBAAyB,YAAY;AAAA,EACnD;AACA,SAAO;AAAA,IACL,OAAO;AAAA,MACL;AAAA,MACA,aAAa,yCAAyC;AAAA,MACtD;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
compareDecimals,
|
|
3
|
+
decimalToNumber,
|
|
4
|
+
decimalToString,
|
|
5
|
+
parseDecimal,
|
|
6
|
+
resolveExactDecimal
|
|
7
|
+
} from "@open-mercato/shared/lib/decimal";
|
|
8
|
+
import { formatCurrency } from "@open-mercato/ui/utils/format";
|
|
9
|
+
const PLAIN_AMOUNT_DECIMAL_PLACES = 2;
|
|
10
|
+
function toPayPageAmount(legacy, exact) {
|
|
11
|
+
const amountExact = resolveExactDecimal(exact, legacy);
|
|
12
|
+
if (amountExact == null) return { amount: null, amountExact: null };
|
|
13
|
+
return { amount: decimalToNumber(amountExact), amountExact };
|
|
14
|
+
}
|
|
15
|
+
function parsePayPageAmountInput(value) {
|
|
16
|
+
const parsed = parseDecimal(value.trim());
|
|
17
|
+
if (!parsed) return { amount: null, amountExact: null };
|
|
18
|
+
return { amount: decimalToNumber(parsed), amountExact: decimalToString(parsed) };
|
|
19
|
+
}
|
|
20
|
+
function applyPayPageAmountValue(current, value) {
|
|
21
|
+
if (typeof value === "string") return parsePayPageAmountInput(value);
|
|
22
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return { amount: null, amountExact: null };
|
|
23
|
+
return { amount: value, amountExact: resolveExactDecimal(current.amountExact, value) };
|
|
24
|
+
}
|
|
25
|
+
function buildPayPageSubmitBody(data) {
|
|
26
|
+
const { amount, amountExact, ...rest } = data;
|
|
27
|
+
return { ...rest, amount: resolveExactDecimal(amountExact, amount) };
|
|
28
|
+
}
|
|
29
|
+
function validatePayPageCustomAmount(bounds, value) {
|
|
30
|
+
const submitted = resolveExactDecimal(value.amountExact, value.amount);
|
|
31
|
+
if (submitted == null) return "required";
|
|
32
|
+
const minimum = resolveExactDecimal(bounds.customAmountMinExact, bounds.customAmountMin);
|
|
33
|
+
const maximum = resolveExactDecimal(bounds.customAmountMaxExact, bounds.customAmountMax);
|
|
34
|
+
if (maximum != null && compareDecimals(submitted, maximum) > 0) return "max";
|
|
35
|
+
if (minimum != null && compareDecimals(submitted, minimum) < 0) return "min";
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
function formatPayPageAmount(value, currencyCode, locale, exact) {
|
|
39
|
+
const exactValue = exact ? resolveExactDecimal(exact, value) : null;
|
|
40
|
+
const normalizedValue = exactValue ?? (typeof value === "number" && !Number.isFinite(value) ? 0 : value ?? 0);
|
|
41
|
+
return formatCurrency(
|
|
42
|
+
normalizedValue,
|
|
43
|
+
currencyCode,
|
|
44
|
+
locale,
|
|
45
|
+
currencyCode ? null : PLAIN_AMOUNT_DECIMAL_PLACES
|
|
46
|
+
) ?? "";
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
applyPayPageAmountValue,
|
|
50
|
+
buildPayPageSubmitBody,
|
|
51
|
+
formatPayPageAmount,
|
|
52
|
+
parsePayPageAmountInput,
|
|
53
|
+
toPayPageAmount,
|
|
54
|
+
validatePayPageCustomAmount
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=payPageAmount.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/checkout/lib/payPageAmount.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n compareDecimals,\n decimalToNumber,\n decimalToString,\n parseDecimal,\n resolveExactDecimal,\n} from '@open-mercato/shared/lib/decimal'\nimport { formatCurrency } from '@open-mercato/ui/utils/format'\n\n/**\n * Client-safe amount helpers for the public pay page. Amounts travel as a\n * `number` (kept for display and injection widgets) plus an exact decimal string\n * so values beyond float precision reach the server unchanged.\n */\n\nexport type PayPageAmount = {\n amount: number | null\n amountExact: string | null\n}\n\nexport type PayPageSubmitBodyInput = {\n amount: number | null\n amountExact?: string | null\n}\n\nexport type PayPageCustomAmountBounds = {\n customAmountMin?: number | null\n customAmountMinExact?: string | null\n customAmountMax?: number | null\n customAmountMaxExact?: string | null\n}\n\nexport type PayPageCustomAmountIssue = 'required' | 'min' | 'max'\n\nconst PLAIN_AMOUNT_DECIMAL_PLACES = 2\n\nexport function toPayPageAmount(legacy: unknown, exact: unknown): PayPageAmount {\n const amountExact = resolveExactDecimal(exact, legacy)\n if (amountExact == null) return { amount: null, amountExact: null }\n return { amount: decimalToNumber(amountExact), amountExact }\n}\n\nexport function parsePayPageAmountInput(value: string): PayPageAmount {\n const parsed = parseDecimal(value.trim())\n if (!parsed) return { amount: null, amountExact: null }\n return { amount: decimalToNumber(parsed), amountExact: decimalToString(parsed) }\n}\n\n/**\n * Applies an amount set through the pay page form API. Strings are parsed\n * exactly; a number keeps the current exact string only while it still stands\n * for the same value, so a widget changing the number is never overridden.\n */\nexport function applyPayPageAmountValue(current: PayPageAmount, value: unknown): PayPageAmount {\n if (typeof value === 'string') return parsePayPageAmountInput(value)\n if (typeof value !== 'number' || !Number.isFinite(value)) return { amount: null, amountExact: null }\n return { amount: value, amountExact: resolveExactDecimal(current.amountExact, value) }\n}\n\nexport function buildPayPageSubmitBody<TData extends PayPageSubmitBodyInput>(\n data: TData,\n): Omit<TData, 'amount' | 'amountExact'> & { amount: string | null } {\n const { amount, amountExact, ...rest } = data\n return { ...rest, amount: resolveExactDecimal(amountExact, amount) }\n}\n\nexport function validatePayPageCustomAmount(\n bounds: PayPageCustomAmountBounds,\n value: PayPageAmount,\n): PayPageCustomAmountIssue | null {\n const submitted = resolveExactDecimal(value.amountExact, value.amount)\n if (submitted == null) return 'required'\n const minimum = resolveExactDecimal(bounds.customAmountMinExact, bounds.customAmountMin)\n const maximum = resolveExactDecimal(bounds.customAmountMaxExact, bounds.customAmountMax)\n if (maximum != null && compareDecimals(submitted, maximum) > 0) return 'max'\n if (minimum != null && compareDecimals(submitted, minimum) < 0) return 'min'\n return null\n}\n\n/**\n * Formats a pay page amount from its exact decimal string, so the page shows\n * every digit that is charged: ISO currencies at their minor-unit digits, codes\n * without a known precision (`ETH`) with all of their decimals.\n */\nexport function formatPayPageAmount(\n value: number | string | null | undefined,\n currencyCode: string | null | undefined,\n locale: string,\n exact?: string | null,\n): string {\n const exactValue = exact ? resolveExactDecimal(exact, value) : null\n const normalizedValue = exactValue ?? (typeof value === 'number' && !Number.isFinite(value) ? 0 : value ?? 0)\n return formatCurrency(\n normalizedValue,\n currencyCode,\n locale,\n currencyCode ? null : PLAIN_AMOUNT_DECIMAL_PLACES,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