@hszrdm/create-commerce 1.19.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.
Files changed (27) hide show
  1. package/package.json +1 -1
  2. package/src/cli.mjs +2 -1
  3. package/templates/backend/.env.example +33 -217
  4. package/templates/backend/medusa-config.ts +14 -1
  5. package/templates/backend/package.json +1 -1
  6. package/templates/backend/src/scripts/core-init.ts +0 -5
  7. package/templates/storefront/package.json +5 -1
  8. package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +2 -2
  9. package/templates/storefront/src/app/globals.css +8 -0
  10. package/templates/storefront/src/app/layout.tsx +6 -0
  11. package/templates/storefront/src/components/account-access-gate.tsx +88 -0
  12. package/templates/storefront/src/components/account-dashboard.tsx +56 -19
  13. package/templates/storefront/src/components/account-verification-panel.tsx +145 -0
  14. package/templates/storefront/src/components/checkout-flow.tsx +83 -30
  15. package/templates/storefront/src/components/product-card.tsx +2 -1
  16. package/templates/storefront/src/lib/core/account.ts +49 -8
  17. package/templates/storefront/src/lib/core/checkout-feedback-state.ts +15 -0
  18. package/templates/storefront/src/lib/core/checkout-payment-choices.ts +38 -0
  19. package/templates/storefront/src/lib/core/checkout-summary.ts +120 -0
  20. package/templates/storefront/src/lib/core/checkout.ts +25 -19
  21. package/templates/storefront/src/lib/core/commerce.ts +14 -0
  22. package/templates/storefront/src/lib/core/use-checkout-feedback.ts +53 -0
  23. package/templates/storefront/tests/account-verification.test.mjs +40 -0
  24. package/templates/storefront/tests/checkout-feedback.test.mjs +27 -0
  25. package/templates/storefront/tests/checkout-payment-choices.test.mjs +59 -0
  26. package/templates/storefront/tests/checkout-summary.test.mjs +168 -0
  27. package/templates/storefront/tests/product-image.test.mjs +31 -0
@@ -3,7 +3,8 @@
3
3
  import Link from "next/link"
4
4
  import { usePathname } from "next/navigation"
5
5
  import { useCallback, useEffect, useMemo, useState, type FormEvent } from "react"
6
- import { accountApi } from "@/lib/core/account"
6
+ import { accountApi, isAccountEmailVerified } from "@/lib/core/account"
7
+ import { AccountVerificationPanel } from "./account-verification-panel"
7
8
  import { stringValue, type JsonRecord } from "@/lib/core/commerce"
8
9
  import { CoreApiError } from "@/lib/core/client"
9
10
  import type { CoreConfig } from "@/lib/core/types"
@@ -52,6 +53,7 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
52
53
  const [busy, setBusy] = useState<string | null>(null)
53
54
  const [error, setError] = useState<string | null>(null)
54
55
  const [message, setMessage] = useState<string | null>(null)
56
+ const [accountNotice, setAccountNotice] = useState<{ tone: "success" | "error"; text: string } | null>(null)
55
57
  const [mode, setMode] = useState<AuthMode>("login")
56
58
  const [tab, setTab] = useState<AccountTab>("profile")
57
59
  const [email, setEmail] = useState("")
@@ -76,6 +78,22 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
76
78
  useEffect(() => {
77
79
  void refresh().catch(() => setCustomer(null)).finally(() => setLoading(false))
78
80
  }, [refresh])
81
+ // The Email Center template is shared with registration verification.
82
+ // Existing email-change links must keep working after adding link support.
83
+ useEffect(() => {
84
+ if (!customer || !isAccountEmailVerified(customer)) return
85
+ const url = new URL(window.location.href)
86
+ const code = url.searchParams.get("change_email_code")
87
+ if (!code) return
88
+ url.searchParams.delete("change_email_code")
89
+ window.history.replaceState(window.history.state, "", url.pathname + url.search + url.hash)
90
+ void api.confirmEmailChange(code).then(() => refresh()).then(() => {
91
+ setAccountNotice({ tone: "success", text: localized(locale, "E-mail-cím módosítva.", "Email address updated.") })
92
+ }).catch((error) => {
93
+ setAccountNotice({ tone: "error", text: error instanceof Error ? error.message : localized(locale, "Az e-mail módosítása nem sikerült.", "Could not change email.") })
94
+ })
95
+ }, [api, customer, refresh, locale])
96
+
79
97
 
80
98
  const authSubmit = async (event: FormEvent) => {
81
99
  event.preventDefault()
@@ -95,8 +113,10 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
95
113
  return
96
114
  }
97
115
  if (mode === "register") {
98
- await api.register({ email, password, first_name: firstName, last_name: lastName })
99
- await transferToCustomer().catch(() => undefined)
116
+ const registered = await api.register({ email, password, first_name: firstName, last_name: lastName })
117
+ if (registered.customer && isAccountEmailVerified(registered.customer)) {
118
+ await transferToCustomer().catch(() => undefined)
119
+ }
100
120
  await refresh()
101
121
  setMessage(
102
122
  localized(
@@ -108,8 +128,10 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
108
128
  return
109
129
  }
110
130
  await api.login(email, password)
111
- await transferToCustomer().catch(() => undefined)
112
- await refresh()
131
+ const signedIn = await refresh()
132
+ if (signedIn && isAccountEmailVerified(signedIn)) {
133
+ await transferToCustomer().catch(() => undefined)
134
+ }
113
135
  setPassword("")
114
136
  } catch (cause) {
115
137
  setError(
@@ -122,6 +144,18 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
122
144
  }
123
145
  }
124
146
 
147
+ const onVerificationComplete = useCallback(async () => {
148
+ const updated = await refresh()
149
+ if (updated && isAccountEmailVerified(updated)) {
150
+ await transferToCustomer().catch(() => undefined)
151
+ }
152
+ }, [refresh, transferToCustomer])
153
+
154
+ const onVerificationLogout = useCallback(async () => {
155
+ await api.logout()
156
+ setCustomer(null)
157
+ }, [api])
158
+
125
159
  if (loading) return <div className="empty-state">{copy.accountLoading}</div>
126
160
 
127
161
  if (!customer) {
@@ -162,6 +196,20 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
162
196
  )
163
197
  }
164
198
 
199
+ if (!isAccountEmailVerified(customer)) {
200
+ return (
201
+ <div className="account-layout">
202
+ <AccountVerificationPanel
203
+ api={api}
204
+ email={stringValue(customer.email)}
205
+ locale={locale}
206
+ onVerified={onVerificationComplete}
207
+ onLogout={onVerificationLogout}
208
+ />
209
+ </div>
210
+ )
211
+ }
212
+
165
213
  return (
166
214
  <div className="account-layout">
167
215
  <aside className="account-sidebar panel">
@@ -181,6 +229,7 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
181
229
  </aside>
182
230
 
183
231
  <main className="stack">
232
+ {accountNotice ? <p role="status" className={accountNotice.tone === "error" ? "error" : "success"}>{accountNotice.text}</p> : null}
184
233
  {tab === "profile" ? <ProfileSection customer={customer} api={api} refresh={refresh} setBusy={setBusy} busy={busy} copy={copy} locale={locale} /> : null}
185
234
  {tab === "addresses" ? <AddressesSection config={config} api={api} copy={copy} locale={locale} /> : null}
186
235
  {tab === "orders" ? <OrdersSection config={config} api={api} copy={copy} locale={locale} /> : null}
@@ -210,10 +259,7 @@ function ProfileSection({
210
259
  const [first, setFirst] = useState(stringValue(customer.first_name))
211
260
  const [last, setLast] = useState(stringValue(customer.last_name))
212
261
  const [phone, setPhone] = useState(stringValue(customer.phone))
213
- const [code, setCode] = useState("")
214
262
  const [message, setMessage] = useState<string | null>(null)
215
- const metadata = isRecordSafe(customer.metadata) ? customer.metadata : {}
216
- const verified = metadata.email_verified === true
217
263
 
218
264
  return (
219
265
  <>
@@ -238,18 +284,9 @@ function ProfileSection({
238
284
 
239
285
  <section className="panel stack-sm">
240
286
  <div className="section-title-row">
241
- <div><p className="eyebrow">{copy.email}</p><h2>{verified ? copy.emailVerified : copy.verificationNeeded}</h2></div>
242
- <span className={`status-pill ${verified ? "success-pill" : "warning-pill"}`}>{verified ? copy.verified : copy.pending}</span>
287
+ <div><p className="eyebrow">{copy.email}</p><h2>{copy.emailVerified}</h2></div>
288
+ <span className="status-pill success-pill">{copy.verified}</span>
243
289
  </div>
244
- {!verified ? (
245
- <>
246
- <button className="button secondary" type="button" onClick={() => void api.requestEmailVerification().then(() => setMessage(localized(locale, "Megerősítő kód elküldve.", "Verification code sent.")))}>{copy.resendCode}</button>
247
- <div className="inline-form">
248
- <input value={code} onChange={(e) => setCode(e.target.value)} placeholder={copy.verificationCode} />
249
- <button className="button" type="button" disabled={!code.trim()} onClick={() => void api.confirmEmailVerification(code).then(refresh).then(() => setMessage(localized(locale, "E-mail megerősítve.", "Email verified.")))}>{copy.verify}</button>
250
- </div>
251
- </>
252
- ) : null}
253
290
  </section>
254
291
  </>
255
292
  )
@@ -0,0 +1,145 @@
1
+ "use client"
2
+
3
+ import { useCallback, useEffect, useRef, useState } from "react"
4
+ import { accountApi } from "@/lib/core/account"
5
+ import { CoreApiError } from "@/lib/core/client"
6
+
7
+ type VerificationStatus = {
8
+ verified: boolean
9
+ retry_after_seconds: number
10
+ resend_available_at: string | null
11
+ }
12
+
13
+ export function AccountVerificationPanel({
14
+ api,
15
+ email,
16
+ locale,
17
+ onVerified,
18
+ onLogout,
19
+ }: {
20
+ api: ReturnType<typeof accountApi>
21
+ email: string
22
+ locale: "hu" | "en"
23
+ onVerified: () => Promise<unknown>
24
+ onLogout: () => Promise<unknown>
25
+ }) {
26
+ const en = locale === "en"
27
+ const [code, setCode] = useState("")
28
+ const [retryAt, setRetryAt] = useState<number | null>(null)
29
+ const [now, setNow] = useState(0)
30
+ const [loading, setLoading] = useState(true)
31
+ const [busy, setBusy] = useState<"resend" | "verify" | "logout" | null>(null)
32
+ const [message, setMessage] = useState("")
33
+ const usedLink = useRef("")
34
+ const onVerifiedRef = useRef(onVerified)
35
+ onVerifiedRef.current = onVerified
36
+
37
+ const refreshStatus = useCallback(async () => {
38
+ const result = await api.emailVerificationStatus() as VerificationStatus
39
+ if (result.verified) {
40
+ await onVerifiedRef.current()
41
+ return
42
+ }
43
+ const millis = result.resend_available_at ? Date.parse(result.resend_available_at) : NaN
44
+ setRetryAt(Number.isFinite(millis) ? millis : null)
45
+ }, [api])
46
+
47
+ useEffect(() => {
48
+ void refreshStatus().catch((error) => {
49
+ setMessage(error instanceof Error ? error.message : (en ? "Could not check verification status." : "A megerősítés állapota nem ellenőrizhető."))
50
+ }).finally(() => setLoading(false))
51
+ }, [refreshStatus, en])
52
+
53
+ useEffect(() => {
54
+ const tick = () => setNow(Date.now())
55
+ tick()
56
+ const timer = window.setInterval(tick, 1000)
57
+ return () => window.clearInterval(timer)
58
+ }, [])
59
+
60
+ const confirm = useCallback(async (value: string) => {
61
+ if (!value.trim()) return
62
+ setBusy("verify")
63
+ setMessage("")
64
+ try {
65
+ await api.confirmEmailVerification(value.trim())
66
+ await onVerifiedRef.current()
67
+ } catch (error) {
68
+ setMessage(error instanceof Error ? error.message : (en ? "Verification failed." : "A megerősítés nem sikerült."))
69
+ } finally {
70
+ setBusy(null)
71
+ }
72
+ }, [api, en])
73
+
74
+ // Links are usable from the same session, or after the customer logs in.
75
+ // Remove the sensitive code from browser history as soon as it is consumed.
76
+ useEffect(() => {
77
+ const url = new URL(window.location.href)
78
+ const linkCode = url.searchParams.get("verify_email")
79
+ if (!linkCode || usedLink.current === linkCode) return
80
+ usedLink.current = linkCode
81
+ url.searchParams.delete("verify_email")
82
+ window.history.replaceState(window.history.state, "", url.pathname + url.search + url.hash)
83
+ setCode(linkCode)
84
+ void confirm(linkCode)
85
+ }, [confirm])
86
+
87
+ const retrySeconds = retryAt && now ? Math.max(0, Math.ceil((retryAt - now) / 1000)) : 0
88
+ const countdown = `${Math.floor(retrySeconds / 60).toString().padStart(2, "0")}:${(retrySeconds % 60).toString().padStart(2, "0")}`
89
+
90
+ const resend = async () => {
91
+ if (busy || loading || retrySeconds > 0) return
92
+ setBusy("resend")
93
+ setMessage("")
94
+ try {
95
+ const result = await api.requestEmailVerification() as {
96
+ resend_available_at?: string | null
97
+ retry_after_seconds?: number
98
+ }
99
+ const millis = result.resend_available_at ? Date.parse(result.resend_available_at) : NaN
100
+ setRetryAt(Number.isFinite(millis) ? millis : Date.now() + 600_000)
101
+ setMessage(en ? "A new verification email has been requested." : "Új megerősítő e-mailt kértünk.")
102
+ } catch (error) {
103
+ if (error instanceof CoreApiError && error.status === 429) {
104
+ const payload = error.payload as { retry_after_seconds?: number } | null
105
+ setRetryAt(Date.now() + Math.max(1, Number(payload?.retry_after_seconds ?? 600)) * 1000)
106
+ } else {
107
+ setMessage(error instanceof Error ? error.message : (en ? "Could not resend email." : "Az újraküldés nem sikerült."))
108
+ }
109
+ } finally {
110
+ setBusy(null)
111
+ }
112
+ }
113
+
114
+ return (
115
+ <section className="panel stack" aria-live="polite">
116
+ <p className="eyebrow">{en ? "Account verification" : "Fiók megerősítése"}</p>
117
+ <h1>{en ? "Your email is not verified yet" : "Az e-mail-címed még nincs megerősítve"}</h1>
118
+ <p>{en
119
+ ? `We sent a confirmation link and code to ${email}. Verify your email to use the store.`
120
+ : `Megerősítő linket és kódot küldtünk a(z) ${email} címre. A webshop használatához erősítsd meg az e-mail-címed.`}</p>
121
+ <button className="button secondary" type="button" onClick={() => void resend()} disabled={loading || busy !== null || retrySeconds > 0}>
122
+ {busy === "resend"
123
+ ? (en ? "Sending…" : "Küldés…")
124
+ : (en ? "Resend verification email" : "Megerősítő e-mail újraküldése")}
125
+ </button>
126
+ {retrySeconds > 0 ? (
127
+ <p className="muted small" role="status">{en ? `Try again in ${countdown}` : `Újraküldés ${countdown} múlva`}</p>
128
+ ) : null}
129
+ <form className="inline-form" onSubmit={(event) => { event.preventDefault(); void confirm(code) }}>
130
+ <label>
131
+ {en ? "Verification code" : "Megerősítő kód"}
132
+ <input autoComplete="one-time-code" value={code} onChange={(event) => setCode(event.target.value)} />
133
+ </label>
134
+ <button className="button" type="submit" disabled={!code.trim() || busy !== null}>
135
+ {en ? "Verify email" : "E-mail megerősítése"}
136
+ </button>
137
+ </form>
138
+ {message ? <p role="status">{message}</p> : null}
139
+ <button className="button secondary" type="button" disabled={busy !== null} onClick={() => {
140
+ setBusy("logout")
141
+ void onLogout().catch((error) => setMessage(error instanceof Error ? error.message : (en ? "Sign out failed." : "A kijelentkezés nem sikerült."))).finally(() => setBusy(null))
142
+ }}>{en ? "Sign out" : "Kijelentkezés"}</button>
143
+ </section>
144
+ )
145
+ }
@@ -9,6 +9,7 @@ import {
9
9
  CART_STRUCTURED_ADDRESSES_KEY, isHungarianAddress, missingAddressParts,
10
10
  } from "@/lib/core/structured-address"
11
11
  import { StripePayment } from "./stripe-payment"
12
+ import { useCheckoutFeedback } from "@/lib/core/use-checkout-feedback"
12
13
  import { stripeCheckoutPhase } from "@/lib/core/stripe-checkout-phase"
13
14
  import { carrierPointToShippingData, type CarrierPickupPoint } from "./carrier-pickup-map"
14
15
  import { CarrierPickupDialog } from "./carrier-pickup-dialog"
@@ -33,13 +34,14 @@ import {
33
34
  type CustomerAddress,
34
35
  } from "@/lib/core/checkout-addresses"
35
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"
36
39
  import {
37
40
  activePaymentSession,
38
41
  asRecords,
39
42
  cartCurrency,
40
43
  cartPaymentCollection,
41
44
  cartRegionId,
42
- cartTotal,
43
45
  formatMoney,
44
46
  isRecord,
45
47
  paymentClientSecret,
@@ -118,13 +120,13 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
118
120
  const [pickupDialogOpen, setPickupDialogOpen] = useState(false)
119
121
  const [providers, setProviders] = useState<JsonRecord[]>([])
120
122
  const [selectedProvider, setSelectedProvider] = useState("")
123
+ const [selectedPaymentMode, setSelectedPaymentMode] = useState<"cod" | "bank_transfer" | "online">("online")
121
124
  const [preparedCart, setPreparedCart] = useState<JsonRecord | null>(null)
122
125
  const [stripeInitError, setStripeInitError] = useState<string | null>(null)
123
126
  const [legalDocs, setLegalDocs] = useState<LegalDocument[]>([])
124
127
  const [accepted, setAccepted] = useState<Record<string, boolean>>({})
125
128
  const [busy, setBusy] = useState<string | null>(null)
126
- const [error, setError] = useState<string | null>(null)
127
- const [message, setMessage] = useState<string | null>(null)
129
+ const { error, setError, setMessage } = useCheckoutFeedback(cartError)
128
130
 
129
131
  const setBillingTaxDefaults = useCallback((
130
132
  cartData: JsonRecord,
@@ -616,6 +618,11 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
616
618
  const verifiedPoint = await verifyCarrierPickupPoint(kind, selectedPickupPoint)
617
619
  const data = shippingData(kind, verifiedPoint, locale)
618
620
  const result = await api.addShippingMethod(cartId, optionId, data)
621
+ // Shipping choice invalidates the previously selected payment and its fee.
622
+ await api.markPaymentMode(cartId, "online", "online")
623
+ setSelectedProvider("")
624
+ setSelectedPaymentMode("online")
625
+ setPreparedCart(null)
619
626
  await refresh(cartId)
620
627
  await loadProviders(result.cart)
621
628
  setMessage(localized(locale, "Szállítási mód kiválasztva.", "Shipping method selected."))
@@ -630,7 +637,7 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
630
637
  }
631
638
  }
632
639
 
633
- const preparePayment = async (id: string) => {
640
+ const preparePayment = async (id: string, mode: "cod" | "bank_transfer" | "online") => {
634
641
  if (!addressOnCart) {
635
642
  setError(localized(locale,
636
643
  "Előbb mentsd a szállítási és számlázási címet.",
@@ -645,7 +652,10 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
645
652
  setStripeInitError(null)
646
653
  setPreparedCart(null)
647
654
  setSelectedProvider(id)
655
+ setSelectedPaymentMode(mode)
648
656
  try {
657
+ // Apply the surcharge and refresh any existing collection BEFORE creating a payment session.
658
+ await api.markPaymentMode(cartId, id, mode)
649
659
  let current = (await api.getCart(cartId)).cart
650
660
  let collection = cartPaymentCollection(current)
651
661
  let collectionId = stringValue(collection?.id)
@@ -669,6 +679,7 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
669
679
  setMessage(copy.paymentPrepared)
670
680
  } catch (cause) {
671
681
  setPreparedCart(null)
682
+ setSelectedProvider("")
672
683
  const message = cause instanceof Error
673
684
  ? cause.message
674
685
  : localized(locale, "A fizetési mód nem készíthető elő.", "The payment method could not be prepared.")
@@ -725,8 +736,11 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
725
736
  initializationError: stripeInitError,
726
737
  })
727
738
  const simplePaySelected = activeProviderId.toLowerCase().includes("simplepay")
728
- 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"
729
741
  const currency = cartCurrency(cart, config.store.default_currency)
742
+ const paymentChoices = checkoutPaymentChoices(providers, config.payments.bank_transfer.enabled)
743
+ const orderSummary = checkoutOrderSummary(cart, currency)
730
744
 
731
745
  return (
732
746
  <div className="checkout-layout">
@@ -1007,22 +1021,24 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
1007
1021
  <p className="muted">{copy.chooseShippingForPayments}</p>
1008
1022
  ) : (
1009
1023
  <div className="choice-list">
1010
- {providers.map((provider) => {
1011
- const id = stringValue(provider.id)
1012
- const cod = shippingMethodIsCod(cart)
1013
- return (
1014
- <button
1015
- className={`choice-card choice-button${selectedProvider === id ? " selected" : ""}`}
1016
- type="button"
1017
- key={id}
1018
- disabled={busy === "payment" || !addressOnCart}
1019
- onClick={() => void preparePayment(id)}
1020
- >
1021
- <strong>{providerLabel(id, cod)}</strong>
1022
- <small>{id}</small>
1023
- </button>
1024
- )
1025
- })}
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
+ ))}
1026
1042
  </div>
1027
1043
  )}
1028
1044
 
@@ -1051,7 +1067,7 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
1051
1067
  className="button secondary"
1052
1068
  type="button"
1053
1069
  disabled={busy === "payment" || !addressOnCart}
1054
- onClick={() => void preparePayment(activeProviderId)}
1070
+ onClick={() => void preparePayment(activeProviderId, "online")}
1055
1071
  >
1056
1072
  {localized(locale, "Stripe fizetés újrapróbálása", "Retry Stripe payment")}
1057
1073
  </button>
@@ -1081,7 +1097,7 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
1081
1097
  </button>
1082
1098
  ) : null}
1083
1099
 
1084
- {systemSelected ? (
1100
+ {offlineSelected ? (
1085
1101
  <button
1086
1102
  className="button button-large"
1087
1103
  type="button"
@@ -1100,7 +1116,7 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
1100
1116
  >
1101
1117
  {busy === "complete"
1102
1118
  ? copy.orderSubmitting
1103
- : shippingMethodIsCod(cart)
1119
+ : (selectedPaymentMode === "cod" || (!selectedProvider && shippingMethodIsCod(cart)))
1104
1120
  ? copy.orderSubmitCod
1105
1121
  : copy.orderSubmit}
1106
1122
  </button>
@@ -1132,8 +1148,6 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
1132
1148
  )}
1133
1149
  </section>
1134
1150
 
1135
- {message ? <div className="notice success-box">{message}</div> : null}
1136
- {error || cartError ? <div className="notice error-box">{error || cartError}</div> : null}
1137
1151
  {(stripeReturn || simplePayReturn) && error ? (
1138
1152
  <button
1139
1153
  className="button secondary"
@@ -1154,17 +1168,56 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
1154
1168
  ) : null}
1155
1169
  </div>
1156
1170
 
1157
- <aside className="checkout-summary panel stack-sm">
1158
- <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>
1159
1173
  {asRecords(cart.items).map((item) => (
1160
1174
  <div className="summary-line" key={stringValue(item.id)}>
1161
1175
  <span>{stringValue(item.product_title || item.title)} × {stringValue(item.quantity)}</span>
1162
1176
  <span>{typeof item.total === "number" ? formatMoney(item.total, currency, numberLocale) : ""}</span>
1163
1177
  </div>
1164
1178
  ))}
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 ? (
1213
+ <div className="summary-line">
1214
+ <span>{localized(locale, "Egyéb jóváírás / korrekció", "Other credit / adjustment")}</span>
1215
+ <span>{formatMoney(orderSummary.adjustment, currency, numberLocale)}</span>
1216
+ </div>
1217
+ ) : null}
1165
1218
  <div className="summary-total">
1166
- <span>{copy.total}</span>
1167
- <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>
1168
1221
  </div>
1169
1222
  </aside>
1170
1223
  </div>
@@ -3,6 +3,7 @@ import { PriceDisplay } from "./price-display"
3
3
  import {
4
4
  asRecords,
5
5
  isRecord,
6
+ productImageUrl,
6
7
  productVariantPriceBreakdown,
7
8
  stringValue,
8
9
  } from "@/lib/core/commerce"
@@ -27,7 +28,7 @@ export function ProductCard({
27
28
  const formatLocale = activeLocale === "en" ? "en-US" : "hu-HU"
28
29
  const copy = storefrontCopy(activeLocale)
29
30
  const href = productPath(activeLocale, handle)
30
- const thumbnail = stringValue(product.thumbnail)
31
+ const thumbnail = productImageUrl(product)
31
32
  const categories = asRecords(product.categories)
32
33
  const title = stringValue(product.title)
33
34
 
@@ -1,7 +1,21 @@
1
1
  import { endpoint, medusaFetch } from "./client"
2
2
  import type { CoreConfig } from "./types"
3
+
4
+ export function isAccountEmailVerified(customer: Record<string, unknown>) {
5
+ const metadata = customer.metadata
6
+ if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) return false
7
+ const state = metadata as Record<string, unknown>
8
+ const email = String(customer.email ?? "").trim().toLowerCase()
9
+ return Boolean(email) && state.email_verified === true
10
+ && String(state.email_verified_address ?? "").trim().toLowerCase() === email
11
+ }
3
12
  import { mergeGuestWishlistAfterLogin } from "./wishlist"
4
13
 
14
+ export const ACCOUNT_AUTH_CHANGED_EVENT = "hszrdm:account-auth-changed"
15
+ function notifyAuthChanged() {
16
+ if (typeof window !== "undefined") window.dispatchEvent(new Event(ACCOUNT_AUTH_CHANGED_EVENT))
17
+ }
18
+
5
19
  export function accountApi(config: CoreConfig) {
6
20
  const paths = config.account.endpoints
7
21
 
@@ -53,8 +67,12 @@ export function accountApi(config: CoreConfig) {
53
67
  method: "POST",
54
68
  headers: { Authorization: `Bearer ${login.token}` },
55
69
  })
56
- await mergeGuestWishlistAfterLogin().catch(() => undefined)
57
- return profile()
70
+ const result = await profile()
71
+ notifyAuthChanged()
72
+ if (isAccountEmailVerified(result.customer)) {
73
+ await mergeGuestWishlistAfterLogin().catch(() => undefined)
74
+ }
75
+ return result
58
76
  },
59
77
 
60
78
  login: async (email: string, password: string) => {
@@ -66,11 +84,19 @@ export function accountApi(config: CoreConfig) {
66
84
  method: "POST",
67
85
  headers: { Authorization: `Bearer ${result.token}` },
68
86
  })
69
- await mergeGuestWishlistAfterLogin().catch(() => undefined)
87
+ const current = await profile().catch(() => null)
88
+ if (current?.customer && isAccountEmailVerified(current.customer)) {
89
+ await mergeGuestWishlistAfterLogin().catch(() => undefined)
90
+ }
91
+ notifyAuthChanged()
70
92
  return result
71
93
  },
72
94
 
73
- logout: () => medusaFetch(paths.logout, { method: "DELETE" }),
95
+ logout: async () => {
96
+ const result = await medusaFetch(paths.logout, { method: "DELETE" })
97
+ notifyAuthChanged()
98
+ return result
99
+ },
74
100
 
75
101
  profile,
76
102
 
@@ -137,17 +163,32 @@ export function accountApi(config: CoreConfig) {
137
163
  body: JSON.stringify({ email, password }),
138
164
  }),
139
165
 
166
+ emailVerificationStatus: () =>
167
+ medusaFetch<{
168
+ verified: boolean
169
+ retry_after_seconds: number
170
+ resend_available_at: string | null
171
+ }>(paths.email_verification, { cache: "no-store" }),
172
+
140
173
  requestEmailVerification: () =>
141
- medusaFetch(paths.email_verification, {
174
+ medusaFetch<{
175
+ success: boolean
176
+ retry_after_seconds: number
177
+ resend_available_at: string | null
178
+ }>(paths.email_verification, {
142
179
  method: "PUT",
143
180
  body: JSON.stringify({}),
144
181
  }),
145
182
 
146
- confirmEmailVerification: (code: string) =>
147
- medusaFetch(paths.email_verification, {
183
+ confirmEmailVerification: async (code: string) => {
184
+ const result = await medusaFetch(paths.email_verification, {
148
185
  method: "POST",
149
186
  body: JSON.stringify({ code }),
150
- }),
187
+ })
188
+ await mergeGuestWishlistAfterLogin().catch(() => undefined)
189
+ notifyAuthChanged()
190
+ return result
191
+ },
151
192
 
152
193
  requestEmailChange: (currentPassword: string, newEmail: string) =>
153
194
  medusaFetch(paths.email_change, {
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Shared checkout notice policy. The checkout owns the domain errors; the
3
+ * notification layer only decides which safe, already-localized text to show.
4
+ */
5
+ export function checkoutErrorMessage(error?: string | null, cartError?: string | null): string | null {
6
+ return error?.trim() || cartError?.trim() || null
7
+ }
8
+
9
+ export function checkoutNoticeMessage(message?: string | null): string | null {
10
+ return message?.trim() || null
11
+ }
12
+
13
+ export function shouldShowCheckoutNotice(previous: string | null, next: string | null): boolean {
14
+ return Boolean(next && next !== previous)
15
+ }