@storepecker/storefront-core 2.7.0 → 2.9.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/dist/api/index.cjs +90 -46
- package/dist/api/index.d.cts +95 -6
- package/dist/api/index.d.ts +95 -6
- package/dist/api/index.js +3 -3
- package/dist/buy-now-B1dkx82V.d.cts +197 -0
- package/dist/buy-now-BgKd5p4J.d.ts +197 -0
- package/dist/checkout/index.cjs +78 -31
- package/dist/checkout/index.d.cts +47 -9
- package/dist/checkout/index.d.ts +47 -9
- package/dist/checkout/index.js +64 -18
- package/dist/{chunk-GTV42PDK.cjs → chunk-57UU7IJ2.cjs} +1 -0
- package/dist/{chunk-IWYO22XV.cjs → chunk-CIBMO44U.cjs} +26 -31
- package/dist/{chunk-5BT3MH4A.cjs → chunk-ETXIP5XE.cjs} +3 -3
- package/dist/{chunk-RNGQUWQW.cjs → chunk-H6FJYRO3.cjs} +49 -1
- package/dist/{chunk-CHRTGR3G.js → chunk-KCLVR6G5.js} +39 -2
- package/dist/{chunk-LCMJYFHC.cjs → chunk-NQZ5GUOG.cjs} +0 -1
- package/dist/{chunk-4C4NTH6O.js → chunk-OOFYY6GR.js} +1 -0
- package/dist/{chunk-6QHEH5XE.js → chunk-SU5LVRZD.js} +9 -14
- package/dist/{chunk-KWYFA2LJ.cjs → chunk-TFWTQTWE.cjs} +37 -19
- package/dist/{chunk-H32TICAM.js → chunk-TH7OAMGC.js} +0 -1
- package/dist/{chunk-5JD6MRVS.js → chunk-UWW5YIHL.js} +35 -17
- package/dist/{chunk-TY5NK7NW.js → chunk-YMZZCVZ2.js} +1 -1
- package/dist/components/digital-product-download-modal.d.cts +1 -1
- package/dist/components/digital-product-download-modal.d.ts +1 -1
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.ts +2 -2
- package/dist/components/theme-data-initializer.d.cts +2 -2
- package/dist/components/theme-data-initializer.d.ts +2 -2
- package/dist/hooks/index.cjs +564 -29
- package/dist/hooks/index.d.cts +179 -2
- package/dist/hooks/index.d.ts +179 -2
- package/dist/hooks/index.js +541 -10
- package/dist/middleware/index.cjs +3 -3
- package/dist/middleware/index.js +1 -1
- package/dist/models/index.d.cts +2 -1
- package/dist/models/index.d.ts +2 -1
- package/dist/{orders-9_scVq_M.d.cts → orders-COKWr7K7.d.cts} +1 -0
- package/dist/{orders-C1XZr8tx.d.ts → orders-Cp8qNCrl.d.ts} +1 -0
- package/dist/{pixelEvents-D0sH22Er.d.ts → pixelEvents-2Tb-_fRP.d.ts} +2 -1
- package/dist/{pixelEvents-uiPHbiAQ.d.cts → pixelEvents-BJNH06rS.d.cts} +2 -1
- package/dist/store/index.cjs +9 -9
- package/dist/store/index.d.cts +9 -4
- package/dist/store/index.d.ts +9 -4
- package/dist/store/index.js +4 -4
- package/dist/utils/index.cjs +7 -7
- package/dist/utils/index.d.cts +4 -3
- package/dist/utils/index.d.ts +4 -3
- package/dist/utils/index.js +2 -2
- package/package.json +1 -1
package/dist/hooks/index.cjs
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var chunkY46EHRJQ_cjs = require('../chunk-Y46EHRJQ.cjs');
|
|
4
4
|
var chunk2AHH3XBW_cjs = require('../chunk-2AHH3XBW.cjs');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
5
|
+
var chunkCIBMO44U_cjs = require('../chunk-CIBMO44U.cjs');
|
|
6
|
+
var chunkETXIP5XE_cjs = require('../chunk-ETXIP5XE.cjs');
|
|
7
|
+
var chunkNQZ5GUOG_cjs = require('../chunk-NQZ5GUOG.cjs');
|
|
8
|
+
var chunkTFWTQTWE_cjs = require('../chunk-TFWTQTWE.cjs');
|
|
9
9
|
var chunkXFOUNOKO_cjs = require('../chunk-XFOUNOKO.cjs');
|
|
10
10
|
require('../chunk-K44JZ5NL.cjs');
|
|
11
|
-
var
|
|
11
|
+
var chunkH6FJYRO3_cjs = require('../chunk-H6FJYRO3.cjs');
|
|
12
12
|
var chunkIVKJJLG7_cjs = require('../chunk-IVKJJLG7.cjs');
|
|
13
13
|
var chunkRDUT4W3B_cjs = require('../chunk-RDUT4W3B.cjs');
|
|
14
14
|
require('../chunk-LJUGNSQQ.cjs');
|
|
@@ -56,7 +56,7 @@ var useCart = (addressId) => {
|
|
|
56
56
|
async (addrId, shippingId) => {
|
|
57
57
|
try {
|
|
58
58
|
setIsLoading(true);
|
|
59
|
-
const result = await
|
|
59
|
+
const result = await chunkETXIP5XE_cjs.getCart("/customer/cart/", addrId ?? addressId, shippingId);
|
|
60
60
|
setData(result);
|
|
61
61
|
setError(null);
|
|
62
62
|
} catch (err) {
|
|
@@ -91,7 +91,7 @@ var useOrders = (filters) => {
|
|
|
91
91
|
try {
|
|
92
92
|
setIsLoading(true);
|
|
93
93
|
const url = `/customer/order/?${queryString}`;
|
|
94
|
-
const result = await
|
|
94
|
+
const result = await chunkH6FJYRO3_cjs.getOrders(url);
|
|
95
95
|
setData(result);
|
|
96
96
|
setError(null);
|
|
97
97
|
} catch (err) {
|
|
@@ -128,7 +128,7 @@ function useGetProducts(initialFilter, options) {
|
|
|
128
128
|
apiParams[key] = value;
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
const result = await
|
|
131
|
+
const result = await chunkETXIP5XE_cjs.getProductList(endpoint, apiParams);
|
|
132
132
|
setData(result);
|
|
133
133
|
if (modeRef.current === "append" && isLoadMoreRef.current) {
|
|
134
134
|
setProducts((prev) => [...prev, ...result.results || []]);
|
|
@@ -196,7 +196,7 @@ var useGetProductDetails = (slug) => {
|
|
|
196
196
|
const fetchData = react.useCallback(async () => {
|
|
197
197
|
try {
|
|
198
198
|
setIsLoading(true);
|
|
199
|
-
const result = await
|
|
199
|
+
const result = await chunkETXIP5XE_cjs.getProductDetail("/inventory/products/", slug);
|
|
200
200
|
setData(result);
|
|
201
201
|
} catch (err) {
|
|
202
202
|
} finally {
|
|
@@ -219,7 +219,7 @@ var useGetProductCategories = () => {
|
|
|
219
219
|
const fetchData = async () => {
|
|
220
220
|
try {
|
|
221
221
|
setIsLoading(true);
|
|
222
|
-
const result = await
|
|
222
|
+
const result = await chunkETXIP5XE_cjs.getProductCategories("/store/categories");
|
|
223
223
|
setData(result || []);
|
|
224
224
|
} catch (err) {
|
|
225
225
|
setError(err);
|
|
@@ -264,7 +264,7 @@ var useWishlist = () => {
|
|
|
264
264
|
const fetchData = react.useCallback(async () => {
|
|
265
265
|
try {
|
|
266
266
|
setIsLoading(true);
|
|
267
|
-
const response = await
|
|
267
|
+
const response = await chunkETXIP5XE_cjs.getWishlist("/customer/wishlist/");
|
|
268
268
|
if (response.data) setData(response.data);
|
|
269
269
|
setError(null);
|
|
270
270
|
} catch (err) {
|
|
@@ -322,7 +322,7 @@ function useCheckoutPayment(options) {
|
|
|
322
322
|
const [isConfirmingPayment, setIsConfirmingPayment] = react.useState(false);
|
|
323
323
|
const [showSuccessModal, setShowSuccessModal] = react.useState(false);
|
|
324
324
|
const [showFailureModal, setShowFailureModal] = react.useState(false);
|
|
325
|
-
const resetCartCount =
|
|
325
|
+
const resetCartCount = chunkCIBMO44U_cjs.useCartStore((s) => s.resetCartCount);
|
|
326
326
|
const callbacks = {
|
|
327
327
|
onSuccess: (order) => {
|
|
328
328
|
setOrderSummary(order);
|
|
@@ -345,7 +345,7 @@ function useCheckoutPayment(options) {
|
|
|
345
345
|
try {
|
|
346
346
|
setIsPlacingOrder(true);
|
|
347
347
|
const isCod = paymentMethod === "cod";
|
|
348
|
-
const response = await
|
|
348
|
+
const response = await chunkH6FJYRO3_cjs.placeOrder(
|
|
349
349
|
addressId,
|
|
350
350
|
options.phonepeRedirectUrl,
|
|
351
351
|
isCod,
|
|
@@ -355,8 +355,9 @@ function useCheckoutPayment(options) {
|
|
|
355
355
|
);
|
|
356
356
|
const order = response.data;
|
|
357
357
|
setOrderSummary(order);
|
|
358
|
-
|
|
359
|
-
} catch {
|
|
358
|
+
chunkTFWTQTWE_cjs.processPayment(order, paymentMethod, callbacks);
|
|
359
|
+
} catch (error) {
|
|
360
|
+
if (options.onPlaceOrderError?.(error) === true) return;
|
|
360
361
|
setShowFailureModal(true);
|
|
361
362
|
} finally {
|
|
362
363
|
setIsPlacingOrder(false);
|
|
@@ -375,6 +376,530 @@ function useCheckoutPayment(options) {
|
|
|
375
376
|
placeAndPay
|
|
376
377
|
};
|
|
377
378
|
}
|
|
379
|
+
var BUY_NOW_PAYLOAD_KEY = "____bn_pl_";
|
|
380
|
+
var DEBOUNCE_MS = 300;
|
|
381
|
+
function messageForPreviewError(code, fallback, isPreorder) {
|
|
382
|
+
switch (code) {
|
|
383
|
+
case "FEATURE_NOT_AVAILABLE":
|
|
384
|
+
return isPreorder ? "Pre Order isn't available for this store." : "Buy Now isn't available for this store.";
|
|
385
|
+
case "PUBLIC_CHECKOUT_DISABLED":
|
|
386
|
+
return "Guest checkout isn't available for this store. Please log in to continue.";
|
|
387
|
+
case "VARIANT_NOT_FOUND":
|
|
388
|
+
return "This product is no longer available.";
|
|
389
|
+
case "VARIANT_UNAVAILABLE":
|
|
390
|
+
return "This product is currently unavailable.";
|
|
391
|
+
case "INVALID_QUANTITY":
|
|
392
|
+
return "Please choose a valid quantity.";
|
|
393
|
+
case "ADDRESS_NOT_FOUND":
|
|
394
|
+
return "The selected address could not be found. Please pick another.";
|
|
395
|
+
default:
|
|
396
|
+
return fallback || "We couldn't load this item. Please try again.";
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function readStashedItem() {
|
|
400
|
+
if (typeof window === "undefined") return null;
|
|
401
|
+
try {
|
|
402
|
+
const raw = window.sessionStorage.getItem(BUY_NOW_PAYLOAD_KEY);
|
|
403
|
+
if (!raw) return null;
|
|
404
|
+
const parsed = JSON.parse(raw);
|
|
405
|
+
if (!parsed?.variant_id) return null;
|
|
406
|
+
return { ...parsed, quantity: parsed.quantity || 1 };
|
|
407
|
+
} catch {
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
function useBuyNow(isAuthenticated = true) {
|
|
412
|
+
const [item, setItem] = react.useState(null);
|
|
413
|
+
const [quantity, setQuantityState] = react.useState(1);
|
|
414
|
+
const [couponCodes, setCouponCodes] = react.useState(void 0);
|
|
415
|
+
const [addressId, setAddressIdState] = react.useState(void 0);
|
|
416
|
+
const [guestAddress, setGuestAddress] = react.useState(void 0);
|
|
417
|
+
const [shippingOptionId, setShippingOptionIdState] = react.useState(void 0);
|
|
418
|
+
const [preview, setPreview] = react.useState(null);
|
|
419
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
420
|
+
const [isRefreshing, setIsRefreshing] = react.useState(false);
|
|
421
|
+
const [placingOrder, setPlacingOrder] = react.useState(false);
|
|
422
|
+
const [notFound, setNotFound] = react.useState(false);
|
|
423
|
+
const [error, setError] = react.useState(null);
|
|
424
|
+
const [refreshNonce, setRefreshNonce] = react.useState(0);
|
|
425
|
+
const debounceRef = react.useRef();
|
|
426
|
+
const stateRef = react.useRef({ quantity, couponCodes, addressId, guestAddress, shippingOptionId, preview });
|
|
427
|
+
stateRef.current = { quantity, couponCodes, addressId, guestAddress, shippingOptionId, preview };
|
|
428
|
+
react.useEffect(() => {
|
|
429
|
+
const stashed = readStashedItem();
|
|
430
|
+
if (!stashed) {
|
|
431
|
+
setNotFound(true);
|
|
432
|
+
setIsLoading(false);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
setItem(stashed);
|
|
436
|
+
setQuantityState(stashed.quantity || 1);
|
|
437
|
+
}, []);
|
|
438
|
+
const runPreview = react.useCallback(async (current) => {
|
|
439
|
+
const { quantity: quantity2, couponCodes: couponCodes2, addressId: addressId2, guestAddress: guestAddress2, shippingOptionId: shippingOptionId2 } = stateRef.current;
|
|
440
|
+
const payload = {
|
|
441
|
+
variant_id: current.variant_id,
|
|
442
|
+
quantity: quantity2,
|
|
443
|
+
customization_inputs: current.customization_inputs
|
|
444
|
+
};
|
|
445
|
+
if (couponCodes2 !== void 0) payload.coupon_codes = couponCodes2;
|
|
446
|
+
if (addressId2 !== void 0) payload.address_id = addressId2;
|
|
447
|
+
if (guestAddress2 !== void 0) payload.address = guestAddress2;
|
|
448
|
+
if (shippingOptionId2 !== void 0) payload.shipping_option_id = shippingOptionId2;
|
|
449
|
+
setIsRefreshing(true);
|
|
450
|
+
try {
|
|
451
|
+
const response = await chunkH6FJYRO3_cjs.buyNowPreview(payload);
|
|
452
|
+
if (response.data) {
|
|
453
|
+
setPreview(response.data);
|
|
454
|
+
setError(null);
|
|
455
|
+
}
|
|
456
|
+
} catch (err) {
|
|
457
|
+
const data = err?.response?.data;
|
|
458
|
+
setError({
|
|
459
|
+
code: data?.error_code || "INTERNAL_ERROR",
|
|
460
|
+
message: messageForPreviewError(data?.error_code, data?.error, current.is_preorder)
|
|
461
|
+
});
|
|
462
|
+
} finally {
|
|
463
|
+
setIsLoading(false);
|
|
464
|
+
setIsRefreshing(false);
|
|
465
|
+
}
|
|
466
|
+
}, []);
|
|
467
|
+
react.useEffect(() => {
|
|
468
|
+
if (!item) return;
|
|
469
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
470
|
+
debounceRef.current = setTimeout(() => runPreview(item), DEBOUNCE_MS);
|
|
471
|
+
return () => {
|
|
472
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
473
|
+
};
|
|
474
|
+
}, [item, quantity, couponCodes, addressId, guestAddress, shippingOptionId, refreshNonce, runPreview]);
|
|
475
|
+
const refresh = react.useCallback(() => {
|
|
476
|
+
setRefreshNonce((n) => n + 1);
|
|
477
|
+
}, []);
|
|
478
|
+
const clearItem = react.useCallback(() => {
|
|
479
|
+
try {
|
|
480
|
+
window.sessionStorage.removeItem(BUY_NOW_PAYLOAD_KEY);
|
|
481
|
+
} catch {
|
|
482
|
+
}
|
|
483
|
+
}, []);
|
|
484
|
+
const setQuantity = react.useCallback((value) => {
|
|
485
|
+
setQuantityState(Math.max(1, value));
|
|
486
|
+
}, []);
|
|
487
|
+
const setAddressId = react.useCallback((id) => {
|
|
488
|
+
setAddressIdState(id);
|
|
489
|
+
setShippingOptionIdState(void 0);
|
|
490
|
+
}, []);
|
|
491
|
+
const setShippingOptionId = react.useCallback((id) => {
|
|
492
|
+
setShippingOptionIdState(id);
|
|
493
|
+
}, []);
|
|
494
|
+
const applyCoupon2 = react.useCallback((code) => {
|
|
495
|
+
setCouponCodes([code]);
|
|
496
|
+
}, []);
|
|
497
|
+
const removeCoupon2 = react.useCallback(() => {
|
|
498
|
+
setCouponCodes([]);
|
|
499
|
+
}, []);
|
|
500
|
+
const placeOrder2 = react.useCallback(
|
|
501
|
+
async ({
|
|
502
|
+
isCod,
|
|
503
|
+
phonepeRedirectUrl,
|
|
504
|
+
stripeRedirectUrl,
|
|
505
|
+
tabbyRedirectUrl,
|
|
506
|
+
guest
|
|
507
|
+
}) => {
|
|
508
|
+
if (!item) return;
|
|
509
|
+
const effectiveShippingId = shippingOptionId ?? stateRef.current.preview?.selected_shipping_option_id ?? void 0;
|
|
510
|
+
setPlacingOrder(true);
|
|
511
|
+
try {
|
|
512
|
+
if (!isAuthenticated) {
|
|
513
|
+
if (!guest) throw new Error("MISSING_ADDRESS");
|
|
514
|
+
const payload2 = {
|
|
515
|
+
cart_items: { [item.variant_id]: quantity },
|
|
516
|
+
is_buy_now: true,
|
|
517
|
+
is_cod: !!isCod,
|
|
518
|
+
email: guest.email,
|
|
519
|
+
phone: guest.phone,
|
|
520
|
+
country_code: guest.country_code,
|
|
521
|
+
address: guest.address
|
|
522
|
+
};
|
|
523
|
+
if (couponCodes !== void 0) payload2.coupon_codes = couponCodes;
|
|
524
|
+
if (effectiveShippingId !== void 0 && effectiveShippingId !== null)
|
|
525
|
+
payload2.shipping_option_id = effectiveShippingId;
|
|
526
|
+
if (phonepeRedirectUrl) payload2.phonepe_redirect_url = phonepeRedirectUrl;
|
|
527
|
+
if (stripeRedirectUrl) payload2.stripe_redirect_url = stripeRedirectUrl;
|
|
528
|
+
if (tabbyRedirectUrl) payload2.tabby_redirect_url = tabbyRedirectUrl;
|
|
529
|
+
const response2 = await chunkH6FJYRO3_cjs.placeGuestBuyNowOrder(payload2);
|
|
530
|
+
return response2.data;
|
|
531
|
+
}
|
|
532
|
+
if (addressId === void 0) throw new Error("MISSING_ADDRESS");
|
|
533
|
+
const payload = {
|
|
534
|
+
variant_id: item.variant_id,
|
|
535
|
+
quantity,
|
|
536
|
+
address_id: addressId,
|
|
537
|
+
customization_inputs: item.customization_inputs,
|
|
538
|
+
is_cod: !!isCod
|
|
539
|
+
};
|
|
540
|
+
if (couponCodes !== void 0) payload.coupon_codes = couponCodes;
|
|
541
|
+
if (effectiveShippingId !== void 0 && effectiveShippingId !== null)
|
|
542
|
+
payload.shipping_option_id = effectiveShippingId;
|
|
543
|
+
if (phonepeRedirectUrl) payload.phonepe_redirect_url = phonepeRedirectUrl;
|
|
544
|
+
if (stripeRedirectUrl) payload.stripe_redirect_url = stripeRedirectUrl;
|
|
545
|
+
if (tabbyRedirectUrl) payload.tabby_redirect_url = tabbyRedirectUrl;
|
|
546
|
+
const response = await chunkH6FJYRO3_cjs.placeBuyNowOrder(payload);
|
|
547
|
+
return response.data;
|
|
548
|
+
} finally {
|
|
549
|
+
setPlacingOrder(false);
|
|
550
|
+
}
|
|
551
|
+
},
|
|
552
|
+
[item, quantity, addressId, couponCodes, shippingOptionId, isAuthenticated]
|
|
553
|
+
);
|
|
554
|
+
return {
|
|
555
|
+
// data
|
|
556
|
+
item,
|
|
557
|
+
preview,
|
|
558
|
+
quantity,
|
|
559
|
+
couponCodes,
|
|
560
|
+
addressId,
|
|
561
|
+
guestAddress,
|
|
562
|
+
shippingOptionId,
|
|
563
|
+
// status
|
|
564
|
+
isLoading,
|
|
565
|
+
isRefreshing,
|
|
566
|
+
placingOrder,
|
|
567
|
+
notFound,
|
|
568
|
+
error,
|
|
569
|
+
missingItems: preview?.missing_items ?? {},
|
|
570
|
+
appliedCoupon: preview?.applied_coupons && Object.keys(preview.applied_coupons).length > 0 ? preview.applied_coupons : null,
|
|
571
|
+
// actions
|
|
572
|
+
setQuantity,
|
|
573
|
+
setAddressId,
|
|
574
|
+
setShippingOptionId,
|
|
575
|
+
applyCoupon: applyCoupon2,
|
|
576
|
+
removeCoupon: removeCoupon2,
|
|
577
|
+
setGuestAddress,
|
|
578
|
+
refresh,
|
|
579
|
+
clearItem,
|
|
580
|
+
placeOrder: placeOrder2
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
function useInlineCheckoutPayment(options) {
|
|
584
|
+
const [orderSummary, setOrderSummary] = react.useState(null);
|
|
585
|
+
const [isPlacingOrder, setIsPlacingOrder] = react.useState(false);
|
|
586
|
+
const [isConfirmingPayment, setIsConfirmingPayment] = react.useState(false);
|
|
587
|
+
const [showSuccessModal, setShowSuccessModal] = react.useState(false);
|
|
588
|
+
const [showFailureModal, setShowFailureModal] = react.useState(false);
|
|
589
|
+
const isPublic = !options.isAuthenticated;
|
|
590
|
+
const callbacks = {
|
|
591
|
+
onSuccess: (order) => {
|
|
592
|
+
setOrderSummary(order);
|
|
593
|
+
setShowSuccessModal(true);
|
|
594
|
+
options.onClearItem?.();
|
|
595
|
+
options.onSuccess?.(order);
|
|
596
|
+
},
|
|
597
|
+
onFailure: (order) => {
|
|
598
|
+
setOrderSummary(order);
|
|
599
|
+
setShowFailureModal(true);
|
|
600
|
+
options.onFailure?.(order);
|
|
601
|
+
},
|
|
602
|
+
onRedirect: options.onRedirect,
|
|
603
|
+
onStripeModalOpen: options.onStripeModalOpen,
|
|
604
|
+
onCartReset: () => {
|
|
605
|
+
},
|
|
606
|
+
onPaymentStart: () => setIsConfirmingPayment(true),
|
|
607
|
+
onPaymentEnd: () => setIsConfirmingPayment(false)
|
|
608
|
+
};
|
|
609
|
+
const placeAndPay = react.useCallback(
|
|
610
|
+
async (paymentMethod) => {
|
|
611
|
+
try {
|
|
612
|
+
setIsPlacingOrder(true);
|
|
613
|
+
const isCod = paymentMethod === "cod";
|
|
614
|
+
const guest = isPublic ? options.getGuestContact?.() : void 0;
|
|
615
|
+
if (isPublic && !guest) {
|
|
616
|
+
setShowFailureModal(true);
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
const order = await options.placeOrder({
|
|
620
|
+
isCod,
|
|
621
|
+
phonepeRedirectUrl: options.phonepeRedirectUrl,
|
|
622
|
+
stripeRedirectUrl: options.stripeRedirectUrl,
|
|
623
|
+
tabbyRedirectUrl: options.tabbyRedirectUrl,
|
|
624
|
+
guest
|
|
625
|
+
});
|
|
626
|
+
if (!order) {
|
|
627
|
+
setShowFailureModal(true);
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
setOrderSummary(order);
|
|
631
|
+
chunkTFWTQTWE_cjs.processPayment(order, paymentMethod, callbacks, { isPublic });
|
|
632
|
+
} catch (error) {
|
|
633
|
+
if (options.onPlaceOrderError?.(error) === true) return;
|
|
634
|
+
setShowFailureModal(true);
|
|
635
|
+
} finally {
|
|
636
|
+
setIsPlacingOrder(false);
|
|
637
|
+
}
|
|
638
|
+
},
|
|
639
|
+
[
|
|
640
|
+
isPublic,
|
|
641
|
+
options.placeOrder,
|
|
642
|
+
options.getGuestContact,
|
|
643
|
+
options.phonepeRedirectUrl,
|
|
644
|
+
options.stripeRedirectUrl,
|
|
645
|
+
options.tabbyRedirectUrl
|
|
646
|
+
]
|
|
647
|
+
);
|
|
648
|
+
return {
|
|
649
|
+
orderSummary,
|
|
650
|
+
isPlacingOrder,
|
|
651
|
+
isConfirmingPayment,
|
|
652
|
+
showSuccessModal,
|
|
653
|
+
showFailureModal,
|
|
654
|
+
setShowSuccessModal,
|
|
655
|
+
setShowFailureModal,
|
|
656
|
+
placeAndPay
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
var DEBOUNCE_MS2 = 400;
|
|
660
|
+
function messageForPreviewError2(code, fallback) {
|
|
661
|
+
switch (code) {
|
|
662
|
+
case "PUBLIC_CHECKOUT_DISABLED":
|
|
663
|
+
return "Guest checkout isn't available for this store. Please log in to continue.";
|
|
664
|
+
case "INVALID_QUANTITY":
|
|
665
|
+
return "One of the items has an invalid quantity. Please review your cart.";
|
|
666
|
+
case "ADDRESS_NOT_FOUND":
|
|
667
|
+
return "The selected address could not be found. Please pick another.";
|
|
668
|
+
case "PREORDER_DIRECT_ONLY":
|
|
669
|
+
return "A pre-order product is in your cart. Please remove it and purchase it directly with Pre Order.";
|
|
670
|
+
default:
|
|
671
|
+
return fallback || "We couldn't price your cart. Please try again.";
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
function readCartItems(cart) {
|
|
675
|
+
if (!cart?.products_quantity) return {};
|
|
676
|
+
return Object.entries(cart.products_quantity).reduce(
|
|
677
|
+
(acc, [id, qty]) => {
|
|
678
|
+
const variantId = Number(id);
|
|
679
|
+
const quantity = Number(qty);
|
|
680
|
+
if (variantId && quantity > 0) acc[variantId] = quantity;
|
|
681
|
+
return acc;
|
|
682
|
+
},
|
|
683
|
+
{}
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
function usePublicCheckout() {
|
|
687
|
+
const [cartItems, setCartItems] = react.useState({});
|
|
688
|
+
const [couponCodes, setCouponCodes] = react.useState(void 0);
|
|
689
|
+
const [guestAddress, setGuestAddressState] = react.useState(void 0);
|
|
690
|
+
const [shippingOptionId, setShippingOptionIdState] = react.useState(
|
|
691
|
+
void 0
|
|
692
|
+
);
|
|
693
|
+
const [isCod, setIsCodState] = react.useState(false);
|
|
694
|
+
const [preview, setPreview] = react.useState(null);
|
|
695
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
696
|
+
const [isRefreshing, setIsRefreshing] = react.useState(false);
|
|
697
|
+
const [placingOrder, setPlacingOrder] = react.useState(false);
|
|
698
|
+
const [isEmpty, setIsEmpty] = react.useState(false);
|
|
699
|
+
const [error, setError] = react.useState(null);
|
|
700
|
+
const [refreshNonce, setRefreshNonce] = react.useState(0);
|
|
701
|
+
const debounceRef = react.useRef();
|
|
702
|
+
const stateRef = react.useRef({
|
|
703
|
+
cartItems,
|
|
704
|
+
couponCodes,
|
|
705
|
+
guestAddress,
|
|
706
|
+
shippingOptionId,
|
|
707
|
+
isCod,
|
|
708
|
+
preview
|
|
709
|
+
});
|
|
710
|
+
stateRef.current = {
|
|
711
|
+
cartItems,
|
|
712
|
+
couponCodes,
|
|
713
|
+
guestAddress,
|
|
714
|
+
shippingOptionId,
|
|
715
|
+
isCod,
|
|
716
|
+
preview
|
|
717
|
+
};
|
|
718
|
+
react.useEffect(() => {
|
|
719
|
+
const cart = chunkNQZ5GUOG_cjs.cart_default.get();
|
|
720
|
+
const items = readCartItems(cart);
|
|
721
|
+
if (Object.keys(items).length === 0) {
|
|
722
|
+
setIsEmpty(true);
|
|
723
|
+
setIsLoading(false);
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
setCartItems(items);
|
|
727
|
+
}, []);
|
|
728
|
+
const pruneStaleItems = react.useCallback(
|
|
729
|
+
(priced) => {
|
|
730
|
+
const missing = priced.missing_items || {};
|
|
731
|
+
const missingIds = Object.keys(missing).map(Number);
|
|
732
|
+
if (missingIds.length === 0) return;
|
|
733
|
+
const pricedIds = new Set((priced.product_variants || []).map((v) => v.id));
|
|
734
|
+
const droppedIds = missingIds.filter((id) => !pricedIds.has(id));
|
|
735
|
+
if (droppedIds.length === 0) return;
|
|
736
|
+
const cart = chunkNQZ5GUOG_cjs.cart_default.get();
|
|
737
|
+
if (cart) {
|
|
738
|
+
droppedIds.forEach((id) => {
|
|
739
|
+
const variant = cart.product_variants?.find((v) => v.id === id);
|
|
740
|
+
if (variant) chunkNQZ5GUOG_cjs.cart_default.remove(variant);
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
setCartItems((prev) => {
|
|
744
|
+
const next = { ...prev };
|
|
745
|
+
droppedIds.forEach((id) => delete next[id]);
|
|
746
|
+
return next;
|
|
747
|
+
});
|
|
748
|
+
},
|
|
749
|
+
[]
|
|
750
|
+
);
|
|
751
|
+
const runPreview = react.useCallback(async () => {
|
|
752
|
+
const {
|
|
753
|
+
cartItems: cartItems2,
|
|
754
|
+
couponCodes: couponCodes2,
|
|
755
|
+
guestAddress: guestAddress2,
|
|
756
|
+
shippingOptionId: shippingOptionId2,
|
|
757
|
+
isCod: isCod2
|
|
758
|
+
} = stateRef.current;
|
|
759
|
+
if (Object.keys(cartItems2).length === 0) {
|
|
760
|
+
setIsEmpty(true);
|
|
761
|
+
setIsLoading(false);
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
const payload = {
|
|
765
|
+
cart_items: cartItems2,
|
|
766
|
+
is_cod: isCod2
|
|
767
|
+
};
|
|
768
|
+
if (couponCodes2 !== void 0) payload.coupon_codes = couponCodes2;
|
|
769
|
+
if (guestAddress2 !== void 0) payload.address = guestAddress2;
|
|
770
|
+
if (shippingOptionId2 !== void 0) payload.shipping_option_id = shippingOptionId2;
|
|
771
|
+
setIsRefreshing(true);
|
|
772
|
+
try {
|
|
773
|
+
const response = await chunkH6FJYRO3_cjs.publicCheckoutPreview(payload);
|
|
774
|
+
if (response.data) {
|
|
775
|
+
setPreview(response.data);
|
|
776
|
+
setError(null);
|
|
777
|
+
pruneStaleItems(response.data);
|
|
778
|
+
}
|
|
779
|
+
} catch (err) {
|
|
780
|
+
const data = err?.response?.data;
|
|
781
|
+
const code = data?.error_code;
|
|
782
|
+
if (code === "CART_EMPTY") {
|
|
783
|
+
chunkNQZ5GUOG_cjs.cart_default.clear();
|
|
784
|
+
setCartItems({});
|
|
785
|
+
setIsEmpty(true);
|
|
786
|
+
setPreview(null);
|
|
787
|
+
setError(null);
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
setError({
|
|
791
|
+
code: code || "INTERNAL_ERROR",
|
|
792
|
+
message: messageForPreviewError2(code, data?.error)
|
|
793
|
+
});
|
|
794
|
+
} finally {
|
|
795
|
+
setIsLoading(false);
|
|
796
|
+
setIsRefreshing(false);
|
|
797
|
+
}
|
|
798
|
+
}, [pruneStaleItems]);
|
|
799
|
+
react.useEffect(() => {
|
|
800
|
+
if (isEmpty) return;
|
|
801
|
+
if (Object.keys(cartItems).length === 0) return;
|
|
802
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
803
|
+
debounceRef.current = setTimeout(runPreview, DEBOUNCE_MS2);
|
|
804
|
+
return () => {
|
|
805
|
+
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
806
|
+
};
|
|
807
|
+
}, [
|
|
808
|
+
cartItems,
|
|
809
|
+
couponCodes,
|
|
810
|
+
guestAddress,
|
|
811
|
+
shippingOptionId,
|
|
812
|
+
isCod,
|
|
813
|
+
refreshNonce,
|
|
814
|
+
isEmpty,
|
|
815
|
+
runPreview
|
|
816
|
+
]);
|
|
817
|
+
const refresh = react.useCallback(() => setRefreshNonce((n) => n + 1), []);
|
|
818
|
+
const setGuestAddress = react.useCallback((address) => {
|
|
819
|
+
const prev = stateRef.current.guestAddress;
|
|
820
|
+
const unchanged = prev?.country_obj === address?.country_obj && prev?.state_obj === address?.state_obj && prev?.pincode === address?.pincode;
|
|
821
|
+
if (unchanged) return;
|
|
822
|
+
const destinationChanged = prev?.country_obj !== address?.country_obj || prev?.state_obj !== address?.state_obj;
|
|
823
|
+
setGuestAddressState(address);
|
|
824
|
+
if (destinationChanged) setShippingOptionIdState(void 0);
|
|
825
|
+
}, []);
|
|
826
|
+
const setShippingOptionId = react.useCallback((id) => {
|
|
827
|
+
setShippingOptionIdState(id);
|
|
828
|
+
}, []);
|
|
829
|
+
const setIsCod = react.useCallback((value) => setIsCodState(value), []);
|
|
830
|
+
const applyCoupon2 = react.useCallback((code) => setCouponCodes([code]), []);
|
|
831
|
+
const removeCoupon2 = react.useCallback(() => setCouponCodes([]), []);
|
|
832
|
+
const clearCart = react.useCallback(() => {
|
|
833
|
+
chunkNQZ5GUOG_cjs.cart_default.clear();
|
|
834
|
+
setCartItems({});
|
|
835
|
+
setIsEmpty(true);
|
|
836
|
+
}, []);
|
|
837
|
+
const placeOrder2 = react.useCallback(
|
|
838
|
+
async ({
|
|
839
|
+
isCod: isCodArg,
|
|
840
|
+
phonepeRedirectUrl,
|
|
841
|
+
stripeRedirectUrl,
|
|
842
|
+
tabbyRedirectUrl,
|
|
843
|
+
guest
|
|
844
|
+
}) => {
|
|
845
|
+
if (!guest) throw new Error("MISSING_ADDRESS");
|
|
846
|
+
const items = stateRef.current.cartItems;
|
|
847
|
+
if (Object.keys(items).length === 0) throw new Error("CART_EMPTY");
|
|
848
|
+
setPlacingOrder(true);
|
|
849
|
+
try {
|
|
850
|
+
const payload = {
|
|
851
|
+
cart_items: items,
|
|
852
|
+
is_cod: !!isCodArg,
|
|
853
|
+
email: guest.email,
|
|
854
|
+
phone: guest.phone,
|
|
855
|
+
country_code: guest.country_code,
|
|
856
|
+
address: guest.address
|
|
857
|
+
};
|
|
858
|
+
if (couponCodes !== void 0) payload.coupon_codes = couponCodes;
|
|
859
|
+
const effectiveShippingId = shippingOptionId ?? stateRef.current.preview?.selected_shipping_option_id ?? void 0;
|
|
860
|
+
if (effectiveShippingId !== void 0 && effectiveShippingId !== null) {
|
|
861
|
+
payload.shipping_option_id = effectiveShippingId;
|
|
862
|
+
}
|
|
863
|
+
if (phonepeRedirectUrl) payload.phonepe_redirect_url = phonepeRedirectUrl;
|
|
864
|
+
if (stripeRedirectUrl) payload.stripe_redirect_url = stripeRedirectUrl;
|
|
865
|
+
if (tabbyRedirectUrl) payload.tabby_redirect_url = tabbyRedirectUrl;
|
|
866
|
+
const response = await chunkH6FJYRO3_cjs.placePublicOrder(payload);
|
|
867
|
+
return response.data;
|
|
868
|
+
} finally {
|
|
869
|
+
setPlacingOrder(false);
|
|
870
|
+
}
|
|
871
|
+
},
|
|
872
|
+
[couponCodes, shippingOptionId]
|
|
873
|
+
);
|
|
874
|
+
return {
|
|
875
|
+
// data
|
|
876
|
+
preview,
|
|
877
|
+
cartItems,
|
|
878
|
+
couponCodes,
|
|
879
|
+
guestAddress,
|
|
880
|
+
shippingOptionId,
|
|
881
|
+
isCod,
|
|
882
|
+
isCodEnabled: !!preview?.is_cod_enabled,
|
|
883
|
+
codAmount: Number(preview?.cod_amount || 0),
|
|
884
|
+
// status
|
|
885
|
+
isLoading,
|
|
886
|
+
isRefreshing,
|
|
887
|
+
placingOrder,
|
|
888
|
+
isEmpty,
|
|
889
|
+
error,
|
|
890
|
+
missingItems: preview?.missing_items ?? {},
|
|
891
|
+
appliedCoupon: preview?.applied_coupons && Object.keys(preview.applied_coupons).length > 0 ? preview.applied_coupons : null,
|
|
892
|
+
// actions
|
|
893
|
+
setGuestAddress,
|
|
894
|
+
setShippingOptionId,
|
|
895
|
+
setIsCod,
|
|
896
|
+
applyCoupon: applyCoupon2,
|
|
897
|
+
removeCoupon: removeCoupon2,
|
|
898
|
+
refresh,
|
|
899
|
+
clearCart,
|
|
900
|
+
placeOrder: placeOrder2
|
|
901
|
+
};
|
|
902
|
+
}
|
|
378
903
|
function useCheckoutCoupon(options) {
|
|
379
904
|
const [availableCoupons, setAvailableCoupons] = react.useState([]);
|
|
380
905
|
const [appliedCoupon, setAppliedCoupon] = react.useState(null);
|
|
@@ -385,7 +910,7 @@ function useCheckoutCoupon(options) {
|
|
|
385
910
|
const refreshCoupons = react.useCallback(async () => {
|
|
386
911
|
setIsLoading(true);
|
|
387
912
|
try {
|
|
388
|
-
const coupons = await
|
|
913
|
+
const coupons = await chunkTFWTQTWE_cjs.fetchAvailableCoupons();
|
|
389
914
|
setAvailableCoupons(coupons);
|
|
390
915
|
} catch {
|
|
391
916
|
} finally {
|
|
@@ -397,7 +922,7 @@ function useCheckoutCoupon(options) {
|
|
|
397
922
|
setError(null);
|
|
398
923
|
setIsApplying(true);
|
|
399
924
|
try {
|
|
400
|
-
const coupon = await
|
|
925
|
+
const coupon = await chunkTFWTQTWE_cjs.applyCheckoutCoupon(code, callbacks);
|
|
401
926
|
setAppliedCoupon(coupon);
|
|
402
927
|
} catch (err) {
|
|
403
928
|
setError(err instanceof Error ? err.message : "Failed to apply coupon");
|
|
@@ -410,7 +935,7 @@ function useCheckoutCoupon(options) {
|
|
|
410
935
|
const removeCouponHandler = react.useCallback(async () => {
|
|
411
936
|
if (!appliedCoupon) return;
|
|
412
937
|
try {
|
|
413
|
-
await
|
|
938
|
+
await chunkTFWTQTWE_cjs.removeCheckoutCoupon(appliedCoupon.coupon_code, callbacks);
|
|
414
939
|
setAppliedCoupon(null);
|
|
415
940
|
setError(null);
|
|
416
941
|
} catch {
|
|
@@ -508,9 +1033,9 @@ function useVariantSelector(options) {
|
|
|
508
1033
|
};
|
|
509
1034
|
}
|
|
510
1035
|
function useShopCheckout(options) {
|
|
511
|
-
const { product, onNavigateToCart, onToast } = options;
|
|
512
|
-
const { addToCart, setCart } =
|
|
513
|
-
const isUserAuthenticated =
|
|
1036
|
+
const { product, onNavigateToCart, onToast, onPreorderRejected } = options;
|
|
1037
|
+
const { addToCart, setCart } = chunkCIBMO44U_cjs.useCartStore();
|
|
1038
|
+
const isUserAuthenticated = chunkCIBMO44U_cjs.useAuthStore((s) => s.isAuthenticated);
|
|
514
1039
|
const [isWishlisted, setIsWishlisted] = react.useState(product.is_wishlisted);
|
|
515
1040
|
const [isAddedToCart, setIsAddedToCart] = react.useState(false);
|
|
516
1041
|
const [loading, setLoading] = react.useState(false);
|
|
@@ -521,7 +1046,7 @@ function useShopCheckout(options) {
|
|
|
521
1046
|
react.useEffect(() => {
|
|
522
1047
|
const fetchCategories = async () => {
|
|
523
1048
|
try {
|
|
524
|
-
const response = await
|
|
1049
|
+
const response = await chunkETXIP5XE_cjs.getCategories();
|
|
525
1050
|
setCategories(response.data);
|
|
526
1051
|
} catch (error) {
|
|
527
1052
|
console.log(error);
|
|
@@ -543,13 +1068,18 @@ function useShopCheckout(options) {
|
|
|
543
1068
|
await addToCart([{ variant_id: product.id, quantity }]);
|
|
544
1069
|
setIsAddedToCart(true);
|
|
545
1070
|
} catch (error) {
|
|
546
|
-
|
|
1071
|
+
const code = error?.response?.data?.error_code;
|
|
1072
|
+
if (code === "PREORDER_DIRECT_ONLY" && onPreorderRejected) {
|
|
1073
|
+
onPreorderRejected();
|
|
1074
|
+
} else {
|
|
1075
|
+
console.log(error);
|
|
1076
|
+
}
|
|
547
1077
|
} finally {
|
|
548
1078
|
setLoading(false);
|
|
549
1079
|
}
|
|
550
1080
|
} else {
|
|
551
|
-
|
|
552
|
-
const localCartItems =
|
|
1081
|
+
chunkNQZ5GUOG_cjs.cart_default.add(product, quantity);
|
|
1082
|
+
const localCartItems = chunkNQZ5GUOG_cjs.cart_default.get();
|
|
553
1083
|
if (localCartItems) {
|
|
554
1084
|
setCart(localCartItems);
|
|
555
1085
|
}
|
|
@@ -562,7 +1092,8 @@ function useShopCheckout(options) {
|
|
|
562
1092
|
quantity,
|
|
563
1093
|
addToCart,
|
|
564
1094
|
setCart,
|
|
565
|
-
onNavigateToCart
|
|
1095
|
+
onNavigateToCart,
|
|
1096
|
+
onPreorderRejected
|
|
566
1097
|
]);
|
|
567
1098
|
const handleCustomizationSubmit = react.useCallback(
|
|
568
1099
|
async (data) => {
|
|
@@ -594,8 +1125,8 @@ function useShopCheckout(options) {
|
|
|
594
1125
|
setLoading(false);
|
|
595
1126
|
}
|
|
596
1127
|
} else {
|
|
597
|
-
|
|
598
|
-
const localCartItems =
|
|
1128
|
+
chunkNQZ5GUOG_cjs.cart_default.add(product, quantity);
|
|
1129
|
+
const localCartItems = chunkNQZ5GUOG_cjs.cart_default.get();
|
|
599
1130
|
if (localCartItems) {
|
|
600
1131
|
setCart(localCartItems);
|
|
601
1132
|
}
|
|
@@ -635,7 +1166,7 @@ function useShopCheckout(options) {
|
|
|
635
1166
|
const handleNotifyMeFormSubmit = react.useCallback(
|
|
636
1167
|
async (values) => {
|
|
637
1168
|
try {
|
|
638
|
-
const response = await
|
|
1169
|
+
const response = await chunkETXIP5XE_cjs.notifyProductStock({
|
|
639
1170
|
...values,
|
|
640
1171
|
variant_slug: product.slug
|
|
641
1172
|
});
|
|
@@ -772,7 +1303,9 @@ Object.defineProperty(exports, "useAddressForm", {
|
|
|
772
1303
|
enumerable: true,
|
|
773
1304
|
get: function () { return chunkIVKJJLG7_cjs.useAddressForm; }
|
|
774
1305
|
});
|
|
1306
|
+
exports.BUY_NOW_PAYLOAD_KEY = BUY_NOW_PAYLOAD_KEY;
|
|
775
1307
|
exports.useAddress = useAddress;
|
|
1308
|
+
exports.useBuyNow = useBuyNow;
|
|
776
1309
|
exports.useCart = useCart;
|
|
777
1310
|
exports.useCheckoutCoupon = useCheckoutCoupon;
|
|
778
1311
|
exports.useCheckoutPayment = useCheckoutPayment;
|
|
@@ -780,8 +1313,10 @@ exports.useCoupon = useCoupon;
|
|
|
780
1313
|
exports.useGetProductCategories = useGetProductCategories;
|
|
781
1314
|
exports.useGetProductDetails = useGetProductDetails;
|
|
782
1315
|
exports.useGetProducts = useGetProducts;
|
|
1316
|
+
exports.useInlineCheckoutPayment = useInlineCheckoutPayment;
|
|
783
1317
|
exports.useOrders = useOrders;
|
|
784
1318
|
exports.useProductDetailModal = useProductDetailModal;
|
|
1319
|
+
exports.usePublicCheckout = usePublicCheckout;
|
|
785
1320
|
exports.useServiceFormModal = useServiceFormModal;
|
|
786
1321
|
exports.useShopCheckout = useShopCheckout;
|
|
787
1322
|
exports.useUserDetails = useUserDetails;
|