@wix/headless-bookings 1.0.2 → 1.0.4

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.
@@ -98,28 +98,40 @@ function buildLineItem(service, totalParticipants, lineItemId) {
98
98
  function getDurationRange(service) {
99
99
  return service.schedule?.availabilityConstraints?.durationRange;
100
100
  }
101
- async function getPreviewedPrice(service, localStartDate, localEndDate, timeZone) {
101
+ async function getPreviewedPrice(service, localStartDate, localEndDate, timeZone, numberOfParticipants) {
102
102
  if (!service._id)
103
103
  return null;
104
104
  const lineItemInput = {
105
105
  serviceId: service._id,
106
106
  localStartDate,
107
107
  localEndDate,
108
+ numberOfParticipants,
108
109
  ...(timeZone ? { timeZone } : {}),
109
110
  };
110
111
  const result = await (0, auto_sdk_bookings_pricing_1.previewPrice)([lineItemInput]);
111
- return result.priceInfo?.calculatedPrice ?? null;
112
+ const price = result.priceInfo?.calculatedPrice;
113
+ if (price == null)
114
+ return null;
115
+ return {
116
+ price,
117
+ deposit: result.priceInfo?.deposit ?? null,
118
+ };
112
119
  }
113
120
  async function buildLineItemWithPreview(item, totalParticipants) {
114
121
  if (item.localStartDate &&
115
122
  item.localEndDate &&
116
123
  getDurationRange(item.service)) {
117
- const previewedPrice = await getPreviewedPrice(item.service, item.localStartDate, item.localEndDate, item.timeZone).catch(() => null);
124
+ const previewedPrice = await getPreviewedPrice(item.service, item.localStartDate, item.localEndDate, item.timeZone, totalParticipants).catch(() => null);
118
125
  if (previewedPrice != null) {
119
126
  const depositValue = item.service.payment?.fixed?.deposit?.value;
120
- const hasDeposit = !!depositValue && Number(depositValue) > 0;
127
+ const previewedDeposit = previewedPrice.deposit;
128
+ const hasDeposit = previewedDeposit != null
129
+ ? previewedDeposit > 0
130
+ : !!depositValue && Number(depositValue) > 0;
121
131
  const deposit = hasDeposit
122
- ? Number(depositValue) * totalParticipants
132
+ ? previewedDeposit != null
133
+ ? previewedDeposit
134
+ : Number(depositValue) * totalParticipants
123
135
  : undefined;
124
136
  return {
125
137
  _id: item.lineItemId,
@@ -127,7 +139,7 @@ async function buildLineItemWithPreview(item, totalParticipants) {
127
139
  catalogItemId: item.service._id || '',
128
140
  appId: constants_js_1.BOOKING_APP_ID,
129
141
  },
130
- price: String(previewedPrice),
142
+ price: String(previewedPrice.price),
131
143
  ...(deposit ? { depositAmount: String(deposit) } : {}),
132
144
  quantity: 1,
133
145
  paymentOption: getPaymentOption(item.service, hasDeposit),
@@ -93,28 +93,40 @@ function buildLineItem(service, totalParticipants, lineItemId) {
93
93
  function getDurationRange(service) {
94
94
  return service.schedule?.availabilityConstraints?.durationRange;
95
95
  }
96
- async function getPreviewedPrice(service, localStartDate, localEndDate, timeZone) {
96
+ async function getPreviewedPrice(service, localStartDate, localEndDate, timeZone, numberOfParticipants) {
97
97
  if (!service._id)
98
98
  return null;
99
99
  const lineItemInput = {
100
100
  serviceId: service._id,
101
101
  localStartDate,
102
102
  localEndDate,
103
+ numberOfParticipants,
103
104
  ...(timeZone ? { timeZone } : {}),
104
105
  };
105
106
  const result = await previewPrice([lineItemInput]);
106
- return result.priceInfo?.calculatedPrice ?? null;
107
+ const price = result.priceInfo?.calculatedPrice;
108
+ if (price == null)
109
+ return null;
110
+ return {
111
+ price,
112
+ deposit: result.priceInfo?.deposit ?? null,
113
+ };
107
114
  }
108
115
  async function buildLineItemWithPreview(item, totalParticipants) {
109
116
  if (item.localStartDate &&
110
117
  item.localEndDate &&
111
118
  getDurationRange(item.service)) {
112
- const previewedPrice = await getPreviewedPrice(item.service, item.localStartDate, item.localEndDate, item.timeZone).catch(() => null);
119
+ const previewedPrice = await getPreviewedPrice(item.service, item.localStartDate, item.localEndDate, item.timeZone, totalParticipants).catch(() => null);
113
120
  if (previewedPrice != null) {
114
121
  const depositValue = item.service.payment?.fixed?.deposit?.value;
115
- const hasDeposit = !!depositValue && Number(depositValue) > 0;
122
+ const previewedDeposit = previewedPrice.deposit;
123
+ const hasDeposit = previewedDeposit != null
124
+ ? previewedDeposit > 0
125
+ : !!depositValue && Number(depositValue) > 0;
116
126
  const deposit = hasDeposit
117
- ? Number(depositValue) * totalParticipants
127
+ ? previewedDeposit != null
128
+ ? previewedDeposit
129
+ : Number(depositValue) * totalParticipants
118
130
  : undefined;
119
131
  return {
120
132
  _id: item.lineItemId,
@@ -122,7 +134,7 @@ async function buildLineItemWithPreview(item, totalParticipants) {
122
134
  catalogItemId: item.service._id || '',
123
135
  appId: BOOKING_APP_ID,
124
136
  },
125
- price: String(previewedPrice),
137
+ price: String(previewedPrice.price),
126
138
  ...(deposit ? { depositAmount: String(deposit) } : {}),
127
139
  quantity: 1,
128
140
  paymentOption: getPaymentOption(item.service, hasDeposit),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-bookings",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
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": "402687344b7c916e00531f83dab622fae9b9efda7b82abadc49c484b"
78
+ "falconPackageHash": "dec47e7070b4b0988f6a3174a24135c58fd38c13c4a9d098bd0e9d99"
79
79
  }