@simpleapps-com/augur-hooks 2.3.1 → 2026.11.1
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/EXPORTS.md +25 -65
- package/README.md +21 -246
- package/dist/checkout/create-checkout-provider.d.ts +25 -0
- package/dist/checkout/create-checkout-provider.d.ts.map +1 -0
- package/dist/checkout/index.cjs +123 -106
- package/dist/checkout/index.cjs.map +1 -1
- package/dist/checkout/index.d.ts +5 -293
- package/dist/checkout/index.d.ts.map +1 -0
- package/dist/checkout/index.js +99 -82
- package/dist/checkout/index.js.map +1 -1
- package/dist/checkout/{index.d.cts → types.d.ts} +18 -40
- package/dist/checkout/types.d.ts.map +1 -0
- package/dist/chunk-6Z6JGK2C.cjs.map +1 -1
- package/dist/chunk-QB7VB5FZ.cjs +523 -0
- package/dist/chunk-QB7VB5FZ.cjs.map +1 -0
- package/dist/{chunk-NRWH2BMN.js → chunk-UTDAFIQP.js} +237 -91
- package/dist/chunk-UTDAFIQP.js.map +1 -0
- package/dist/hooks/use-cart-actions.d.ts +68 -0
- package/dist/hooks/use-cart-actions.d.ts.map +1 -0
- package/dist/hooks/use-cart-initialization.d.ts +60 -0
- package/dist/hooks/use-cart-initialization.d.ts.map +1 -0
- package/dist/hooks/use-cart-pricing.d.ts +41 -0
- package/dist/hooks/use-cart-pricing.d.ts.map +1 -0
- package/dist/hooks/use-checkout-persistence.d.ts +40 -0
- package/dist/hooks/use-checkout-persistence.d.ts.map +1 -0
- package/dist/hooks/use-debounce.d.ts +6 -0
- package/dist/hooks/use-debounce.d.ts.map +1 -0
- package/dist/hooks/use-format-price.d.ts +29 -0
- package/dist/hooks/use-format-price.d.ts.map +1 -0
- package/dist/hooks/use-latest.d.ts +8 -0
- package/dist/hooks/use-latest.d.ts.map +1 -0
- package/dist/hooks/use-modal-lifecycle.d.ts +11 -0
- package/dist/hooks/use-modal-lifecycle.d.ts.map +1 -0
- package/dist/hooks/use-order-readiness.d.ts +47 -0
- package/dist/hooks/use-order-readiness.d.ts.map +1 -0
- package/dist/hooks/use-pagination-prefetch.d.ts +26 -0
- package/dist/hooks/use-pagination-prefetch.d.ts.map +1 -0
- package/dist/{use-order-readiness-DZTIfRzw.d.ts → hooks/use-payment-flow.d.ts} +23 -67
- package/dist/hooks/use-payment-flow.d.ts.map +1 -0
- package/dist/hooks/use-stock.d.ts +32 -0
- package/dist/hooks/use-stock.d.ts.map +1 -0
- package/dist/index.cjs +251 -192
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +32 -456
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +230 -171
- package/dist/index.js.map +1 -1
- package/dist/persistence/apply-limits.d.ts +8 -0
- package/dist/persistence/apply-limits.d.ts.map +1 -0
- package/dist/persistence/create-persister.d.ts +10 -0
- package/dist/persistence/create-persister.d.ts.map +1 -0
- package/dist/persistence/serializer.d.ts +11 -0
- package/dist/persistence/serializer.d.ts.map +1 -0
- package/dist/persistence/use-persistence.d.ts +59 -0
- package/dist/persistence/use-persistence.d.ts.map +1 -0
- package/dist/persistence/use-storage-monitor.d.ts +11 -0
- package/dist/persistence/use-storage-monitor.d.ts.map +1 -0
- package/dist/provider.d.ts +89 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/queries/batch-query.d.ts +23 -0
- package/dist/queries/batch-query.d.ts.map +1 -0
- package/dist/queries/cache-helper.d.ts +16 -0
- package/dist/queries/cache-helper.d.ts.map +1 -0
- package/dist/queries/index.d.ts +3 -0
- package/dist/queries/index.d.ts.map +1 -0
- package/dist/query-action-registry.d.ts +19 -0
- package/dist/query-action-registry.d.ts.map +1 -0
- package/dist/rules.d.ts +130 -0
- package/dist/rules.d.ts.map +1 -0
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +10 -12
- package/dist/server.d.ts.map +1 -0
- package/dist/stores/cart-store.d.ts +51 -0
- package/dist/stores/cart-store.d.ts.map +1 -0
- package/dist/stores/items-filters-store.d.ts +30 -0
- package/dist/stores/items-filters-store.d.ts.map +1 -0
- package/dist/types.d.ts +48 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/web/use-image-with-fallback.d.ts +16 -0
- package/dist/web/use-image-with-fallback.d.ts.map +1 -0
- package/dist/web/use-mobile-detection.d.ts +28 -0
- package/dist/web/use-mobile-detection.d.ts.map +1 -0
- package/dist/web/use-mobile-optimized-intersection.d.ts +17 -0
- package/dist/web/use-mobile-optimized-intersection.d.ts.map +1 -0
- package/dist/web.cjs.map +1 -1
- package/dist/web.d.ts +4 -60
- package/dist/web.d.ts.map +1 -0
- package/dist/web.js.map +1 -1
- package/llms.txt +76 -54
- package/package.json +25 -14
- package/dist/batch-query-CTlvxSmL.d.cts +0 -165
- package/dist/batch-query-CTlvxSmL.d.ts +0 -165
- package/dist/chunk-I4A5L2I6.cjs +0 -377
- package/dist/chunk-I4A5L2I6.cjs.map +0 -1
- package/dist/chunk-NRWH2BMN.js.map +0 -1
- package/dist/index.d.cts +0 -456
- package/dist/server.d.cts +0 -44
- package/dist/use-order-readiness-DZTIfRzw.d.cts +0 -137
- package/dist/web.d.cts +0 -60
|
@@ -1,6 +1,98 @@
|
|
|
1
1
|
// src/stores/cart-store.ts
|
|
2
2
|
import { create } from "zustand";
|
|
3
3
|
import { devtools } from "zustand/middleware";
|
|
4
|
+
|
|
5
|
+
// ../utils/src/strings.ts
|
|
6
|
+
function codeAt(s, i) {
|
|
7
|
+
return i >= 0 && i < s.length ? s.charCodeAt(i) : -1;
|
|
8
|
+
}
|
|
9
|
+
function indexOfCode(s, code, from) {
|
|
10
|
+
const c = codeAt(s, from);
|
|
11
|
+
if (c === code) return from;
|
|
12
|
+
if (c === -1) return -1;
|
|
13
|
+
return indexOfCode(s, code, from + 1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/rules.ts
|
|
17
|
+
function quantityTotalFrom(quantities, i, acc) {
|
|
18
|
+
if (i === quantities.length) return acc;
|
|
19
|
+
return quantityTotalFrom(quantities, i + 1, acc + quantities[i]);
|
|
20
|
+
}
|
|
21
|
+
function qtyOrZero(q) {
|
|
22
|
+
if (q === null) return 0;
|
|
23
|
+
return q;
|
|
24
|
+
}
|
|
25
|
+
function indexOfUidFrom(uids, uid, i) {
|
|
26
|
+
if (i === uids.length) return -1;
|
|
27
|
+
if (uids[i] === uid) return i;
|
|
28
|
+
return indexOfUidFrom(uids, uid, i + 1);
|
|
29
|
+
}
|
|
30
|
+
function keepsAfterReverse(current, q) {
|
|
31
|
+
return qtyOrZero(current) - q > 0;
|
|
32
|
+
}
|
|
33
|
+
function requiredCartUid(uid) {
|
|
34
|
+
if (uid === void 0) return null;
|
|
35
|
+
if (uid === 0) return null;
|
|
36
|
+
return uid;
|
|
37
|
+
}
|
|
38
|
+
function checkoutCartUid(uid) {
|
|
39
|
+
if (uid === void 0) return 0;
|
|
40
|
+
return uid;
|
|
41
|
+
}
|
|
42
|
+
function defaultPaymentMethodOf(fromHook, hasCallbacks) {
|
|
43
|
+
if (fromHook !== void 0 && fromHook !== "") return fromHook;
|
|
44
|
+
return hasCallbacks ? "credit-card" : "invoice";
|
|
45
|
+
}
|
|
46
|
+
function defaultReady(r) {
|
|
47
|
+
return nothingBusy(r) && detailsComplete(r) && paymentSettled(r);
|
|
48
|
+
}
|
|
49
|
+
function nothingBusy(r) {
|
|
50
|
+
return !r.editShippingInfo && !r.editShippingMethods && !r.editBillingInfo && !r.editCc && !r.processing;
|
|
51
|
+
}
|
|
52
|
+
function detailsComplete(r) {
|
|
53
|
+
return r.cartUidSet && r.hasShippingAddress && r.hasBillingAddress && r.methodSaved && r.showBillingSummary;
|
|
54
|
+
}
|
|
55
|
+
function paymentSettled(r) {
|
|
56
|
+
return (!r.isCreditCard || r.hasAccountId && r.hasUnifiedBilling) && (r.isFreeShipping || r.hasShippingFee);
|
|
57
|
+
}
|
|
58
|
+
function orderReadyOf(custom, ready) {
|
|
59
|
+
if (custom !== void 0) return custom;
|
|
60
|
+
return ready;
|
|
61
|
+
}
|
|
62
|
+
function preSubmitOutcome(validateError, beforeSubmitFalse, hasShippingAddress) {
|
|
63
|
+
if (validateError !== void 0 && validateError !== "") {
|
|
64
|
+
return { kind: "refused", message: validateError };
|
|
65
|
+
}
|
|
66
|
+
if (beforeSubmitFalse) return { kind: "cancelled" };
|
|
67
|
+
if (!hasShippingAddress) return { kind: "refused", message: "Shipping address is required." };
|
|
68
|
+
return { kind: "ok" };
|
|
69
|
+
}
|
|
70
|
+
function secondEqualsField(s) {
|
|
71
|
+
const k = indexOfCode(s, 61, 0);
|
|
72
|
+
if (k < 0) return "";
|
|
73
|
+
const j = indexOfCode(s, 61, k + 1);
|
|
74
|
+
if (j < 0) return s.slice(k + 1);
|
|
75
|
+
return s.slice(k + 1, j);
|
|
76
|
+
}
|
|
77
|
+
function isExpired(now, savedAt, ttl) {
|
|
78
|
+
return now - savedAt > ttl;
|
|
79
|
+
}
|
|
80
|
+
function shouldPersistOf(hasHead, succeeded, listed) {
|
|
81
|
+
return hasHead && succeeded && listed;
|
|
82
|
+
}
|
|
83
|
+
function pow2(n) {
|
|
84
|
+
if (n === 0) return 1;
|
|
85
|
+
return 2 * pow2(n - 1);
|
|
86
|
+
}
|
|
87
|
+
function stockRetryDelay(attemptIndex) {
|
|
88
|
+
if (attemptIndex >= 4) return 1e4;
|
|
89
|
+
return 1e3 * pow2(attemptIndex);
|
|
90
|
+
}
|
|
91
|
+
function stockEnabled(enabled, uidSet) {
|
|
92
|
+
return (enabled === void 0 || enabled === true) && uidSet;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/stores/cart-store.ts
|
|
4
96
|
var useCartStore = create()(
|
|
5
97
|
devtools(
|
|
6
98
|
(set) => ({
|
|
@@ -10,7 +102,8 @@ var useCartStore = create()(
|
|
|
10
102
|
cartLineCount: 0,
|
|
11
103
|
setCartHdrUid: (cartHdrUid) => set({ cartHdrUid }, false, "setCartHdrUid"),
|
|
12
104
|
setCartLines: (cartLines) => {
|
|
13
|
-
const
|
|
105
|
+
const quantities = cartLines.map((line) => line.quantity || 0);
|
|
106
|
+
const cartQuantityTotal = quantityTotalFrom(quantities, 0, 0);
|
|
14
107
|
const cartLineCount = cartLines.length;
|
|
15
108
|
set({ cartLines, cartQuantityTotal, cartLineCount }, false, "setCartLines");
|
|
16
109
|
},
|
|
@@ -46,7 +139,7 @@ function loadFromSession(key, ttl = DEFAULT_TTL, validate) {
|
|
|
46
139
|
const raw = sessionStorage.getItem(key);
|
|
47
140
|
if (!raw) return null;
|
|
48
141
|
const entry = JSON.parse(raw);
|
|
49
|
-
if (Date.now()
|
|
142
|
+
if (isExpired(Date.now(), entry.savedAt, ttl)) {
|
|
50
143
|
sessionStorage.removeItem(key);
|
|
51
144
|
return null;
|
|
52
145
|
}
|
|
@@ -78,7 +171,7 @@ function useCheckoutPersistence(fields) {
|
|
|
78
171
|
}, []);
|
|
79
172
|
const serialized = JSON.stringify(fields.map((f) => [f.key, f.value]));
|
|
80
173
|
useEffect(() => {
|
|
81
|
-
for (const field of
|
|
174
|
+
for (const field of fieldsRef.current) {
|
|
82
175
|
if (field.value !== void 0 && field.value !== null) {
|
|
83
176
|
saveToSession(field.key, field.value);
|
|
84
177
|
}
|
|
@@ -94,6 +187,23 @@ function clearCheckoutPersistence(keys) {
|
|
|
94
187
|
// src/hooks/use-payment-flow.ts
|
|
95
188
|
import { useCallback, useEffect as useEffect2, useRef as useRef2, useState } from "react";
|
|
96
189
|
var PAYMENT_STORAGE_KEY = "checkout:payment";
|
|
190
|
+
function toastError(callbacks, message) {
|
|
191
|
+
callbacks.toast?.error?.(message);
|
|
192
|
+
}
|
|
193
|
+
function withCapturedBin(account, capturedBin) {
|
|
194
|
+
return capturedBin && !account.Bin ? { ...account, Bin: capturedBin } : account;
|
|
195
|
+
}
|
|
196
|
+
function paymentToPersist(transactionSetupId, uiEndpoint, account, persistPayment) {
|
|
197
|
+
if (!persistPayment || !account.PaymentAccountID) return null;
|
|
198
|
+
return {
|
|
199
|
+
transactionSetupId,
|
|
200
|
+
uiEndpoint,
|
|
201
|
+
paymentAccountId: account.PaymentAccountID
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function isRestorable(saved) {
|
|
205
|
+
return Boolean(saved?.transactionSetupId && saved.uiEndpoint && saved.paymentAccountId);
|
|
206
|
+
}
|
|
97
207
|
function usePaymentFlow({
|
|
98
208
|
callbacks,
|
|
99
209
|
customerId,
|
|
@@ -115,6 +225,7 @@ function usePaymentFlow({
|
|
|
115
225
|
}, []);
|
|
116
226
|
const customerIdRef = useRef2(customerId);
|
|
117
227
|
customerIdRef.current = customerId;
|
|
228
|
+
const hasVerifiedRef = useRef2(null);
|
|
118
229
|
const postUnified = useCallback(async () => {
|
|
119
230
|
if (!customerIdRef.current) return;
|
|
120
231
|
try {
|
|
@@ -122,47 +233,50 @@ function usePaymentFlow({
|
|
|
122
233
|
customerId: String(customerIdRef.current)
|
|
123
234
|
});
|
|
124
235
|
if (!result) {
|
|
125
|
-
callbacks
|
|
236
|
+
toastError(callbacks, "Unable to initialize payment. Please try again.");
|
|
126
237
|
return;
|
|
127
238
|
}
|
|
128
239
|
setUnified(result);
|
|
129
240
|
} catch (error) {
|
|
130
241
|
console.error("transactionSetup failed:", error);
|
|
131
|
-
callbacks
|
|
242
|
+
toastError(callbacks, "Unable to initialize payment. Please try again.");
|
|
132
243
|
}
|
|
133
244
|
}, [callbacks]);
|
|
134
|
-
const getCardInfo = useCallback(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
245
|
+
const getCardInfo = useCallback(
|
|
246
|
+
async (transactionSetupId) => {
|
|
247
|
+
try {
|
|
248
|
+
const result = await callbacks.cardInfo({ transactionSetupId });
|
|
249
|
+
if (!result) {
|
|
250
|
+
toastError(callbacks, "Unable to verify card details. Please try again.");
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
setUnifiedCc(result);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
console.error("cardInfo failed:", error);
|
|
256
|
+
toastError(callbacks, "Unable to verify card details. Please try again.");
|
|
141
257
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
callbacks.toast?.error?.("Unable to verify card details. Please try again.");
|
|
146
|
-
}
|
|
147
|
-
}, [unified, callbacks]);
|
|
258
|
+
},
|
|
259
|
+
[callbacks]
|
|
260
|
+
);
|
|
148
261
|
const verifyUnified = useCallback(async () => {
|
|
149
|
-
|
|
262
|
+
const transactionSetupId = unified?.transactionSetupId;
|
|
263
|
+
if (!transactionSetupId || !customerIdRef.current) return;
|
|
150
264
|
try {
|
|
151
265
|
const result = await callbacks.validatePayment({
|
|
152
|
-
transactionSetupId
|
|
266
|
+
transactionSetupId,
|
|
153
267
|
customerId: String(customerIdRef.current)
|
|
154
268
|
});
|
|
155
|
-
if (
|
|
156
|
-
callbacks
|
|
269
|
+
if (result === void 0) {
|
|
270
|
+
toastError(callbacks, "Payment verification failed. Please try again.");
|
|
157
271
|
return;
|
|
158
272
|
}
|
|
159
|
-
setUnifiedResponse(result
|
|
160
|
-
if (result
|
|
161
|
-
await getCardInfo();
|
|
273
|
+
setUnifiedResponse(result);
|
|
274
|
+
if (result) {
|
|
275
|
+
await getCardInfo(transactionSetupId);
|
|
162
276
|
}
|
|
163
277
|
} catch (error) {
|
|
164
278
|
console.error("validatePayment failed:", error);
|
|
165
|
-
callbacks
|
|
279
|
+
toastError(callbacks, "Payment verification failed. Please try again.");
|
|
166
280
|
}
|
|
167
281
|
}, [unified, getCardInfo, callbacks]);
|
|
168
282
|
const getUnifiedPayment = useCallback(async () => {
|
|
@@ -173,44 +287,46 @@ function usePaymentFlow({
|
|
|
173
287
|
customerId: String(customerIdRef.current)
|
|
174
288
|
});
|
|
175
289
|
if (!result) {
|
|
176
|
-
callbacks
|
|
290
|
+
toastError(callbacks, "Unable to retrieve payment account. Please try again.");
|
|
177
291
|
return;
|
|
178
292
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
293
|
+
setUnifiedPayment(withCapturedBin(result, capturedBin));
|
|
294
|
+
const toPersist = paymentToPersist(
|
|
295
|
+
unified.transactionSetupId,
|
|
296
|
+
unified.uiEndpoint,
|
|
297
|
+
result,
|
|
298
|
+
persistPayment
|
|
299
|
+
);
|
|
300
|
+
if (toPersist) saveToSession(PAYMENT_STORAGE_KEY, toPersist);
|
|
187
301
|
} catch (error) {
|
|
188
302
|
console.error("accountQuery failed:", error);
|
|
189
|
-
callbacks
|
|
303
|
+
toastError(callbacks, "Unable to retrieve payment account. Please try again.");
|
|
190
304
|
}
|
|
191
305
|
}, [unified, capturedBin, callbacks, persistPayment]);
|
|
192
|
-
const updateUnifiedBilling = useCallback(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
306
|
+
const updateUnifiedBilling = useCallback(
|
|
307
|
+
async (transactionSetupId, address) => {
|
|
308
|
+
try {
|
|
309
|
+
const result = await callbacks.billingUpdate({
|
|
310
|
+
transactionSetupId,
|
|
311
|
+
address1: address.address1,
|
|
312
|
+
address2: address.address2,
|
|
313
|
+
city: address.city,
|
|
314
|
+
state: address.state,
|
|
315
|
+
zip: address.postalCode
|
|
316
|
+
});
|
|
317
|
+
if (!result) {
|
|
318
|
+
toastError(callbacks, "Billing update failed. Please try again.");
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
setUnifiedBilling(true);
|
|
322
|
+
void getUnifiedPayment();
|
|
323
|
+
} catch (error) {
|
|
324
|
+
console.error("billingUpdate failed:", error);
|
|
325
|
+
toastError(callbacks, "Billing update failed. Please try again.");
|
|
206
326
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
console.error("billingUpdate failed:", error);
|
|
211
|
-
callbacks.toast?.error?.("Billing update failed. Please try again.");
|
|
212
|
-
}
|
|
213
|
-
}, [unified, billingAddress, getUnifiedPayment, callbacks]);
|
|
327
|
+
},
|
|
328
|
+
[getUnifiedPayment, callbacks]
|
|
329
|
+
);
|
|
214
330
|
useEffect2(() => {
|
|
215
331
|
if (isOpen && (!shippingAccepted || paymentMethod !== "credit-card")) {
|
|
216
332
|
setIsOpen(false);
|
|
@@ -222,20 +338,25 @@ function usePaymentFlow({
|
|
|
222
338
|
}
|
|
223
339
|
}, [isOpen, shippingAccepted, paymentMethod, unified, postUnified]);
|
|
224
340
|
useEffect2(() => {
|
|
225
|
-
|
|
341
|
+
const setupId2 = unified?.transactionSetupId;
|
|
342
|
+
if (!isOpen && setupId2 && shippingAccepted && paymentMethod === "credit-card") {
|
|
343
|
+
if (hasVerifiedRef.current === setupId2) return;
|
|
344
|
+
hasVerifiedRef.current = setupId2;
|
|
226
345
|
void verifyUnified();
|
|
227
346
|
}
|
|
228
347
|
}, [isOpen, unified, shippingAccepted, paymentMethod, verifyUnified]);
|
|
348
|
+
const setupId = unified?.transactionSetupId;
|
|
229
349
|
useEffect2(() => {
|
|
230
|
-
if (unifiedResponse && billingAddress !== void 0 && unifiedCc?.transactionSetupId && paymentMethod === "credit-card") {
|
|
231
|
-
void updateUnifiedBilling();
|
|
350
|
+
if (unifiedResponse && billingAddress !== void 0 && unifiedCc?.transactionSetupId && paymentMethod === "credit-card" && setupId) {
|
|
351
|
+
void updateUnifiedBilling(setupId, billingAddress);
|
|
232
352
|
}
|
|
233
353
|
}, [
|
|
234
354
|
unifiedResponse,
|
|
235
355
|
billingAddress,
|
|
236
356
|
unifiedCc?.transactionSetupId,
|
|
237
357
|
updateUnifiedBilling,
|
|
238
|
-
paymentMethod
|
|
358
|
+
paymentMethod,
|
|
359
|
+
setupId
|
|
239
360
|
]);
|
|
240
361
|
useEffect2(() => {
|
|
241
362
|
if (editCc) {
|
|
@@ -246,6 +367,7 @@ function usePaymentFlow({
|
|
|
246
367
|
setUnifiedBilling(false);
|
|
247
368
|
setUnifiedResponse(false);
|
|
248
369
|
setCapturedBin(null);
|
|
370
|
+
hasVerifiedRef.current = null;
|
|
249
371
|
if (persistPayment) {
|
|
250
372
|
clearFromSession(PAYMENT_STORAGE_KEY);
|
|
251
373
|
}
|
|
@@ -254,8 +376,8 @@ function usePaymentFlow({
|
|
|
254
376
|
const restorePayment = useCallback(async () => {
|
|
255
377
|
if (!customerIdRef.current) return;
|
|
256
378
|
const saved = loadFromSession(PAYMENT_STORAGE_KEY);
|
|
257
|
-
if (!saved
|
|
258
|
-
const { transactionSetupId } = saved;
|
|
379
|
+
if (!isRestorable(saved)) return;
|
|
380
|
+
const { transactionSetupId, uiEndpoint } = saved;
|
|
259
381
|
try {
|
|
260
382
|
const account = await callbacks.accountQuery({
|
|
261
383
|
transactionSetupId,
|
|
@@ -265,7 +387,8 @@ function usePaymentFlow({
|
|
|
265
387
|
clearFromSession(PAYMENT_STORAGE_KEY);
|
|
266
388
|
return;
|
|
267
389
|
}
|
|
268
|
-
|
|
390
|
+
hasVerifiedRef.current = transactionSetupId;
|
|
391
|
+
setUnified({ transactionSetupId, uiEndpoint });
|
|
269
392
|
setUnifiedPayment(account);
|
|
270
393
|
setUnifiedResponse(true);
|
|
271
394
|
setUnifiedBilling(true);
|
|
@@ -275,9 +398,11 @@ function usePaymentFlow({
|
|
|
275
398
|
clearFromSession(PAYMENT_STORAGE_KEY);
|
|
276
399
|
}
|
|
277
400
|
}, [callbacks]);
|
|
401
|
+
const restorePaymentRef = useRef2(restorePayment);
|
|
402
|
+
restorePaymentRef.current = restorePayment;
|
|
278
403
|
useEffect2(() => {
|
|
279
404
|
if (persistPayment) {
|
|
280
|
-
void
|
|
405
|
+
void restorePaymentRef.current();
|
|
281
406
|
}
|
|
282
407
|
}, [persistPayment]);
|
|
283
408
|
return {
|
|
@@ -297,44 +422,53 @@ function usePaymentFlow({
|
|
|
297
422
|
|
|
298
423
|
// src/hooks/use-order-readiness.ts
|
|
299
424
|
import { useEffect as useEffect3, useState as useState2 } from "react";
|
|
425
|
+
|
|
426
|
+
// src/hooks/use-latest.ts
|
|
427
|
+
import { useRef as useRef3 } from "react";
|
|
428
|
+
function useLatest(value) {
|
|
429
|
+
const ref = useRef3(value);
|
|
430
|
+
ref.current = value;
|
|
431
|
+
return ref;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// src/hooks/use-order-readiness.ts
|
|
300
435
|
function determineOrderReadiness(params) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
params.
|
|
308
|
-
params.
|
|
309
|
-
params.
|
|
310
|
-
params.
|
|
311
|
-
params.
|
|
312
|
-
params.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
params.
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
if (!params.isFreeShipping && params.shippingFee === void 0) {
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
|
-
return true;
|
|
436
|
+
return orderReadyOf(params.customReadinessCheck?.(params), defaultReady(readinessFlags(params)));
|
|
437
|
+
}
|
|
438
|
+
function readinessFlags(params) {
|
|
439
|
+
return {
|
|
440
|
+
cartUidSet: !!params.cartHdrUid,
|
|
441
|
+
editShippingInfo: params.isEditShippingInfo,
|
|
442
|
+
editShippingMethods: params.isEditShippingMethods,
|
|
443
|
+
editBillingInfo: params.isEditBillingInfo,
|
|
444
|
+
editCc: params.editCc,
|
|
445
|
+
hasShippingAddress: params.shippingAddress !== void 0,
|
|
446
|
+
hasBillingAddress: params.billingAddress !== void 0,
|
|
447
|
+
methodSaved: params.shippingMethodSaved,
|
|
448
|
+
showBillingSummary: params.showBillingInfoSummary,
|
|
449
|
+
processing: params.processingOrder,
|
|
450
|
+
isCreditCard: params.paymentMethod === "credit-card",
|
|
451
|
+
hasAccountId: !!params.unifiedPaymentAccountId,
|
|
452
|
+
hasUnifiedBilling: params.unifiedBilling,
|
|
453
|
+
isFreeShipping: params.isFreeShipping,
|
|
454
|
+
hasShippingFee: params.shippingFee !== void 0
|
|
455
|
+
};
|
|
325
456
|
}
|
|
326
457
|
function useOrderReadiness(params) {
|
|
327
458
|
const [enableProcessOrderBtn, setEnableProcessOrderBtn] = useState2(false);
|
|
328
459
|
const [processingValidation, setProcessingValidation] = useState2(false);
|
|
460
|
+
const paramsRef = useLatest(params);
|
|
329
461
|
useEffect3(() => {
|
|
330
462
|
setProcessingValidation(true);
|
|
463
|
+
const current = paramsRef.current;
|
|
331
464
|
const timeoutId = setTimeout(() => {
|
|
332
|
-
const ready = determineOrderReadiness(
|
|
465
|
+
const ready = determineOrderReadiness(current);
|
|
333
466
|
setEnableProcessOrderBtn(ready);
|
|
334
467
|
setProcessingValidation(false);
|
|
335
468
|
}, 300);
|
|
336
469
|
return () => clearTimeout(timeoutId);
|
|
337
470
|
}, [
|
|
471
|
+
paramsRef,
|
|
338
472
|
params.billingAddress,
|
|
339
473
|
params.shippingAddress,
|
|
340
474
|
params.isEditShippingInfo,
|
|
@@ -356,6 +490,18 @@ function useOrderReadiness(params) {
|
|
|
356
490
|
}
|
|
357
491
|
|
|
358
492
|
export {
|
|
493
|
+
useLatest,
|
|
494
|
+
qtyOrZero,
|
|
495
|
+
indexOfUidFrom,
|
|
496
|
+
keepsAfterReverse,
|
|
497
|
+
requiredCartUid,
|
|
498
|
+
checkoutCartUid,
|
|
499
|
+
defaultPaymentMethodOf,
|
|
500
|
+
preSubmitOutcome,
|
|
501
|
+
secondEqualsField,
|
|
502
|
+
shouldPersistOf,
|
|
503
|
+
stockRetryDelay,
|
|
504
|
+
stockEnabled,
|
|
359
505
|
useCartStore,
|
|
360
506
|
useCartHdrUid,
|
|
361
507
|
useCartLines,
|
|
@@ -374,4 +520,4 @@ export {
|
|
|
374
520
|
determineOrderReadiness,
|
|
375
521
|
useOrderReadiness
|
|
376
522
|
};
|
|
377
|
-
//# sourceMappingURL=chunk-
|
|
523
|
+
//# sourceMappingURL=chunk-UTDAFIQP.js.map
|