@loczer/storefront-sdk 0.202.0 → 0.204.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.
@@ -16,14 +16,14 @@ import { CheckoutPaymentSummaryCard as be } from "./checkout/components/Checkout
16
16
  import { CheckoutInsuranceCard as xe } from "./checkout/components/CheckoutInsuranceCard.js";
17
17
  import { CheckoutSummaryColumn as Se } from "./checkout/components/CheckoutSummaryColumn.js";
18
18
  import { checkoutFormSchema as Ce } from "./checkout/types.js";
19
- import { useEffect as s, useMemo as c, useState as l } from "react";
19
+ import { useEffect as s, useMemo as c, useRef as we, useState as l } from "react";
20
20
  import { jsx as u, jsxs as d } from "react/jsx-runtime";
21
- import { Link as we, useNavigate as Te, useParams as Ee, useSearchParams as De } from "@rpcbase/router";
22
- import { useTranslation as Oe } from "react-i18next";
23
- import { ArrowLeft as ke } from "lucide-react";
24
- import { useForm as Ae, zodResolver as je } from "@rpcbase/form";
21
+ import { Link as Te, useNavigate as Ee, useParams as De, useSearchParams as Oe } from "@rpcbase/router";
22
+ import { useTranslation as ke } from "react-i18next";
23
+ import { ArrowLeft as Ae } from "lucide-react";
24
+ import { useForm as je, zodResolver as Me } from "@rpcbase/form";
25
25
  //#region src/pages/CheckoutPage.tsx
26
- var Me = .2, Ne = (e) => e <= 0 ? 1 : Math.max(1, Math.ceil(e / 1440)), f = (e, t, n) => {
26
+ var Ne = .2, Pe = (e) => e <= 0 ? 1 : Math.max(1, Math.ceil(e / 1440)), f = (e, t, n) => {
27
27
  try {
28
28
  return new Intl.NumberFormat(n, {
29
29
  style: "currency",
@@ -32,7 +32,7 @@ var Me = .2, Ne = (e) => e <= 0 ? 1 : Math.max(1, Math.ceil(e / 1440)), f = (e,
32
32
  } catch {
33
33
  return `${(e / 100).toFixed(2)} ${t.toUpperCase()}`;
34
34
  }
35
- }, Pe = (e, t) => {
35
+ }, Fe = (e, t) => {
36
36
  try {
37
37
  return new Intl.NumberFormat(t, {
38
38
  style: "percent",
@@ -42,7 +42,7 @@ var Me = .2, Ne = (e) => e <= 0 ? 1 : Math.max(1, Math.ceil(e / 1440)), f = (e,
42
42
  } catch {
43
43
  return `${Math.round(e * 100)}%`;
44
44
  }
45
- }, Fe = (e, t, n) => {
45
+ }, Ie = (e, t, n) => {
46
46
  let r = {
47
47
  dateStyle: "medium",
48
48
  timeStyle: "short"
@@ -56,101 +56,111 @@ var Me = .2, Ne = (e) => e <= 0 ? 1 : Math.max(1, Math.ceil(e / 1440)), f = (e,
56
56
  return new Intl.DateTimeFormat(t, r).format(e);
57
57
  };
58
58
  function p() {
59
- let { t: p, i18n: m } = Oe(), { storefrontConfiguration: h } = me(), Ie = h.workspace?.workspaceLanguage, { bikes: Le, accessories: Re } = he(), { storeSlug: g } = Ee(), [_, ze] = De(), Be = Te(), { items: Ve, itemCount: He, setQuantity: Ue, removeItem: We, clear: Ge } = te(), [v, Ke] = l(!1), [y, b] = l(null), [qe, Je] = l(!1), [Ye, x] = l(null), Xe = _.get("coupon") ?? _.get("code") ?? "", [Ze, S] = l(Xe), [Qe, $e] = l(Xe.trim()), [C, w] = l(null), [T, E] = l(null), [et, D] = l(!1), [tt, O] = l(null), [nt, k] = l(null), [A, rt] = l(!1), [j, it] = l(!1), at = c(() => i(_, g), [_, g]), M = h.settings.fulfillmentModes.includes("delivery"), ot = h.settings.deliveryDisabledReason.trim(), st = M || ot.length > 0, ct = h.shop.address?.trim() ?? "", N = c(() => {
60
- let e = r(at, {
59
+ let { t: p, i18n: m } = ke(), { storefrontConfiguration: h } = me(), Le = h.workspace?.workspaceLanguage, { bikes: g, accessories: Re } = he(), { storeSlug: _ } = De(), [v, ze] = Oe(), Be = Ee(), { items: Ve, itemCount: He, checkoutSessionId: y, setQuantity: Ue, removeItem: We, ensureCheckoutSessionId: Ge, clearCheckoutSession: Ke, clear: qe } = te(), [b, Je] = l(!1), Ye = we(!1), [x, S] = l(null), [Xe, Ze] = l(!1), [Qe, C] = l(null), $e = v.get("coupon") ?? v.get("code") ?? "", [et, w] = l($e), [tt, nt] = l($e.trim()), [T, E] = l(null), [D, O] = l(null), [k, A] = l(!1), [rt, j] = l(null), [it, M] = l(null), [N, at] = l(!1), [P, ot] = l(!1), st = c(() => i(v, _), [v, _]), F = h.settings.fulfillmentModes.includes("delivery"), ct = h.settings.deliveryDisabledReason.trim(), lt = F || ct.length > 0, ut = h.shop.address?.trim() ?? "", I = c(() => {
60
+ let e = r(st, {
61
61
  start_time: "",
62
62
  end_time: ""
63
63
  });
64
- return e.fulfillment === "delivery" && !M ? {
64
+ return e.fulfillment === "delivery" && !F ? {
65
65
  ...e,
66
66
  fulfillment: "pickup"
67
67
  } : e;
68
- }, [at, M]), P = c(() => ue(N), [N]), lt = c(() => t(N), [N]), ut = c(() => n(N), [N]), dt = c(() => Ne(ut), [ut]), F = c(() => ne({
68
+ }, [st, F]), L = c(() => ue(I), [I]), dt = c(() => t(I), [I]), ft = c(() => n(I), [I]), pt = c(() => Pe(ft), [ft]), R = c(() => ne({
69
69
  items: Ve,
70
70
  language: m.language,
71
- fallbackLanguage: Ie,
71
+ fallbackLanguage: Le,
72
72
  products: {
73
- bikes: Le,
73
+ bikes: g,
74
74
  accessories: Re
75
75
  },
76
- estimatedDays: dt
76
+ estimatedDays: pt
77
77
  }), [
78
78
  Re,
79
- Le,
80
- dt,
79
+ g,
80
+ pt,
81
81
  m.language,
82
82
  Ve,
83
- Ie
84
- ]), I = c(() => F.lines.map((e) => ({
83
+ Le
84
+ ]), z = c(() => R.lines.map((e) => ({
85
85
  productId: e.checkoutProductId,
86
86
  productVariantId: e.productVariantId,
87
87
  quantity: e.quantity
88
- })), [F.lines]), [ft, L] = l([]), [R, z] = l(!1);
88
+ })), [R.lines]), [mt, B] = l([]), [ht, V] = l(!1);
89
89
  s(() => {
90
- if (!g || I.length === 0) {
91
- L([]), z(!1);
90
+ if (!_ || z.length === 0) {
91
+ B([]), V(!1);
92
92
  return;
93
93
  }
94
- if (!P) {
95
- L([]), z(!1);
94
+ if (!L) {
95
+ B([]), V(!1);
96
96
  return;
97
97
  }
98
98
  let e = !1;
99
- return z(!0), L([]), (async () => {
99
+ return V(!0), B([]), (async () => {
100
100
  try {
101
101
  let t = await o(se, {
102
- storeSlug: g,
103
- schedule: P,
104
- products: I
102
+ storeSlug: _,
103
+ schedule: L,
104
+ products: z
105
105
  }), n = de.parse(t);
106
106
  if (e) return;
107
- L(n.success ? n.availability ?? [] : []);
107
+ B(n.success ? n.availability ?? [] : []);
108
108
  } catch (t) {
109
109
  if (e) return;
110
- console.error("Failed to load checkout cart availability", t), L([]);
110
+ console.error("Failed to load checkout cart availability", t), B([]);
111
111
  } finally {
112
- e || z(!1);
112
+ e || V(!1);
113
113
  }
114
114
  })(), () => {
115
115
  e = !0;
116
116
  };
117
117
  }, [
118
- N.end_date,
119
- N.end_time,
120
- N.start_date,
121
- N.start_time,
122
- P,
123
- I,
124
- g
118
+ I.end_date,
119
+ I.end_time,
120
+ I.start_date,
121
+ I.start_time,
122
+ L,
123
+ z,
124
+ _
125
125
  ]);
126
- let pt = c(() => new Map(ft.map((e) => [ce(e.productId, e.productVariantId), e])), [ft]), B = c(() => ({
127
- ...F,
128
- lines: F.lines.map((e) => {
129
- let t = pt.get(ce(e.checkoutProductId, e.productVariantId)), n = t ? le(t) : e.availabilityStatus === "OUT_OF_STOCK" ? "unavailable" : void 0;
126
+ let gt = c(() => new Map(mt.map((e) => [ce(e.productId, e.productVariantId), e])), [mt]), H = c(() => ({
127
+ ...R,
128
+ lines: R.lines.map((e) => {
129
+ let t = gt.get(ce(e.checkoutProductId, e.productVariantId)), n = t ? le(t) : e.availabilityStatus === "OUT_OF_STOCK" ? "unavailable" : void 0;
130
130
  return {
131
131
  ...e,
132
- insufficientCapacity: !R && n !== void 0,
133
- availabilityIssue: R ? void 0 : n
132
+ insufficientCapacity: !ht && n !== void 0,
133
+ availabilityIssue: ht ? void 0 : n
134
134
  };
135
135
  })
136
136
  }), [
137
- pt,
138
- R,
139
- F
140
- ]), V = c(() => F.lines.map((e) => ({
137
+ gt,
138
+ ht,
139
+ R
140
+ ]), U = c(() => R.lines.map((e) => ({
141
141
  kind: e.kind,
142
142
  productId: e.checkoutProductId,
143
143
  productVariantId: e.productVariantId,
144
144
  quantity: e.quantity
145
- })), [F.lines]), mt = new Map(Le.map((e) => [e.checkoutProductId?.trim() || e.id, e])), H = F.lines.flatMap((e) => {
146
- let t = mt.get(e.checkoutProductId);
145
+ })), [R.lines]), _t = new Map(g.map((e) => [e.checkoutProductId?.trim() || e.id, e])), W = R.lines.flatMap((e) => {
146
+ let t = _t.get(e.checkoutProductId);
147
147
  return t?.insurance?.enabled ? [{
148
148
  quantity: e.quantity,
149
149
  pricePerDayMinor: t.insurance.pricePerDayMinor,
150
150
  deductibleAmountMinor: t.insurance.deductibleAmountMinor
151
151
  }] : [];
152
- }), U = h.modules?.insurance?.enabled === !0 && H.length > 0, W = U && j, ht = H.reduce((e, t) => e + t.pricePerDayMinor * t.quantity, 0), gt = H.reduce((e, t) => Math.max(e, t.deductibleAmountMinor), 0), _t = F.estimatedTotalMinor ?? F.totalPerDayMinor, G = T?.totalMinor ?? _t, K = C?.discountAmountMinor ?? 0, q = e(new URLSearchParams(), N).toString(), J = `/${g ?? ""}/booking${q ? `?${q}` : ""}`, vt = `/${g ?? ""}/checkout${q ? `?${q}` : ""}`, yt = Ae({
153
- resolver: je(Ce),
152
+ }), G = h.modules?.insurance?.enabled === !0 && W.length > 0, K = G && P, vt = W.reduce((e, t) => e + t.pricePerDayMinor * t.quantity, 0), yt = W.reduce((e, t) => Math.max(e, t.deductibleAmountMinor), 0), bt = R.estimatedTotalMinor ?? R.totalPerDayMinor, q = D?.totalMinor ?? bt, J = T?.discountAmountMinor ?? 0, Y = e(new URLSearchParams(), I).toString(), xt = `/${_ ?? ""}/booking${Y ? `?${Y}` : ""}`, St = `/${_ ?? ""}/checkout${Y ? `?${Y}` : ""}`, Ct = new URLSearchParams(Y);
153
+ y && Ct.set("checkout_session_id", y);
154
+ let wt = y ? `/${_ ?? ""}/checkout/payment?${Ct.toString()}` : null;
155
+ s(() => {
156
+ !_ || !wt || Ye.current || Be(wt, { replace: !0 });
157
+ }, [
158
+ wt,
159
+ Be,
160
+ _
161
+ ]);
162
+ let Tt = je({
163
+ resolver: Me(Ce),
154
164
  defaultValues: {
155
165
  first_name: "",
156
166
  last_name: "",
@@ -160,157 +170,158 @@ function p() {
160
170
  }
161
171
  });
162
172
  s(() => {
163
- ee(g, N);
164
- }, [N, g]), s(() => {
165
- !U && j && it(!1);
166
- }, [j, U]);
167
- let bt = (t) => {
173
+ ee(_, I);
174
+ }, [I, _]), s(() => {
175
+ !G && P && ot(!1);
176
+ }, [P, G]);
177
+ let Et = (t) => {
168
178
  let n = {
169
- ...N,
179
+ ...I,
170
180
  ...t
171
- }, r = e(_, n);
172
- ze(r, { replace: !0 }), ee(g, r);
181
+ }, r = e(v, n);
182
+ ze(r, { replace: !0 }), ee(_, r);
173
183
  };
174
184
  s(() => {
175
- if (!g || V.length === 0 || !P) {
176
- w(null), E(null), D(!1), O(null), k(null);
185
+ if (!_ || U.length === 0 || !L) {
186
+ E(null), O(null), A(!1), j(null), M(null);
177
187
  return;
178
188
  }
179
- let e = Qe.trim(), t = e.length === 0 && !A, n = !1;
180
- return D(!0), k(null), O(null), (async () => {
189
+ let e = tt.trim(), t = e.length === 0 && !N, n = !1;
190
+ return A(!0), M(null), j(null), (async () => {
181
191
  try {
182
192
  let r = await o(_e, {
183
- storeSlug: g,
184
- schedule: P,
185
- items: V,
193
+ storeSlug: _,
194
+ schedule: L,
195
+ items: U,
186
196
  couponCode: e || void 0,
187
197
  includeAutoApply: t,
188
- insuranceAccepted: W
198
+ insuranceAccepted: K
189
199
  }), i = ve.parse(r);
190
200
  if (n) return;
191
- if (E(typeof i.subtotalMinor == "number" && typeof i.totalMinor == "number" ? {
201
+ if (O(typeof i.subtotalMinor == "number" && typeof i.totalMinor == "number" ? {
192
202
  subtotalMinor: i.subtotalMinor,
193
203
  totalMinor: i.totalMinor,
194
204
  lateReturnSurchargeMinor: i.lateReturnSurchargeMinor,
195
205
  insuranceSubtotalMinor: i.insuranceSubtotalMinor,
196
206
  insuranceBillableDays: i.insuranceBillableDays
197
207
  } : null), !i.success) {
198
- w(null), k(i.message || p("checkout_coupon_invalid"));
208
+ E(null), M(i.message || p("checkout_coupon_invalid"));
199
209
  return;
200
210
  }
201
- w(i.coupon ?? null), i.coupon && (i.coupon.autoApplied && e.length === 0 ? (S(i.coupon.code), O(p("checkout_coupon_auto_applied", { code: i.coupon.code }))) : O(p("checkout_coupon_manual_applied")));
211
+ E(i.coupon ?? null), i.coupon && (i.coupon.autoApplied && e.length === 0 ? (w(i.coupon.code), j(p("checkout_coupon_auto_applied", { code: i.coupon.code }))) : j(p("checkout_coupon_manual_applied")));
202
212
  } catch (e) {
203
213
  if (n) return;
204
- console.error("Failed to verify checkout coupon", e), w(null), E(null), k(p("checkout_coupon_error"));
214
+ console.error("Failed to verify checkout coupon", e), E(null), O(null), M(p("checkout_coupon_error"));
205
215
  } finally {
206
- n || D(!1);
216
+ n || A(!1);
207
217
  }
208
218
  })(), () => {
209
219
  n = !0;
210
220
  };
211
221
  }, [
212
- A,
213
- N.end_date,
214
- N.end_time,
215
- N.start_date,
216
- N.start_time,
217
- P,
218
- V,
219
- W,
220
- g,
221
- Qe,
222
+ N,
223
+ I.end_date,
224
+ I.end_time,
225
+ I.start_date,
226
+ I.start_time,
227
+ L,
228
+ U,
229
+ K,
230
+ _,
231
+ tt,
222
232
  p
223
233
  ]), s(() => {
224
- if (!g || F.lines.length === 0 || !P) {
225
- b(null), x(null), Je(!1);
234
+ if (!_ || R.lines.length === 0 || !L) {
235
+ S(null), C(null), Ze(!1);
226
236
  return;
227
237
  }
228
238
  let e = !1;
229
- return Je(!0), x(null), (async () => {
239
+ return Ze(!0), C(null), (async () => {
230
240
  try {
231
241
  let t = await o(re, {
232
- storeSlug: g,
233
- schedule: P,
234
- estimatedTotalMinor: G
242
+ storeSlug: _,
243
+ schedule: L,
244
+ estimatedTotalMinor: q
235
245
  }), n = ie.parse(t);
236
246
  if (e) return;
237
247
  if (!n.success || !n.decision) {
238
- b(null), x(n.errorCode === "online_payment_provider_missing" ? p("checkout_payment_error") : n.message || p("checkout_payment_error"));
248
+ S(null), C(n.errorCode === "online_payment_provider_missing" ? p("checkout_payment_error") : n.message || p("checkout_payment_error"));
239
249
  return;
240
250
  }
241
- b(n.decision);
251
+ S(n.decision);
242
252
  } catch (t) {
243
253
  if (e) return;
244
- console.error("Failed to load checkout payment decision", t), b(null), x(p("checkout_payment_error"));
254
+ console.error("Failed to load checkout payment decision", t), S(null), C(p("checkout_payment_error"));
245
255
  } finally {
246
- e || Je(!1);
256
+ e || Ze(!1);
247
257
  }
248
258
  })(), () => {
249
259
  e = !0;
250
260
  };
251
261
  }, [
252
- N.end_date,
253
- N.end_time,
254
- N.start_date,
255
- N.start_time,
256
- P,
257
- G,
258
- F.lines.length,
259
- g,
262
+ I.end_date,
263
+ I.end_time,
264
+ I.start_date,
265
+ I.start_time,
266
+ L,
267
+ q,
268
+ R.lines.length,
269
+ _,
260
270
  p
261
271
  ]);
262
- let Y = y?.currency ?? "EUR", xt = f(G, Y, m.language), St = K > 0 ? `-${f(K, Y, m.language)}` : null, X = T?.insuranceSubtotalMinor ?? 0, Ct = Math.max(0, G - X), wt = Math.round(Ct / 1.2), Tt = wt + X, Et = Math.max(0, Ct - wt), Dt = f(Tt, Y, m.language), Ot = f(Et, Y, m.language), kt = Pe(Me, m.language), At = X > 0 ? f(X, Y, m.language) : void 0, Z = y?.amountToCollectMinor ?? 0, jt = f(Z, Y, m.language), Mt = y?.paymentMode === "deposit" && Z > 0 ? f(Z, Y, m.language) : null, Nt = y?.shouldCollectOnlinePayment === !0 && Z > 0, Pt = h.shop.timeZone?.trim() || void 0, Q = c(() => y ? Pe(Math.max(0, Math.min(1, y.bookingDepositPercentage)), m.language) : null, [m.language, y]), $ = c(() => {
263
- if (!y?.depositRefundableUntilIso) return null;
264
- let e = new Date(y.depositRefundableUntilIso);
265
- return Number.isNaN(e.getTime()) ? null : Fe(e, m.language, Pt);
272
+ let X = x?.currency ?? "EUR", Dt = f(q, X, m.language), Ot = J > 0 ? `-${f(J, X, m.language)}` : null, Z = D?.insuranceSubtotalMinor ?? 0, kt = Math.max(0, q - Z), At = Math.round(kt / 1.2), jt = At + Z, Mt = Math.max(0, kt - At), Nt = f(jt, X, m.language), Pt = f(Mt, X, m.language), Ft = Fe(Ne, m.language), It = Z > 0 ? f(Z, X, m.language) : void 0, Q = x?.amountToCollectMinor ?? 0, Lt = f(Q, X, m.language), Rt = x?.paymentMode === "deposit" && Q > 0 ? f(Q, X, m.language) : null, zt = x?.shouldCollectOnlinePayment === !0 && Q > 0, Bt = h.shop.timeZone?.trim() || void 0, $ = c(() => x ? Fe(Math.max(0, Math.min(1, x.bookingDepositPercentage)), m.language) : null, [m.language, x]), Vt = c(() => {
273
+ if (!x?.depositRefundableUntilIso) return null;
274
+ let e = new Date(x.depositRefundableUntilIso);
275
+ return Number.isNaN(e.getTime()) ? null : Ie(e, m.language, Bt);
266
276
  }, [
267
277
  m.language,
268
- y?.depositRefundableUntilIso,
269
- Pt
270
- ]), Ft = c(() => y ? y.paymentMode === "deposit" && Z > 0 && Q ? $ ? p("checkout_payment_due_now_helper_deposit_refundable_until", {
271
- percent: Q,
272
- date: $
273
- }) : p("checkout_payment_due_now_helper_deposit", { percent: Q }) : y.paymentMode === "none" || Z <= 0 ? p("checkout_payment_due_now_helper_none") : null : null, [
274
- Z,
278
+ x?.depositRefundableUntilIso,
279
+ Bt
280
+ ]), Ht = c(() => x ? x.paymentMode === "deposit" && Q > 0 && $ ? Vt ? p("checkout_payment_due_now_helper_deposit_refundable_until", {
281
+ percent: $,
282
+ date: Vt
283
+ }) : p("checkout_payment_due_now_helper_deposit", { percent: $ }) : x.paymentMode === "none" || Q <= 0 ? p("checkout_payment_due_now_helper_none") : null : null, [
275
284
  Q,
276
285
  $,
277
- y,
286
+ Vt,
287
+ x,
278
288
  p
279
- ]), It = yt.handleSubmit(async (e) => {
280
- if (!(!g || V.length === 0 || !P)) {
281
- Ke(!0);
282
- try {
283
- let t = await o(ae, {
284
- storeSlug: g,
285
- schedule: P,
286
- fulfillment: N.fulfillment,
287
- startAddress: N.fulfillment === "delivery" ? N.start_address : void 0,
288
- endAddress: N.fulfillment === "delivery" ? N.end_address : void 0,
289
- couponCode: C?.code,
290
- couponAutoApplied: !A && C?.autoApplied,
291
- insuranceAccepted: W,
292
- customer: {
293
- firstName: e.first_name,
294
- lastName: e.last_name,
295
- email: e.email,
296
- phone: e.phone,
297
- notes: e.notes
298
- },
299
- items: V
300
- }), n = oe.parse(t);
301
- if (!n.success || !n.checkout) {
302
- a.error(n.errorCode === "online_payment_provider_missing" ? p("checkout_payment_error") : n.message || p("checkout_payment_error"));
303
- return;
304
- }
305
- n.checkout.requiresPayment || a.success(p("checkout_success_toast")), await Be(n.checkout.nextPath), Ge();
306
- } catch (e) {
307
- console.error("Failed to submit storefront checkout", e), a.error(p("checkout_payment_error"));
308
- } finally {
309
- Ke(!1);
289
+ ]), Ut = Tt.handleSubmit(async (e) => {
290
+ if (!_ || U.length === 0 || !L) return;
291
+ Je(!0), Ye.current = !0;
292
+ let t = Ge();
293
+ try {
294
+ let n = await o(ae, {
295
+ storeSlug: _,
296
+ checkoutSessionId: t,
297
+ schedule: L,
298
+ fulfillment: I.fulfillment,
299
+ startAddress: I.fulfillment === "delivery" ? I.start_address : void 0,
300
+ endAddress: I.fulfillment === "delivery" ? I.end_address : void 0,
301
+ couponCode: T?.code,
302
+ couponAutoApplied: !N && T?.autoApplied,
303
+ insuranceAccepted: K,
304
+ customer: {
305
+ firstName: e.first_name,
306
+ lastName: e.last_name,
307
+ email: e.email,
308
+ phone: e.phone,
309
+ notes: e.notes
310
+ },
311
+ items: U
312
+ }), r = oe.parse(n);
313
+ if (!r.success || !r.checkout) {
314
+ Ke(), a.error(r.errorCode === "online_payment_provider_missing" ? p("checkout_payment_error") : r.message || p("checkout_payment_error"));
315
+ return;
310
316
  }
317
+ r.checkout.requiresPayment || a.success(p("checkout_success_toast")), await Be(r.checkout.nextPath), r.checkout.requiresPayment || qe();
318
+ } catch (e) {
319
+ console.error("Failed to submit storefront checkout", e), a.error(p("checkout_payment_error"));
320
+ } finally {
321
+ Ye.current = !1, Je(!1);
311
322
  }
312
- }), Lt = p(Nt ? "checkout_continue_to_payment" : "checkout_submit"), Rt = N.fulfillment === "delivery" && N.start_address.trim().length === 0, zt = !v && !qe && !Ye && !et && !nt && !!y && !!P && !Rt && V.length > 0;
313
- return F.lines.length === 0 ? /* @__PURE__ */ u("div", {
323
+ }), Wt = p(zt ? "checkout_continue_to_payment" : "checkout_submit"), Gt = I.fulfillment === "delivery" && I.start_address.trim().length === 0, Kt = !b && !Xe && !Qe && !k && !it && !!x && !!L && !Gt && U.length > 0;
324
+ return R.lines.length === 0 ? /* @__PURE__ */ u("div", {
314
325
  className: "mx-auto max-w-3xl px-4 py-10 sm:px-6",
315
326
  children: /* @__PURE__ */ d("div", {
316
327
  className: "rounded-xl border border-slate-200 bg-white p-4 shadow-sm",
@@ -325,11 +336,11 @@ function p() {
325
336
  }),
326
337
  /* @__PURE__ */ u("div", {
327
338
  className: "mt-6",
328
- children: /* @__PURE__ */ u(we, {
329
- to: J,
339
+ children: /* @__PURE__ */ u(Te, {
340
+ to: xt,
330
341
  children: /* @__PURE__ */ d(fe, {
331
342
  className: "gap-2",
332
- children: [/* @__PURE__ */ u(ke, {
343
+ children: [/* @__PURE__ */ u(Ae, {
333
344
  className: "h-4 w-4",
334
345
  "aria-hidden": "true"
335
346
  }), /* @__PURE__ */ u("span", { children: p("back_to_booking") })]
@@ -345,13 +356,13 @@ function p() {
345
356
  children: [
346
357
  /* @__PURE__ */ u(pe, {
347
358
  currentStep: "checkout",
348
- bookingPath: J,
349
- checkoutPath: vt
359
+ bookingPath: xt,
360
+ checkoutPath: St
350
361
  }),
351
- /* @__PURE__ */ d(we, {
352
- to: J,
362
+ /* @__PURE__ */ d(Te, {
363
+ to: xt,
353
364
  className: "inline-flex items-center gap-2 text-sm font-medium text-slate-700 hover:text-slate-950",
354
- children: [/* @__PURE__ */ u(ke, {
365
+ children: [/* @__PURE__ */ u(Ae, {
355
366
  className: "h-4 w-4",
356
367
  "aria-hidden": "true"
357
368
  }), /* @__PURE__ */ u("span", { children: p("back_to_booking") })]
@@ -365,7 +376,7 @@ function p() {
365
376
  className: "text-xl font-semibold tracking-tight text-slate-950",
366
377
  children: /* @__PURE__ */ u("span", { children: p("checkout_title") })
367
378
  }),
368
- P ? null : /* @__PURE__ */ u("p", {
379
+ L ? null : /* @__PURE__ */ u("p", {
369
380
  role: "alert",
370
381
  className: "mt-3 text-sm text-destructive",
371
382
  children: /* @__PURE__ */ u("span", { children: p("booking_time_slots_required") })
@@ -373,63 +384,63 @@ function p() {
373
384
  /* @__PURE__ */ d("div", {
374
385
  className: "mt-5 grid gap-4",
375
386
  children: [
376
- st ? /* @__PURE__ */ u("div", {
387
+ lt ? /* @__PURE__ */ u("div", {
377
388
  className: "rounded-xl border border-slate-200 bg-white p-3 shadow-sm",
378
389
  children: /* @__PURE__ */ u(ge, {
379
- value: N.fulfillment,
380
- onValueChange: (e) => bt({ fulfillment: e }),
381
- pickupAddress: ct,
382
- deliveryEnabled: M,
383
- deliveryDisabledReason: ot,
384
- startAddress: N.start_address,
385
- onStartAddressChange: (e) => bt({ start_address: e }),
386
- endAddress: N.end_address,
387
- onEndAddressChange: (e) => bt({ end_address: e }),
390
+ value: I.fulfillment,
391
+ onValueChange: (e) => Et({ fulfillment: e }),
392
+ pickupAddress: ut,
393
+ deliveryEnabled: F,
394
+ deliveryDisabledReason: ct,
395
+ startAddress: I.start_address,
396
+ onStartAddressChange: (e) => Et({ start_address: e }),
397
+ endAddress: I.end_address,
398
+ onEndAddressChange: (e) => Et({ end_address: e }),
388
399
  showPickupAddressWhenPickupOnly: !1,
389
400
  testIdPrefix: "storefront-checkout-fulfillment"
390
401
  })
391
402
  }) : null,
392
- /* @__PURE__ */ u(ye, { form: yt }),
393
- U ? /* @__PURE__ */ u(xe, {
394
- accepted: W,
395
- disabled: v || et,
396
- dailyAmountLabel: f(ht, Y, m.language),
397
- totalAmountLabel: At,
398
- billableDays: T?.insuranceBillableDays,
399
- deductibleLabel: gt > 0 ? f(gt, Y, m.language) : void 0,
400
- onAcceptedChange: it
403
+ /* @__PURE__ */ u(ye, { form: Tt }),
404
+ G ? /* @__PURE__ */ u(xe, {
405
+ accepted: K,
406
+ disabled: b || k,
407
+ dailyAmountLabel: f(vt, X, m.language),
408
+ totalAmountLabel: It,
409
+ billableDays: D?.insuranceBillableDays,
410
+ deductibleLabel: yt > 0 ? f(yt, X, m.language) : void 0,
411
+ onAcceptedChange: ot
401
412
  }) : null,
402
413
  /* @__PURE__ */ u(be, {
403
- estimatedTotalLabel: xt,
404
- couponCode: C?.code,
405
- discountAmountLabel: St,
406
- totalExcludingTaxLabel: Dt,
407
- vatAmountLabel: Ot,
408
- vatRateLabel: kt,
409
- insuranceAmountLabel: At,
410
- depositAmountLabel: Mt,
411
- amountToCollectMinor: Z,
412
- amountToCollectLabel: jt,
413
- paymentSummaryHelper: Ft,
414
- paymentDecisionLoading: qe,
415
- paymentDecisionError: Ye,
414
+ estimatedTotalLabel: Dt,
415
+ couponCode: T?.code,
416
+ discountAmountLabel: Ot,
417
+ totalExcludingTaxLabel: Nt,
418
+ vatAmountLabel: Pt,
419
+ vatRateLabel: Ft,
420
+ insuranceAmountLabel: It,
421
+ depositAmountLabel: Rt,
422
+ amountToCollectMinor: Q,
423
+ amountToCollectLabel: Lt,
424
+ paymentSummaryHelper: Ht,
425
+ paymentDecisionLoading: Xe,
426
+ paymentDecisionError: Qe,
416
427
  canChoosePaymentMethod: !1,
417
428
  showAmountDueNowRow: !0,
418
429
  selectedPaymentMethod: "card",
419
- submitting: v,
430
+ submitting: b,
420
431
  onSelectPaymentMethod: () => {}
421
432
  }),
422
433
  /* @__PURE__ */ u(fe, {
423
434
  type: "button",
424
435
  size: "lg",
425
436
  onClick: () => {
426
- It();
437
+ Ut();
427
438
  },
428
- disabled: !zt,
439
+ disabled: !Kt,
429
440
  className: "mt-4 w-fit",
430
- children: /* @__PURE__ */ u("span", { children: Lt })
441
+ children: /* @__PURE__ */ u("span", { children: Wt })
431
442
  }),
432
- Rt ? /* @__PURE__ */ u("p", {
443
+ Gt ? /* @__PURE__ */ u("p", {
433
444
  className: "text-sm text-slate-600",
434
445
  children: /* @__PURE__ */ u("span", { children: p("checkout_delivery_address_required") })
435
446
  }) : null
@@ -437,34 +448,34 @@ function p() {
437
448
  })
438
449
  ]
439
450
  }), /* @__PURE__ */ u(Se, {
440
- lines: B.lines,
451
+ lines: H.lines,
441
452
  itemCount: He,
442
- totalPerDayMinor: B.totalPerDayMinor,
443
- estimatedDays: B.estimatedDays,
444
- estimatedTotalMinor: B.estimatedTotalMinor,
445
- discountedEstimatedTotalMinor: G,
446
- discountAmountMinor: K,
447
- lateReturnSurchargeMinor: T?.lateReturnSurchargeMinor,
448
- couponCode: C?.code,
449
- durationLabel: lt.label,
453
+ totalPerDayMinor: H.totalPerDayMinor,
454
+ estimatedDays: H.estimatedDays,
455
+ estimatedTotalMinor: H.estimatedTotalMinor,
456
+ discountedEstimatedTotalMinor: q,
457
+ discountAmountMinor: J,
458
+ lateReturnSurchargeMinor: D?.lateReturnSurchargeMinor,
459
+ couponCode: T?.code,
460
+ durationLabel: dt.label,
450
461
  onQuantityChange: Ue,
451
462
  onRemove: We,
452
463
  coupon: {
453
- code: Ze,
454
- appliedCode: C?.code,
455
- discountLabel: C && K > 0 ? f(K, Y, m.language) : null,
456
- message: tt,
457
- error: nt,
458
- loading: et,
459
- disabled: v,
464
+ code: et,
465
+ appliedCode: T?.code,
466
+ discountLabel: T && J > 0 ? f(J, X, m.language) : null,
467
+ message: rt,
468
+ error: it,
469
+ loading: k,
470
+ disabled: b,
460
471
  onCodeChange: (e) => {
461
- S(e), k(null), O(null);
472
+ w(e), M(null), j(null);
462
473
  },
463
474
  onApply: () => {
464
- rt(!1), $e(Ze.trim());
475
+ at(!1), nt(et.trim());
465
476
  },
466
477
  onRemove: () => {
467
- S(""), $e(""), w(null), E(null), k(null), O(null), rt(!0);
478
+ w(""), nt(""), E(null), O(null), M(null), j(null), at(!0);
468
479
  }
469
480
  }
470
481
  })]
@@ -1 +1 @@
1
- {"version":3,"file":"CheckoutPaymentPage.d.ts","sourceRoot":"","sources":["../../src/pages/CheckoutPaymentPage.tsx"],"names":[],"mappings":"AAmGA,MAAM,CAAC,OAAO,UAAU,mBAAmB,4CA0V1C"}
1
+ {"version":3,"file":"CheckoutPaymentPage.d.ts","sourceRoot":"","sources":["../../src/pages/CheckoutPaymentPage.tsx"],"names":[],"mappings":"AAmGA,MAAM,CAAC,OAAO,UAAU,mBAAmB,4CA+Y1C"}