@wix/headless-bookings 1.0.4 → 1.0.6

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.
Files changed (67) hide show
  1. package/cjs/dist/__mocks__/booking/booking-client-service.js +4 -1
  2. package/cjs/dist/api/create-booking/index.d.ts +4 -4
  3. package/cjs/dist/api/create-bulk-booking/index.d.ts +54 -0
  4. package/cjs/dist/api/create-bulk-booking/index.js +54 -0
  5. package/cjs/dist/api/create-multi-service-booking/index.d.ts +53 -0
  6. package/cjs/dist/api/create-multi-service-booking/index.js +47 -0
  7. package/cjs/dist/api/index.d.ts +4 -1
  8. package/cjs/dist/api/index.js +32 -13
  9. package/cjs/dist/react/core/booking/Booking.d.ts +6 -1
  10. package/cjs/dist/react/core/booking/Booking.js +2 -0
  11. package/cjs/dist/services/booking/book-action/bookAction.js +39 -27
  12. package/cjs/dist/services/booking/book-action/buildBookingRequest.d.ts +1 -1
  13. package/cjs/dist/services/booking/book-action/buildBookingRequest.js +4 -2
  14. package/cjs/dist/services/booking/book-action/buildCartRequest.d.ts +20 -2
  15. package/cjs/dist/services/booking/book-action/buildCartRequest.js +24 -13
  16. package/cjs/dist/services/booking/book-action/buildDayRangeBookingRequest.d.ts +37 -0
  17. package/cjs/dist/services/booking/book-action/buildDayRangeBookingRequest.js +70 -0
  18. package/cjs/dist/services/booking/book-action/canBook.d.ts +2 -1
  19. package/cjs/dist/services/booking/book-action/canBook.js +4 -2
  20. package/cjs/dist/services/booking/book-action/createBookingsForCart.d.ts +22 -0
  21. package/cjs/dist/services/booking/book-action/createBookingsForCart.js +69 -0
  22. package/cjs/dist/services/booking/book-action/dayRange.d.ts +34 -0
  23. package/cjs/dist/services/booking/book-action/dayRange.js +43 -0
  24. package/cjs/dist/services/booking/book-action/index.d.ts +9 -6
  25. package/cjs/dist/services/booking/book-action/index.js +23 -13
  26. package/cjs/dist/services/booking/book-action/types.d.ts +15 -0
  27. package/cjs/dist/services/booking/booking.d.ts +31 -2
  28. package/cjs/dist/services/booking/booking.js +8 -0
  29. package/cjs/dist/services/index.d.ts +1 -1
  30. package/cjs/dist/services/index.js +6 -1
  31. package/cjs/dist/services/payment/payment.d.ts +4 -0
  32. package/cjs/dist/services/payment/payment.def.d.ts +6 -0
  33. package/cjs/dist/services/payment/payment.js +39 -17
  34. package/dist/__mocks__/booking/booking-client-service.js +4 -1
  35. package/dist/api/create-booking/index.d.ts +4 -4
  36. package/dist/api/create-bulk-booking/index.d.ts +54 -0
  37. package/dist/api/create-bulk-booking/index.js +51 -0
  38. package/dist/api/create-multi-service-booking/index.d.ts +53 -0
  39. package/dist/api/create-multi-service-booking/index.js +44 -0
  40. package/dist/api/index.d.ts +4 -1
  41. package/dist/api/index.js +3 -0
  42. package/dist/react/core/booking/Booking.d.ts +6 -1
  43. package/dist/react/core/booking/Booking.js +2 -0
  44. package/dist/services/booking/book-action/bookAction.js +34 -22
  45. package/dist/services/booking/book-action/buildBookingRequest.d.ts +1 -1
  46. package/dist/services/booking/book-action/buildBookingRequest.js +4 -2
  47. package/dist/services/booking/book-action/buildCartRequest.d.ts +20 -2
  48. package/dist/services/booking/book-action/buildCartRequest.js +23 -13
  49. package/dist/services/booking/book-action/buildDayRangeBookingRequest.d.ts +37 -0
  50. package/dist/services/booking/book-action/buildDayRangeBookingRequest.js +67 -0
  51. package/dist/services/booking/book-action/canBook.d.ts +2 -1
  52. package/dist/services/booking/book-action/canBook.js +4 -2
  53. package/dist/services/booking/book-action/createBookingsForCart.d.ts +22 -0
  54. package/dist/services/booking/book-action/createBookingsForCart.js +66 -0
  55. package/dist/services/booking/book-action/dayRange.d.ts +34 -0
  56. package/dist/services/booking/book-action/dayRange.js +39 -0
  57. package/dist/services/booking/book-action/index.d.ts +9 -6
  58. package/dist/services/booking/book-action/index.js +9 -6
  59. package/dist/services/booking/book-action/types.d.ts +15 -0
  60. package/dist/services/booking/booking.d.ts +31 -2
  61. package/dist/services/booking/booking.js +8 -0
  62. package/dist/services/index.d.ts +1 -1
  63. package/dist/services/index.js +1 -1
  64. package/dist/services/payment/payment.d.ts +4 -0
  65. package/dist/services/payment/payment.def.d.ts +6 -0
  66. package/dist/services/payment/payment.js +39 -17
  67. package/package.json +2 -2
@@ -52,7 +52,21 @@ function getAdditionalInfo(service, lineItemId) {
52
52
  : undefined;
53
53
  return { lineItemId, customPrice };
54
54
  }
55
- function getPaymentOption(service, hasDeposit) {
55
+ /**
56
+ * Resolves the line item's `paymentOption`.
57
+ *
58
+ * Precedence: explicit consumer choice (`selectedPaymentOption`) wins over the
59
+ * service-config heuristic so the preview always agrees with what `book()`
60
+ * will send. When unset, the existing heuristic is preserved for backward
61
+ * compat.
62
+ */
63
+ function getPaymentOption(service, hasDeposit, selectedPaymentOption) {
64
+ if (selectedPaymentOption === 'OFFLINE') {
65
+ return 'FULL_PAYMENT_OFFLINE';
66
+ }
67
+ if (selectedPaymentOption === 'ONLINE') {
68
+ return hasDeposit ? 'DEPOSIT_ONLINE' : 'FULL_PAYMENT_ONLINE';
69
+ }
56
70
  const options = service.payment?.options;
57
71
  if (options?.inPerson) {
58
72
  return 'FULL_PAYMENT_OFFLINE';
@@ -63,7 +77,7 @@ function getPaymentOption(service, hasDeposit) {
63
77
  }
64
78
  return 'FULL_PAYMENT_ONLINE';
65
79
  }
66
- function buildLineItem(service, totalParticipants, lineItemId) {
80
+ function buildLineItem(service, totalParticipants, lineItemId, selectedPaymentOption) {
67
81
  // Get fixed price from service
68
82
  const servicePrice = service.payment?.fixed?.price?.value;
69
83
  const price = Number(servicePrice || 0) * totalParticipants;
@@ -74,7 +88,7 @@ function buildLineItem(service, totalParticipants, lineItemId) {
74
88
  ? Number(depositValue) * totalParticipants
75
89
  : undefined;
76
90
  // Get payment option from service configuration (pass hasDeposit for correct API behavior)
77
- const paymentOption = getPaymentOption(service, hasDeposit);
91
+ const paymentOption = getPaymentOption(service, hasDeposit, selectedPaymentOption);
78
92
  return {
79
93
  _id: lineItemId,
80
94
  catalogReference: {
@@ -112,7 +126,7 @@ async function getPreviewedPrice(service, localStartDate, localEndDate, timeZone
112
126
  deposit: result.priceInfo?.deposit ?? null,
113
127
  };
114
128
  }
115
- async function buildLineItemWithPreview(item, totalParticipants) {
129
+ async function buildLineItemWithPreview(item, totalParticipants, selectedPaymentOption) {
116
130
  if (item.localStartDate &&
117
131
  item.localEndDate &&
118
132
  getDurationRange(item.service)) {
@@ -137,18 +151,18 @@ async function buildLineItemWithPreview(item, totalParticipants) {
137
151
  price: String(previewedPrice.price),
138
152
  ...(deposit ? { depositAmount: String(deposit) } : {}),
139
153
  quantity: 1,
140
- paymentOption: getPaymentOption(item.service, hasDeposit),
154
+ paymentOption: getPaymentOption(item.service, hasDeposit, selectedPaymentOption),
141
155
  };
142
156
  }
143
157
  }
144
- return buildLineItem(item.service, totalParticipants, item.lineItemId);
158
+ return buildLineItem(item.service, totalParticipants, item.lineItemId, selectedPaymentOption);
145
159
  }
146
- async function calculatePaymentDetails(pricingServiceSelections, totalParticipants) {
160
+ async function calculatePaymentDetails(pricingServiceSelections, totalParticipants, selectedPaymentOption) {
147
161
  const data = pricingServiceSelections.map((selection) => ({
148
162
  ...selection,
149
163
  lineItemId: selection.lineItemId || generateLineItemId(),
150
164
  }));
151
- const lineItems = await Promise.all(data.map((item) => buildLineItemWithPreview(item, totalParticipants)));
165
+ const lineItems = await Promise.all(data.map((item) => buildLineItemWithPreview(item, totalParticipants, selectedPaymentOption)));
152
166
  const response = await calculateTotals({
153
167
  lineItems,
154
168
  });
@@ -179,7 +193,7 @@ export const PaymentService = implementService.withConfig()(PaymentServiceDefini
179
193
  const errorSignal = signalsService.signal(null);
180
194
  const serviceOptionsSignal = signalsService.signal(config.serviceOptions || DEFAULT_SERVICE_OPTIONS);
181
195
  // Internal calculate function
182
- const calculate = async (pricingServiceSelections, totalParticipants) => {
196
+ const calculate = async (pricingServiceSelections, totalParticipants, selectedPaymentOption) => {
183
197
  if (!pricingServiceSelections.length) {
184
198
  paymentDetailsSignal.set(null);
185
199
  return;
@@ -187,7 +201,7 @@ export const PaymentService = implementService.withConfig()(PaymentServiceDefini
187
201
  isLoadingSignal.set(true);
188
202
  errorSignal.set(null);
189
203
  try {
190
- const paymentDetails = await calculatePaymentDetails(pricingServiceSelections, totalParticipants);
204
+ const paymentDetails = await calculatePaymentDetails(pricingServiceSelections, totalParticipants, selectedPaymentOption);
191
205
  paymentDetailsSignal.set(paymentDetails);
192
206
  }
193
207
  catch (error) {
@@ -215,24 +229,30 @@ export const PaymentService = implementService.withConfig()(PaymentServiceDefini
215
229
  // Mode 2: Lazy loading - pricingServiceSelections provided via internal config
216
230
  else if (config.pricingServiceSelections?.length) {
217
231
  serviceOptionsSignal.set(deriveServiceOptions(config.pricingServiceSelections));
218
- void calculate(config.pricingServiceSelections, config.totalParticipants ?? 1);
232
+ void calculate(config.pricingServiceSelections, config.totalParticipants ?? 1, config.selectedPaymentOption);
219
233
  }
220
234
  // Mode 3: Reactive - observe BookingService signals (client-side only)
221
235
  else if (typeof window !== 'undefined' && bookingService) {
222
- // Computed signal that changes when services or selected time slots change (not participants)
236
+ // Computed signal that changes when services, selected time slots, or
237
+ // the consumer-selected payment option change (not participants).
223
238
  const servicesKey = signalsService.computed(() => {
224
239
  const selections = bookingService?.serviceSelections.get() || [];
225
240
  const timezone = bookingService?.timezone.get();
241
+ const selectedPaymentOption = bookingService?.selectedPaymentOption.get();
226
242
  return (selections
227
243
  .map((s) => `${s.service._id}:${s.timeSlot?.startDate ?? ''}:${s.timeSlot?.endDate ?? ''}`)
228
- .join(',') + `:${timezone ?? ''}`);
244
+ .join(',') +
245
+ `:${timezone ?? ''}` +
246
+ `:${selectedPaymentOption ?? ''}`);
229
247
  });
230
248
  signalsService.effect(() => {
231
- // Subscribe to servicesKey to trigger effect when service or time slot changes
249
+ // Subscribe to servicesKey to trigger effect when service, time
250
+ // slot, or selected payment option changes.
232
251
  servicesKey.get();
233
252
  // Read current selections without subscribing (peek)
234
253
  const selections = bookingService?.serviceSelections.peek() || [];
235
254
  const timezone = bookingService?.timezone.peek();
255
+ const selectedPaymentOption = bookingService?.selectedPaymentOption.peek();
236
256
  // For single service mode, take the first selection
237
257
  const firstSelection = selections[0];
238
258
  const numParticipants = firstSelection?.totalParticipants || 1;
@@ -246,7 +266,7 @@ export const PaymentService = implementService.withConfig()(PaymentServiceDefini
246
266
  if (pricingServiceSelections.length) {
247
267
  serviceOptionsSignal.set(deriveServiceOptions(pricingServiceSelections));
248
268
  }
249
- void calculate(pricingServiceSelections, numParticipants);
269
+ void calculate(pricingServiceSelections, numParticipants, selectedPaymentOption);
250
270
  });
251
271
  }
252
272
  return {
@@ -262,10 +282,12 @@ export const PaymentService = implementService.withConfig()(PaymentServiceDefini
262
282
  *
263
283
  * @param params.pricingServiceSelections - Pricing service selections for calculation
264
284
  * @param params.totalParticipants - Number of participants (default: 1)
285
+ * @param params.selectedPaymentOption - Optional consumer-selected payment option;
286
+ * overrides the service-config heuristic on each line item's `paymentOption`.
265
287
  */
266
288
  export async function loadPaymentConfig(params) {
267
289
  try {
268
- const { pricingServiceSelections, totalParticipants = 1 } = params;
290
+ const { pricingServiceSelections, totalParticipants = 1, selectedPaymentOption, } = params;
269
291
  if (!pricingServiceSelections.length) {
270
292
  return {
271
293
  type: 'success',
@@ -275,7 +297,7 @@ export async function loadPaymentConfig(params) {
275
297
  },
276
298
  };
277
299
  }
278
- const paymentDetails = await calculatePaymentDetails(pricingServiceSelections, totalParticipants);
300
+ const paymentDetails = await calculatePaymentDetails(pricingServiceSelections, totalParticipants, selectedPaymentOption);
279
301
  return {
280
302
  type: 'success',
281
303
  config: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-bookings",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -75,5 +75,5 @@
75
75
  "groupId": "com.wixpress.headless-components"
76
76
  }
77
77
  },
78
- "falconPackageHash": "dec47e7070b4b0988f6a3174a24135c58fd38c13c4a9d098bd0e9d99"
78
+ "falconPackageHash": "de3338c8d4e43446a69ef7116ba391beea6642f2f39551d997fe0ca1"
79
79
  }