@simpleapps-com/augur-hooks 2.3.0 → 2.3.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/dist/checkout/index.cjs +41 -31
- package/dist/checkout/index.cjs.map +1 -1
- package/dist/checkout/index.d.cts +36 -3
- package/dist/checkout/index.d.ts +36 -3
- package/dist/checkout/index.js +14 -4
- package/dist/checkout/index.js.map +1 -1
- package/dist/{chunk-XLBU5PCT.cjs → chunk-I4A5L2I6.cjs} +3 -2
- package/dist/chunk-I4A5L2I6.cjs.map +1 -0
- package/dist/{chunk-5YN2RPZ4.js → chunk-NRWH2BMN.js} +3 -2
- package/dist/{chunk-5YN2RPZ4.js.map → chunk-NRWH2BMN.js.map} +1 -1
- package/dist/index.cjs +10 -10
- package/dist/index.d.cts +2 -43
- package/dist/index.d.ts +2 -43
- package/dist/index.js +1 -1
- package/dist/{use-payment-flow-u8RwBTbO.d.cts → use-order-readiness-DZTIfRzw.d.cts} +48 -1
- package/dist/{use-payment-flow-u8RwBTbO.d.ts → use-order-readiness-DZTIfRzw.d.ts} +48 -1
- package/package.json +3 -3
- package/dist/chunk-XLBU5PCT.cjs.map +0 -1
package/dist/checkout/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkI4A5L2I6cjs = require('../chunk-I4A5L2I6.cjs');
|
|
10
10
|
|
|
11
11
|
// src/checkout/create-checkout-provider.tsx
|
|
12
12
|
|
|
@@ -64,8 +64,18 @@ function resolveCartHdrUid(cartHdrUid) {
|
|
|
64
64
|
if (typeof cartHdrUid === "string") return Number(cartHdrUid);
|
|
65
65
|
return _nullishCoalesce(cartHdrUid, () => ( 0));
|
|
66
66
|
}
|
|
67
|
+
function resolveDefaultPaymentMethod(config) {
|
|
68
|
+
const explicit = _optionalChain([config, 'access', _18 => _18.hooks, 'optionalAccess', _19 => _19.getDefaultPaymentMethod, 'optionalCall', _20 => _20()]);
|
|
69
|
+
if (explicit) return explicit;
|
|
70
|
+
return _optionalChain([config, 'access', _21 => _21.payments, 'optionalAccess', _22 => _22.callbacks]) ? "credit-card" : "invoice";
|
|
71
|
+
}
|
|
72
|
+
function buildReadinessOverride(config, ctxRef) {
|
|
73
|
+
const siteIsOrderReady = _optionalChain([config, 'access', _23 => _23.hooks, 'optionalAccess', _24 => _24.isOrderReady]);
|
|
74
|
+
if (!siteIsOrderReady) return void 0;
|
|
75
|
+
return (params) => siteIsOrderReady(ctxRef.current, params);
|
|
76
|
+
}
|
|
67
77
|
function assembleOrderPayload(config, ctx, contextValue, stateSnapshot) {
|
|
68
|
-
if (_optionalChain([config, 'access',
|
|
78
|
+
if (_optionalChain([config, 'access', _25 => _25.hooks, 'optionalAccess', _26 => _26.assembleOrder])) {
|
|
69
79
|
const assembled = config.hooks.assembleOrder(ctx, contextValue);
|
|
70
80
|
if (assembled.error) return { orderData: {}, error: assembled.error };
|
|
71
81
|
return { orderData: assembled.order };
|
|
@@ -102,14 +112,14 @@ function prepareOrderPayload(config, ctx, contextValue, stateSnapshot, setProces
|
|
|
102
112
|
);
|
|
103
113
|
if (assemblyError) {
|
|
104
114
|
setProcessingOrder(false);
|
|
105
|
-
_optionalChain([config, 'access',
|
|
115
|
+
_optionalChain([config, 'access', _27 => _27.ui, 'optionalAccess', _28 => _28.onError, 'optionalCall', _29 => _29("Order Error", assemblyError)]);
|
|
106
116
|
return null;
|
|
107
117
|
}
|
|
108
118
|
const validationError = validateOrderPayload(orderData);
|
|
109
119
|
if (validationError) {
|
|
110
120
|
console.error("Order payload validation failed:", orderData);
|
|
111
121
|
setProcessingOrder(false);
|
|
112
|
-
_optionalChain([config, 'access',
|
|
122
|
+
_optionalChain([config, 'access', _30 => _30.ui, 'optionalAccess', _31 => _31.onError, 'optionalCall', _32 => _32("Order Error", validationError)]);
|
|
113
123
|
return null;
|
|
114
124
|
}
|
|
115
125
|
return orderData;
|
|
@@ -129,10 +139,10 @@ function buildOrderConfirmation(orderData, resultData, state, orderCartLines) {
|
|
|
129
139
|
};
|
|
130
140
|
}
|
|
131
141
|
function handleOrderSuccess(config, ctx, resultData, confirmation, setProcessingOrder, redirect, queryClient, clearCart) {
|
|
132
|
-
if (_optionalChain([config, 'access',
|
|
133
|
-
|
|
142
|
+
if (_optionalChain([config, 'access', _33 => _33.payments, 'optionalAccess', _34 => _34.persistence])) {
|
|
143
|
+
_chunkI4A5L2I6cjs.clearFromSession.call(void 0, _chunkI4A5L2I6cjs.PAYMENT_STORAGE_KEY);
|
|
134
144
|
}
|
|
135
|
-
_optionalChain([config, 'access',
|
|
145
|
+
_optionalChain([config, 'access', _35 => _35.hooks, 'optionalAccess', _36 => _36.onAfterSubmit, 'optionalCall', _37 => _37(ctx, resultData)]);
|
|
136
146
|
if (config.order.persistence !== false) {
|
|
137
147
|
try {
|
|
138
148
|
sessionStorage.setItem(ORDER_CONFIRMATION_KEY, JSON.stringify(confirmation));
|
|
@@ -152,7 +162,7 @@ async function executeOrder(config, ctxRef, stateRef, contextValueRef, cartHdrUi
|
|
|
152
162
|
const preCheck = runPreSubmitChecks(config, ctx, s.shippingAddress);
|
|
153
163
|
if (preCheck === "__cancelled__") return;
|
|
154
164
|
if (preCheck) {
|
|
155
|
-
_optionalChain([config, 'access',
|
|
165
|
+
_optionalChain([config, 'access', _38 => _38.ui, 'optionalAccess', _39 => _39.onError, 'optionalCall', _40 => _40("Missing Information", preCheck)]);
|
|
156
166
|
return;
|
|
157
167
|
}
|
|
158
168
|
setProcessingOrder(true);
|
|
@@ -173,7 +183,7 @@ async function executeOrder(config, ctxRef, stateRef, contextValueRef, cartHdrUi
|
|
|
173
183
|
}
|
|
174
184
|
if (!result.ok) {
|
|
175
185
|
setProcessingOrder(false);
|
|
176
|
-
_optionalChain([config, 'access',
|
|
186
|
+
_optionalChain([config, 'access', _41 => _41.ui, 'optionalAccess', _42 => _42.onError, 'optionalCall', _43 => _43("Order Failed", _nullishCoalesce(result.error, () => ( "Something went wrong.")))]);
|
|
177
187
|
return;
|
|
178
188
|
}
|
|
179
189
|
const confirmation = buildOrderConfirmation(
|
|
@@ -202,7 +212,7 @@ var NOOP_PAYMENT_CALLBACKS = {
|
|
|
202
212
|
};
|
|
203
213
|
var Ctx = _react.createContext.call(void 0, null);
|
|
204
214
|
function createCheckoutProvider(config) {
|
|
205
|
-
const hasPaymentFlow = !!_optionalChain([config, 'access',
|
|
215
|
+
const hasPaymentFlow = !!_optionalChain([config, 'access', _44 => _44.payments, 'optionalAccess', _45 => _45.callbacks]);
|
|
206
216
|
function CheckoutProvider({
|
|
207
217
|
children,
|
|
208
218
|
identity: propsIdentity
|
|
@@ -216,8 +226,7 @@ function createCheckoutProvider(config) {
|
|
|
216
226
|
const [carrierId, setCarrierId] = _react.useState.call(void 0, config.shipping.defaultCarrierId);
|
|
217
227
|
const [showShippingMethod, setShowShippingMethod] = _react.useState.call(void 0, false);
|
|
218
228
|
const [billingAddress, setBillingAddress] = _react.useState.call(void 0, );
|
|
219
|
-
const
|
|
220
|
-
const [paymentMethod, setPaymentMethod] = _react.useState.call(void 0, defaultPaymentMethod);
|
|
229
|
+
const [paymentMethod, setPaymentMethod] = _react.useState.call(void 0, () => resolveDefaultPaymentMethod(config));
|
|
221
230
|
const [showBillingInfoSummary, setShowBillingInfoSummary] = _react.useState.call(void 0, false);
|
|
222
231
|
const [orderCartLines, setOrderCartLines] = _react.useState.call(void 0, );
|
|
223
232
|
const [processingOrder, setProcessingOrder] = _react.useState.call(void 0, false);
|
|
@@ -236,13 +245,13 @@ function createCheckoutProvider(config) {
|
|
|
236
245
|
setCustomState((prev) => ({ ...prev, [key]: value2 }));
|
|
237
246
|
}, []);
|
|
238
247
|
const identity = _nullishCoalesce(propsIdentity, () => ( config.identity));
|
|
239
|
-
const payment =
|
|
240
|
-
callbacks: _nullishCoalesce(_optionalChain([config, 'access',
|
|
241
|
-
customerId: _optionalChain([identity, 'optionalAccess',
|
|
248
|
+
const payment = _chunkI4A5L2I6cjs.usePaymentFlow.call(void 0, {
|
|
249
|
+
callbacks: _nullishCoalesce(_optionalChain([config, 'access', _46 => _46.payments, 'optionalAccess', _47 => _47.callbacks]), () => ( NOOP_PAYMENT_CALLBACKS)),
|
|
250
|
+
customerId: _optionalChain([identity, 'optionalAccess', _48 => _48.customerId]),
|
|
242
251
|
billingAddress,
|
|
243
252
|
paymentMethod,
|
|
244
253
|
shippingAccepted,
|
|
245
|
-
persistPayment: _optionalChain([config, 'access',
|
|
254
|
+
persistPayment: _optionalChain([config, 'access', _49 => _49.payments, 'optionalAccess', _50 => _50.persistence])
|
|
246
255
|
});
|
|
247
256
|
const paymentModal = hasPaymentFlow ? {
|
|
248
257
|
isOpen: payment.isOpen,
|
|
@@ -255,7 +264,7 @@ function createCheckoutProvider(config) {
|
|
|
255
264
|
unifiedBilling: payment.unifiedBilling,
|
|
256
265
|
unifiedPayment: payment.unifiedPayment,
|
|
257
266
|
handleBinCapture: payment.handleBinCapture,
|
|
258
|
-
hasValidPayment: !!_optionalChain([payment, 'access',
|
|
267
|
+
hasValidPayment: !!_optionalChain([payment, 'access', _51 => _51.unifiedPayment, 'optionalAccess', _52 => _52.PaymentAccountID])
|
|
259
268
|
} : void 0;
|
|
260
269
|
const ctxRef = _react.useRef.call(void 0, null);
|
|
261
270
|
ctxRef.current = {
|
|
@@ -281,18 +290,18 @@ function createCheckoutProvider(config) {
|
|
|
281
290
|
const goToStep = _react.useCallback.call(void 0,
|
|
282
291
|
(step) => {
|
|
283
292
|
const from = currentStep;
|
|
284
|
-
if (_optionalChain([config, 'access',
|
|
293
|
+
if (_optionalChain([config, 'access', _53 => _53.hooks, 'optionalAccess', _54 => _54.onStepChange])) {
|
|
285
294
|
config.hooks.onStepChange(ctxRef.current, from, step);
|
|
286
295
|
}
|
|
287
296
|
setCurrentStep(step);
|
|
288
297
|
},
|
|
289
298
|
[currentStep]
|
|
290
299
|
);
|
|
291
|
-
const cartHdrUid =
|
|
292
|
-
const cartLines =
|
|
293
|
-
const clearCart =
|
|
300
|
+
const cartHdrUid = _chunkI4A5L2I6cjs.useCartHdrUid.call(void 0, );
|
|
301
|
+
const cartLines = _chunkI4A5L2I6cjs.useCartLines.call(void 0, );
|
|
302
|
+
const clearCart = _chunkI4A5L2I6cjs.useClearCart.call(void 0, );
|
|
294
303
|
const queryClient = _reactquery.useQueryClient.call(void 0, );
|
|
295
|
-
const { enableProcessOrderBtn, processingValidation } =
|
|
304
|
+
const { enableProcessOrderBtn, processingValidation } = _chunkI4A5L2I6cjs.useOrderReadiness.call(void 0, {
|
|
296
305
|
cartHdrUid,
|
|
297
306
|
shippingAddress,
|
|
298
307
|
billingAddress,
|
|
@@ -300,7 +309,7 @@ function createCheckoutProvider(config) {
|
|
|
300
309
|
showBillingInfoSummary,
|
|
301
310
|
processingOrder,
|
|
302
311
|
paymentMethod,
|
|
303
|
-
unifiedPaymentAccountId: _optionalChain([payment, 'access',
|
|
312
|
+
unifiedPaymentAccountId: _optionalChain([payment, 'access', _55 => _55.unifiedPayment, 'optionalAccess', _56 => _56.PaymentAccountID]),
|
|
304
313
|
unifiedBilling: payment.unifiedBilling,
|
|
305
314
|
isFreeShipping,
|
|
306
315
|
carrierId,
|
|
@@ -308,7 +317,8 @@ function createCheckoutProvider(config) {
|
|
|
308
317
|
isEditShippingInfo,
|
|
309
318
|
isEditShippingMethods,
|
|
310
319
|
isEditBillingInfo,
|
|
311
|
-
editCc: payment.editCc
|
|
320
|
+
editCc: payment.editCc,
|
|
321
|
+
customReadinessCheck: buildReadinessOverride(config, ctxRef)
|
|
312
322
|
});
|
|
313
323
|
_react.useEffect.call(void 0, () => {
|
|
314
324
|
if (config.order.fetchClientIp) {
|
|
@@ -316,29 +326,29 @@ function createCheckoutProvider(config) {
|
|
|
316
326
|
}
|
|
317
327
|
}, []);
|
|
318
328
|
_react.useEffect.call(void 0, () => {
|
|
319
|
-
const custId = _optionalChain([identity, 'optionalAccess',
|
|
320
|
-
if (custId && _optionalChain([identity, 'optionalAccess',
|
|
329
|
+
const custId = _optionalChain([identity, 'optionalAccess', _57 => _57.customerId]);
|
|
330
|
+
if (custId && _optionalChain([identity, 'optionalAccess', _58 => _58.fetchCustomerDoc])) {
|
|
321
331
|
void identity.fetchCustomerDoc(custId).then(setCustomerDoc).catch(() => setCustomerDoc(null));
|
|
322
332
|
}
|
|
323
|
-
}, [_optionalChain([identity, 'optionalAccess',
|
|
333
|
+
}, [_optionalChain([identity, 'optionalAccess', _59 => _59.customerId])]);
|
|
324
334
|
_react.useEffect.call(void 0, () => {
|
|
325
|
-
if (!config.order.calculateTax || !_optionalChain([billingAddress, 'optionalAccess',
|
|
335
|
+
if (!config.order.calculateTax || !_optionalChain([billingAddress, 'optionalAccess', _60 => _60.postalCode])) return;
|
|
326
336
|
void config.order.calculateTax({
|
|
327
|
-
customerId: _optionalChain([identity, 'optionalAccess',
|
|
337
|
+
customerId: _optionalChain([identity, 'optionalAccess', _61 => _61.customerId]),
|
|
328
338
|
postalCode: billingAddress.postalCode,
|
|
329
339
|
items: _nullishCoalesce(orderCartLines, () => ( [])),
|
|
330
340
|
customerDoc
|
|
331
341
|
}).then((tax) => {
|
|
332
342
|
if (tax !== void 0) setTaxRate(tax);
|
|
333
343
|
});
|
|
334
|
-
}, [_optionalChain([billingAddress, 'optionalAccess',
|
|
344
|
+
}, [_optionalChain([billingAddress, 'optionalAccess', _62 => _62.postalCode]), orderCartLines]);
|
|
335
345
|
_react.useEffect.call(void 0, () => {
|
|
336
346
|
if (shippingAccepted && shippingAddress && !billingAddress) {
|
|
337
347
|
setBillingAddress(shippingAddress);
|
|
338
348
|
}
|
|
339
349
|
}, [shippingAccepted, shippingAddress, billingAddress]);
|
|
340
350
|
_react.useEffect.call(void 0, () => {
|
|
341
|
-
if (_optionalChain([config, 'access',
|
|
351
|
+
if (_optionalChain([config, 'access', _63 => _63.hooks, 'optionalAccess', _64 => _64.onShippingAccepted]) && shippingAccepted && shippingAddress) {
|
|
342
352
|
config.hooks.onShippingAccepted(ctxRef.current, shippingAddress, _nullishCoalesce(orderCartLines, () => ( [])));
|
|
343
353
|
}
|
|
344
354
|
}, [shippingAccepted, shippingAddress]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/augur-packages/augur-packages/packages/augur-hooks/dist/checkout/index.cjs","../../src/checkout/create-checkout-provider.tsx"],"names":["value"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,yDAA8B;AAC9B;AACA;ACRA;AACE;AACA;AACA;AACA;AACA;AACA;AAAA,8BAEK;AACP,mDAAiD;AA+qBtC,+CAAA;AA9pBJ,IAAM,uBAAA,EAAyB,mBAAA;AAGtC,SAAS,eAAA,CAAgB,GAAA,EAAmB;AAC1C,EAAA,MAAA,CAAO,QAAA,CAAS,KAAA,EAAO,GAAA;AACzB;AAmBA,SAAS,kBAAA,CACP,MAAA,EACA,GAAA,EACA,eAAA,EACe;AACf,EAAA,GAAA,iBAAI,MAAA,mBAAO,KAAA,6BAAO,YAAA,EAAY;AAC5B,IAAA,MAAM,MAAA,EAAQ,MAAA,CAAO,KAAA,CAAM,UAAA,CAAW,GAAG,CAAA;AACzC,IAAA,GAAA,CAAI,KAAA,EAAO,OAAO,KAAA;AAAA,EACpB;AACA,EAAA,GAAA,iBAAI,MAAA,qBAAO,KAAA,6BAAO,gBAAA,EAAgB;AAChC,IAAA,MAAM,OAAA,EAAS,MAAA,CAAO,KAAA,CAAM,cAAA,CAAe,GAAG,CAAA;AAC9C,IAAA,GAAA,CAAI,OAAA,IAAW,KAAA,EAAO,OAAO,eAAA;AAAA,EAC/B;AACA,EAAA,GAAA,CAAI,CAAC,eAAA,EAAiB,OAAO,+BAAA;AAC7B,EAAA,OAAO,IAAA;AACT;AAGA,SAAS,cAAA,CAAe,CAAA,EAAgD;AACtE,EAAA,OAAO;AAAA,IACL,eAAA,EAAiB,CAAA,CAAE,eAAA;AAAA,IACnB,cAAA,EAAgB,CAAA,CA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file":"/home/runner/work/augur-packages/augur-packages/packages/augur-hooks/dist/checkout/index.cjs","sourcesContent":[null,"\"use client\";\n\nimport React, {\n createContext,\n useContext,\n useState,\n useCallback,\n useEffect,\n useRef,\n type ReactElement,\n} from \"react\";\nimport { useQueryClient, type QueryClient } from \"@tanstack/react-query\";\nimport { usePaymentFlow, PAYMENT_STORAGE_KEY } from \"../hooks/use-payment-flow\";\nimport type { PaymentFlowCallbacks } from \"../hooks/use-payment-flow\";\nimport { clearFromSession } from \"../hooks/use-checkout-persistence\";\nimport { useOrderReadiness } from \"../hooks/use-order-readiness\";\nimport { useCartHdrUid, useCartLines, useClearCart } from \"../stores/cart-store\";\nimport type { CustomerDocument } from \"@simpleapps-com/augur-utils\";\nimport type {\n CheckoutAddress,\n CheckoutContextValue,\n CheckoutContext,\n CheckoutPaymentModal,\n CheckoutProviderConfig,\n CheckoutProviderProps,\n} from \"./types\";\n\n/** sessionStorage key for persisted order confirmation data. */\nexport const ORDER_CONFIRMATION_KEY = \"orderConfirmation\";\n\n/** Default redirect via full page navigation. */\nfunction defaultRedirect(url: string): void {\n window.location.href = url;\n}\n\n/** Shape of the order state snapshot taken via ref. */\ninterface OrderStateSnapshot {\n shippingAddress: CheckoutAddress | undefined;\n billingAddress: CheckoutAddress | undefined;\n carrierId: string;\n shippingMethod: string | undefined;\n shippingFee: number | undefined;\n paymentMethod: string;\n taxRate: number | undefined;\n clientIp: string | undefined;\n isFreeShipping: boolean;\n identity: CheckoutProviderConfig[\"identity\"];\n unifiedPayment: unknown;\n unifiedCc: unknown;\n}\n\n/** Run pre-submit validation hooks. Returns error string or null. */\nfunction runPreSubmitChecks<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctx: CheckoutContext<TCustom>,\n shippingAddress: CheckoutAddress | undefined,\n): string | null {\n if (config.hooks?.onValidate) {\n const error = config.hooks.onValidate(ctx);\n if (error) return error;\n }\n if (config.hooks?.onBeforeSubmit) {\n const result = config.hooks.onBeforeSubmit(ctx);\n if (result === false) return \"__cancelled__\";\n }\n if (!shippingAddress) return \"Shipping address is required.\";\n return null;\n}\n\n/** Build the order data payload from current state. */\nfunction buildOrderData(s: OrderStateSnapshot): Record<string, unknown> {\n return {\n shippingAddress: s.shippingAddress,\n billingAddress: s.billingAddress,\n carrierId: s.carrierId,\n shippingMethod: s.shippingMethod,\n shippingFee: s.shippingFee,\n paymentMethod: s.paymentMethod,\n taxRate: s.taxRate,\n clientIp: s.clientIp,\n isFreeShipping: s.isFreeShipping,\n customerId: s.identity?.customerId,\n contactId: s.identity?.contactId,\n companyId: s.identity?.companyId,\n userId: s.identity?.userId,\n userEmail: s.identity?.userEmail,\n unifiedPayment: s.unifiedPayment,\n unifiedCc: s.unifiedCc,\n };\n}\n\n/** Handle order submission failure. */\nfunction handleOrderError<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n setProcessingOrder: (v: boolean) => void,\n error: unknown,\n): void {\n setProcessingOrder(false);\n const message = error instanceof Error ? error.message : \"Something went wrong.\";\n config.ui?.onError?.(\"Order Failed\", message);\n}\n\n/** Coerce cartHdrUid from store (string | number | undefined) to number. */\nfunction resolveCartHdrUid(cartHdrUid: number | string | undefined): number {\n if (typeof cartHdrUid === \"string\") return Number(cartHdrUid);\n return cartHdrUid ?? 0;\n}\n\n/** Build order payload via assembleOrder hook or fallback to buildOrderData. */\nfunction assembleOrderPayload<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctx: CheckoutContext<TCustom>,\n contextValue: CheckoutContextValue<TCustom>,\n stateSnapshot: OrderStateSnapshot,\n): { orderData: Record<string, unknown>; error?: string } {\n if (config.hooks?.assembleOrder) {\n const assembled = config.hooks.assembleOrder(ctx, contextValue);\n if (assembled.error) return { orderData: {}, error: assembled.error };\n return { orderData: assembled.order };\n }\n return { orderData: buildOrderData(stateSnapshot) };\n}\n\n/**\n * Validate the minimum viable shape of an assembled order payload.\n *\n * Returns an error message when the payload is obviously broken, or `null`\n * when it passes. Invariants are conditional on key presence so sites using\n * the legacy `oe_hdr`/`oe_line` payload shape (or any shape without top-level\n * `lines`/`header`) pass through unchecked.\n *\n * Enforced invariants:\n * - `orderData` MUST be a non-null, non-array object.\n * - If `orderData.lines` is present, it MUST be a non-empty array.\n * - If `orderData.header` is present and is an object, it MUST include a\n * non-empty `customer_id`.\n */\nfunction validateOrderPayload(orderData: Record<string, unknown>): string | null {\n if (orderData === null || typeof orderData !== \"object\" || Array.isArray(orderData)) {\n return \"Order payload is empty or malformed.\";\n }\n\n if (\"lines\" in orderData) {\n const lines = orderData[\"lines\"];\n if (!Array.isArray(lines) || lines.length === 0) {\n return \"Order has no line items.\";\n }\n }\n\n if (\"header\" in orderData) {\n const header = orderData[\"header\"];\n if (header !== null && typeof header === \"object\" && !Array.isArray(header)) {\n const customerId = (header as Record<string, unknown>)[\"customer_id\"];\n if (customerId == null || String(customerId).trim() === \"\") {\n return \"Order is missing a customer.\";\n }\n }\n }\n\n return null;\n}\n\n/**\n * Assemble and validate the order payload. Surfaces any failure via\n * `config.ui.onError` + `setProcessingOrder(false)`, and additionally logs\n * the offending payload to `console.error` on validation failure. Returns\n * `null` when the payload was not produced or was rejected; returns the\n * `orderData` ready for `submitOrder` otherwise.\n */\nfunction prepareOrderPayload<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctx: CheckoutContext<TCustom>,\n contextValue: CheckoutContextValue<TCustom>,\n stateSnapshot: OrderStateSnapshot,\n setProcessingOrder: (v: boolean) => void,\n): Record<string, unknown> | null {\n const { orderData, error: assemblyError } = assembleOrderPayload(\n config,\n ctx,\n contextValue,\n stateSnapshot,\n );\n if (assemblyError) {\n setProcessingOrder(false);\n config.ui?.onError?.(\"Order Error\", assemblyError);\n return null;\n }\n\n const validationError = validateOrderPayload(orderData);\n if (validationError) {\n console.error(\"Order payload validation failed:\", orderData);\n setProcessingOrder(false);\n config.ui?.onError?.(\"Order Error\", validationError);\n return null;\n }\n\n return orderData;\n}\n\n/** Shape of persisted order confirmation data. */\nexport interface OrderConfirmation {\n orderData: Record<string, unknown>;\n result: unknown;\n shippingAddress: CheckoutAddress | undefined;\n billingAddress: CheckoutAddress | undefined;\n shippingFee: number | undefined;\n shippingMethod: string | undefined;\n taxRate: number | undefined;\n paymentMethod: string;\n carrierId: string;\n orderCartLines: unknown[] | undefined;\n}\n\n/** Build the confirmation snapshot from checkout state + API result. */\nfunction buildOrderConfirmation(\n orderData: Record<string, unknown>,\n resultData: unknown,\n state: OrderStateSnapshot,\n orderCartLines: unknown[] | undefined,\n): OrderConfirmation {\n return {\n orderData,\n result: resultData,\n shippingAddress: state.shippingAddress,\n billingAddress: state.billingAddress,\n shippingFee: state.shippingFee,\n shippingMethod: state.shippingMethod,\n taxRate: state.taxRate,\n paymentMethod: state.paymentMethod,\n carrierId: state.carrierId,\n orderCartLines,\n };\n}\n\n/**\n * Handle successful order submission.\n *\n * After running the site's `onAfterSubmit` hook and persisting the order\n * confirmation snapshot, the package clears its own client-side cart state:\n * the zustand cart store is reset, and the cart-related React Query caches\n * (`cartLines`, `cart-also-bought`, and the proxy-shape `commerce.cartLine`)\n * are invalidated so any subsequent page mount refetches from the server.\n * The redirect fires last. Sites retain responsibility for backend cart\n * cleanup inside `onAfterSubmit` or their `submitOrder` wrapper.\n */\nfunction handleOrderSuccess<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctx: CheckoutContext<TCustom>,\n resultData: unknown,\n confirmation: OrderConfirmation,\n setProcessingOrder: (v: boolean) => void,\n redirect: (url: string) => void,\n queryClient: QueryClient,\n clearCart: () => void,\n): void {\n if (config.payments?.persistence) {\n clearFromSession(PAYMENT_STORAGE_KEY);\n }\n config.hooks?.onAfterSubmit?.(ctx, resultData);\n if (config.order.persistence !== false) {\n try {\n sessionStorage.setItem(ORDER_CONFIRMATION_KEY, JSON.stringify(confirmation));\n } catch {\n // sessionStorage unavailable (private browsing, quota)\n }\n }\n clearCart();\n void queryClient.invalidateQueries({ queryKey: [\"cartLines\"] });\n void queryClient.invalidateQueries({ queryKey: [\"cart-also-bought\"] });\n void queryClient.invalidateQueries({ queryKey: [\"commerce\", \"cartLine\"] });\n redirect(config.order.successRedirect);\n setProcessingOrder(false);\n}\n\n/** Execute order submission -- extracted to reduce component complexity. */\nasync function executeOrder<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctxRef: React.RefObject<CheckoutContext<TCustom>>,\n stateRef: React.RefObject<OrderStateSnapshot>,\n contextValueRef: React.RefObject<CheckoutContextValue<TCustom>>,\n cartHdrUid: number | string | undefined,\n setProcessingOrder: (v: boolean) => void,\n redirect: (url: string) => void,\n queryClient: QueryClient,\n clearCart: () => void,\n): Promise<void> {\n const ctx = ctxRef.current;\n const s = stateRef.current;\n\n const preCheck = runPreSubmitChecks(config, ctx, s.shippingAddress);\n if (preCheck === \"__cancelled__\") return;\n if (preCheck) {\n config.ui?.onError?.(\"Missing Information\", preCheck);\n return;\n }\n\n setProcessingOrder(true);\n\n const orderData = prepareOrderPayload(\n config,\n ctx,\n contextValueRef.current,\n s,\n setProcessingOrder,\n );\n if (!orderData) return;\n\n let result: { ok: boolean; data?: unknown; error?: string };\n try {\n result = await config.order.submitOrder(orderData, resolveCartHdrUid(cartHdrUid));\n } catch (error) {\n handleOrderError(config, setProcessingOrder, error);\n return;\n }\n\n if (!result.ok) {\n setProcessingOrder(false);\n config.ui?.onError?.(\"Order Failed\", result.error ?? \"Something went wrong.\");\n return;\n }\n\n const confirmation = buildOrderConfirmation(\n orderData,\n result.data,\n s,\n contextValueRef.current.orderCartLines,\n );\n handleOrderSuccess(\n config,\n ctx,\n result.data,\n confirmation,\n setProcessingOrder,\n redirect,\n queryClient,\n clearCart,\n );\n}\n\n/** No-op callbacks for when payment is not configured. */\nconst NOOP_PAYMENT_CALLBACKS: PaymentFlowCallbacks = {\n transactionSetup: async () => undefined,\n cardInfo: async () => undefined,\n validatePayment: async () => undefined,\n accountQuery: async () => undefined,\n billingUpdate: async () => undefined,\n};\n\n/**\n * Creates a CheckoutProvider component and useCheckout() hook from site config.\n *\n * The package owns all state, transitions, validation, and order submission.\n * Sites own layout and inject configuration + lifecycle hooks.\n *\n * Steps are string-based -- sites define their own step names.\n * Payment flow is optional -- B2B sites without payment processing omit payments.callbacks.\n *\n * @example\n * ```ts\n * // Full checkout with payment\n * const { CheckoutProvider, useCheckout } = createCheckoutProvider({\n * shipping: { carriers: { \"100008\": \"UPS Ground\" }, defaultCarrierId: \"100008\" },\n * payments: { callbacks: { transactionSetup, cardInfo, validatePayment, accountQuery, billingUpdate } },\n * order: { successRedirect: \"/thank-you\", submitOrder },\n * });\n *\n * // B2B checkout without payment\n * const { CheckoutProvider, useCheckout } = createCheckoutProvider({\n * shipping: { carriers: { \"100008\": \"UPS Ground\" }, defaultCarrierId: \"100008\" },\n * order: { successRedirect: \"/thank-you\", submitOrder },\n * });\n * ```\n */\n// Single context instance at module scope. Prevents stale context references\n// when createCheckoutProvider is re-called during HMR or page navigation.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Ctx = createContext<any>(null);\n\nexport function createCheckoutProvider<\n TCustom extends Record<string, unknown> = Record<string, never>,\n>(config: CheckoutProviderConfig<TCustom>) {\n const hasPaymentFlow = !!config.payments?.callbacks;\n\n function CheckoutProvider({\n children,\n identity: propsIdentity,\n }: CheckoutProviderProps): ReactElement {\n // -- Shipping state --\n const [shippingAddress, setShippingAddress] = useState<CheckoutAddress | undefined>();\n const [shippingFee, setShippingFee] = useState<number | undefined>();\n const [shippingMethod, setShippingMethod] = useState<string | undefined>();\n const [shippingAccepted, setShippingAccepted] = useState(false);\n const [shippingMethodSaved, setShippingMethodSaved] = useState(false);\n const [isFreeShipping, setIsFreeShipping] = useState(false);\n const [carrierId, setCarrierId] = useState(config.shipping.defaultCarrierId);\n const [showShippingMethod, setShowShippingMethod] = useState(false);\n\n // -- Billing state --\n const [billingAddress, setBillingAddress] = useState<CheckoutAddress | undefined>();\n const defaultPaymentMethod = config.hooks?.getDefaultPaymentMethod?.() ?? \"credit-card\";\n const [paymentMethod, setPaymentMethod] = useState(defaultPaymentMethod);\n const [showBillingInfoSummary, setShowBillingInfoSummary] = useState(false);\n\n // -- Order state --\n const [orderCartLines, setOrderCartLines] = useState<unknown[] | undefined>();\n const [processingOrder, setProcessingOrder] = useState(false);\n const [taxRate, setTaxRate] = useState<number | undefined>(undefined);\n const [clientIp, setClientIp] = useState<string | undefined>();\n const [cartToken, setCartToken] = useState<string>(\"\");\n const [customerDoc, setCustomerDoc] = useState<CustomerDocument | null>(null);\n\n // -- Edit flags --\n const [isEditShippingInfo, setIsEditShippingInfo] = useState(false);\n const [isEditShippingMethods, setIsEditShippingMethods] = useState(false);\n const [isEditBillingInfo, setIsEditBillingInfo] = useState(false);\n\n // -- Step navigation (string-based, sites define their own steps) --\n const [currentStep, setCurrentStep] = useState<string>(config.initialStep ?? \"shipping\");\n\n // -- Custom state --\n const [customState, setCustomState] = useState<TCustom>(\n () => (config.customState ?? {}) as TCustom,\n );\n\n const setCustomField = useCallback(<K extends keyof TCustom>(key: K, value: TCustom[K]) => {\n setCustomState((prev) => ({ ...prev, [key]: value }));\n }, []);\n\n // -- Identity (props override config for runtime hook values) --\n const identity = propsIdentity ?? config.identity;\n const payment = usePaymentFlow({\n callbacks: config.payments?.callbacks ?? NOOP_PAYMENT_CALLBACKS,\n customerId: identity?.customerId,\n billingAddress,\n paymentMethod,\n shippingAccepted,\n persistPayment: config.payments?.persistence,\n });\n\n const paymentModal: CheckoutPaymentModal | undefined = hasPaymentFlow\n ? {\n isOpen: payment.isOpen,\n setIsOpen: payment.setIsOpen,\n editCc: payment.editCc,\n setEditCc: payment.setEditCc,\n unified: payment.unified,\n unifiedCc: payment.unifiedCc,\n unifiedResponse: payment.unifiedResponse,\n unifiedBilling: payment.unifiedBilling,\n unifiedPayment: payment.unifiedPayment,\n handleBinCapture: payment.handleBinCapture,\n hasValidPayment: !!payment.unifiedPayment?.PaymentAccountID,\n }\n : undefined;\n\n // -- Lifecycle context (passed to hooks) --\n const ctxRef = useRef<CheckoutContext<TCustom>>(null!);\n ctxRef.current = {\n get: <K extends keyof TCustom>(key: K) => customState[key],\n set: setCustomField,\n skipToStep: setCurrentStep,\n setBillingAddress,\n setCarrierId,\n };\n\n // -- Edit flag transitions --\n const handleSetIsEditShippingInfo = useCallback((editing: boolean) => {\n setIsEditShippingInfo(editing);\n if (editing) {\n setShippingMethodSaved(false);\n setShowShippingMethod(false);\n }\n }, []);\n\n const handleSetIsEditShippingMethods = useCallback((editing: boolean) => {\n setIsEditShippingMethods(editing);\n if (editing) {\n setShippingMethodSaved(false);\n }\n }, []);\n\n // -- Step transitions with lifecycle hook --\n const goToStep = useCallback(\n (step: string) => {\n const from = currentStep;\n if (config.hooks?.onStepChange) {\n config.hooks.onStepChange(ctxRef.current, from, step);\n }\n setCurrentStep(step);\n },\n [currentStep],\n );\n\n // -- Cart store integration --\n const cartHdrUid = useCartHdrUid();\n const cartLines = useCartLines();\n const clearCart = useClearCart();\n const queryClient = useQueryClient();\n\n // -- Order readiness --\n const { enableProcessOrderBtn, processingValidation } = useOrderReadiness({\n cartHdrUid,\n shippingAddress,\n billingAddress,\n shippingMethodSaved,\n showBillingInfoSummary,\n processingOrder,\n paymentMethod,\n unifiedPaymentAccountId: payment.unifiedPayment?.PaymentAccountID,\n unifiedBilling: payment.unifiedBilling,\n isFreeShipping,\n carrierId,\n shippingFee,\n isEditShippingInfo,\n isEditShippingMethods,\n isEditBillingInfo,\n editCc: payment.editCc,\n });\n\n // -- Effects: data fetching on mount --\n\n useEffect(() => {\n if (config.order.fetchClientIp) {\n void config.order.fetchClientIp().then(setClientIp);\n }\n }, []);\n\n useEffect(() => {\n const custId = identity?.customerId;\n if (custId && identity?.fetchCustomerDoc) {\n void identity\n .fetchCustomerDoc(custId)\n .then(setCustomerDoc)\n .catch(() => setCustomerDoc(null));\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [identity?.customerId]);\n\n // -- Effect: tax calculation when billing address changes --\n useEffect(() => {\n if (!config.order.calculateTax || !billingAddress?.postalCode) return;\n void config.order\n .calculateTax({\n customerId: identity?.customerId,\n postalCode: billingAddress.postalCode,\n items: orderCartLines ?? [],\n customerDoc,\n })\n .then((tax) => {\n if (tax !== undefined) setTaxRate(tax);\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [billingAddress?.postalCode, orderCartLines]);\n\n // -- Effect: auto-copy shipping to billing (default \"same as shipping\") --\n useEffect(() => {\n if (shippingAccepted && shippingAddress && !billingAddress) {\n setBillingAddress(shippingAddress);\n }\n }, [shippingAccepted, shippingAddress, billingAddress]);\n\n // -- Effect: fire onShippingAccepted lifecycle hook --\n useEffect(() => {\n if (config.hooks?.onShippingAccepted && shippingAccepted && shippingAddress) {\n config.hooks.onShippingAccepted(ctxRef.current, shippingAddress, orderCartLines ?? []);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [shippingAccepted, shippingAddress]);\n\n // -- Effect: cart token from cookie --\n useEffect(() => {\n if (typeof document === \"undefined\") return;\n const cookies = document.cookie.split(\";\");\n const match = cookies.find((c) => c.trim().startsWith(\"cartToken=\"));\n if (match) {\n const token = match.split(\"=\")[1];\n if (token) setCartToken(token);\n }\n }, []);\n\n // -- Order submission with double-submit prevention --\n\n const resetProcessing = useCallback(() => setProcessingOrder(false), []);\n\n const isProcessingRef = useRef(false);\n\n const orderStateRef = useRef<OrderStateSnapshot>({\n shippingAddress,\n billingAddress,\n carrierId,\n shippingMethod,\n shippingFee,\n paymentMethod,\n taxRate,\n clientIp,\n isFreeShipping,\n identity,\n unifiedPayment: payment.unifiedPayment,\n unifiedCc: payment.unifiedCc,\n });\n orderStateRef.current = {\n shippingAddress,\n billingAddress,\n carrierId,\n shippingMethod,\n shippingFee,\n paymentMethod,\n taxRate,\n clientIp,\n isFreeShipping,\n identity,\n unifiedPayment: payment.unifiedPayment,\n unifiedCc: payment.unifiedCc,\n };\n\n const contextValueRef = useRef<CheckoutContextValue<TCustom>>(null!);\n\n const redirect = useCallback((url: string) => {\n if (config.order.redirect) {\n config.order.redirect(url);\n } else {\n defaultRedirect(url);\n }\n }, []);\n\n const processOrder = useCallback(async () => {\n if (isProcessingRef.current) return;\n isProcessingRef.current = true;\n try {\n await executeOrder(\n config,\n ctxRef,\n orderStateRef,\n contextValueRef,\n cartHdrUid,\n setProcessingOrder,\n redirect,\n queryClient,\n clearCart,\n );\n } finally {\n isProcessingRef.current = false;\n }\n }, [cartHdrUid, redirect, queryClient, clearCart]);\n\n // -- Context value --\n const value: CheckoutContextValue<TCustom> = {\n shippingAddress,\n setShippingAddress,\n shippingFee,\n setShippingFee,\n shippingMethod,\n setShippingMethod,\n shippingAccepted,\n setShippingAccepted,\n shippingMethodSaved,\n setShippingMethodSaved,\n isFreeShipping,\n setIsFreeShipping,\n carrierId,\n setCarrierId,\n showShippingMethod,\n setShowShippingMethod,\n billingAddress,\n setBillingAddress,\n paymentMethod,\n setPaymentMethod,\n showBillingInfoSummary,\n setShowBillingInfoSummary,\n paymentModal,\n cartLines,\n orderCartLines,\n setOrderCartLines,\n processingOrder,\n processOrder,\n resetProcessing,\n customerDoc,\n taxRate,\n setTaxRate,\n clientIp,\n cartToken,\n isEditShippingInfo,\n setIsEditShippingInfo: handleSetIsEditShippingInfo,\n isEditShippingMethods,\n setIsEditShippingMethods: handleSetIsEditShippingMethods,\n isEditBillingInfo,\n setIsEditBillingInfo,\n enableProcessOrderBtn,\n processingValidation,\n currentStep,\n goToStep,\n custom: customState,\n setCustom: setCustomField,\n config,\n };\n\n contextValueRef.current = value;\n\n return <Ctx.Provider value={value}>{children}</Ctx.Provider>;\n }\n\n /** Access checkout state from any child of CheckoutProvider. */\n function useCheckout(): CheckoutContextValue<TCustom> {\n const ctx = useContext(Ctx);\n if (!ctx) {\n throw new Error(\"useCheckout must be used within a CheckoutProvider\");\n }\n return ctx;\n }\n\n return { CheckoutProvider, useCheckout };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/augur-packages/augur-packages/packages/augur-hooks/dist/checkout/index.cjs","../../src/checkout/create-checkout-provider.tsx"],"names":["value"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,yDAA8B;AAC9B;AACA;ACRA;AACE;AACA;AACA;AACA;AACA;AACA;AAAA,8BAEK;AACP,mDAAiD;AA2sBtC,+CAAA;AAzrBJ,IAAM,uBAAA,EAAyB,mBAAA;AAGtC,SAAS,eAAA,CAAgB,GAAA,EAAmB;AAC1C,EAAA,MAAA,CAAO,QAAA,CAAS,KAAA,EAAO,GAAA;AACzB;AAmBA,SAAS,kBAAA,CACP,MAAA,EACA,GAAA,EACA,eAAA,EACe;AACf,EAAA,GAAA,iBAAI,MAAA,mBAAO,KAAA,6BAAO,YAAA,EAAY;AAC5B,IAAA,MAAM,MAAA,EAAQ,MAAA,CAAO,KAAA,CAAM,UAAA,CAAW,GAAG,CAAA;AACzC,IAAA,GAAA,CAAI,KAAA,EAAO,OAAO,KAAA;AAAA,EACpB;AACA,EAAA,GAAA,iBAAI,MAAA,qBAAO,KAAA,6BAAO,gBAAA,EAAgB;AAChC,IAAA,MAAM,OAAA,EAAS,MAAA,CAAO,KAAA,CAAM,cAAA,CAAe,GAAG,CAAA;AAC9C,IAAA,GAAA,CAAI,OAAA,IAAW,KAAA,EAAO,OAAO,eAAA;AAAA,EAC/B;AACA,EAAA,GAAA,CAAI,CAAC,eAAA,EAAiB,OAAO,+BAAA;AAC7B,EAAA,OAAO,IAAA;AACT;AAGA,SAAS,cAAA,CAAe,CAAA,EAAgD;AACtE,EAAA,OAAO;AAAA,IACL,eAAA,EAAiB,CAAA,CAAE,eAAA;AAAA,IACnB,cAAA,EAAgB,CAAA,CAAE,cAAA;AAAA,IAClB,SAAA,EAAW,CAAA,CAAE,SAAA;AAAA,IACb,cAAA,EAAgB,CAAA,CAAE,cAAA;AAAA,IAClB,WAAA,EAAa,CAAA,CAAE,WAAA;AA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,6BAAA,GAAC,CAAI,QAAA,EAAJ,EAAa,KAAA,EAAe,SAAA,CAAS,CAAA;AAAA,EAC/C;AAGA,EAAA,SAAS,WAAA,CAAA,EAA6C;AACpD,IAAA,MAAM,IAAA,EAAM,+BAAA,GAAc,CAAA;AAC1B,IAAA,GAAA,CAAI,CAAC,GAAA,EAAK;AACR,MAAA,MAAM,IAAI,KAAA,CAAM,oDAAoD,CAAA;AAAA,IACtE;AACA,IAAA,OAAO,GAAA;AAAA,EACT;AAEA,EAAA,OAAO,EAAE,gBAAA,EAAkB,YAAY,CAAA;AACzC;ADlQA;AACE;AACA;AACF,iHAAC","file":"/home/runner/work/augur-packages/augur-packages/packages/augur-hooks/dist/checkout/index.cjs","sourcesContent":[null,"\"use client\";\n\nimport React, {\n createContext,\n useContext,\n useState,\n useCallback,\n useEffect,\n useRef,\n type ReactElement,\n} from \"react\";\nimport { useQueryClient, type QueryClient } from \"@tanstack/react-query\";\nimport { usePaymentFlow, PAYMENT_STORAGE_KEY } from \"../hooks/use-payment-flow\";\nimport type { PaymentFlowCallbacks } from \"../hooks/use-payment-flow\";\nimport { clearFromSession } from \"../hooks/use-checkout-persistence\";\nimport { useOrderReadiness } from \"../hooks/use-order-readiness\";\nimport type { OrderReadinessParams } from \"../hooks/use-order-readiness\";\nimport { useCartHdrUid, useCartLines, useClearCart } from \"../stores/cart-store\";\nimport type { CustomerDocument } from \"@simpleapps-com/augur-utils\";\nimport type {\n CheckoutAddress,\n CheckoutContextValue,\n CheckoutContext,\n CheckoutPaymentModal,\n CheckoutProviderConfig,\n CheckoutProviderProps,\n} from \"./types\";\n\n/** sessionStorage key for persisted order confirmation data. */\nexport const ORDER_CONFIRMATION_KEY = \"orderConfirmation\";\n\n/** Default redirect via full page navigation. */\nfunction defaultRedirect(url: string): void {\n window.location.href = url;\n}\n\n/** Shape of the order state snapshot taken via ref. */\ninterface OrderStateSnapshot {\n shippingAddress: CheckoutAddress | undefined;\n billingAddress: CheckoutAddress | undefined;\n carrierId: string;\n shippingMethod: string | undefined;\n shippingFee: number | undefined;\n paymentMethod: string;\n taxRate: number | undefined;\n clientIp: string | undefined;\n isFreeShipping: boolean;\n identity: CheckoutProviderConfig[\"identity\"];\n unifiedPayment: unknown;\n unifiedCc: unknown;\n}\n\n/** Run pre-submit validation hooks. Returns error string or null. */\nfunction runPreSubmitChecks<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctx: CheckoutContext<TCustom>,\n shippingAddress: CheckoutAddress | undefined,\n): string | null {\n if (config.hooks?.onValidate) {\n const error = config.hooks.onValidate(ctx);\n if (error) return error;\n }\n if (config.hooks?.onBeforeSubmit) {\n const result = config.hooks.onBeforeSubmit(ctx);\n if (result === false) return \"__cancelled__\";\n }\n if (!shippingAddress) return \"Shipping address is required.\";\n return null;\n}\n\n/** Build the order data payload from current state. */\nfunction buildOrderData(s: OrderStateSnapshot): Record<string, unknown> {\n return {\n shippingAddress: s.shippingAddress,\n billingAddress: s.billingAddress,\n carrierId: s.carrierId,\n shippingMethod: s.shippingMethod,\n shippingFee: s.shippingFee,\n paymentMethod: s.paymentMethod,\n taxRate: s.taxRate,\n clientIp: s.clientIp,\n isFreeShipping: s.isFreeShipping,\n customerId: s.identity?.customerId,\n contactId: s.identity?.contactId,\n companyId: s.identity?.companyId,\n userId: s.identity?.userId,\n userEmail: s.identity?.userEmail,\n unifiedPayment: s.unifiedPayment,\n unifiedCc: s.unifiedCc,\n };\n}\n\n/** Handle order submission failure. */\nfunction handleOrderError<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n setProcessingOrder: (v: boolean) => void,\n error: unknown,\n): void {\n setProcessingOrder(false);\n const message = error instanceof Error ? error.message : \"Something went wrong.\";\n config.ui?.onError?.(\"Order Failed\", message);\n}\n\n/** Coerce cartHdrUid from store (string | number | undefined) to number. */\nfunction resolveCartHdrUid(cartHdrUid: number | string | undefined): number {\n if (typeof cartHdrUid === \"string\") return Number(cartHdrUid);\n return cartHdrUid ?? 0;\n}\n\n/**\n * Resolve the initial payment method. Honors `hooks.getDefaultPaymentMethod`\n * when provided; otherwise falls back to `\"credit-card\"` when payment\n * processing is configured and `\"invoice\"` when it is not.\n */\nfunction resolveDefaultPaymentMethod<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n): string {\n const explicit = config.hooks?.getDefaultPaymentMethod?.();\n if (explicit) return explicit;\n return config.payments?.callbacks ? \"credit-card\" : \"invoice\";\n}\n\n/**\n * Build the `customReadinessCheck` adapter for useOrderReadiness from the\n * site's `hooks.isOrderReady`. Returns `undefined` when no site hook is\n * provided so useOrderReadiness runs its default gates.\n */\nfunction buildReadinessOverride<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctxRef: React.RefObject<CheckoutContext<TCustom>>,\n): ((params: OrderReadinessParams) => boolean | undefined) | undefined {\n const siteIsOrderReady = config.hooks?.isOrderReady;\n if (!siteIsOrderReady) return undefined;\n return (params) => siteIsOrderReady(ctxRef.current, params);\n}\n\n/** Build order payload via assembleOrder hook or fallback to buildOrderData. */\nfunction assembleOrderPayload<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctx: CheckoutContext<TCustom>,\n contextValue: CheckoutContextValue<TCustom>,\n stateSnapshot: OrderStateSnapshot,\n): { orderData: Record<string, unknown>; error?: string } {\n if (config.hooks?.assembleOrder) {\n const assembled = config.hooks.assembleOrder(ctx, contextValue);\n if (assembled.error) return { orderData: {}, error: assembled.error };\n return { orderData: assembled.order };\n }\n return { orderData: buildOrderData(stateSnapshot) };\n}\n\n/**\n * Validate the minimum viable shape of an assembled order payload.\n *\n * Returns an error message when the payload is obviously broken, or `null`\n * when it passes. Invariants are conditional on key presence so sites using\n * the legacy `oe_hdr`/`oe_line` payload shape (or any shape without top-level\n * `lines`/`header`) pass through unchecked.\n *\n * Enforced invariants:\n * - `orderData` MUST be a non-null, non-array object.\n * - If `orderData.lines` is present, it MUST be a non-empty array.\n * - If `orderData.header` is present and is an object, it MUST include a\n * non-empty `customer_id`.\n */\nfunction validateOrderPayload(orderData: Record<string, unknown>): string | null {\n if (orderData === null || typeof orderData !== \"object\" || Array.isArray(orderData)) {\n return \"Order payload is empty or malformed.\";\n }\n\n if (\"lines\" in orderData) {\n const lines = orderData[\"lines\"];\n if (!Array.isArray(lines) || lines.length === 0) {\n return \"Order has no line items.\";\n }\n }\n\n if (\"header\" in orderData) {\n const header = orderData[\"header\"];\n if (header !== null && typeof header === \"object\" && !Array.isArray(header)) {\n const customerId = (header as Record<string, unknown>)[\"customer_id\"];\n if (customerId == null || String(customerId).trim() === \"\") {\n return \"Order is missing a customer.\";\n }\n }\n }\n\n return null;\n}\n\n/**\n * Assemble and validate the order payload. Surfaces any failure via\n * `config.ui.onError` + `setProcessingOrder(false)`, and additionally logs\n * the offending payload to `console.error` on validation failure. Returns\n * `null` when the payload was not produced or was rejected; returns the\n * `orderData` ready for `submitOrder` otherwise.\n */\nfunction prepareOrderPayload<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctx: CheckoutContext<TCustom>,\n contextValue: CheckoutContextValue<TCustom>,\n stateSnapshot: OrderStateSnapshot,\n setProcessingOrder: (v: boolean) => void,\n): Record<string, unknown> | null {\n const { orderData, error: assemblyError } = assembleOrderPayload(\n config,\n ctx,\n contextValue,\n stateSnapshot,\n );\n if (assemblyError) {\n setProcessingOrder(false);\n config.ui?.onError?.(\"Order Error\", assemblyError);\n return null;\n }\n\n const validationError = validateOrderPayload(orderData);\n if (validationError) {\n console.error(\"Order payload validation failed:\", orderData);\n setProcessingOrder(false);\n config.ui?.onError?.(\"Order Error\", validationError);\n return null;\n }\n\n return orderData;\n}\n\n/** Shape of persisted order confirmation data. */\nexport interface OrderConfirmation {\n orderData: Record<string, unknown>;\n result: unknown;\n shippingAddress: CheckoutAddress | undefined;\n billingAddress: CheckoutAddress | undefined;\n shippingFee: number | undefined;\n shippingMethod: string | undefined;\n taxRate: number | undefined;\n paymentMethod: string;\n carrierId: string;\n orderCartLines: unknown[] | undefined;\n}\n\n/** Build the confirmation snapshot from checkout state + API result. */\nfunction buildOrderConfirmation(\n orderData: Record<string, unknown>,\n resultData: unknown,\n state: OrderStateSnapshot,\n orderCartLines: unknown[] | undefined,\n): OrderConfirmation {\n return {\n orderData,\n result: resultData,\n shippingAddress: state.shippingAddress,\n billingAddress: state.billingAddress,\n shippingFee: state.shippingFee,\n shippingMethod: state.shippingMethod,\n taxRate: state.taxRate,\n paymentMethod: state.paymentMethod,\n carrierId: state.carrierId,\n orderCartLines,\n };\n}\n\n/**\n * Handle successful order submission.\n *\n * After running the site's `onAfterSubmit` hook and persisting the order\n * confirmation snapshot, the package clears its own client-side cart state:\n * the zustand cart store is reset, and the cart-related React Query caches\n * (`cartLines`, `cart-also-bought`, and the proxy-shape `commerce.cartLine`)\n * are invalidated so any subsequent page mount refetches from the server.\n * The redirect fires last. Sites retain responsibility for backend cart\n * cleanup inside `onAfterSubmit` or their `submitOrder` wrapper.\n */\nfunction handleOrderSuccess<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctx: CheckoutContext<TCustom>,\n resultData: unknown,\n confirmation: OrderConfirmation,\n setProcessingOrder: (v: boolean) => void,\n redirect: (url: string) => void,\n queryClient: QueryClient,\n clearCart: () => void,\n): void {\n if (config.payments?.persistence) {\n clearFromSession(PAYMENT_STORAGE_KEY);\n }\n config.hooks?.onAfterSubmit?.(ctx, resultData);\n if (config.order.persistence !== false) {\n try {\n sessionStorage.setItem(ORDER_CONFIRMATION_KEY, JSON.stringify(confirmation));\n } catch {\n // sessionStorage unavailable (private browsing, quota)\n }\n }\n clearCart();\n void queryClient.invalidateQueries({ queryKey: [\"cartLines\"] });\n void queryClient.invalidateQueries({ queryKey: [\"cart-also-bought\"] });\n void queryClient.invalidateQueries({ queryKey: [\"commerce\", \"cartLine\"] });\n redirect(config.order.successRedirect);\n setProcessingOrder(false);\n}\n\n/** Execute order submission -- extracted to reduce component complexity. */\nasync function executeOrder<TCustom extends Record<string, unknown>>(\n config: CheckoutProviderConfig<TCustom>,\n ctxRef: React.RefObject<CheckoutContext<TCustom>>,\n stateRef: React.RefObject<OrderStateSnapshot>,\n contextValueRef: React.RefObject<CheckoutContextValue<TCustom>>,\n cartHdrUid: number | string | undefined,\n setProcessingOrder: (v: boolean) => void,\n redirect: (url: string) => void,\n queryClient: QueryClient,\n clearCart: () => void,\n): Promise<void> {\n const ctx = ctxRef.current;\n const s = stateRef.current;\n\n const preCheck = runPreSubmitChecks(config, ctx, s.shippingAddress);\n if (preCheck === \"__cancelled__\") return;\n if (preCheck) {\n config.ui?.onError?.(\"Missing Information\", preCheck);\n return;\n }\n\n setProcessingOrder(true);\n\n const orderData = prepareOrderPayload(\n config,\n ctx,\n contextValueRef.current,\n s,\n setProcessingOrder,\n );\n if (!orderData) return;\n\n let result: { ok: boolean; data?: unknown; error?: string };\n try {\n result = await config.order.submitOrder(orderData, resolveCartHdrUid(cartHdrUid));\n } catch (error) {\n handleOrderError(config, setProcessingOrder, error);\n return;\n }\n\n if (!result.ok) {\n setProcessingOrder(false);\n config.ui?.onError?.(\"Order Failed\", result.error ?? \"Something went wrong.\");\n return;\n }\n\n const confirmation = buildOrderConfirmation(\n orderData,\n result.data,\n s,\n contextValueRef.current.orderCartLines,\n );\n handleOrderSuccess(\n config,\n ctx,\n result.data,\n confirmation,\n setProcessingOrder,\n redirect,\n queryClient,\n clearCart,\n );\n}\n\n/** No-op callbacks for when payment is not configured. */\nconst NOOP_PAYMENT_CALLBACKS: PaymentFlowCallbacks = {\n transactionSetup: async () => undefined,\n cardInfo: async () => undefined,\n validatePayment: async () => undefined,\n accountQuery: async () => undefined,\n billingUpdate: async () => undefined,\n};\n\n/**\n * Creates a CheckoutProvider component and useCheckout() hook from site config.\n *\n * The package owns all state, transitions, validation, and order submission.\n * Sites own layout and inject configuration + lifecycle hooks.\n *\n * Steps are string-based -- sites define their own step names.\n * Payment flow is optional -- B2B sites without payment processing omit payments.callbacks.\n *\n * @example\n * ```ts\n * // Full checkout with payment\n * const { CheckoutProvider, useCheckout } = createCheckoutProvider({\n * shipping: { carriers: { \"100008\": \"UPS Ground\" }, defaultCarrierId: \"100008\" },\n * payments: { callbacks: { transactionSetup, cardInfo, validatePayment, accountQuery, billingUpdate } },\n * order: { successRedirect: \"/thank-you\", submitOrder },\n * });\n *\n * // B2B checkout without payment\n * const { CheckoutProvider, useCheckout } = createCheckoutProvider({\n * shipping: { carriers: { \"100008\": \"UPS Ground\" }, defaultCarrierId: \"100008\" },\n * order: { successRedirect: \"/thank-you\", submitOrder },\n * });\n * ```\n */\n// Single context instance at module scope. Prevents stale context references\n// when createCheckoutProvider is re-called during HMR or page navigation.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Ctx = createContext<any>(null);\n\nexport function createCheckoutProvider<\n TCustom extends Record<string, unknown> = Record<string, never>,\n>(config: CheckoutProviderConfig<TCustom>) {\n const hasPaymentFlow = !!config.payments?.callbacks;\n\n function CheckoutProvider({\n children,\n identity: propsIdentity,\n }: CheckoutProviderProps): ReactElement {\n // -- Shipping state --\n const [shippingAddress, setShippingAddress] = useState<CheckoutAddress | undefined>();\n const [shippingFee, setShippingFee] = useState<number | undefined>();\n const [shippingMethod, setShippingMethod] = useState<string | undefined>();\n const [shippingAccepted, setShippingAccepted] = useState(false);\n const [shippingMethodSaved, setShippingMethodSaved] = useState(false);\n const [isFreeShipping, setIsFreeShipping] = useState(false);\n const [carrierId, setCarrierId] = useState(config.shipping.defaultCarrierId);\n const [showShippingMethod, setShowShippingMethod] = useState(false);\n\n // -- Billing state --\n const [billingAddress, setBillingAddress] = useState<CheckoutAddress | undefined>();\n const [paymentMethod, setPaymentMethod] = useState(() => resolveDefaultPaymentMethod(config));\n const [showBillingInfoSummary, setShowBillingInfoSummary] = useState(false);\n\n // -- Order state --\n const [orderCartLines, setOrderCartLines] = useState<unknown[] | undefined>();\n const [processingOrder, setProcessingOrder] = useState(false);\n const [taxRate, setTaxRate] = useState<number | undefined>(undefined);\n const [clientIp, setClientIp] = useState<string | undefined>();\n const [cartToken, setCartToken] = useState<string>(\"\");\n const [customerDoc, setCustomerDoc] = useState<CustomerDocument | null>(null);\n\n // -- Edit flags --\n const [isEditShippingInfo, setIsEditShippingInfo] = useState(false);\n const [isEditShippingMethods, setIsEditShippingMethods] = useState(false);\n const [isEditBillingInfo, setIsEditBillingInfo] = useState(false);\n\n // -- Step navigation (string-based, sites define their own steps) --\n const [currentStep, setCurrentStep] = useState<string>(config.initialStep ?? \"shipping\");\n\n // -- Custom state --\n const [customState, setCustomState] = useState<TCustom>(\n () => (config.customState ?? {}) as TCustom,\n );\n\n const setCustomField = useCallback(<K extends keyof TCustom>(key: K, value: TCustom[K]) => {\n setCustomState((prev) => ({ ...prev, [key]: value }));\n }, []);\n\n // -- Identity (props override config for runtime hook values) --\n const identity = propsIdentity ?? config.identity;\n const payment = usePaymentFlow({\n callbacks: config.payments?.callbacks ?? NOOP_PAYMENT_CALLBACKS,\n customerId: identity?.customerId,\n billingAddress,\n paymentMethod,\n shippingAccepted,\n persistPayment: config.payments?.persistence,\n });\n\n const paymentModal: CheckoutPaymentModal | undefined = hasPaymentFlow\n ? {\n isOpen: payment.isOpen,\n setIsOpen: payment.setIsOpen,\n editCc: payment.editCc,\n setEditCc: payment.setEditCc,\n unified: payment.unified,\n unifiedCc: payment.unifiedCc,\n unifiedResponse: payment.unifiedResponse,\n unifiedBilling: payment.unifiedBilling,\n unifiedPayment: payment.unifiedPayment,\n handleBinCapture: payment.handleBinCapture,\n hasValidPayment: !!payment.unifiedPayment?.PaymentAccountID,\n }\n : undefined;\n\n // -- Lifecycle context (passed to hooks) --\n const ctxRef = useRef<CheckoutContext<TCustom>>(null!);\n ctxRef.current = {\n get: <K extends keyof TCustom>(key: K) => customState[key],\n set: setCustomField,\n skipToStep: setCurrentStep,\n setBillingAddress,\n setCarrierId,\n };\n\n // -- Edit flag transitions --\n const handleSetIsEditShippingInfo = useCallback((editing: boolean) => {\n setIsEditShippingInfo(editing);\n if (editing) {\n setShippingMethodSaved(false);\n setShowShippingMethod(false);\n }\n }, []);\n\n const handleSetIsEditShippingMethods = useCallback((editing: boolean) => {\n setIsEditShippingMethods(editing);\n if (editing) {\n setShippingMethodSaved(false);\n }\n }, []);\n\n // -- Step transitions with lifecycle hook --\n const goToStep = useCallback(\n (step: string) => {\n const from = currentStep;\n if (config.hooks?.onStepChange) {\n config.hooks.onStepChange(ctxRef.current, from, step);\n }\n setCurrentStep(step);\n },\n [currentStep],\n );\n\n // -- Cart store integration --\n const cartHdrUid = useCartHdrUid();\n const cartLines = useCartLines();\n const clearCart = useClearCart();\n const queryClient = useQueryClient();\n\n // -- Order readiness --\n const { enableProcessOrderBtn, processingValidation } = useOrderReadiness({\n cartHdrUid,\n shippingAddress,\n billingAddress,\n shippingMethodSaved,\n showBillingInfoSummary,\n processingOrder,\n paymentMethod,\n unifiedPaymentAccountId: payment.unifiedPayment?.PaymentAccountID,\n unifiedBilling: payment.unifiedBilling,\n isFreeShipping,\n carrierId,\n shippingFee,\n isEditShippingInfo,\n isEditShippingMethods,\n isEditBillingInfo,\n editCc: payment.editCc,\n customReadinessCheck: buildReadinessOverride(config, ctxRef),\n });\n\n // -- Effects: data fetching on mount --\n\n useEffect(() => {\n if (config.order.fetchClientIp) {\n void config.order.fetchClientIp().then(setClientIp);\n }\n }, []);\n\n useEffect(() => {\n const custId = identity?.customerId;\n if (custId && identity?.fetchCustomerDoc) {\n void identity\n .fetchCustomerDoc(custId)\n .then(setCustomerDoc)\n .catch(() => setCustomerDoc(null));\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [identity?.customerId]);\n\n // -- Effect: tax calculation when billing address changes --\n useEffect(() => {\n if (!config.order.calculateTax || !billingAddress?.postalCode) return;\n void config.order\n .calculateTax({\n customerId: identity?.customerId,\n postalCode: billingAddress.postalCode,\n items: orderCartLines ?? [],\n customerDoc,\n })\n .then((tax) => {\n if (tax !== undefined) setTaxRate(tax);\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [billingAddress?.postalCode, orderCartLines]);\n\n // -- Effect: auto-copy shipping to billing (default \"same as shipping\") --\n useEffect(() => {\n if (shippingAccepted && shippingAddress && !billingAddress) {\n setBillingAddress(shippingAddress);\n }\n }, [shippingAccepted, shippingAddress, billingAddress]);\n\n // -- Effect: fire onShippingAccepted lifecycle hook --\n useEffect(() => {\n if (config.hooks?.onShippingAccepted && shippingAccepted && shippingAddress) {\n config.hooks.onShippingAccepted(ctxRef.current, shippingAddress, orderCartLines ?? []);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [shippingAccepted, shippingAddress]);\n\n // -- Effect: cart token from cookie --\n useEffect(() => {\n if (typeof document === \"undefined\") return;\n const cookies = document.cookie.split(\";\");\n const match = cookies.find((c) => c.trim().startsWith(\"cartToken=\"));\n if (match) {\n const token = match.split(\"=\")[1];\n if (token) setCartToken(token);\n }\n }, []);\n\n // -- Order submission with double-submit prevention --\n\n const resetProcessing = useCallback(() => setProcessingOrder(false), []);\n\n const isProcessingRef = useRef(false);\n\n const orderStateRef = useRef<OrderStateSnapshot>({\n shippingAddress,\n billingAddress,\n carrierId,\n shippingMethod,\n shippingFee,\n paymentMethod,\n taxRate,\n clientIp,\n isFreeShipping,\n identity,\n unifiedPayment: payment.unifiedPayment,\n unifiedCc: payment.unifiedCc,\n });\n orderStateRef.current = {\n shippingAddress,\n billingAddress,\n carrierId,\n shippingMethod,\n shippingFee,\n paymentMethod,\n taxRate,\n clientIp,\n isFreeShipping,\n identity,\n unifiedPayment: payment.unifiedPayment,\n unifiedCc: payment.unifiedCc,\n };\n\n const contextValueRef = useRef<CheckoutContextValue<TCustom>>(null!);\n\n const redirect = useCallback((url: string) => {\n if (config.order.redirect) {\n config.order.redirect(url);\n } else {\n defaultRedirect(url);\n }\n }, []);\n\n const processOrder = useCallback(async () => {\n if (isProcessingRef.current) return;\n isProcessingRef.current = true;\n try {\n await executeOrder(\n config,\n ctxRef,\n orderStateRef,\n contextValueRef,\n cartHdrUid,\n setProcessingOrder,\n redirect,\n queryClient,\n clearCart,\n );\n } finally {\n isProcessingRef.current = false;\n }\n }, [cartHdrUid, redirect, queryClient, clearCart]);\n\n // -- Context value --\n const value: CheckoutContextValue<TCustom> = {\n shippingAddress,\n setShippingAddress,\n shippingFee,\n setShippingFee,\n shippingMethod,\n setShippingMethod,\n shippingAccepted,\n setShippingAccepted,\n shippingMethodSaved,\n setShippingMethodSaved,\n isFreeShipping,\n setIsFreeShipping,\n carrierId,\n setCarrierId,\n showShippingMethod,\n setShowShippingMethod,\n billingAddress,\n setBillingAddress,\n paymentMethod,\n setPaymentMethod,\n showBillingInfoSummary,\n setShowBillingInfoSummary,\n paymentModal,\n cartLines,\n orderCartLines,\n setOrderCartLines,\n processingOrder,\n processOrder,\n resetProcessing,\n customerDoc,\n taxRate,\n setTaxRate,\n clientIp,\n cartToken,\n isEditShippingInfo,\n setIsEditShippingInfo: handleSetIsEditShippingInfo,\n isEditShippingMethods,\n setIsEditShippingMethods: handleSetIsEditShippingMethods,\n isEditBillingInfo,\n setIsEditBillingInfo,\n enableProcessOrderBtn,\n processingValidation,\n currentStep,\n goToStep,\n custom: customState,\n setCustom: setCustomField,\n config,\n };\n\n contextValueRef.current = value;\n\n return <Ctx.Provider value={value}>{children}</Ctx.Provider>;\n }\n\n /** Access checkout state from any child of CheckoutProvider. */\n function useCheckout(): CheckoutContextValue<TCustom> {\n const ctx = useContext(Ctx);\n if (!ctx) {\n throw new Error(\"useCheckout must be used within a CheckoutProvider\");\n }\n return ctx;\n }\n\n return { CheckoutProvider, useCheckout };\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode, ReactElement } from 'react';
|
|
2
|
-
import { a as PaymentFlowCallbacks } from '../use-
|
|
2
|
+
import { a as PaymentFlowCallbacks, O as OrderReadinessParams } from '../use-order-readiness-DZTIfRzw.cjs';
|
|
3
3
|
import { TCardInfo, TAccountQuery, TCartLine, CustomerDocument } from '@simpleapps-com/augur-utils';
|
|
4
4
|
export { TCartLine } from '@simpleapps-com/augur-utils';
|
|
5
5
|
|
|
@@ -104,7 +104,14 @@ interface CheckoutIdentityConfig {
|
|
|
104
104
|
/** Fetch customer document. Called once on mount with customerId. */
|
|
105
105
|
fetchCustomerDoc?: (customerId: string | number) => Promise<CustomerDocument | null>;
|
|
106
106
|
}
|
|
107
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* Lifecycle hooks that sites inject for customization.
|
|
109
|
+
*
|
|
110
|
+
* Hooks SHOULD be referenced stably (defined at module scope or memoized
|
|
111
|
+
* with `useMemo` / `useCallback`). A fresh function identity on every render
|
|
112
|
+
* is tolerated today but may cause redundant effect runs if dependency
|
|
113
|
+
* handling tightens in future versions.
|
|
114
|
+
*/
|
|
108
115
|
interface CheckoutLifecycleHooks<TCustom extends Record<string, unknown>> {
|
|
109
116
|
/**
|
|
110
117
|
* Called after shipping address is accepted.
|
|
@@ -122,13 +129,39 @@ interface CheckoutLifecycleHooks<TCustom extends Record<string, unknown>> {
|
|
|
122
129
|
onStepChange?: (ctx: CheckoutContext<TCustom>, fromStep: string, toStep: string) => void;
|
|
123
130
|
/** Custom validation. Return a string to block submission with a message. */
|
|
124
131
|
onValidate?: (ctx: CheckoutContext<TCustom>) => string | undefined;
|
|
125
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* Resolve the default payment method. Called once on mount.
|
|
134
|
+
*
|
|
135
|
+
* When omitted, the provider defaults to `"credit-card"` if
|
|
136
|
+
* `config.payments.callbacks` is configured and `"invoice"` otherwise.
|
|
137
|
+
* Sites with non-standard flows (sample-only, invoice-only) SHOULD
|
|
138
|
+
* return the correct default for their flow from here.
|
|
139
|
+
*/
|
|
126
140
|
getDefaultPaymentMethod?: () => string;
|
|
127
141
|
/** Assemble the order payload from checkout state. If not provided, uses buildCheckoutPayload. */
|
|
128
142
|
assembleOrder?: (ctx: CheckoutContext<TCustom>, state: CheckoutContextValue<TCustom>) => {
|
|
129
143
|
order: Record<string, unknown>;
|
|
130
144
|
error?: string;
|
|
131
145
|
};
|
|
146
|
+
/**
|
|
147
|
+
* Custom order-readiness check for non-standard order flows
|
|
148
|
+
* (sample-only, pickup-only, invoice-only, quote-only).
|
|
149
|
+
*
|
|
150
|
+
* Return `true` or `false` to override the default Process Order
|
|
151
|
+
* button gates (shipping-method, billing, credit-card validation).
|
|
152
|
+
* Return `undefined` to defer to the default gates.
|
|
153
|
+
*
|
|
154
|
+
* Compose default gates with site-specific logic by invoking
|
|
155
|
+
* `determineOrderReadiness` with a nulled override:
|
|
156
|
+
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* isOrderReady: (ctx, params) => {
|
|
159
|
+
* if (!ctx.get("isSampleItems")) return undefined; // defer
|
|
160
|
+
* return determineOrderReadiness({ ...params, customReadinessCheck: undefined });
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
isOrderReady?: (ctx: CheckoutContext<TCustom>, params: OrderReadinessParams) => boolean | undefined;
|
|
132
165
|
}
|
|
133
166
|
/** Full checkout provider configuration. */
|
|
134
167
|
interface CheckoutProviderConfig<TCustom extends Record<string, unknown> = Record<string, never>> {
|
package/dist/checkout/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode, ReactElement } from 'react';
|
|
2
|
-
import { a as PaymentFlowCallbacks } from '../use-
|
|
2
|
+
import { a as PaymentFlowCallbacks, O as OrderReadinessParams } from '../use-order-readiness-DZTIfRzw.js';
|
|
3
3
|
import { TCardInfo, TAccountQuery, TCartLine, CustomerDocument } from '@simpleapps-com/augur-utils';
|
|
4
4
|
export { TCartLine } from '@simpleapps-com/augur-utils';
|
|
5
5
|
|
|
@@ -104,7 +104,14 @@ interface CheckoutIdentityConfig {
|
|
|
104
104
|
/** Fetch customer document. Called once on mount with customerId. */
|
|
105
105
|
fetchCustomerDoc?: (customerId: string | number) => Promise<CustomerDocument | null>;
|
|
106
106
|
}
|
|
107
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* Lifecycle hooks that sites inject for customization.
|
|
109
|
+
*
|
|
110
|
+
* Hooks SHOULD be referenced stably (defined at module scope or memoized
|
|
111
|
+
* with `useMemo` / `useCallback`). A fresh function identity on every render
|
|
112
|
+
* is tolerated today but may cause redundant effect runs if dependency
|
|
113
|
+
* handling tightens in future versions.
|
|
114
|
+
*/
|
|
108
115
|
interface CheckoutLifecycleHooks<TCustom extends Record<string, unknown>> {
|
|
109
116
|
/**
|
|
110
117
|
* Called after shipping address is accepted.
|
|
@@ -122,13 +129,39 @@ interface CheckoutLifecycleHooks<TCustom extends Record<string, unknown>> {
|
|
|
122
129
|
onStepChange?: (ctx: CheckoutContext<TCustom>, fromStep: string, toStep: string) => void;
|
|
123
130
|
/** Custom validation. Return a string to block submission with a message. */
|
|
124
131
|
onValidate?: (ctx: CheckoutContext<TCustom>) => string | undefined;
|
|
125
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* Resolve the default payment method. Called once on mount.
|
|
134
|
+
*
|
|
135
|
+
* When omitted, the provider defaults to `"credit-card"` if
|
|
136
|
+
* `config.payments.callbacks` is configured and `"invoice"` otherwise.
|
|
137
|
+
* Sites with non-standard flows (sample-only, invoice-only) SHOULD
|
|
138
|
+
* return the correct default for their flow from here.
|
|
139
|
+
*/
|
|
126
140
|
getDefaultPaymentMethod?: () => string;
|
|
127
141
|
/** Assemble the order payload from checkout state. If not provided, uses buildCheckoutPayload. */
|
|
128
142
|
assembleOrder?: (ctx: CheckoutContext<TCustom>, state: CheckoutContextValue<TCustom>) => {
|
|
129
143
|
order: Record<string, unknown>;
|
|
130
144
|
error?: string;
|
|
131
145
|
};
|
|
146
|
+
/**
|
|
147
|
+
* Custom order-readiness check for non-standard order flows
|
|
148
|
+
* (sample-only, pickup-only, invoice-only, quote-only).
|
|
149
|
+
*
|
|
150
|
+
* Return `true` or `false` to override the default Process Order
|
|
151
|
+
* button gates (shipping-method, billing, credit-card validation).
|
|
152
|
+
* Return `undefined` to defer to the default gates.
|
|
153
|
+
*
|
|
154
|
+
* Compose default gates with site-specific logic by invoking
|
|
155
|
+
* `determineOrderReadiness` with a nulled override:
|
|
156
|
+
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* isOrderReady: (ctx, params) => {
|
|
159
|
+
* if (!ctx.get("isSampleItems")) return undefined; // defer
|
|
160
|
+
* return determineOrderReadiness({ ...params, customReadinessCheck: undefined });
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
isOrderReady?: (ctx: CheckoutContext<TCustom>, params: OrderReadinessParams) => boolean | undefined;
|
|
132
165
|
}
|
|
133
166
|
/** Full checkout provider configuration. */
|
|
134
167
|
interface CheckoutProviderConfig<TCustom extends Record<string, unknown> = Record<string, never>> {
|
package/dist/checkout/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
useClearCart,
|
|
7
7
|
useOrderReadiness,
|
|
8
8
|
usePaymentFlow
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-NRWH2BMN.js";
|
|
10
10
|
|
|
11
11
|
// src/checkout/create-checkout-provider.tsx
|
|
12
12
|
import {
|
|
@@ -64,6 +64,16 @@ function resolveCartHdrUid(cartHdrUid) {
|
|
|
64
64
|
if (typeof cartHdrUid === "string") return Number(cartHdrUid);
|
|
65
65
|
return cartHdrUid ?? 0;
|
|
66
66
|
}
|
|
67
|
+
function resolveDefaultPaymentMethod(config) {
|
|
68
|
+
const explicit = config.hooks?.getDefaultPaymentMethod?.();
|
|
69
|
+
if (explicit) return explicit;
|
|
70
|
+
return config.payments?.callbacks ? "credit-card" : "invoice";
|
|
71
|
+
}
|
|
72
|
+
function buildReadinessOverride(config, ctxRef) {
|
|
73
|
+
const siteIsOrderReady = config.hooks?.isOrderReady;
|
|
74
|
+
if (!siteIsOrderReady) return void 0;
|
|
75
|
+
return (params) => siteIsOrderReady(ctxRef.current, params);
|
|
76
|
+
}
|
|
67
77
|
function assembleOrderPayload(config, ctx, contextValue, stateSnapshot) {
|
|
68
78
|
if (config.hooks?.assembleOrder) {
|
|
69
79
|
const assembled = config.hooks.assembleOrder(ctx, contextValue);
|
|
@@ -216,8 +226,7 @@ function createCheckoutProvider(config) {
|
|
|
216
226
|
const [carrierId, setCarrierId] = useState(config.shipping.defaultCarrierId);
|
|
217
227
|
const [showShippingMethod, setShowShippingMethod] = useState(false);
|
|
218
228
|
const [billingAddress, setBillingAddress] = useState();
|
|
219
|
-
const
|
|
220
|
-
const [paymentMethod, setPaymentMethod] = useState(defaultPaymentMethod);
|
|
229
|
+
const [paymentMethod, setPaymentMethod] = useState(() => resolveDefaultPaymentMethod(config));
|
|
221
230
|
const [showBillingInfoSummary, setShowBillingInfoSummary] = useState(false);
|
|
222
231
|
const [orderCartLines, setOrderCartLines] = useState();
|
|
223
232
|
const [processingOrder, setProcessingOrder] = useState(false);
|
|
@@ -308,7 +317,8 @@ function createCheckoutProvider(config) {
|
|
|
308
317
|
isEditShippingInfo,
|
|
309
318
|
isEditShippingMethods,
|
|
310
319
|
isEditBillingInfo,
|
|
311
|
-
editCc: payment.editCc
|
|
320
|
+
editCc: payment.editCc,
|
|
321
|
+
customReadinessCheck: buildReadinessOverride(config, ctxRef)
|
|
312
322
|
});
|
|
313
323
|
useEffect(() => {
|
|
314
324
|
if (config.order.fetchClientIp) {
|