@hszrdm/create-commerce 1.20.0 → 1.21.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hszrdm/create-commerce",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "description": "Create a complete HSZRDM Commerce webshop project.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
package/src/cli.mjs CHANGED
@@ -287,7 +287,8 @@ function configureProject(root, settings) {
287
287
  ".DS_Store",
288
288
  "*.log",
289
289
  "backups/",
290
- ".core/deployment-environment",
290
+ ".core/",
291
+ "backend/.core/",
291
292
  "",
292
293
  ].join("\n"),
293
294
  )
@@ -7,9 +7,13 @@
7
7
  # Required for every shop: DATABASE_URL, JWT_SECRET, COOKIE_SECRET,
8
8
  # STORE_CORS, ADMIN_CORS, AUTH_CORS.
9
9
  #
10
- # External integrations are preferably configured in HSZRDM Commerce Admin
11
- # (Settings -> Integrációk). Environment variables below are fallback/bootstrap
12
- # options only. Do not copy unused integration secrets into production.
10
+ # Merchant credentials and customer-specific settings belong only in encrypted
11
+ # Admin Integration Settings, not in generated .env files.
12
+ # Configure optional integrations after startup in Medusa Admin.
13
+ # Deployment transport, infrastructure and webhook security remain ENV-only.
14
+ # Carrier transport endpoints, sandbox modes and timeouts belong only in the
15
+ # deployment ENV. Prices and free-shipping thresholds belong in Medusa Shipping Options.
16
+ # Never put real customer secrets into generated templates or source control.
13
17
 
14
18
  # -----------------------------------------------------------------------------
15
19
  # Runtime / infrastructure
@@ -37,9 +41,9 @@ AUTH_CORS=http://localhost:3000,http://localhost:9000,http://localhost:7001
37
41
  # Encrypts secrets stored by Settings -> Integrációk.
38
42
  INTEGRATION_SETTINGS_ENCRYPTION_KEY=replace-with-at-least-32-random-characters
39
43
  INTEGRATION_SETTINGS_FILE=
40
- # Shared inbound shipping callback secret. Required only for enabled callback-based providers.
41
- # Security PR #53 requires 32-256 random characters; weaker configuration disables callbacks.
42
- # Generate a unique secret per deployment: openssl rand -hex 32
44
+ # Inbound FOXPOST/GLS status callbacks: deployment ENV only, never Admin DB.
45
+ # Keep off until the callback provider uses the same 32-256 character secret.
46
+ SHIPPING_WEBHOOK_ENABLED=false
43
47
  SHIPPING_WEBHOOK_SECRET=
44
48
 
45
49
  # -----------------------------------------------------------------------------
@@ -82,42 +86,11 @@ OPENAI_BASE_URL=https://api.openai.com/v1
82
86
  # Email Center / transactional email
83
87
  # -----------------------------------------------------------------------------
84
88
  EMAIL_CENTER_ENABLED=true
85
- # SMTP is the only supported email transport. This legacy selector is optional.
89
+ # SMTP is the only supported email transport. Configure and enable it in Admin.
90
+ # SMTP credentials, sender identities and event switches are DB-only.
86
91
  EMAIL_PROVIDER=smtp
87
- # New stores have no SMTP host yet; enable after configuring and verifying SMTP in Admin.
88
- SMTP_ENABLED=false
89
92
  EMAIL_FROM="Example Store <system@example.com>"
90
93
  EMAIL_REPLY_TO=support@example.com
91
- SMTP_HOST=
92
- SMTP_PORT=587
93
- # true for implicit TLS (typically 465), false for STARTTLS (typically 587)
94
- SMTP_SECURE=false
95
- SMTP_REQUIRE_TLS=true
96
- SMTP_USER=
97
- SMTP_PASSWORD=
98
- SMTP_FROM="Example Store <system@example.com>"
99
- SMTP_REPLY_TO=
100
- # Opcionális, a SMTP-szolgáltatónál engedélyezett alternatív feladócímek (Send As)
101
- SMTP_ALLOWED_FROM_ADDRESSES=
102
-
103
- EMAIL_CUSTOMER_WELCOME_ENABLED=
104
- EMAIL_REGISTRATION_VERIFICATION_ENABLED=
105
- EMAIL_PASSWORD_RESET_ENABLED=
106
- EMAIL_CHANGE_VERIFICATION_ENABLED=
107
- EMAIL_PASSWORD_CHANGED_ENABLED=
108
- EMAIL_CHANGED_ENABLED=
109
- EMAIL_ACCOUNT_DELETED_ENABLED=
110
- EMAIL_ORDER_PLACED_ENABLED=
111
- EMAIL_PAYMENT_CAPTURED_ENABLED=
112
- EMAIL_FULFILLMENT_CREATED_ENABLED=
113
- EMAIL_SHIPMENT_CREATED_ENABLED=
114
- EMAIL_ORDER_CANCELED_ENABLED=
115
- EMAIL_PAYMENT_REFUNDED_ENABLED=
116
- EMAIL_AFTER_SALES_SUBMITTED_ENABLED=
117
- EMAIL_AFTER_SALES_APPROVED_ENABLED=
118
- EMAIL_AFTER_SALES_REJECTED_ENABLED=
119
- EMAIL_RETURN_INSTRUCTIONS_ENABLED=
120
- EMAIL_RETURN_RECEIVED_ENABLED=
121
94
 
122
95
  EMAIL_LOGO_URL=
123
96
  EMAIL_TRACKING_ENABLED=true
@@ -209,56 +182,11 @@ SEO_ALLOW_INDEXING=
209
182
  SEO_ROBOTS_DISALLOW=
210
183
 
211
184
  # -----------------------------------------------------------------------------
212
- # Payment fallback/bootstrap settings
213
- # Prefer Admin -> Settings -> Integrációk.
214
- # -----------------------------------------------------------------------------
215
- STRIPE_ENABLED=false
216
- STRIPE_API_KEY=
217
- STRIPE_WEBHOOK_SECRET=
218
- STRIPE_WEBHOOK_URL=http://localhost:9000/hooks/payment/stripe_stripe
219
-
220
- SIMPLEPAY_ENABLED=false
221
- SIMPLEPAY_SANDBOX=true
222
- SIMPLEPAY_HUF_MERCHANT=
223
- SIMPLEPAY_HUF_SECRET_KEY=
224
- SIMPLEPAY_EUR_MERCHANT=
225
- SIMPLEPAY_EUR_SECRET_KEY=
226
- SIMPLEPAY_USD_MERCHANT=
227
- SIMPLEPAY_USD_SECRET_KEY=
228
- SIMPLEPAY_RETURN_BASE_URL=http://localhost:9000/store/simplepay/back
229
- SIMPLEPAY_STOREFRONT_URL=http://localhost:3000
230
- SIMPLEPAY_TIMEOUT_MS=15000
231
-
232
- BANK_TRANSFER_ENABLED=false
233
- BANK_TRANSFER_BANK_NAME=
234
- BANK_TRANSFER_ACCOUNT_HOLDER=
235
- BANK_TRANSFER_ACCOUNT_NUMBER=
236
- BANK_TRANSFER_IBAN=
237
- BANK_TRANSFER_BIC=
238
- BANK_TRANSFER_DUE_DAYS=3
239
- BANK_TRANSFER_REFERENCE_PREFIX=
240
- BANK_TRANSFER_EMAIL_ENABLED=true
241
- BANK_TRANSFER_BILLINGO_PROFORMA=false
242
- BANK_TRANSFER_BILLINGO_PROFORMA_SEND=true
243
-
244
- # -----------------------------------------------------------------------------
245
- # Billingo fallback/bootstrap settings
185
+ # Provider deployment defaults; merchant payment and Billingo integration
186
+ # fields are configured in Admin -> Settings -> Integrációk.
246
187
  # -----------------------------------------------------------------------------
247
- BILLINGO_ENABLED=false
248
- BILLINGO_API_URL=https://api.billingo.hu/v3
249
- BILLINGO_API_KEY=
250
- BILLINGO_DOCUMENT_BLOCK_ID=
251
- BILLINGO_BANK_ACCOUNT_ID=
252
188
  BILLINGO_PAYMENT_METHOD=stripe
253
- BILLINGO_LANGUAGE=hu
254
- BILLINGO_ELECTRONIC=true
255
- BILLINGO_DUE_DAYS=0
256
189
  BILLINGO_UNIT=db
257
- BILLINGO_TIMEOUT_MS=30000
258
- BILLINGO_AUTO_INVOICE=true
259
- BILLINGO_AUTO_SEND=true
260
- BILLINGO_AUTO_CANCEL_ON_ORDER_CANCELED=false
261
- BILLINGO_INVOICE_TRIGGER=payment_captured
262
190
 
263
191
  # -----------------------------------------------------------------------------
264
192
  # Background carrier status sync: FOXPOST, GLS, Packeta, Csomagpiac every 30 minutes.
@@ -267,33 +195,22 @@ BILLINGO_INVOICE_TRIGGER=payment_captured
267
195
  SHIPPING_STATUS_SYNC_ENABLED=true
268
196
  SHIPPING_STATUS_SYNC_BATCH_SIZE=100
269
197
 
270
- # Shipping fallback/bootstrap settings
271
- # Prefer Admin -> Settings -> Integrációk.
198
+ # Carrier technical URL, mode, feed and timeout: deployment ENV only.
199
+ # Merchant credentials: encrypted Admin DB. Rates: Medusa Shipping Options.
272
200
  # -----------------------------------------------------------------------------
273
- FOXPOST_ENABLED=false
274
201
  # FOXPOST transport: operator-owned ENV only, never editable in Admin.
275
202
  # A blank FOXPOST_SANDBOX follows APP_ENV (production=false, other=true).
276
203
  # Egyedi környezetben itt felülírható.
277
204
  FOXPOST_API_URL=
278
- FOXPOST_API_USERNAME=
279
- FOXPOST_API_PASSWORD=
280
- FOXPOST_API_KEY=
281
205
  FOXPOST_SANDBOX=
282
206
  # Fixed FOXPOST parcel size sent during Create Fulfillment (XS/S/M/L/XL); default M.
283
207
  FOXPOST_PACKAGE_SIZE=M
284
208
  FOXPOST_LOCKER_FEED_URL=https://cdn.foxpost.hu/foxplus.json
285
209
  FOXPOST_TIMEOUT_MS=10000
286
210
 
287
- GLS_ENABLED=false
288
211
  GLS_API_URL=https://api.mygls.hu
289
- GLS_USERNAME=
290
- GLS_PASSWORD=
291
- GLS_CLIENT_NUMBER=
292
212
  GLS_SANDBOX=false
293
213
  GLS_DELIVERY_POINTS_URL=https://map.gls-hungary.com/data/deliveryPoints/hu.json
294
- GLS_POINT_PRICE_HUF=1490
295
- GLS_HOME_DELIVERY_PRICE_HUF=1990
296
- GLS_FREE_SHIPPING_THRESHOLD_HUF=
297
214
  GLS_TIMEOUT_MS=15000
298
215
  GLS_PRINTER_TYPE=A4_2x2
299
216
  # Optional absolute PRIVATE directory for original GLS PDF labels.
@@ -301,137 +218,45 @@ GLS_PRINTER_TYPE=A4_2x2
301
218
  # Must survive deploy and be included in filesystem backups. Never expose via /static.
302
219
  GLS_PRIVATE_LABEL_DIR=
303
220
  GLS_WEBSHOP_ENGINE=HSZRDM Commerce
304
- GLS_PICKUP_NAME=Example Store
305
- GLS_PICKUP_STREET=
306
- GLS_PICKUP_HOUSE_NUMBER=
307
- GLS_PICKUP_HOUSE_NUMBER_INFO=
308
- GLS_PICKUP_CITY=
309
- GLS_PICKUP_POSTAL_CODE=
310
- GLS_PICKUP_COUNTRY_CODE=HU
311
- GLS_PICKUP_CONTACT_NAME=
312
- GLS_PICKUP_PHONE=
313
- GLS_PICKUP_EMAIL=
314
221
 
315
- PACKETA_ENABLED=false
316
222
  PACKETA_API_URL=https://www.zasilkovna.cz/api/rest
317
- PACKETA_API_KEY=
318
- PACKETA_API_PASSWORD=
319
- PACKETA_SENDER_INDICATION=
320
- PACKETA_HOME_CARRIER_ID=
321
223
  # Optional JSON map of destination country to contracted Packeta HOME carrier ID.
322
- PACKETA_HOME_CARRIER_IDS=
323
224
  # Technical, fixed at server deployment; not mutable from Admin.
324
225
  PACKETA_TIMEOUT_MS=15000
325
- PACKETA_DEFAULT_WEIGHT_KG=1
326
- PACKETA_LABEL_FORMAT=A6 on A6
327
- PACKETA_LANGUAGE=hu
328
226
  # Signing key for signed Packeta callbacks. Confirm provider compatibility;
329
227
  # raw body and timestamp are mandatory. Rotate separately from other webhook secrets.
330
228
  PACKETA_WEBHOOK_SIGNING_KEY=
331
229
 
332
230
  # DPD technical settings are deployment-controlled. Blank sandbox follows APP_ENV.
333
231
  # Shipping prices are fixed Medusa Shipping Options, not DPD ENV fields.
334
- DPD_ENABLED=false
335
232
  DPD_SANDBOX=
336
233
  DPD_API_URL=
337
- DPD_TOKEN=
338
- DPD_BU_CODE=
339
- DPD_CUSTOMER_ID=
340
- DPD_SENDER_ADDRESS_ID=
341
- DPD_HOME_SERVICE_CODE=
342
- DPD_COD_PAYMENT_TYPE=Cash
343
- DPD_PUDO_SOURCE=disabled
344
- DPD_PUDO_SERVICE_CODE=
345
234
  DPD_PUDO_LOCATOR_URL=
346
- DPD_PUDO_DELIS_ID=
347
- DPD_PUDO_PASSWORD=
348
- DPD_PUDO_MESSAGE_LANGUAGE=en_US
349
235
  DPD_TIMEOUT_MS=15000
350
- DPD_DEFAULT_WEIGHT_KG=1
351
- DPD_LABEL_SIZE=A6
352
- DPD_PRINT_FORMAT=PDF
353
- DPD_LABEL_DPI=203
354
236
  DPD_STATUSDATA_ENABLED=false
355
- DPD_STATUSDATA_FTP_HOST=
356
- DPD_STATUSDATA_FTP_PORT=21
357
- DPD_STATUSDATA_FTP_USERNAME=
358
- DPD_STATUSDATA_FTP_PASSWORD=
359
- DPD_STATUSDATA_FTP_DIR=
360
- DPD_STATUSDATA_FTP_TIMEOUT_MS=15000
361
237
 
362
- MPL_ENABLED=false
363
- MPL_SANDBOX=true
238
+ # MPL sandbox mode is ENV-only; blank follows APP_ENV (production = live).
239
+ MPL_SANDBOX=
364
240
  MPL_API_URL=
365
241
  MPL_TRACKING_API_URL=
366
242
  MPL_PUSH_TRACKING_API_URL=
367
243
  MPL_PUSH_TRACKING_STREAM_URL=https://net.posta.hu/tracking/public/tracking/TrackingData
368
244
  MPL_TOKEN_URL=
369
- MPL_API_KEY=
370
- MPL_API_SECRET=
371
- MPL_AGREEMENT=
372
- MPL_ACCOUNT_NO=
373
- MPL_SENDER_NAME=Example Store
374
- MPL_SENDER_EMAIL=orders@example.com
375
- MPL_SENDER_PHONE=
376
- MPL_SENDER_POST_CODE=
377
- MPL_SENDER_CITY=
378
- MPL_SENDER_ADDRESS=
379
- MPL_DEVELOPER=HSZRDM Commerce
380
- MPL_BASIC_SERVICE_CODE=
381
- MPL_EXTRA_SERVICES=
382
- MPL_PAYMENT_MODE=
383
- MPL_TAG=
384
- MPL_HOME_DELIVERY_MODE=HA
385
- MPL_POINT_PRICE_HUF=1290
386
- MPL_HOME_DELIVERY_PRICE_HUF=1990
387
- MPL_FREE_SHIPPING_THRESHOLD_HUF=
388
245
  MPL_TIMEOUT_MS=15000
389
- MPL_DEFAULT_WEIGHT_KG=1
390
- MPL_LABEL_TYPE=A6
391
- MPL_PACKAGE_RETENTION=5
392
246
  MPL_TRACKING_ENABLED=false
393
247
  MPL_PUSH_TRACKING_ENABLED=false
394
- MPL_TRACKING_ACCOUNT_CODE=
395
248
  MPL_PUSH_READ_WINDOW_MS=8000
396
249
  MPL_TRACKING_LANGUAGE=hu
397
250
 
398
- # Csomagpiac technical transport is operator-owned; credentials, sender ID,
399
- # label format and service profiles are configured in the encrypted Admin DB.
251
+ # Csomagpiac transport is operator-owned; merchant fields and service
252
+ # profiles are configured in the encrypted Admin DB.
400
253
  # Leave CSOMAGPIAC_LIVE unset to follow APP_ENV automatically.
401
254
  CSOMAGPIAC_LIVE=
402
255
  CSOMAGPIAC_API_URL=
403
256
  CSOMAGPIAC_TIMEOUT_MS=15000
404
257
 
405
258
  # -----------------------------------------------------------------------------
406
- # Product feeds / trust widgets - optional
407
- # -----------------------------------------------------------------------------
408
- GOOGLE_MERCHANT_ENABLED=false
409
- GOOGLE_MERCHANT_COUNTRY_CODE=HU
410
- GOOGLE_MERCHANT_CURRENCY_CODE=HUF
411
- GOOGLE_MERCHANT_LOCALE=hu-HU
412
- GOOGLE_MERCHANT_STOREFRONT_URL=
413
- GOOGLE_MERCHANT_PRODUCT_PATH_TEMPLATE=/{locale}/{products_segment}/{handle}?v_id={variant_id}
414
- GOOGLE_MERCHANT_SALES_CHANNEL_ID=
415
- GOOGLE_MERCHANT_FEED_TITLE=
416
- GOOGLE_MERCHANT_FEED_DESCRIPTION=
417
- GOOGLE_MERCHANT_DEFAULT_BRAND=
418
- GOOGLE_MERCHANT_DEFAULT_CONDITION=new
419
- GOOGLE_MERCHANT_INCLUDE_OUT_OF_STOCK=true
420
-
421
- ARUKERESO_ENABLED=false
422
- ARUKERESO_STOREFRONT_URL=
423
- ARUKERESO_PRODUCT_PATH_TEMPLATE=/hu/termekek/{handle}?v_id={variant_id}
424
- ARUKERESO_SALES_CHANNEL_ID=
425
- ARUKERESO_DEFAULT_MANUFACTURER=
426
- ARUKERESO_USE_SKU_AS_PRODUCT_NUMBER=false
427
- ARUKERESO_INCLUDE_OUT_OF_STOCK=true
428
- ARUKERESO_DEFAULT_DELIVERY_TIME=
429
- ARUKERESO_DEFAULT_DELIVERY_COST=
430
-
431
- FOGYASZTOBARAT_ENABLED=false
432
- # Admin integration: paste full provider <script> snippet (legacy ID still supported)
433
- FOGYASZTOBARAT_EMBED_CODE=
434
- FOGYASZTOBARAT_DATA_ID=
259
+ # Product feed and legal/trust widget credentials and options are Admin DB only.
435
260
 
436
261
  # -----------------------------------------------------------------------------
437
262
  # Generator only (not used by a running shop)
@@ -23,7 +23,7 @@
23
23
  "start:prod": "cd .medusa/server && medusa start"
24
24
  },
25
25
  "dependencies": {
26
- "@hszrdm/core": "1.20.0",
26
+ "@hszrdm/core": "1.21.0",
27
27
  "@medusajs/admin-sdk": "2.22.2",
28
28
  "@medusajs/cli": "2.22.2",
29
29
  "@medusajs/draft-order": "2.22.2",
@@ -16,7 +16,9 @@
16
16
  "test:ga4": "node --experimental-strip-types --test tests/ga4-bootstrap.test.mjs",
17
17
  "test:seo": "node --experimental-strip-types --test tests/technical-seo.test.mjs",
18
18
  "test:account-verification": "node --test tests/account-verification.test.mjs",
19
- "test:product-images": "node --experimental-strip-types --test tests/product-image.test.mjs"
19
+ "test:product-images": "node --experimental-strip-types --test tests/product-image.test.mjs",
20
+ "test:checkout-summary": "node --experimental-strip-types --test tests/checkout-summary.test.mjs",
21
+ "test:checkout-payment-choices": "node --experimental-strip-types --test tests/checkout-payment-choices.test.mjs"
20
22
  },
21
23
  "dependencies": {
22
24
  "@stripe/react-stripe-js": "7.0.0",
@@ -138,6 +138,14 @@ input[readonly] { background: var(--surface-soft); color: var(--muted); }
138
138
 
139
139
  .checkout-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; align-items: start; }
140
140
  .checkout-summary { position: sticky; top: 18px; }
141
+ .checkout-summary-heading { margin: 0; font-size: 1.2rem; line-height: 1.25; font-weight: 850; }
142
+ .checkout-summary-group { display: flex; flex-direction: column; gap: 9px; padding-top: 14px; border-top: 1px solid var(--line); }
143
+ .checkout-summary-group h3 { margin: 0 0 2px; font-size: .93rem; font-weight: 800; }
144
+ .checkout-summary-group .summary-line { font-size: .9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
145
+ .checkout-summary-group .summary-line span:last-child { color: var(--text); }
146
+ .checkout-summary-group .checkout-summary-gross { color: var(--text); font-weight: 750; }
147
+ .checkout-summary-cod { padding-top: 14px; border-top: 1px solid var(--line); font-weight: 750; font-variant-numeric: tabular-nums; }
148
+ .checkout-summary .summary-total { font-variant-numeric: tabular-nums; }
141
149
 
142
150
  /* Stripe SDK and Payment Element both have an explicit loading stage.
143
151
  Keep Elements mounted (for onReady/confirmPayment) underneath the loader. */
@@ -1,6 +1,6 @@
1
1
  "use client"
2
2
 
3
- import { Fragment, useCallback, useEffect, useMemo, useRef, useState, useId } from "react"
3
+ import { useCallback, useEffect, useMemo, useRef, useState, useId } from "react"
4
4
  import { usePathname, useRouter, useSearchParams } from "next/navigation"
5
5
  import { useCart } from "./cart-provider"
6
6
  import { AddressStreetFields } from "./address-street-fields"
@@ -34,13 +34,14 @@ import {
34
34
  type CustomerAddress,
35
35
  } from "@/lib/core/checkout-addresses"
36
36
  import { normalizeShippingPhone, requireShippingText, validateShippingEmail } from "@/lib/core/shipping-input-validation"
37
+ import { checkoutOrderSummary } from "@/lib/core/checkout-summary"
38
+ import { checkoutPaymentChoices } from "@/lib/core/checkout-payment-choices"
37
39
  import {
38
40
  activePaymentSession,
39
41
  asRecords,
40
42
  cartCurrency,
41
43
  cartPaymentCollection,
42
44
  cartRegionId,
43
- cartTotal,
44
45
  formatMoney,
45
46
  isRecord,
46
47
  paymentClientSecret,
@@ -735,23 +736,11 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
735
736
  initializationError: stripeInitError,
736
737
  })
737
738
  const simplePaySelected = activeProviderId.toLowerCase().includes("simplepay")
738
- const systemSelected = activeProviderId.toLowerCase().includes("system")
739
+ // Both offline providers submit the native Medusa order without card UI.
740
+ const offlineSelected = activeProviderId === "pp_system_default" || activeProviderId === "pp_cod_cod"
739
741
  const currency = cartCurrency(cart, config.store.default_currency)
740
- const selectedMethod = asRecords(cart.shipping_methods)[0]
741
- const activeShippingOption = shippingOptions.find(option =>
742
- stringValue(option.id) === stringValue(selectedMethod?.shipping_option_id))
743
- const optionData = isRecord(activeShippingOption?.data) ? activeShippingOption.data : {}
744
- const selectedShippingData = isRecord(selectedMethod?.data) ? selectedMethod.data : {}
745
- const csomagpiacData = isRecord(selectedShippingData.csomagpiac) ? selectedShippingData.csomagpiac : {}
746
- const codAvailable = currency === "HUF" &&
747
- activeShippingOption?.price_type === "flat" &&
748
- csomagpiacData.codEnabled !== false &&
749
- (optionData.hszrdm_cod_enabled === true ||
750
- (optionData.hszrdm_cod_enabled === undefined && optionData.cod === true)) &&
751
- asRecords(cart.shipping_methods).length === 1
752
- const appliedCodFee = shippingMethodIsCod(cart)
753
- ? Number(selectedShippingData.hszrdm_cod_applied_fee_huf || 0)
754
- : 0
742
+ const paymentChoices = checkoutPaymentChoices(providers, config.payments.bank_transfer.enabled)
743
+ const orderSummary = checkoutOrderSummary(cart, currency)
755
744
 
756
745
  return (
757
746
  <div className="checkout-layout">
@@ -1032,37 +1021,24 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
1032
1021
  <p className="muted">{copy.chooseShippingForPayments}</p>
1033
1022
  ) : (
1034
1023
  <div className="choice-list">
1035
- {providers.map((provider) => {
1036
- const id = stringValue(provider.id)
1037
- const system = id.toLowerCase().includes("system")
1038
- const normalMode = system ? "bank_transfer" : "online"
1039
- return (
1040
- <Fragment key={id}>
1041
- {system && codAvailable ? (
1042
- <button
1043
- className={`choice-card choice-button${selectedProvider === id && selectedPaymentMode === "cod" ? " selected" : ""}`}
1044
- type="button"
1045
- disabled={busy === "payment" || !addressOnCart}
1046
- onClick={() => void preparePayment(id, "cod")}
1047
- >
1048
- <strong>{localized(locale, "Utánvét", "Cash on delivery")}</strong>
1049
- <small>{localized(locale, "Fizetés kézbesítéskor", "Pay on delivery")}</small>
1050
- </button>
1051
- ) : null}
1052
- {(!system || config.payments.bank_transfer.enabled) ? (
1053
- <button
1054
- className={`choice-card choice-button${selectedProvider === id && selectedPaymentMode === normalMode ? " selected" : ""}`}
1055
- type="button"
1056
- disabled={busy === "payment" || !addressOnCart}
1057
- onClick={() => void preparePayment(id, normalMode)}
1058
- >
1059
- <strong>{providerLabel(id, false)}</strong>
1060
- <small>{id}</small>
1061
- </button>
1062
- ) : null}
1063
- </Fragment>
1064
- )
1065
- })}
1024
+ {paymentChoices.map((choice) => (
1025
+ <button
1026
+ key={`${choice.providerId}:${choice.mode}`}
1027
+ className={`choice-card choice-button${selectedProvider === choice.providerId && selectedPaymentMode === choice.mode ? " selected" : ""}`}
1028
+ type="button"
1029
+ disabled={busy === "payment" || !addressOnCart}
1030
+ onClick={() => void preparePayment(choice.providerId, choice.mode)}
1031
+ >
1032
+ <strong>{choice.mode === "cod"
1033
+ ? localized(locale, "Utánvét", "Cash on delivery")
1034
+ : providerLabel(choice.providerId, false)}</strong>
1035
+ <small>{choice.mode === "cod"
1036
+ ? localized(locale, "Fizetés kézbesítéskor", "Pay on delivery")
1037
+ : choice.mode === "bank_transfer"
1038
+ ? localized(locale, "Fizetés banki átutalással", "Pay by bank transfer")
1039
+ : localized(locale, "Online fizetés", "Online payment")}</small>
1040
+ </button>
1041
+ ))}
1066
1042
  </div>
1067
1043
  )}
1068
1044
 
@@ -1121,7 +1097,7 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
1121
1097
  </button>
1122
1098
  ) : null}
1123
1099
 
1124
- {systemSelected ? (
1100
+ {offlineSelected ? (
1125
1101
  <button
1126
1102
  className="button button-large"
1127
1103
  type="button"
@@ -1192,23 +1168,56 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
1192
1168
  ) : null}
1193
1169
  </div>
1194
1170
 
1195
- <aside className="checkout-summary panel stack-sm">
1196
- <p className="eyebrow">{copy.orderSummary}</p>
1171
+ <aside className="checkout-summary panel stack-sm" aria-label={copy.orderSummary}>
1172
+ <h2 className="checkout-summary-heading">{copy.orderSummary}</h2>
1197
1173
  {asRecords(cart.items).map((item) => (
1198
1174
  <div className="summary-line" key={stringValue(item.id)}>
1199
1175
  <span>{stringValue(item.product_title || item.title)} × {stringValue(item.quantity)}</span>
1200
1176
  <span>{typeof item.total === "number" ? formatMoney(item.total, currency, numberLocale) : ""}</span>
1201
1177
  </div>
1202
1178
  ))}
1203
- {appliedCodFee > 0 && Number.isFinite(appliedCodFee) ? (
1179
+
1180
+ <section className="checkout-summary-group" aria-label={localized(locale, "Termékek", "Products")}>
1181
+ <h3>{localized(locale, "Termékek", "Products")}</h3>
1182
+ {orderSummary.taxDetailsVisible ? (
1183
+ <>
1184
+ <div className="summary-line"><span>{localized(locale, "Nettó", "Net")}</span><span>{formatMoney(orderSummary.items.net, currency, numberLocale)}</span></div>
1185
+ <div className="summary-line"><span>{localized(locale, "ÁFA", "VAT")}</span><span>{formatMoney(orderSummary.items.tax, currency, numberLocale)}</span></div>
1186
+ </>
1187
+ ) : null}
1188
+ <div className="summary-line checkout-summary-gross"><span>{localized(locale, "Bruttó", "Gross")}</span><strong>{formatMoney(orderSummary.items.gross, currency, numberLocale)}</strong></div>
1189
+ </section>
1190
+
1191
+ <section className="checkout-summary-group" aria-label={localized(locale, "Szállítási költség", "Shipping cost")}>
1192
+ <h3>{localized(locale, "Szállítási költség", "Shipping cost")}</h3>
1193
+ {orderSummary.shipping ? (
1194
+ <>
1195
+ {orderSummary.taxDetailsVisible ? (
1196
+ <>
1197
+ <div className="summary-line"><span>{localized(locale, "Nettó", "Net")}</span><span>{formatMoney(orderSummary.shipping.net, currency, numberLocale)}</span></div>
1198
+ <div className="summary-line"><span>{localized(locale, "ÁFA", "VAT")}</span><span>{formatMoney(orderSummary.shipping.tax, currency, numberLocale)}</span></div>
1199
+ </>
1200
+ ) : null}
1201
+ <div className="summary-line checkout-summary-gross"><span>{localized(locale, "Bruttó", "Gross")}</span><strong>{formatMoney(orderSummary.shipping.gross, currency, numberLocale)}</strong></div>
1202
+ </>
1203
+ ) : <p className="muted small">{localized(locale, "Még nincs kiválasztva", "Not selected yet")}</p>}
1204
+ </section>
1205
+
1206
+ {orderSummary.codGross !== null ? (
1207
+ <div className="checkout-summary-cod summary-line">
1208
+ <span>{localized(locale, "Utánvét (bruttó)", "Cash on delivery (gross)")}</span>
1209
+ <strong>{formatMoney(orderSummary.codGross, currency, numberLocale)}</strong>
1210
+ </div>
1211
+ ) : null}
1212
+ {Math.abs(orderSummary.adjustment) > 0.005 ? (
1204
1213
  <div className="summary-line">
1205
- <span>{localized(locale, "Ebből utánvét kezelési díj", "Including COD handling fee")}</span>
1206
- <span>{formatMoney(appliedCodFee, currency, numberLocale)}</span>
1214
+ <span>{localized(locale, "Egyéb jóváírás / korrekció", "Other credit / adjustment")}</span>
1215
+ <span>{formatMoney(orderSummary.adjustment, currency, numberLocale)}</span>
1207
1216
  </div>
1208
1217
  ) : null}
1209
1218
  <div className="summary-total">
1210
- <span>{copy.total}</span>
1211
- <strong>{formatMoney(cartTotal(cart), currency, numberLocale)}</strong>
1219
+ <span>{localized(locale, "Bruttó végösszeg", "Gross total")}</span>
1220
+ <strong>{formatMoney(orderSummary.grossTotal, currency, numberLocale)}</strong>
1212
1221
  </div>
1213
1222
  </aside>
1214
1223
  </div>
@@ -0,0 +1,38 @@
1
+ import type { JsonRecord } from "./commerce"
2
+
3
+ export type CheckoutPaymentMode = "online" | "bank_transfer" | "cod"
4
+
5
+ export type CheckoutPaymentChoice = {
6
+ providerId: string
7
+ mode: CheckoutPaymentMode
8
+ }
9
+
10
+ /**
11
+ * Payment options are user choices, not shipping-price conditions.
12
+ *
13
+ * Cash on delivery (pp_cod_cod) and bank transfer (pp_system_default)
14
+ * have separate Medusa provider IDs, separate sessions and separate regional
15
+ * enablement. COD eligibility and the fee are still checked by the Core
16
+ * backend; the frontend must not duplicate shipping eligibility rules.
17
+ */
18
+ export function checkoutPaymentChoices(
19
+ providers: JsonRecord[],
20
+ bankTransferEnabled: boolean,
21
+ ): CheckoutPaymentChoice[] {
22
+ const choices: CheckoutPaymentChoice[] = []
23
+ for (const provider of providers) {
24
+ const id = typeof provider.id === "string" ? provider.id : ""
25
+ if (!id) continue
26
+
27
+ if (id === "pp_cod_cod") {
28
+ choices.push({ providerId: id, mode: "cod" })
29
+ } else if (id === "pp_system_default") {
30
+ if (bankTransferEnabled) {
31
+ choices.push({ providerId: id, mode: "bank_transfer" })
32
+ }
33
+ } else {
34
+ choices.push({ providerId: id, mode: "online" })
35
+ }
36
+ }
37
+ return choices
38
+ }
@@ -0,0 +1,120 @@
1
+ import type { JsonRecord } from "./commerce"
2
+
3
+ function isRecord(value: unknown): value is JsonRecord {
4
+ return value !== null && typeof value === "object" && !Array.isArray(value)
5
+ }
6
+
7
+ function asRecords(value: unknown): JsonRecord[] {
8
+ return Array.isArray(value) ? value.filter(isRecord) : []
9
+ }
10
+
11
+ export type CheckoutAmountBreakdown = {
12
+ net: number
13
+ tax: number
14
+ gross: number
15
+ }
16
+
17
+ export type CheckoutOrderSummary = {
18
+ items: CheckoutAmountBreakdown
19
+ shipping: CheckoutAmountBreakdown | null
20
+ codGross: number | null
21
+ taxDetailsVisible: boolean
22
+ adjustment: number
23
+ grossTotal: number
24
+ }
25
+
26
+ function optionalAmount(value: unknown): number | null {
27
+ return typeof value === "number" && Number.isFinite(value) ? value : null
28
+ }
29
+
30
+ function amount(value: unknown): number {
31
+ return optionalAmount(value) ?? 0
32
+ }
33
+
34
+ function precision(currency: string): number {
35
+ return currency.toUpperCase() === "HUF" ? 0 : 2
36
+ }
37
+
38
+ function rounded(value: number, digits: number): number {
39
+ const factor = 10 ** digits
40
+ return Math.round((value + Number.EPSILON) * factor) / factor
41
+ }
42
+
43
+ function taxLinesPresent(cart: JsonRecord): boolean {
44
+ return asRecords(cart.items).some(item => asRecords(item.tax_lines).length > 0) ||
45
+ asRecords(cart.shipping_methods).some(method => asRecords(method.tax_lines).length > 0)
46
+ }
47
+
48
+ /**
49
+ * This is presentation only. Medusa owns cart.item_total, cart.shipping_total,
50
+ * their tax totals, discounts and cart.total. Never use cart.subtotal as an
51
+ * item-only figure: it also contains shipping.
52
+ *
53
+ * Core stores COD as part of the native shipping method. Its applied
54
+ * gross fee is shown separately, and the original Medusa shipping tax is
55
+ * preserved for an exact net / VAT / gross presentation.
56
+ */
57
+ export function checkoutOrderSummary(
58
+ cart: JsonRecord,
59
+ currency: string,
60
+ ): CheckoutOrderSummary {
61
+ const digits = precision(currency)
62
+ const itemGross = amount(cart.item_total)
63
+ const itemTax = amount(cart.item_tax_total)
64
+ const items = {
65
+ gross: itemGross,
66
+ tax: itemTax,
67
+ net: rounded(itemGross - itemTax, digits),
68
+ }
69
+
70
+ const methods = asRecords(cart.shipping_methods)
71
+ const hasShipping = methods.length > 0
72
+ const method = methods[0]
73
+ const data = isRecord(method?.data) ? method.data : {}
74
+ const codSelected = methods.length === 1 && (data.cod === true || data.cod === "true")
75
+ const rawFee = optionalAmount(data.hszrdm_cod_applied_fee_huf)
76
+ const shippingGrossWithCod = amount(cart.shipping_total)
77
+ const codGross = codSelected && rawFee !== null && Number.isInteger(rawFee) &&
78
+ rawFee >= 0 && rawFee <= shippingGrossWithCod
79
+ ? rawFee : codSelected ? 0 : null
80
+
81
+ const shippingTaxWithCod = amount(cart.shipping_tax_total)
82
+ const shippingGross = rounded(shippingGrossWithCod - (codGross ?? 0), digits)
83
+
84
+ // Core stores the exact native shipping tax from before the COD change,
85
+ // avoiding VAT rounding inaccuracies after the fee joins the method amount.
86
+ // Existing carts without that snapshot can still fall back to tax lines or
87
+ // Medusa's overall shipping tax ratio for a presentation-only estimate.
88
+ const baseTaxSnapshot = optionalAmount(data.hszrdm_cod_base_shipping_tax_huf)
89
+ const baseTaxValid = codGross !== null && baseTaxSnapshot !== null &&
90
+ baseTaxSnapshot >= 0 && baseTaxSnapshot <= shippingTaxWithCod
91
+ const taxLines = asRecords(method?.tax_lines)
92
+ const rates = taxLines.map(line => optionalAmount(line.rate))
93
+ const hasRates = rates.length > 0 && rates.every(rate => rate !== null && rate >= 0)
94
+ const combinedRate = hasRates ? rates.reduce<number>((sum, rate) => sum + (rate ?? 0), 0) / 100 : null
95
+ const shippingTax = baseTaxValid
96
+ ? baseTaxSnapshot
97
+ : codGross !== null && codGross > 0 && shippingGrossWithCod > 0
98
+ ? rounded(
99
+ combinedRate !== null
100
+ ? Math.min(shippingTaxWithCod, shippingGross * combinedRate / (1 + combinedRate))
101
+ : shippingTaxWithCod * shippingGross / shippingGrossWithCod,
102
+ digits,
103
+ )
104
+ : shippingTaxWithCod
105
+ const shipping = hasShipping ? {
106
+ gross: shippingGross,
107
+ tax: shippingTax,
108
+ net: rounded(shippingGross - shippingTax, digits),
109
+ } : null
110
+
111
+ const grossTotal = amount(cart.total)
112
+ // Medusa's item/shipping totals already include ordinary discounts. A
113
+ // difference can represent a credit line or another native cart adjustment.
114
+ const adjustment = rounded(grossTotal - itemGross - shippingGrossWithCod, digits)
115
+ const taxDetailsVisible =
116
+ amount(cart.tax_total) !== 0 || itemTax !== 0 || shippingTaxWithCod !== 0 ||
117
+ taxLinesPresent(cart)
118
+
119
+ return { items, shipping, codGross, taxDetailsVisible, adjustment, grossTotal }
120
+ }
@@ -69,7 +69,14 @@ export function checkoutApi(config: CoreConfig) {
69
69
  choice: "cod" | "bank_transfer" | "online" = "online",
70
70
  ) => {
71
71
  // Price authority is the backend. Never send a fee/amount from the browser.
72
- const mode = selectedProviderId.toLowerCase().includes("system") ? choice : "online"
72
+ const mode = choice === "cod" && selectedProviderId === "pp_cod_cod"
73
+ ? "cod"
74
+ : choice === "bank_transfer" && selectedProviderId === "pp_system_default"
75
+ ? "bank_transfer"
76
+ : "online"
77
+ if ((choice === "cod" || choice === "bank_transfer") && mode === "online") {
78
+ throw new Error("A kiválasztott fizetési módhoz nem megfelelő Medusa payment provider tartozik.")
79
+ }
73
80
  await medusaFetch<Record<string, unknown>>(
74
81
  `/store/carts/${encodeURIComponent(cartId)}/cod`, {
75
82
  method: "POST", body: JSON.stringify({ mode }),
@@ -216,6 +216,9 @@ export function providerLabel(
216
216
  ) {
217
217
  const normalized = id.toLowerCase()
218
218
  const english = locale.toLowerCase().startsWith("en")
219
+ if (normalized === "pp_cod_cod") {
220
+ return english ? "Cash on delivery" : "Utánvét"
221
+ }
219
222
  if (normalized.startsWith("pp_stripe_") || normalized.includes("stripe")) {
220
223
  return english ? "Card (Stripe)" : "Bankkártya (Stripe)"
221
224
  }
@@ -0,0 +1,59 @@
1
+ import assert from "node:assert/strict"
2
+ import { readFileSync } from "node:fs"
3
+ import test from "node:test"
4
+ import { checkoutPaymentChoices } from "../src/lib/core/checkout-payment-choices.ts"
5
+
6
+ const stripe = { id: "pp_stripe_stripe" }
7
+ const manual = { id: "pp_system_default" }
8
+ const cod = { id: "pp_cod_cod" }
9
+ const simplepay = { id: "pp_simplepay_simplepay" }
10
+
11
+ test("COD has its own Medusa provider and is independent of bank transfer", () => {
12
+ assert.deepEqual(checkoutPaymentChoices([stripe, cod, manual], true), [
13
+ { providerId: stripe.id, mode: "online" },
14
+ { providerId: cod.id, mode: "cod" },
15
+ { providerId: manual.id, mode: "bank_transfer" },
16
+ ])
17
+ })
18
+
19
+ test("COD remains available when bank transfer is disabled or provider is absent", () => {
20
+ assert.deepEqual(checkoutPaymentChoices([cod, manual], false), [
21
+ { providerId: cod.id, mode: "cod" },
22
+ ])
23
+ assert.deepEqual(checkoutPaymentChoices([cod], true), [
24
+ { providerId: cod.id, mode: "cod" },
25
+ ])
26
+ })
27
+
28
+ test("system-only provider never offers COD without its own regional provider", () => {
29
+ assert.deepEqual(checkoutPaymentChoices([manual], true), [
30
+ { providerId: manual.id, mode: "bank_transfer" },
31
+ ])
32
+ assert.deepEqual(checkoutPaymentChoices([manual], false), [])
33
+ })
34
+
35
+ test("online providers stay unchanged and missing COD provider creates no fake COD", () => {
36
+ assert.deepEqual(checkoutPaymentChoices([stripe, simplepay], true), [
37
+ { providerId: stripe.id, mode: "online" },
38
+ { providerId: simplepay.id, mode: "online" },
39
+ ])
40
+ assert.deepEqual(checkoutPaymentChoices([], true), [])
41
+ assert.deepEqual(checkoutPaymentChoices([{ id: "" }], true), [])
42
+ })
43
+
44
+ test("Core checkout uses separate providers with backend-owned COD pricing", () => {
45
+ const flow = readFileSync(new URL("../src/components/checkout-flow.tsx", import.meta.url), "utf8")
46
+ const api = readFileSync(new URL("../src/lib/core/checkout.ts", import.meta.url), "utf8")
47
+ assert.match(flow, /checkoutPaymentChoices\(providers, config\.payments\.bank_transfer\.enabled\)/)
48
+ assert.match(flow, /paymentChoices\.map\(\(choice\) => \(/)
49
+ assert.match(flow, /preparePayment\(choice\.providerId, choice\.mode\)/)
50
+ assert.match(flow, /choice\.mode === "cod"/)
51
+ assert.doesNotMatch(flow, /\bcodAvailable\b/)
52
+ assert.doesNotMatch(flow, /hszrdm_cod_enabled/)
53
+ assert.ok(flow.includes('activeProviderId === "pp_system_default" || activeProviderId === "pp_cod_cod"'))
54
+ assert.ok(flow.includes("{offlineSelected ? ("))
55
+ assert.match(api, /selectedProviderId === "pp_cod_cod"/)
56
+ assert.match(api, /selectedProviderId === "pp_system_default"/)
57
+ assert.match(api, /\/store\/carts\/\$\{encodeURIComponent\(cartId\)\}\/cod/)
58
+ assert.match(api, /JSON\.stringify\(\{ mode \}\)/)
59
+ })
@@ -0,0 +1,168 @@
1
+ import assert from "node:assert/strict"
2
+ import { readFileSync } from "node:fs"
3
+ import test from "node:test"
4
+ import { checkoutOrderSummary } from "../src/lib/core/checkout-summary.ts"
5
+
6
+ function cart(overrides = {}) {
7
+ return {
8
+ currency_code: "huf",
9
+ item_total: 1905,
10
+ item_tax_total: 405,
11
+ shipping_total: 2000,
12
+ shipping_tax_total: 425,
13
+ tax_total: 830,
14
+ total: 3905,
15
+ subtotal: 3075, // combined net item + shipping, must never be labeled products
16
+ items: [{ id: "item_1", total: 1905, tax_total: 405 }],
17
+ shipping_methods: [{ id: "sm_1", data: {}, tax_lines: [{ rate: 27 }] }],
18
+ ...overrides,
19
+ }
20
+ }
21
+
22
+ test("uses only Medusa item totals for products; subtotal must not include shipping", () => {
23
+ const actual = checkoutOrderSummary(cart(), "HUF")
24
+ assert.equal(actual.taxDetailsVisible, true)
25
+ assert.deepEqual(actual.items, { net: 1500, tax: 405, gross: 1905 })
26
+ assert.deepEqual(actual.shipping, { net: 1575, tax: 425, gross: 2000 })
27
+ assert.equal(actual.codGross, null)
28
+ assert.equal(actual.grossTotal, 3905)
29
+ assert.equal(actual.adjustment, 0)
30
+ assert.equal(actual.items.gross + actual.shipping.gross, actual.grossTotal)
31
+ })
32
+
33
+ test("COD is a separate fixed gross row, with shipping's original net/tax/gross preserved", () => {
34
+ const withCod = cart({
35
+ shipping_total: 2350,
36
+ shipping_tax_total: 500,
37
+ tax_total: 905,
38
+ total: 4255,
39
+ shipping_methods: [{
40
+ id: "sm_1",
41
+ data: { cod: true, hszrdm_cod_applied_fee_huf: 350, hszrdm_cod_base_shipping_tax_huf: 425 },
42
+ tax_lines: [{ rate: 27 }],
43
+ }],
44
+ })
45
+ const actual = checkoutOrderSummary(withCod, "HUF")
46
+ assert.deepEqual(actual.items, { net: 1500, tax: 405, gross: 1905 })
47
+ assert.deepEqual(actual.shipping, { net: 1575, tax: 425, gross: 2000 })
48
+ assert.equal(actual.codGross, 350)
49
+ assert.equal(actual.grossTotal, 4255)
50
+ assert.equal(actual.items.gross + actual.shipping.gross + actual.codGross, actual.grossTotal)
51
+ })
52
+
53
+ test("authoritative tax snapshot stays exact even when tax lines are not expanded", () => {
54
+ const withCod = cart({
55
+ shipping_total: 2350,
56
+ shipping_tax_total: 500,
57
+ tax_total: 905,
58
+ total: 4255,
59
+ shipping_methods: [{ id: "sm_1", data: {
60
+ cod: true, hszrdm_cod_applied_fee_huf: 350, hszrdm_cod_base_shipping_tax_huf: 425,
61
+ } }],
62
+ })
63
+ const actual = checkoutOrderSummary(withCod, "HUF")
64
+ assert.deepEqual(actual.shipping, { net: 1575, tax: 425, gross: 2000 })
65
+ assert.equal(actual.codGross, 350)
66
+ })
67
+
68
+ test("COD tax is apportioned from Medusa's native tax totals without a fixed VAT rate", () => {
69
+ const withCod = cart({
70
+ shipping_total: 2350,
71
+ shipping_tax_total: 500,
72
+ tax_total: 905,
73
+ total: 4255,
74
+ shipping_methods: [{ id: "sm_1", data: { cod: true, hszrdm_cod_applied_fee_huf: 350 } }],
75
+ })
76
+ const actual = checkoutOrderSummary(withCod, "HUF")
77
+ assert.equal(actual.shipping.gross, 2000)
78
+ assert.equal(actual.shipping.net + actual.shipping.tax, 2000)
79
+ assert.equal(actual.codGross, 350)
80
+ assert.equal(actual.grossTotal, 4255)
81
+ assert.equal(actual.items.gross + actual.shipping.gross + actual.codGross, actual.grossTotal)
82
+ })
83
+
84
+ test("VAT rows are omitted if the cart has no tax amounts or tax lines", () => {
85
+ const withoutTax = cart({
86
+ item_total: 1500,
87
+ item_tax_total: 0,
88
+ shipping_total: 1000,
89
+ shipping_tax_total: 0,
90
+ tax_total: 0,
91
+ total: 2500,
92
+ items: [{ id: "item_1", total: 1500, tax_total: 0 }],
93
+ shipping_methods: [{ id: "sm_1", data: {} }],
94
+ })
95
+ const actual = checkoutOrderSummary(withoutTax, "HUF")
96
+ assert.equal(actual.taxDetailsVisible, false)
97
+ assert.deepEqual(actual.items, { net: 1500, tax: 0, gross: 1500 })
98
+ assert.deepEqual(actual.shipping, { net: 1000, tax: 0, gross: 1000 })
99
+ })
100
+
101
+ test("keeps zero-tax tax lines visible and zero-fee COD as a separate row", () => {
102
+ const zero = cart({
103
+ item_total: 1500,
104
+ item_tax_total: 0,
105
+ shipping_total: 1000,
106
+ shipping_tax_total: 0,
107
+ tax_total: 0,
108
+ total: 2500,
109
+ items: [{ id: "item_1", tax_lines: [{ rate: 0 }] }],
110
+ shipping_methods: [{
111
+ id: "sm_1",
112
+ data: { cod: true, hszrdm_cod_applied_fee_huf: 0 },
113
+ tax_lines: [{ rate: 0 }],
114
+ }],
115
+ })
116
+ const actual = checkoutOrderSummary(zero, "HUF")
117
+ assert.equal(actual.taxDetailsVisible, true)
118
+ assert.equal(actual.codGross, 0)
119
+ assert.equal(actual.shipping.gross, 1000)
120
+ })
121
+
122
+ test("discounted item totals and native credit lines are not charged twice", () => {
123
+ const credited = cart({
124
+ item_total: 1800,
125
+ item_tax_total: 383,
126
+ shipping_total: 2000,
127
+ shipping_tax_total: 425,
128
+ tax_total: 808,
129
+ total: 3400,
130
+ subtotal: 9000,
131
+ })
132
+ const actual = checkoutOrderSummary(credited, "HUF")
133
+ assert.equal(actual.items.gross, 1800)
134
+ assert.equal(actual.adjustment, -400)
135
+ assert.equal(actual.items.gross + actual.shipping.gross + actual.adjustment, actual.grossTotal)
136
+ })
137
+
138
+ test("no selected shipping remains unselected, not a fabricated zero-cost delivery", () => {
139
+ const noShipping = cart({
140
+ shipping_total: 0,
141
+ shipping_tax_total: 0,
142
+ tax_total: 405,
143
+ total: 1905,
144
+ shipping_methods: [],
145
+ })
146
+ const actual = checkoutOrderSummary(noShipping, "HUF")
147
+ assert.equal(actual.shipping, null)
148
+ assert.equal(actual.codGross, null)
149
+ assert.equal(actual.grossTotal, 1905)
150
+ })
151
+
152
+ test("Core starter summary renders tax groups, COD and the Medusa gross total", () => {
153
+ const flow = readFileSync(new URL("../src/components/checkout-flow.tsx", import.meta.url), "utf8")
154
+ const style = readFileSync(new URL("../src/app/globals.css", import.meta.url), "utf8")
155
+ assert.match(flow, /checkoutOrderSummary\(cart, currency\)/)
156
+ assert.match(flow, /orderSummary\.taxDetailsVisible/)
157
+ assert.match(flow, /orderSummary\.items\.net/)
158
+ assert.match(flow, /orderSummary\.items\.tax/)
159
+ assert.match(flow, /orderSummary\.items\.gross/)
160
+ assert.match(flow, /orderSummary\.shipping\.net/)
161
+ assert.match(flow, /orderSummary\.shipping\.tax/)
162
+ assert.match(flow, /orderSummary\.shipping\.gross/)
163
+ assert.match(flow, /orderSummary\.codGross !== null/)
164
+ assert.match(flow, /Bruttó végösszeg/)
165
+ assert.match(style, /\.checkout-summary-group/)
166
+ assert.doesNotMatch(flow, /Ebből utánvét kezelési díj/)
167
+ assert.doesNotMatch(flow, /cartSubtotal\(cart\)/)
168
+ })