@simpleapps-com/augur-hooks 2.4.0 → 2026.11.2
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-JJX23M5N.js +532 -0
- package/dist/chunk-JJX23M5N.js.map +1 -0
- package/dist/chunk-UZAFXUAO.cjs +532 -0
- package/dist/chunk-UZAFXUAO.cjs.map +1 -0
- package/dist/duration.d.ts +16 -0
- package/dist/duration.d.ts.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 +41 -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 +27 -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 +227 -184
- 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 +205 -162
- 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/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 +133 -0
- package/dist/rules.d.ts.map +1 -0
- package/dist/server.cjs +2 -1
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +10 -12
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +2 -1
- package/dist/server.js.map +1 -1
- 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 +26 -14
- package/dist/batch-query-CTlvxSmL.d.cts +0 -165
- package/dist/batch-query-CTlvxSmL.d.ts +0 -165
- package/dist/chunk-F5DUFW57.cjs +0 -383
- package/dist/chunk-F5DUFW57.cjs.map +0 -1
- package/dist/chunk-JNOHB4OP.js +0 -383
- package/dist/chunk-JNOHB4OP.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
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/stores/cart-store.ts
|
|
2
|
+
var _zustand = require('zustand');
|
|
3
|
+
var _middleware = require('zustand/middleware');
|
|
4
|
+
|
|
5
|
+
// ../foundation/src/duration.ts
|
|
6
|
+
function seconds(n) {
|
|
7
|
+
return n;
|
|
8
|
+
}
|
|
9
|
+
function toMillis(d) {
|
|
10
|
+
return d * 1e3;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// ../utils/src/strings.ts
|
|
14
|
+
function codeAt(s, i) {
|
|
15
|
+
return i >= 0 && i < s.length ? s.charCodeAt(i) : -1;
|
|
16
|
+
}
|
|
17
|
+
function indexOfCode(s, code, from) {
|
|
18
|
+
const c = codeAt(s, from);
|
|
19
|
+
if (c === code) return from;
|
|
20
|
+
if (c === -1) return -1;
|
|
21
|
+
return indexOfCode(s, code, from + 1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/rules.ts
|
|
25
|
+
function quantityTotalFrom(quantities, i, acc) {
|
|
26
|
+
if (i === quantities.length) return acc;
|
|
27
|
+
return quantityTotalFrom(quantities, i + 1, acc + quantities[i]);
|
|
28
|
+
}
|
|
29
|
+
function qtyOrZero(q) {
|
|
30
|
+
if (q === null) return 0;
|
|
31
|
+
return q;
|
|
32
|
+
}
|
|
33
|
+
function indexOfUidFrom(uids, uid, i) {
|
|
34
|
+
if (i === uids.length) return -1;
|
|
35
|
+
if (uids[i] === uid) return i;
|
|
36
|
+
return indexOfUidFrom(uids, uid, i + 1);
|
|
37
|
+
}
|
|
38
|
+
function keepsAfterReverse(current, q) {
|
|
39
|
+
return qtyOrZero(current) - q > 0;
|
|
40
|
+
}
|
|
41
|
+
function requiredCartUid(uid) {
|
|
42
|
+
if (uid === void 0) return null;
|
|
43
|
+
if (uid === 0) return null;
|
|
44
|
+
return uid;
|
|
45
|
+
}
|
|
46
|
+
function checkoutCartUid(uid) {
|
|
47
|
+
if (uid === void 0) return 0;
|
|
48
|
+
return uid;
|
|
49
|
+
}
|
|
50
|
+
function defaultPaymentMethodOf(fromHook, hasCallbacks) {
|
|
51
|
+
if (fromHook !== void 0 && fromHook !== "") return fromHook;
|
|
52
|
+
return hasCallbacks ? "credit-card" : "invoice";
|
|
53
|
+
}
|
|
54
|
+
function defaultReady(r) {
|
|
55
|
+
return nothingBusy(r) && detailsComplete(r) && paymentSettled(r);
|
|
56
|
+
}
|
|
57
|
+
function nothingBusy(r) {
|
|
58
|
+
return !r.editShippingInfo && !r.editShippingMethods && !r.editBillingInfo && !r.editCc && !r.processing;
|
|
59
|
+
}
|
|
60
|
+
function detailsComplete(r) {
|
|
61
|
+
return r.cartUidSet && r.hasShippingAddress && r.hasBillingAddress && r.methodSaved && r.showBillingSummary;
|
|
62
|
+
}
|
|
63
|
+
function paymentSettled(r) {
|
|
64
|
+
return (!r.isCreditCard || r.hasAccountId && r.hasUnifiedBilling) && (r.isFreeShipping || r.hasShippingFee);
|
|
65
|
+
}
|
|
66
|
+
function orderReadyOf(custom, ready) {
|
|
67
|
+
if (custom !== void 0) return custom;
|
|
68
|
+
return ready;
|
|
69
|
+
}
|
|
70
|
+
function preSubmitOutcome(validateError, beforeSubmitFalse, hasShippingAddress) {
|
|
71
|
+
if (validateError !== void 0 && validateError !== "") {
|
|
72
|
+
return { kind: "refused", message: validateError };
|
|
73
|
+
}
|
|
74
|
+
if (beforeSubmitFalse) return { kind: "cancelled" };
|
|
75
|
+
if (!hasShippingAddress) return { kind: "refused", message: "Shipping address is required." };
|
|
76
|
+
return { kind: "ok" };
|
|
77
|
+
}
|
|
78
|
+
function secondEqualsField(s) {
|
|
79
|
+
const k = indexOfCode(s, 61, 0);
|
|
80
|
+
if (k < 0) return "";
|
|
81
|
+
const j = indexOfCode(s, 61, k + 1);
|
|
82
|
+
if (j < 0) return s.slice(k + 1);
|
|
83
|
+
return s.slice(k + 1, j);
|
|
84
|
+
}
|
|
85
|
+
function isExpired(now, savedAt, ttl) {
|
|
86
|
+
return now - savedAt > ttl;
|
|
87
|
+
}
|
|
88
|
+
function shouldPersistOf(hasHead, succeeded, listed) {
|
|
89
|
+
return hasHead && succeeded && listed;
|
|
90
|
+
}
|
|
91
|
+
function stockRetryDelay(attemptIndex) {
|
|
92
|
+
if (attemptIndex >= 4) return toMillis(seconds(10));
|
|
93
|
+
if (attemptIndex === 3) return toMillis(seconds(8));
|
|
94
|
+
if (attemptIndex === 2) return toMillis(seconds(4));
|
|
95
|
+
if (attemptIndex === 1) return toMillis(seconds(2));
|
|
96
|
+
return toMillis(seconds(1));
|
|
97
|
+
}
|
|
98
|
+
function stockEnabled(enabled, uidSet) {
|
|
99
|
+
return (enabled === void 0 || enabled === true) && uidSet;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/stores/cart-store.ts
|
|
103
|
+
var useCartStore = _zustand.create.call(void 0, )(
|
|
104
|
+
_middleware.devtools.call(void 0,
|
|
105
|
+
(set) => ({
|
|
106
|
+
cartHdrUid: void 0,
|
|
107
|
+
cartLines: [],
|
|
108
|
+
cartQuantityTotal: 0,
|
|
109
|
+
cartLineCount: 0,
|
|
110
|
+
setCartHdrUid: (cartHdrUid) => set({ cartHdrUid }, false, "setCartHdrUid"),
|
|
111
|
+
setCartLines: (cartLines) => {
|
|
112
|
+
const quantities = cartLines.map((line) => line.quantity || 0);
|
|
113
|
+
const cartQuantityTotal = quantityTotalFrom(quantities, 0, 0);
|
|
114
|
+
const cartLineCount = cartLines.length;
|
|
115
|
+
set({ cartLines, cartQuantityTotal, cartLineCount }, false, "setCartLines");
|
|
116
|
+
},
|
|
117
|
+
clearCart: () => set(
|
|
118
|
+
{ cartHdrUid: void 0, cartLines: [], cartQuantityTotal: 0, cartLineCount: 0 },
|
|
119
|
+
false,
|
|
120
|
+
"clearCart"
|
|
121
|
+
)
|
|
122
|
+
}),
|
|
123
|
+
{ name: "CartStore", enabled: process.env["NODE_ENV"] === "development" }
|
|
124
|
+
)
|
|
125
|
+
);
|
|
126
|
+
var useCartHdrUid = () => useCartStore((s) => s.cartHdrUid);
|
|
127
|
+
var useCartLines = () => useCartStore((s) => s.cartLines);
|
|
128
|
+
var useCartQuantityTotal = () => useCartStore((s) => s.cartQuantityTotal);
|
|
129
|
+
var useCartLineCount = () => useCartStore((s) => s.cartLineCount);
|
|
130
|
+
var useSetCartHdrUid = () => useCartStore((s) => s.setCartHdrUid);
|
|
131
|
+
var useSetCartLines = () => useCartStore((s) => s.setCartLines);
|
|
132
|
+
var useClearCart = () => useCartStore((s) => s.clearCart);
|
|
133
|
+
|
|
134
|
+
// src/hooks/use-checkout-persistence.ts
|
|
135
|
+
var _augurutils = require('@simpleapps-com/augur-utils');
|
|
136
|
+
var _react = require('react');
|
|
137
|
+
var DEFAULT_TTL = _augurutils.toMillis.call(void 0, _augurutils.minutes.call(void 0, 30));
|
|
138
|
+
function saveToSession(key, value) {
|
|
139
|
+
try {
|
|
140
|
+
const entry = { value, savedAt: _augurutils.millis.call(void 0, Date.now()) };
|
|
141
|
+
sessionStorage.setItem(key, JSON.stringify(entry));
|
|
142
|
+
} catch (e) {
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function loadFromSession(key, ttl = DEFAULT_TTL, validate) {
|
|
146
|
+
try {
|
|
147
|
+
const raw = sessionStorage.getItem(key);
|
|
148
|
+
if (!raw) return null;
|
|
149
|
+
const entry = JSON.parse(raw);
|
|
150
|
+
const savedAt = _nullishCoalesce(_augurutils.millisOf.call(void 0, entry.savedAt), () => ( _augurutils.millis.call(void 0, 0)));
|
|
151
|
+
if (isExpired(_augurutils.millis.call(void 0, Date.now()), savedAt, ttl)) {
|
|
152
|
+
sessionStorage.removeItem(key);
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
if (validate) {
|
|
156
|
+
return validate(entry.value);
|
|
157
|
+
}
|
|
158
|
+
return entry.value;
|
|
159
|
+
} catch (e2) {
|
|
160
|
+
sessionStorage.removeItem(key);
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function clearFromSession(key) {
|
|
165
|
+
try {
|
|
166
|
+
sessionStorage.removeItem(key);
|
|
167
|
+
} catch (e3) {
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function useCheckoutPersistence(fields) {
|
|
171
|
+
const fieldsRef = _react.useRef.call(void 0, fields);
|
|
172
|
+
fieldsRef.current = fields;
|
|
173
|
+
_react.useEffect.call(void 0, () => {
|
|
174
|
+
for (const field of fieldsRef.current) {
|
|
175
|
+
const restored = loadFromSession(field.key, _nullishCoalesce(field.ttl, () => ( DEFAULT_TTL)), field.validate);
|
|
176
|
+
if (restored !== null) {
|
|
177
|
+
field.set(restored);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}, []);
|
|
181
|
+
const serialized = JSON.stringify(fields.map((f) => [f.key, f.value]));
|
|
182
|
+
_react.useEffect.call(void 0, () => {
|
|
183
|
+
for (const field of fieldsRef.current) {
|
|
184
|
+
if (field.value !== void 0 && field.value !== null) {
|
|
185
|
+
saveToSession(field.key, field.value);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}, [serialized]);
|
|
189
|
+
}
|
|
190
|
+
function clearCheckoutPersistence(keys) {
|
|
191
|
+
for (const key of keys) {
|
|
192
|
+
clearFromSession(key);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/hooks/use-payment-flow.ts
|
|
197
|
+
|
|
198
|
+
var PAYMENT_STORAGE_KEY = "checkout:payment";
|
|
199
|
+
function toastError(callbacks, message) {
|
|
200
|
+
_optionalChain([callbacks, 'access', _ => _.toast, 'optionalAccess', _2 => _2.error, 'optionalCall', _3 => _3(message)]);
|
|
201
|
+
}
|
|
202
|
+
function withCapturedBin(account, capturedBin) {
|
|
203
|
+
return capturedBin && !account.Bin ? { ...account, Bin: capturedBin } : account;
|
|
204
|
+
}
|
|
205
|
+
function paymentToPersist(transactionSetupId, uiEndpoint, account, persistPayment) {
|
|
206
|
+
if (!persistPayment || !account.PaymentAccountID) return null;
|
|
207
|
+
return {
|
|
208
|
+
transactionSetupId,
|
|
209
|
+
uiEndpoint,
|
|
210
|
+
paymentAccountId: account.PaymentAccountID
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function isRestorable(saved) {
|
|
214
|
+
return Boolean(_optionalChain([saved, 'optionalAccess', _4 => _4.transactionSetupId]) && saved.uiEndpoint && saved.paymentAccountId);
|
|
215
|
+
}
|
|
216
|
+
function usePaymentFlow({
|
|
217
|
+
callbacks,
|
|
218
|
+
customerId,
|
|
219
|
+
billingAddress,
|
|
220
|
+
paymentMethod,
|
|
221
|
+
shippingAccepted,
|
|
222
|
+
persistPayment
|
|
223
|
+
}) {
|
|
224
|
+
const [isOpen, setIsOpen] = _react.useState.call(void 0, false);
|
|
225
|
+
const [unified, setUnified] = _react.useState.call(void 0, null);
|
|
226
|
+
const [unifiedCc, setUnifiedCc] = _react.useState.call(void 0, null);
|
|
227
|
+
const [unifiedResponse, setUnifiedResponse] = _react.useState.call(void 0, false);
|
|
228
|
+
const [unifiedBilling, setUnifiedBilling] = _react.useState.call(void 0, false);
|
|
229
|
+
const [unifiedPayment, setUnifiedPayment] = _react.useState.call(void 0, null);
|
|
230
|
+
const [capturedBin, setCapturedBin] = _react.useState.call(void 0, null);
|
|
231
|
+
const [editCc, setEditCc] = _react.useState.call(void 0, false);
|
|
232
|
+
const handleBinCapture = _react.useCallback.call(void 0, (bin) => {
|
|
233
|
+
setCapturedBin(bin);
|
|
234
|
+
}, []);
|
|
235
|
+
const customerIdRef = _react.useRef.call(void 0, customerId);
|
|
236
|
+
customerIdRef.current = customerId;
|
|
237
|
+
const hasVerifiedRef = _react.useRef.call(void 0, null);
|
|
238
|
+
const postUnified = _react.useCallback.call(void 0, async () => {
|
|
239
|
+
if (!customerIdRef.current) return;
|
|
240
|
+
try {
|
|
241
|
+
const result = await callbacks.transactionSetup({
|
|
242
|
+
customerId: String(customerIdRef.current)
|
|
243
|
+
});
|
|
244
|
+
if (!result) {
|
|
245
|
+
toastError(callbacks, "Unable to initialize payment. Please try again.");
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
setUnified(result);
|
|
249
|
+
} catch (error) {
|
|
250
|
+
console.error("transactionSetup failed:", error);
|
|
251
|
+
toastError(callbacks, "Unable to initialize payment. Please try again.");
|
|
252
|
+
}
|
|
253
|
+
}, [callbacks]);
|
|
254
|
+
const getCardInfo = _react.useCallback.call(void 0,
|
|
255
|
+
async (transactionSetupId) => {
|
|
256
|
+
try {
|
|
257
|
+
const result = await callbacks.cardInfo({ transactionSetupId });
|
|
258
|
+
if (!result) {
|
|
259
|
+
toastError(callbacks, "Unable to verify card details. Please try again.");
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
setUnifiedCc(result);
|
|
263
|
+
} catch (error) {
|
|
264
|
+
console.error("cardInfo failed:", error);
|
|
265
|
+
toastError(callbacks, "Unable to verify card details. Please try again.");
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
[callbacks]
|
|
269
|
+
);
|
|
270
|
+
const verifyUnified = _react.useCallback.call(void 0, async () => {
|
|
271
|
+
const transactionSetupId = _optionalChain([unified, 'optionalAccess', _5 => _5.transactionSetupId]);
|
|
272
|
+
if (!transactionSetupId || !customerIdRef.current) return;
|
|
273
|
+
try {
|
|
274
|
+
const result = await callbacks.validatePayment({
|
|
275
|
+
transactionSetupId,
|
|
276
|
+
customerId: String(customerIdRef.current)
|
|
277
|
+
});
|
|
278
|
+
if (result === void 0) {
|
|
279
|
+
toastError(callbacks, "Payment verification failed. Please try again.");
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
setUnifiedResponse(result);
|
|
283
|
+
if (result) {
|
|
284
|
+
await getCardInfo(transactionSetupId);
|
|
285
|
+
}
|
|
286
|
+
} catch (error) {
|
|
287
|
+
console.error("validatePayment failed:", error);
|
|
288
|
+
toastError(callbacks, "Payment verification failed. Please try again.");
|
|
289
|
+
}
|
|
290
|
+
}, [unified, getCardInfo, callbacks]);
|
|
291
|
+
const getUnifiedPayment = _react.useCallback.call(void 0, async () => {
|
|
292
|
+
if (!_optionalChain([unified, 'optionalAccess', _6 => _6.transactionSetupId]) || !customerIdRef.current) return;
|
|
293
|
+
try {
|
|
294
|
+
const result = await callbacks.accountQuery({
|
|
295
|
+
transactionSetupId: unified.transactionSetupId,
|
|
296
|
+
customerId: String(customerIdRef.current)
|
|
297
|
+
});
|
|
298
|
+
if (!result) {
|
|
299
|
+
toastError(callbacks, "Unable to retrieve payment account. Please try again.");
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
setUnifiedPayment(withCapturedBin(result, capturedBin));
|
|
303
|
+
const toPersist = paymentToPersist(
|
|
304
|
+
unified.transactionSetupId,
|
|
305
|
+
unified.uiEndpoint,
|
|
306
|
+
result,
|
|
307
|
+
persistPayment
|
|
308
|
+
);
|
|
309
|
+
if (toPersist) saveToSession(PAYMENT_STORAGE_KEY, toPersist);
|
|
310
|
+
} catch (error) {
|
|
311
|
+
console.error("accountQuery failed:", error);
|
|
312
|
+
toastError(callbacks, "Unable to retrieve payment account. Please try again.");
|
|
313
|
+
}
|
|
314
|
+
}, [unified, capturedBin, callbacks, persistPayment]);
|
|
315
|
+
const updateUnifiedBilling = _react.useCallback.call(void 0,
|
|
316
|
+
async (transactionSetupId, address) => {
|
|
317
|
+
try {
|
|
318
|
+
const result = await callbacks.billingUpdate({
|
|
319
|
+
transactionSetupId,
|
|
320
|
+
address1: address.address1,
|
|
321
|
+
address2: address.address2,
|
|
322
|
+
city: address.city,
|
|
323
|
+
state: address.state,
|
|
324
|
+
zip: address.postalCode
|
|
325
|
+
});
|
|
326
|
+
if (!result) {
|
|
327
|
+
toastError(callbacks, "Billing update failed. Please try again.");
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
setUnifiedBilling(true);
|
|
331
|
+
void getUnifiedPayment();
|
|
332
|
+
} catch (error) {
|
|
333
|
+
console.error("billingUpdate failed:", error);
|
|
334
|
+
toastError(callbacks, "Billing update failed. Please try again.");
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
[getUnifiedPayment, callbacks]
|
|
338
|
+
);
|
|
339
|
+
_react.useEffect.call(void 0, () => {
|
|
340
|
+
if (isOpen && (!shippingAccepted || paymentMethod !== "credit-card")) {
|
|
341
|
+
setIsOpen(false);
|
|
342
|
+
}
|
|
343
|
+
}, [isOpen, shippingAccepted, paymentMethod]);
|
|
344
|
+
_react.useEffect.call(void 0, () => {
|
|
345
|
+
if (isOpen && shippingAccepted && paymentMethod === "credit-card" && unified === null) {
|
|
346
|
+
void postUnified();
|
|
347
|
+
}
|
|
348
|
+
}, [isOpen, shippingAccepted, paymentMethod, unified, postUnified]);
|
|
349
|
+
_react.useEffect.call(void 0, () => {
|
|
350
|
+
const setupId2 = _optionalChain([unified, 'optionalAccess', _7 => _7.transactionSetupId]);
|
|
351
|
+
if (!isOpen && setupId2 && shippingAccepted && paymentMethod === "credit-card") {
|
|
352
|
+
if (hasVerifiedRef.current === setupId2) return;
|
|
353
|
+
hasVerifiedRef.current = setupId2;
|
|
354
|
+
void verifyUnified();
|
|
355
|
+
}
|
|
356
|
+
}, [isOpen, unified, shippingAccepted, paymentMethod, verifyUnified]);
|
|
357
|
+
const setupId = _optionalChain([unified, 'optionalAccess', _8 => _8.transactionSetupId]);
|
|
358
|
+
_react.useEffect.call(void 0, () => {
|
|
359
|
+
if (unifiedResponse && billingAddress !== void 0 && _optionalChain([unifiedCc, 'optionalAccess', _9 => _9.transactionSetupId]) && paymentMethod === "credit-card" && setupId) {
|
|
360
|
+
void updateUnifiedBilling(setupId, billingAddress);
|
|
361
|
+
}
|
|
362
|
+
}, [
|
|
363
|
+
unifiedResponse,
|
|
364
|
+
billingAddress,
|
|
365
|
+
_optionalChain([unifiedCc, 'optionalAccess', _10 => _10.transactionSetupId]),
|
|
366
|
+
updateUnifiedBilling,
|
|
367
|
+
paymentMethod,
|
|
368
|
+
setupId
|
|
369
|
+
]);
|
|
370
|
+
_react.useEffect.call(void 0, () => {
|
|
371
|
+
if (editCc) {
|
|
372
|
+
setIsOpen(true);
|
|
373
|
+
setUnified(null);
|
|
374
|
+
setUnifiedCc(null);
|
|
375
|
+
setUnifiedPayment(null);
|
|
376
|
+
setUnifiedBilling(false);
|
|
377
|
+
setUnifiedResponse(false);
|
|
378
|
+
setCapturedBin(null);
|
|
379
|
+
hasVerifiedRef.current = null;
|
|
380
|
+
if (persistPayment) {
|
|
381
|
+
clearFromSession(PAYMENT_STORAGE_KEY);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}, [editCc, persistPayment]);
|
|
385
|
+
const restorePayment = _react.useCallback.call(void 0, async () => {
|
|
386
|
+
if (!customerIdRef.current) return;
|
|
387
|
+
const saved = loadFromSession(PAYMENT_STORAGE_KEY);
|
|
388
|
+
if (!isRestorable(saved)) return;
|
|
389
|
+
const { transactionSetupId, uiEndpoint } = saved;
|
|
390
|
+
try {
|
|
391
|
+
const account = await callbacks.accountQuery({
|
|
392
|
+
transactionSetupId,
|
|
393
|
+
customerId: String(customerIdRef.current)
|
|
394
|
+
});
|
|
395
|
+
if (!_optionalChain([account, 'optionalAccess', _11 => _11.PaymentAccountID])) {
|
|
396
|
+
clearFromSession(PAYMENT_STORAGE_KEY);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
hasVerifiedRef.current = transactionSetupId;
|
|
400
|
+
setUnified({ transactionSetupId, uiEndpoint });
|
|
401
|
+
setUnifiedPayment(account);
|
|
402
|
+
setUnifiedResponse(true);
|
|
403
|
+
setUnifiedBilling(true);
|
|
404
|
+
const card = await callbacks.cardInfo({ transactionSetupId });
|
|
405
|
+
if (card) setUnifiedCc(card);
|
|
406
|
+
} catch (e4) {
|
|
407
|
+
clearFromSession(PAYMENT_STORAGE_KEY);
|
|
408
|
+
}
|
|
409
|
+
}, [callbacks]);
|
|
410
|
+
const restorePaymentRef = _react.useRef.call(void 0, restorePayment);
|
|
411
|
+
restorePaymentRef.current = restorePayment;
|
|
412
|
+
_react.useEffect.call(void 0, () => {
|
|
413
|
+
if (persistPayment) {
|
|
414
|
+
void restorePaymentRef.current();
|
|
415
|
+
}
|
|
416
|
+
}, [persistPayment]);
|
|
417
|
+
return {
|
|
418
|
+
isOpen,
|
|
419
|
+
setIsOpen,
|
|
420
|
+
editCc,
|
|
421
|
+
setEditCc,
|
|
422
|
+
unified,
|
|
423
|
+
unifiedCc,
|
|
424
|
+
unifiedResponse,
|
|
425
|
+
unifiedBilling,
|
|
426
|
+
unifiedPayment,
|
|
427
|
+
capturedBin,
|
|
428
|
+
handleBinCapture
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// src/hooks/use-order-readiness.ts
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
// src/hooks/use-latest.ts
|
|
436
|
+
|
|
437
|
+
function useLatest(value) {
|
|
438
|
+
const ref = _react.useRef.call(void 0, value);
|
|
439
|
+
ref.current = value;
|
|
440
|
+
return ref;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// src/hooks/use-order-readiness.ts
|
|
444
|
+
function determineOrderReadiness(params) {
|
|
445
|
+
return orderReadyOf(_optionalChain([params, 'access', _12 => _12.customReadinessCheck, 'optionalCall', _13 => _13(params)]), defaultReady(readinessFlags(params)));
|
|
446
|
+
}
|
|
447
|
+
function readinessFlags(params) {
|
|
448
|
+
return {
|
|
449
|
+
cartUidSet: !!params.cartHdrUid,
|
|
450
|
+
editShippingInfo: params.isEditShippingInfo,
|
|
451
|
+
editShippingMethods: params.isEditShippingMethods,
|
|
452
|
+
editBillingInfo: params.isEditBillingInfo,
|
|
453
|
+
editCc: params.editCc,
|
|
454
|
+
hasShippingAddress: params.shippingAddress !== void 0,
|
|
455
|
+
hasBillingAddress: params.billingAddress !== void 0,
|
|
456
|
+
methodSaved: params.shippingMethodSaved,
|
|
457
|
+
showBillingSummary: params.showBillingInfoSummary,
|
|
458
|
+
processing: params.processingOrder,
|
|
459
|
+
isCreditCard: params.paymentMethod === "credit-card",
|
|
460
|
+
hasAccountId: !!params.unifiedPaymentAccountId,
|
|
461
|
+
hasUnifiedBilling: params.unifiedBilling,
|
|
462
|
+
isFreeShipping: params.isFreeShipping,
|
|
463
|
+
hasShippingFee: params.shippingFee !== void 0
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
function useOrderReadiness(params) {
|
|
467
|
+
const [enableProcessOrderBtn, setEnableProcessOrderBtn] = _react.useState.call(void 0, false);
|
|
468
|
+
const [processingValidation, setProcessingValidation] = _react.useState.call(void 0, false);
|
|
469
|
+
const paramsRef = useLatest(params);
|
|
470
|
+
_react.useEffect.call(void 0, () => {
|
|
471
|
+
setProcessingValidation(true);
|
|
472
|
+
const current = paramsRef.current;
|
|
473
|
+
const timeoutId = setTimeout(() => {
|
|
474
|
+
const ready = determineOrderReadiness(current);
|
|
475
|
+
setEnableProcessOrderBtn(ready);
|
|
476
|
+
setProcessingValidation(false);
|
|
477
|
+
}, 300);
|
|
478
|
+
return () => clearTimeout(timeoutId);
|
|
479
|
+
}, [
|
|
480
|
+
paramsRef,
|
|
481
|
+
params.billingAddress,
|
|
482
|
+
params.shippingAddress,
|
|
483
|
+
params.isEditShippingInfo,
|
|
484
|
+
params.isEditShippingMethods,
|
|
485
|
+
params.isEditBillingInfo,
|
|
486
|
+
params.editCc,
|
|
487
|
+
params.isFreeShipping,
|
|
488
|
+
params.unifiedPaymentAccountId,
|
|
489
|
+
params.unifiedBilling,
|
|
490
|
+
params.paymentMethod,
|
|
491
|
+
params.processingOrder,
|
|
492
|
+
params.carrierId,
|
|
493
|
+
params.shippingFee,
|
|
494
|
+
params.shippingMethodSaved,
|
|
495
|
+
params.showBillingInfoSummary,
|
|
496
|
+
params.cartHdrUid
|
|
497
|
+
]);
|
|
498
|
+
return { enableProcessOrderBtn, processingValidation };
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
exports.useLatest = useLatest; exports.qtyOrZero = qtyOrZero; exports.indexOfUidFrom = indexOfUidFrom; exports.keepsAfterReverse = keepsAfterReverse; exports.requiredCartUid = requiredCartUid; exports.checkoutCartUid = checkoutCartUid; exports.defaultPaymentMethodOf = defaultPaymentMethodOf; exports.preSubmitOutcome = preSubmitOutcome; exports.secondEqualsField = secondEqualsField; exports.shouldPersistOf = shouldPersistOf; exports.stockRetryDelay = stockRetryDelay; exports.stockEnabled = stockEnabled; exports.useCartStore = useCartStore; exports.useCartHdrUid = useCartHdrUid; exports.useCartLines = useCartLines; exports.useCartQuantityTotal = useCartQuantityTotal; exports.useCartLineCount = useCartLineCount; exports.useSetCartHdrUid = useSetCartHdrUid; exports.useSetCartLines = useSetCartLines; exports.useClearCart = useClearCart; exports.saveToSession = saveToSession; exports.loadFromSession = loadFromSession; exports.clearFromSession = clearFromSession; exports.useCheckoutPersistence = useCheckoutPersistence; exports.clearCheckoutPersistence = clearCheckoutPersistence; exports.PAYMENT_STORAGE_KEY = PAYMENT_STORAGE_KEY; exports.usePaymentFlow = usePaymentFlow; exports.determineOrderReadiness = determineOrderReadiness; exports.useOrderReadiness = useOrderReadiness;
|
|
532
|
+
//# sourceMappingURL=chunk-UZAFXUAO.cjs.map
|