@wix/headless-bookings 0.0.118 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/dist/api/calculate-cart/index.d.ts +3 -0
- package/cjs/dist/api/calculate-cart/index.js +7 -0
- package/cjs/dist/api/create-cart/index.d.ts +3 -0
- package/cjs/dist/api/create-cart/index.js +10 -0
- package/cjs/dist/api/index.d.ts +3 -9
- package/cjs/dist/api/index.js +12 -17
- package/cjs/dist/api/place-order/index.d.ts +3 -0
- package/cjs/dist/api/place-order/index.js +7 -0
- package/cjs/dist/react/booking/Book.js +1 -1
- package/cjs/dist/react/core/booking/Book.d.ts +1 -1
- package/cjs/dist/react/core/booking/Book.js +1 -1
- package/cjs/dist/services/booking/book-action/bookAction.d.ts +0 -22
- package/cjs/dist/services/booking/book-action/bookAction.js +20 -39
- package/cjs/dist/services/booking/book-action/buildCartRequest.d.ts +10 -0
- package/cjs/dist/services/booking/book-action/buildCartRequest.js +37 -0
- package/cjs/dist/services/booking/book-action/index.d.ts +1 -1
- package/cjs/dist/services/booking/book-action/index.js +3 -3
- package/cjs/dist/services/booking/book-action/isCheckoutRequired.d.ts +3 -19
- package/cjs/dist/services/booking/book-action/isCheckoutRequired.js +11 -29
- package/cjs/dist/services/booking/book-action/types.d.ts +1 -1
- package/cjs/dist/services/index.d.ts +1 -1
- package/cjs/dist/services/index.js +2 -2
- package/cjs/dist/utils/navigation.d.ts +2 -2
- package/cjs/dist/utils/navigation.js +2 -2
- package/dist/api/calculate-cart/index.d.ts +3 -0
- package/dist/api/calculate-cart/index.js +4 -0
- package/dist/api/create-cart/index.d.ts +3 -0
- package/dist/api/create-cart/index.js +5 -0
- package/dist/api/index.d.ts +3 -9
- package/dist/api/index.js +3 -9
- package/dist/api/place-order/index.d.ts +3 -0
- package/dist/api/place-order/index.js +4 -0
- package/dist/react/booking/Book.js +1 -1
- package/dist/react/core/booking/Book.d.ts +1 -1
- package/dist/react/core/booking/Book.js +1 -1
- package/dist/services/booking/book-action/bookAction.d.ts +0 -22
- package/dist/services/booking/book-action/bookAction.js +20 -39
- package/dist/services/booking/book-action/buildCartRequest.d.ts +10 -0
- package/dist/services/booking/book-action/buildCartRequest.js +34 -0
- package/dist/services/booking/book-action/index.d.ts +1 -1
- package/dist/services/booking/book-action/index.js +1 -1
- package/dist/services/booking/book-action/isCheckoutRequired.d.ts +3 -19
- package/dist/services/booking/book-action/isCheckoutRequired.js +11 -29
- package/dist/services/booking/book-action/types.d.ts +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/utils/navigation.d.ts +2 -2
- package/dist/utils/navigation.js +2 -2
- package/package.json +3 -3
- package/cjs/dist/api/create-checkout/index.d.ts +0 -40
- package/cjs/dist/api/create-checkout/index.js +0 -42
- package/cjs/dist/api/create-order/index.d.ts +0 -20
- package/cjs/dist/api/create-order/index.js +0 -24
- package/cjs/dist/services/booking/book-action/buildCheckoutRequest.d.ts +0 -28
- package/cjs/dist/services/booking/book-action/buildCheckoutRequest.js +0 -65
- package/dist/api/create-checkout/index.d.ts +0 -40
- package/dist/api/create-checkout/index.js +0 -37
- package/dist/api/create-order/index.d.ts +0 -20
- package/dist/api/create-order/index.js +0 -21
- package/dist/services/booking/book-action/buildCheckoutRequest.d.ts +0 -28
- package/dist/services/booking/book-action/buildCheckoutRequest.js +0 -62
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type CalculateCartOptions, type CalculateCartResponse } from '@wix/auto_sdk_ecom_cart-v-2';
|
|
2
|
+
export declare function calculateCart(cartId: string, options?: CalculateCartOptions): Promise<CalculateCartResponse>;
|
|
3
|
+
export type { CalculateCartResponse, CartSummary, } from '@wix/auto_sdk_ecom_cart-v-2';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateCart = calculateCart;
|
|
4
|
+
const auto_sdk_ecom_cart_v_2_1 = require("@wix/auto_sdk_ecom_cart-v-2");
|
|
5
|
+
async function calculateCart(cartId, options) {
|
|
6
|
+
return (0, auto_sdk_ecom_cart_v_2_1.calculateCart)(cartId, options);
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChannelType = void 0;
|
|
4
|
+
exports.createCart = createCart;
|
|
5
|
+
const auto_sdk_ecom_cart_v_2_1 = require("@wix/auto_sdk_ecom_cart-v-2");
|
|
6
|
+
async function createCart(options) {
|
|
7
|
+
return (0, auto_sdk_ecom_cart_v_2_1.createCart)(options);
|
|
8
|
+
}
|
|
9
|
+
var auto_sdk_ecom_cart_v_2_2 = require("@wix/auto_sdk_ecom_cart-v-2");
|
|
10
|
+
Object.defineProperty(exports, "ChannelType", { enumerable: true, get: function () { return auto_sdk_ecom_cart_v_2_2.ChannelType; } });
|
package/cjs/dist/api/index.d.ts
CHANGED
|
@@ -7,14 +7,8 @@
|
|
|
7
7
|
export { getServiceById, getServiceBySlug, queryServices, convertPlatformFilterToApiFilter, type PagingMetadata, type QueryServicesRequest, SYNTHETIC_CUSTOM_ID, SYNTHETIC_CUSTOMER_ID, } from './query-services/index.js';
|
|
8
8
|
export { fetchAvailability } from './fetch-availability/index.js';
|
|
9
9
|
export { createBooking, type CreateBookingOptions, type Booking, type CreateBookingRequest, type CreateBookingResponse, type ParticipantNotification, type ContactDetails, } from './create-booking/index.js';
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
10
|
+
export { createCart, ChannelType, type CreateCartOptions, type Cart, } from './create-cart/index.js';
|
|
11
|
+
export { calculateCart, type CalculateCartResponse, type CartSummary, } from './calculate-cart/index.js';
|
|
12
|
+
export { placeOrder, type PlaceOrderOptions, type PlaceOrderResponse, } from './place-order/index.js';
|
|
12
13
|
export { queryLocations, getLocationById, type QueryLocationsResult, type LocationData, } from './query-locations/index.js';
|
|
13
14
|
export { queryCategories, type QueryCategoriesResult, type Category, } from './query-categories/index.js';
|
|
14
|
-
/**
|
|
15
|
-
* PagingMetadata includes:
|
|
16
|
-
* - limit: Number of items per page
|
|
17
|
-
* - offset: Number of items to skip
|
|
18
|
-
* - count: Number of items returned in the current page
|
|
19
|
-
* - hasNext: Whether there are more services available to load
|
|
20
|
-
*/
|
package/cjs/dist/api/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @module API
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.queryCategories = exports.getLocationById = exports.queryLocations = exports.
|
|
9
|
+
exports.queryCategories = exports.getLocationById = exports.queryLocations = exports.placeOrder = exports.calculateCart = exports.ChannelType = exports.createCart = exports.createBooking = exports.fetchAvailability = exports.SYNTHETIC_CUSTOMER_ID = exports.SYNTHETIC_CUSTOM_ID = exports.convertPlatformFilterToApiFilter = exports.queryServices = exports.getServiceBySlug = exports.getServiceById = void 0;
|
|
10
10
|
var index_js_1 = require("./query-services/index.js");
|
|
11
11
|
Object.defineProperty(exports, "getServiceById", { enumerable: true, get: function () { return index_js_1.getServiceById; } });
|
|
12
12
|
Object.defineProperty(exports, "getServiceBySlug", { enumerable: true, get: function () { return index_js_1.getServiceBySlug; } });
|
|
@@ -18,20 +18,15 @@ var index_js_2 = require("./fetch-availability/index.js");
|
|
|
18
18
|
Object.defineProperty(exports, "fetchAvailability", { enumerable: true, get: function () { return index_js_2.fetchAvailability; } });
|
|
19
19
|
var index_js_3 = require("./create-booking/index.js");
|
|
20
20
|
Object.defineProperty(exports, "createBooking", { enumerable: true, get: function () { return index_js_3.createBooking; } });
|
|
21
|
-
var index_js_4 = require("./create-
|
|
22
|
-
Object.defineProperty(exports, "
|
|
21
|
+
var index_js_4 = require("./create-cart/index.js");
|
|
22
|
+
Object.defineProperty(exports, "createCart", { enumerable: true, get: function () { return index_js_4.createCart; } });
|
|
23
23
|
Object.defineProperty(exports, "ChannelType", { enumerable: true, get: function () { return index_js_4.ChannelType; } });
|
|
24
|
-
var index_js_5 = require("./
|
|
25
|
-
Object.defineProperty(exports, "
|
|
26
|
-
var index_js_6 = require("./
|
|
27
|
-
Object.defineProperty(exports, "
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Object.defineProperty(exports, "
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* - limit: Number of items per page
|
|
34
|
-
* - offset: Number of items to skip
|
|
35
|
-
* - count: Number of items returned in the current page
|
|
36
|
-
* - hasNext: Whether there are more services available to load
|
|
37
|
-
*/
|
|
24
|
+
var index_js_5 = require("./calculate-cart/index.js");
|
|
25
|
+
Object.defineProperty(exports, "calculateCart", { enumerable: true, get: function () { return index_js_5.calculateCart; } });
|
|
26
|
+
var index_js_6 = require("./place-order/index.js");
|
|
27
|
+
Object.defineProperty(exports, "placeOrder", { enumerable: true, get: function () { return index_js_6.placeOrder; } });
|
|
28
|
+
var index_js_7 = require("./query-locations/index.js");
|
|
29
|
+
Object.defineProperty(exports, "queryLocations", { enumerable: true, get: function () { return index_js_7.queryLocations; } });
|
|
30
|
+
Object.defineProperty(exports, "getLocationById", { enumerable: true, get: function () { return index_js_7.getLocationById; } });
|
|
31
|
+
var index_js_8 = require("./query-categories/index.js");
|
|
32
|
+
Object.defineProperty(exports, "queryCategories", { enumerable: true, get: function () { return index_js_8.queryCategories; } });
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type PlaceOrderOptions, type PlaceOrderResponse } from '@wix/auto_sdk_ecom_cart-v-2';
|
|
2
|
+
export declare function placeOrder(cartId: string, options?: PlaceOrderOptions): Promise<PlaceOrderResponse>;
|
|
3
|
+
export type { PlaceOrderOptions, PlaceOrderResponse, } from '@wix/auto_sdk_ecom_cart-v-2';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.placeOrder = placeOrder;
|
|
4
|
+
const auto_sdk_ecom_cart_v_2_1 = require("@wix/auto_sdk_ecom_cart-v-2");
|
|
5
|
+
async function placeOrder(cartId, options) {
|
|
6
|
+
return (0, auto_sdk_ecom_cart_v_2_1.placeOrder)(cartId, options);
|
|
7
|
+
}
|
|
@@ -99,7 +99,7 @@ exports.Book = react_1.default.forwardRef((props, ref) => {
|
|
|
99
99
|
return ((0, jsx_runtime_1.jsx)(CoreBook.Book, { onCheckout: (result) => {
|
|
100
100
|
// Create navigateToCheckout with checkoutId captured
|
|
101
101
|
const navigateToCheckout = (options) => (0, navigation_js_1.navigateToCheckout)({
|
|
102
|
-
|
|
102
|
+
cartId: result.cartId,
|
|
103
103
|
navigationInfo: { postFlowUrl: options.postFlowUrl },
|
|
104
104
|
});
|
|
105
105
|
// Return user's callback result so core can await it
|
|
@@ -24,7 +24,7 @@ export interface BookProps {
|
|
|
24
24
|
* Return a Promise to keep loading state active until it resolves.
|
|
25
25
|
*/
|
|
26
26
|
onCheckout?: (result: {
|
|
27
|
-
|
|
27
|
+
cartId: string;
|
|
28
28
|
}) => void | Promise<unknown>;
|
|
29
29
|
/**
|
|
30
30
|
* Called when booking completes without requiring checkout.
|
|
@@ -52,7 +52,7 @@ function Book(props) {
|
|
|
52
52
|
try {
|
|
53
53
|
const result = await bookingService.actions.book();
|
|
54
54
|
if (result.type === types_js_1.BookResultType.CheckoutRequired) {
|
|
55
|
-
await onCheckout?.({
|
|
55
|
+
await onCheckout?.({ cartId: result.cartId });
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
58
58
|
await onComplete?.({ orderId: result.orderId });
|
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Book Action - Orchestrates the booking flow
|
|
3
|
-
*
|
|
4
|
-
* 1. Validates booking data with canBook()
|
|
5
|
-
* 2. Creates a booking via createBooking() from API layer
|
|
6
|
-
* 3. Creates a checkout via createCheckout() from API layer
|
|
7
|
-
* 4. Determines if checkout is required or can be skipped
|
|
8
|
-
* 5. Returns appropriate result for navigation
|
|
9
|
-
*/
|
|
10
1
|
import { type BookActionParams, type BookResult } from './types.js';
|
|
11
|
-
/**
|
|
12
|
-
* Executes the complete booking flow:
|
|
13
|
-
* 1. Validates that all required data is present
|
|
14
|
-
* 2. Creates a booking with the selected service, time slot, and form data
|
|
15
|
-
* 3. Creates a checkout session for payment (includes contact details from booking)
|
|
16
|
-
* 4. Determines if checkout page is required or can be skipped
|
|
17
|
-
* 5. If checkout can be skipped (free/offline), creates order directly
|
|
18
|
-
* 6. Returns appropriate result for navigation
|
|
19
|
-
*
|
|
20
|
-
* @param params - The booking action parameters
|
|
21
|
-
* @returns BookResult with either checkoutId or orderId
|
|
22
|
-
* @throws Error if validation fails, or booking/checkout/order creation fails
|
|
23
|
-
*/
|
|
24
2
|
export declare function executeBookAction(params: BookActionParams): Promise<BookResult>;
|
|
@@ -1,38 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Book Action - Orchestrates the booking flow
|
|
4
|
-
*
|
|
5
|
-
* 1. Validates booking data with canBook()
|
|
6
|
-
* 2. Creates a booking via createBooking() from API layer
|
|
7
|
-
* 3. Creates a checkout via createCheckout() from API layer
|
|
8
|
-
* 4. Determines if checkout is required or can be skipped
|
|
9
|
-
* 5. Returns appropriate result for navigation
|
|
10
|
-
*/
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.executeBookAction = executeBookAction;
|
|
13
4
|
const index_js_1 = require("../../../api/create-booking/index.js");
|
|
14
|
-
const index_js_2 = require("../../../api/create-
|
|
15
|
-
const index_js_3 = require("../../../api/
|
|
5
|
+
const index_js_2 = require("../../../api/create-cart/index.js");
|
|
6
|
+
const index_js_3 = require("../../../api/calculate-cart/index.js");
|
|
7
|
+
const index_js_4 = require("../../../api/place-order/index.js");
|
|
16
8
|
const buildBookingRequest_js_1 = require("./buildBookingRequest.js");
|
|
17
|
-
const
|
|
9
|
+
const buildCartRequest_js_1 = require("./buildCartRequest.js");
|
|
18
10
|
const canBook_js_1 = require("./canBook.js");
|
|
19
11
|
const isCheckoutRequired_js_1 = require("./isCheckoutRequired.js");
|
|
20
12
|
const types_js_1 = require("./types.js");
|
|
21
|
-
/**
|
|
22
|
-
* Executes the complete booking flow:
|
|
23
|
-
* 1. Validates that all required data is present
|
|
24
|
-
* 2. Creates a booking with the selected service, time slot, and form data
|
|
25
|
-
* 3. Creates a checkout session for payment (includes contact details from booking)
|
|
26
|
-
* 4. Determines if checkout page is required or can be skipped
|
|
27
|
-
* 5. If checkout can be skipped (free/offline), creates order directly
|
|
28
|
-
* 6. Returns appropriate result for navigation
|
|
29
|
-
*
|
|
30
|
-
* @param params - The booking action parameters
|
|
31
|
-
* @returns BookResult with either checkoutId or orderId
|
|
32
|
-
* @throws Error if validation fails, or booking/checkout/order creation fails
|
|
33
|
-
*/
|
|
34
13
|
async function executeBookAction(params) {
|
|
35
|
-
// Step 0: Validate
|
|
36
14
|
if (!(0, canBook_js_1.canBook)({
|
|
37
15
|
serviceSelections: params.serviceSelections,
|
|
38
16
|
formSubmission: params.formSubmission,
|
|
@@ -51,34 +29,37 @@ async function executeBookAction(params) {
|
|
|
51
29
|
if (!bookingId) {
|
|
52
30
|
throw new Error('Failed to create booking');
|
|
53
31
|
}
|
|
54
|
-
// Step 2: Create
|
|
55
|
-
// businessLocationId: prefer timeSlot.location, fallback to global location
|
|
32
|
+
// Step 2: Create cart
|
|
56
33
|
const firstSelection = params.serviceSelections[0];
|
|
57
34
|
if (!firstSelection) {
|
|
58
35
|
throw new Error('No service selection found');
|
|
59
36
|
}
|
|
60
37
|
const businessLocationId = firstSelection.timeSlot?.location?._id ?? undefined;
|
|
61
|
-
const
|
|
38
|
+
const cartRequest = (0, buildCartRequest_js_1.buildCartRequest)({
|
|
62
39
|
bookingId,
|
|
63
40
|
contactDetails,
|
|
64
41
|
businessLocationId,
|
|
65
42
|
appId: params.appId,
|
|
66
43
|
});
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
throw new Error('Failed to create checkout');
|
|
44
|
+
const cart = await (0, index_js_2.createCart)(cartRequest);
|
|
45
|
+
if (!cart._id) {
|
|
46
|
+
throw new Error('Failed to create cart');
|
|
71
47
|
}
|
|
72
|
-
// Step 3:
|
|
48
|
+
// Step 3: Calculate cart to get totals (not stored on Cart V2 entity)
|
|
49
|
+
const { cart: calculatedCart, summary } = await (0, index_js_3.calculateCart)(cart._id);
|
|
50
|
+
if (!calculatedCart || !summary) {
|
|
51
|
+
throw new Error('Failed to calculate cart');
|
|
52
|
+
}
|
|
53
|
+
// Step 4: Determine if checkout is required or can be skipped
|
|
73
54
|
const service = firstSelection.service;
|
|
74
|
-
if ((0, isCheckoutRequired_js_1.isCheckoutRequired)(
|
|
75
|
-
return { type: types_js_1.BookResultType.CheckoutRequired,
|
|
55
|
+
if ((0, isCheckoutRequired_js_1.isCheckoutRequired)(calculatedCart, summary, service)) {
|
|
56
|
+
return { type: types_js_1.BookResultType.CheckoutRequired, cartId: cart._id };
|
|
76
57
|
}
|
|
77
|
-
// Step
|
|
78
|
-
const orderResponse = await (0,
|
|
58
|
+
// Step 5: Skip checkout — place order directly
|
|
59
|
+
const orderResponse = await (0, index_js_4.placeOrder)(cart._id);
|
|
79
60
|
const orderId = orderResponse.orderId;
|
|
80
61
|
if (!orderId) {
|
|
81
|
-
throw new Error('Failed to
|
|
62
|
+
throw new Error('Failed to place order');
|
|
82
63
|
}
|
|
83
64
|
return { type: types_js_1.BookResultType.CheckoutSkipped, orderId };
|
|
84
65
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CreateCartOptions } from '../../../api/create-cart/index.js';
|
|
2
|
+
import type { ContactDetails } from '../../../api/create-booking/index.js';
|
|
3
|
+
export interface BuildCartParams {
|
|
4
|
+
bookingId: string;
|
|
5
|
+
contactDetails?: ContactDetails;
|
|
6
|
+
businessLocationId?: string;
|
|
7
|
+
/** Optional app ID override for the catalog reference. Defaults to BOOKING_APP_ID. */
|
|
8
|
+
appId?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function buildCartRequest(params: BuildCartParams): CreateCartOptions;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildCartRequest = buildCartRequest;
|
|
4
|
+
const index_js_1 = require("../../../api/create-cart/index.js");
|
|
5
|
+
const constants_js_1 = require("../../constants.js");
|
|
6
|
+
function buildCartRequest(params) {
|
|
7
|
+
const { bookingId, contactDetails, businessLocationId, appId } = params;
|
|
8
|
+
const cart = {
|
|
9
|
+
source: { channelType: index_js_1.ChannelType.WEB },
|
|
10
|
+
};
|
|
11
|
+
if (businessLocationId) {
|
|
12
|
+
cart.businessInfo = { locationId: businessLocationId };
|
|
13
|
+
}
|
|
14
|
+
if (contactDetails) {
|
|
15
|
+
cart.customerInfo = {
|
|
16
|
+
...(contactDetails.email ? { email: contactDetails.email } : {}),
|
|
17
|
+
};
|
|
18
|
+
if (contactDetails.fullAddress?.country) {
|
|
19
|
+
cart.deliveryInfo = { address: { ...contactDetails.fullAddress } };
|
|
20
|
+
cart.paymentInfo = {
|
|
21
|
+
billingAddress: { ...contactDetails.fullAddress },
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
catalogItems: [
|
|
27
|
+
{
|
|
28
|
+
quantity: 1,
|
|
29
|
+
catalogReference: {
|
|
30
|
+
catalogItemId: bookingId,
|
|
31
|
+
appId: appId ?? constants_js_1.BOOKING_APP_ID,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
cart,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
export { executeBookAction } from './bookAction.js';
|
|
5
5
|
export { canBook, type CanBookParams } from './canBook.js';
|
|
6
6
|
export { buildBookingRequest } from './buildBookingRequest.js';
|
|
7
|
-
export {
|
|
7
|
+
export { buildCartRequest, type BuildCartParams } from './buildCartRequest.js';
|
|
8
8
|
export { isCheckoutRequired } from './isCheckoutRequired.js';
|
|
9
9
|
export { BookResultType, type BookProps, type BookResult, type BookingError, type BookActionParams, type BookChildProps, } from './types.js';
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
* Book Action - Exports
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.BookResultType = exports.isCheckoutRequired = exports.
|
|
6
|
+
exports.BookResultType = exports.isCheckoutRequired = exports.buildCartRequest = exports.buildBookingRequest = exports.canBook = exports.executeBookAction = void 0;
|
|
7
7
|
var bookAction_js_1 = require("./bookAction.js");
|
|
8
8
|
Object.defineProperty(exports, "executeBookAction", { enumerable: true, get: function () { return bookAction_js_1.executeBookAction; } });
|
|
9
9
|
var canBook_js_1 = require("./canBook.js");
|
|
10
10
|
Object.defineProperty(exports, "canBook", { enumerable: true, get: function () { return canBook_js_1.canBook; } });
|
|
11
11
|
var buildBookingRequest_js_1 = require("./buildBookingRequest.js");
|
|
12
12
|
Object.defineProperty(exports, "buildBookingRequest", { enumerable: true, get: function () { return buildBookingRequest_js_1.buildBookingRequest; } });
|
|
13
|
-
var
|
|
14
|
-
Object.defineProperty(exports, "
|
|
13
|
+
var buildCartRequest_js_1 = require("./buildCartRequest.js");
|
|
14
|
+
Object.defineProperty(exports, "buildCartRequest", { enumerable: true, get: function () { return buildCartRequest_js_1.buildCartRequest; } });
|
|
15
15
|
var isCheckoutRequired_js_1 = require("./isCheckoutRequired.js");
|
|
16
16
|
Object.defineProperty(exports, "isCheckoutRequired", { enumerable: true, get: function () { return isCheckoutRequired_js_1.isCheckoutRequired; } });
|
|
17
17
|
var types_js_1 = require("./types.js");
|
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import type { Checkout } from '@wix/auto_sdk_ecom_checkout';
|
|
1
|
+
import type { Cart } from '../../../api/create-cart/index.js';
|
|
2
|
+
import type { CartSummary } from '../../../api/calculate-cart/index.js';
|
|
5
3
|
import type { Service } from '@wix/auto_sdk_bookings_services';
|
|
6
|
-
|
|
7
|
-
* Determines if checkout page is required based on payment amounts.
|
|
8
|
-
*
|
|
9
|
-
* Skip checkout when:
|
|
10
|
-
* - Free booking: payNow = 0 AND payLater = 0
|
|
11
|
-
* - Offline payment: payNow = 0
|
|
12
|
-
*
|
|
13
|
-
* Force checkout when:
|
|
14
|
-
* - Service has cancellation fee policy
|
|
15
|
-
*
|
|
16
|
-
* @param checkout - The checkout response from createCheckout
|
|
17
|
-
* @param service - The service being booked
|
|
18
|
-
* @returns true if checkout page is required, false if can skip to order
|
|
19
|
-
*/
|
|
20
|
-
export declare function isCheckoutRequired(checkout: Checkout, service: Service): boolean;
|
|
4
|
+
export declare function isCheckoutRequired(cart: Cart, summary: CartSummary, service: Service): boolean;
|
|
@@ -1,35 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Determines if checkout page is required based on payment amounts
|
|
4
|
-
*/
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.isCheckoutRequired = isCheckoutRequired;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
* Skip checkout when:
|
|
11
|
-
* - Free booking: payNow = 0 AND payLater = 0
|
|
12
|
-
* - Offline payment: payNow = 0
|
|
13
|
-
*
|
|
14
|
-
* Force checkout when:
|
|
15
|
-
* - Service has cancellation fee policy
|
|
16
|
-
*
|
|
17
|
-
* @param checkout - The checkout response from createCheckout
|
|
18
|
-
* @param service - The service being booked
|
|
19
|
-
* @returns true if checkout page is required, false if can skip to order
|
|
20
|
-
*/
|
|
21
|
-
function isCheckoutRequired(checkout, service) {
|
|
22
|
-
// Force checkout for cancellation fee policy
|
|
23
|
-
const hasCancellationFee = service.bookingPolicy?.cancellationFeePolicy?.enabled;
|
|
24
|
-
if (hasCancellationFee) {
|
|
4
|
+
function isCheckoutRequired(cart, summary, service) {
|
|
5
|
+
if (service.bookingPolicy?.cancellationFeePolicy?.enabled) {
|
|
25
6
|
return true;
|
|
26
7
|
}
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
8
|
+
const total = Number(summary.priceSummary?.total?.amount ?? 0);
|
|
9
|
+
if (total === 0) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const paymentOption = cart.lineItems?.[0]?.paymentConfig?.paymentOption;
|
|
13
|
+
if (paymentOption === 'FULL_PAYMENT_OFFLINE') {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
35
17
|
}
|
|
@@ -7,7 +7,7 @@ export { BookingService, BookingServiceDefinition, type BookingServiceConfig, ty
|
|
|
7
7
|
export { TimeSlotListService, TimeSlotListServiceDefinition, TimeSlotService, TimeSlotServiceDefinition, ViewMode, loadTimeSlotListConfig, type TimeSlotListServiceAPI, type TimeSlotListServiceActions, type TimeSlotListServiceConfig, type TimeSlotServiceAPI, type TimeSlotServiceConfig, type LoadTimeSlotListConfigOptions, type LoadTimeSlotListConfigResult, } from './time-slot-list/index.js';
|
|
8
8
|
export { ServiceListService, ServiceListServiceDefinition, type ServiceListServiceAPI, type ServiceListServiceConfig, type ServiceListActions, type QueryOptions, loadServiceListServiceInitialData, type SuccessServiceListServiceConfigResult, type ErrorServiceListServiceConfigResult, } from './service-list/service-list.js';
|
|
9
9
|
export { SYNTHETIC_CUSTOM_ID, SYNTHETIC_CUSTOMER_ID, } from '../api/query-services/index.js';
|
|
10
|
-
export { executeBookAction, canBook, buildBookingRequest,
|
|
10
|
+
export { executeBookAction, canBook, buildBookingRequest, buildCartRequest, type CanBookParams, type BookResult, type BookingError, type BookActionParams, type BookChildProps, type BookProps, type BuildCartParams, } from './booking/book-action/index.js';
|
|
11
11
|
export { BookingFormService, BookingFormServiceDefinition, type BookingFormServiceAPI, type BookingFormServiceConfig, } from './booking-form/booking-form.js';
|
|
12
12
|
export { PaymentService, PaymentServiceDefinition, type PaymentServiceAPI, type PaymentServiceConfig, type PaymentDetails, type PricingServiceSelection, type LineItemAdditionalInfo, type ServicePaymentOptions, loadPaymentConfig, type SuccessPaymentConfigResult, type ErrorPaymentConfigResult, } from './payment/payment.js';
|
|
13
13
|
export { LocationListService, LocationListServiceDefinition, LocationType, loadLocationListServiceInitialData, locationListServiceBinding, type LocationListServiceAPI, type LocationListServiceConfig, type LocationListActions, type Location, type LoadLocationListServiceResult, getLocationById, } from './location-list/location-list.js';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Main export file for all service definitions and implementations
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.staffMemberListServiceBinding = exports.loadStaffMemberListServiceInitialData = exports.StaffMemberListServiceDefinition = exports.StaffMemberListService = exports.getLocationById = exports.locationListServiceBinding = exports.loadLocationListServiceInitialData = exports.LocationType = exports.LocationListServiceDefinition = exports.LocationListService = exports.loadPaymentConfig = exports.PaymentServiceDefinition = exports.PaymentService = exports.BookingFormServiceDefinition = exports.BookingFormService = exports.
|
|
7
|
+
exports.staffMemberListServiceBinding = exports.loadStaffMemberListServiceInitialData = exports.StaffMemberListServiceDefinition = exports.StaffMemberListService = exports.getLocationById = exports.locationListServiceBinding = exports.loadLocationListServiceInitialData = exports.LocationType = exports.LocationListServiceDefinition = exports.LocationListService = exports.loadPaymentConfig = exports.PaymentServiceDefinition = exports.PaymentService = exports.BookingFormServiceDefinition = exports.BookingFormService = exports.buildCartRequest = exports.buildBookingRequest = exports.canBook = exports.executeBookAction = exports.SYNTHETIC_CUSTOMER_ID = exports.SYNTHETIC_CUSTOM_ID = exports.loadServiceListServiceInitialData = exports.ServiceListServiceDefinition = exports.ServiceListService = exports.loadTimeSlotListConfig = exports.ViewMode = exports.TimeSlotServiceDefinition = exports.TimeSlotService = exports.TimeSlotListServiceDefinition = exports.TimeSlotListService = exports.BookingServiceDefinition = exports.BookingService = exports.loadServiceServiceInitialData = exports.ServiceServiceDefinition = exports.ServiceService = void 0;
|
|
8
8
|
var service_js_1 = require("./service/service.js");
|
|
9
9
|
Object.defineProperty(exports, "ServiceService", { enumerable: true, get: function () { return service_js_1.ServiceService; } });
|
|
10
10
|
Object.defineProperty(exports, "ServiceServiceDefinition", { enumerable: true, get: function () { return service_js_1.ServiceServiceDefinition; } });
|
|
@@ -30,7 +30,7 @@ var index_js_3 = require("./booking/book-action/index.js");
|
|
|
30
30
|
Object.defineProperty(exports, "executeBookAction", { enumerable: true, get: function () { return index_js_3.executeBookAction; } });
|
|
31
31
|
Object.defineProperty(exports, "canBook", { enumerable: true, get: function () { return index_js_3.canBook; } });
|
|
32
32
|
Object.defineProperty(exports, "buildBookingRequest", { enumerable: true, get: function () { return index_js_3.buildBookingRequest; } });
|
|
33
|
-
Object.defineProperty(exports, "
|
|
33
|
+
Object.defineProperty(exports, "buildCartRequest", { enumerable: true, get: function () { return index_js_3.buildCartRequest; } });
|
|
34
34
|
var booking_form_js_1 = require("./booking-form/booking-form.js");
|
|
35
35
|
Object.defineProperty(exports, "BookingFormService", { enumerable: true, get: function () { return booking_form_js_1.BookingFormService; } });
|
|
36
36
|
Object.defineProperty(exports, "BookingFormServiceDefinition", { enumerable: true, get: function () { return booking_form_js_1.BookingFormServiceDefinition; } });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export interface NavigationInfo {
|
|
2
2
|
postFlowUrl: string;
|
|
3
3
|
}
|
|
4
|
-
export declare function navigateToCheckout({
|
|
5
|
-
|
|
4
|
+
export declare function navigateToCheckout({ cartId, navigationInfo, }: {
|
|
5
|
+
cartId: string;
|
|
6
6
|
navigationInfo: NavigationInfo;
|
|
7
7
|
}): Promise<void>;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.navigateToCheckout = navigateToCheckout;
|
|
4
4
|
const redirects_1 = require("@wix/redirects");
|
|
5
|
-
async function navigateToCheckout({
|
|
5
|
+
async function navigateToCheckout({ cartId, navigationInfo, }) {
|
|
6
6
|
const { redirectSession } = await redirects_1.redirects.createRedirectSession({
|
|
7
|
-
ecomCheckout: { checkoutId },
|
|
7
|
+
ecomCheckout: { checkoutId: cartId },
|
|
8
8
|
callbacks: {
|
|
9
9
|
postFlowUrl: navigationInfo.postFlowUrl,
|
|
10
10
|
},
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type CalculateCartOptions, type CalculateCartResponse } from '@wix/auto_sdk_ecom_cart-v-2';
|
|
2
|
+
export declare function calculateCart(cartId: string, options?: CalculateCartOptions): Promise<CalculateCartResponse>;
|
|
3
|
+
export type { CalculateCartResponse, CartSummary, } from '@wix/auto_sdk_ecom_cart-v-2';
|
package/dist/api/index.d.ts
CHANGED
|
@@ -7,14 +7,8 @@
|
|
|
7
7
|
export { getServiceById, getServiceBySlug, queryServices, convertPlatformFilterToApiFilter, type PagingMetadata, type QueryServicesRequest, SYNTHETIC_CUSTOM_ID, SYNTHETIC_CUSTOMER_ID, } from './query-services/index.js';
|
|
8
8
|
export { fetchAvailability } from './fetch-availability/index.js';
|
|
9
9
|
export { createBooking, type CreateBookingOptions, type Booking, type CreateBookingRequest, type CreateBookingResponse, type ParticipantNotification, type ContactDetails, } from './create-booking/index.js';
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
10
|
+
export { createCart, ChannelType, type CreateCartOptions, type Cart, } from './create-cart/index.js';
|
|
11
|
+
export { calculateCart, type CalculateCartResponse, type CartSummary, } from './calculate-cart/index.js';
|
|
12
|
+
export { placeOrder, type PlaceOrderOptions, type PlaceOrderResponse, } from './place-order/index.js';
|
|
12
13
|
export { queryLocations, getLocationById, type QueryLocationsResult, type LocationData, } from './query-locations/index.js';
|
|
13
14
|
export { queryCategories, type QueryCategoriesResult, type Category, } from './query-categories/index.js';
|
|
14
|
-
/**
|
|
15
|
-
* PagingMetadata includes:
|
|
16
|
-
* - limit: Number of items per page
|
|
17
|
-
* - offset: Number of items to skip
|
|
18
|
-
* - count: Number of items returned in the current page
|
|
19
|
-
* - hasNext: Whether there are more services available to load
|
|
20
|
-
*/
|
package/dist/api/index.js
CHANGED
|
@@ -7,14 +7,8 @@
|
|
|
7
7
|
export { getServiceById, getServiceBySlug, queryServices, convertPlatformFilterToApiFilter, SYNTHETIC_CUSTOM_ID, SYNTHETIC_CUSTOMER_ID, } from './query-services/index.js';
|
|
8
8
|
export { fetchAvailability } from './fetch-availability/index.js';
|
|
9
9
|
export { createBooking, } from './create-booking/index.js';
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
10
|
+
export { createCart, ChannelType, } from './create-cart/index.js';
|
|
11
|
+
export { calculateCart, } from './calculate-cart/index.js';
|
|
12
|
+
export { placeOrder, } from './place-order/index.js';
|
|
12
13
|
export { queryLocations, getLocationById, } from './query-locations/index.js';
|
|
13
14
|
export { queryCategories, } from './query-categories/index.js';
|
|
14
|
-
/**
|
|
15
|
-
* PagingMetadata includes:
|
|
16
|
-
* - limit: Number of items per page
|
|
17
|
-
* - offset: Number of items to skip
|
|
18
|
-
* - count: Number of items returned in the current page
|
|
19
|
-
* - hasNext: Whether there are more services available to load
|
|
20
|
-
*/
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type PlaceOrderOptions, type PlaceOrderResponse } from '@wix/auto_sdk_ecom_cart-v-2';
|
|
2
|
+
export declare function placeOrder(cartId: string, options?: PlaceOrderOptions): Promise<PlaceOrderResponse>;
|
|
3
|
+
export type { PlaceOrderOptions, PlaceOrderResponse, } from '@wix/auto_sdk_ecom_cart-v-2';
|
|
@@ -60,7 +60,7 @@ export const Book = React.forwardRef((props, ref) => {
|
|
|
60
60
|
return (_jsx(CoreBook.Book, { onCheckout: (result) => {
|
|
61
61
|
// Create navigateToCheckout with checkoutId captured
|
|
62
62
|
const navigateToCheckout = (options) => navigateToCheckoutUtil({
|
|
63
|
-
|
|
63
|
+
cartId: result.cartId,
|
|
64
64
|
navigationInfo: { postFlowUrl: options.postFlowUrl },
|
|
65
65
|
});
|
|
66
66
|
// Return user's callback result so core can await it
|
|
@@ -24,7 +24,7 @@ export interface BookProps {
|
|
|
24
24
|
* Return a Promise to keep loading state active until it resolves.
|
|
25
25
|
*/
|
|
26
26
|
onCheckout?: (result: {
|
|
27
|
-
|
|
27
|
+
cartId: string;
|
|
28
28
|
}) => void | Promise<unknown>;
|
|
29
29
|
/**
|
|
30
30
|
* Called when booking completes without requiring checkout.
|
|
@@ -49,7 +49,7 @@ export function Book(props) {
|
|
|
49
49
|
try {
|
|
50
50
|
const result = await bookingService.actions.book();
|
|
51
51
|
if (result.type === BookResultType.CheckoutRequired) {
|
|
52
|
-
await onCheckout?.({
|
|
52
|
+
await onCheckout?.({ cartId: result.cartId });
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
55
|
await onComplete?.({ orderId: result.orderId });
|
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Book Action - Orchestrates the booking flow
|
|
3
|
-
*
|
|
4
|
-
* 1. Validates booking data with canBook()
|
|
5
|
-
* 2. Creates a booking via createBooking() from API layer
|
|
6
|
-
* 3. Creates a checkout via createCheckout() from API layer
|
|
7
|
-
* 4. Determines if checkout is required or can be skipped
|
|
8
|
-
* 5. Returns appropriate result for navigation
|
|
9
|
-
*/
|
|
10
1
|
import { type BookActionParams, type BookResult } from './types.js';
|
|
11
|
-
/**
|
|
12
|
-
* Executes the complete booking flow:
|
|
13
|
-
* 1. Validates that all required data is present
|
|
14
|
-
* 2. Creates a booking with the selected service, time slot, and form data
|
|
15
|
-
* 3. Creates a checkout session for payment (includes contact details from booking)
|
|
16
|
-
* 4. Determines if checkout page is required or can be skipped
|
|
17
|
-
* 5. If checkout can be skipped (free/offline), creates order directly
|
|
18
|
-
* 6. Returns appropriate result for navigation
|
|
19
|
-
*
|
|
20
|
-
* @param params - The booking action parameters
|
|
21
|
-
* @returns BookResult with either checkoutId or orderId
|
|
22
|
-
* @throws Error if validation fails, or booking/checkout/order creation fails
|
|
23
|
-
*/
|
|
24
2
|
export declare function executeBookAction(params: BookActionParams): Promise<BookResult>;
|