@wix/headless-bookings 0.0.57 → 0.0.58
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/react/booking/Booking.js +1 -1
- package/cjs/dist/react/core/booking/Booking.d.ts +3 -3
- package/cjs/dist/react/core/booking/Booking.js +2 -2
- package/cjs/dist/react/core/payment/Payment.d.ts +84 -5
- package/cjs/dist/react/core/payment/Payment.js +102 -4
- package/cjs/dist/react/payment/Payment.d.ts +64 -58
- package/cjs/dist/react/payment/Payment.js +66 -80
- package/cjs/dist/services/index.d.ts +1 -1
- package/cjs/dist/services/payment/payment.d.ts +4 -4
- package/cjs/dist/services/payment/payment.def.d.ts +4 -4
- package/cjs/dist/services/payment/payment.js +26 -18
- package/dist/react/booking/Booking.js +1 -1
- package/dist/react/core/booking/Booking.d.ts +3 -3
- package/dist/react/core/booking/Booking.js +2 -2
- package/dist/react/core/payment/Payment.d.ts +84 -5
- package/dist/react/core/payment/Payment.js +102 -4
- package/dist/react/payment/Payment.d.ts +64 -58
- package/dist/react/payment/Payment.js +66 -80
- package/dist/services/index.d.ts +1 -1
- package/dist/services/payment/payment.d.ts +4 -4
- package/dist/services/payment/payment.def.d.ts +4 -4
- package/dist/services/payment/payment.js +26 -18
- package/package.json +2 -2
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Handles calculating total prices, taxes, discounts, and deposit information
|
|
4
4
|
* Supports two modes: SSR (config with pre-fetched data) and lazy loading (reactive)
|
|
5
5
|
*/
|
|
6
|
-
import { type PaymentServiceConfig, type PaymentServiceInternalConfig, type
|
|
7
|
-
export { PaymentServiceDefinition, type PaymentServiceConfig, type PaymentDetails, type LineItemAdditionalInfo, type
|
|
6
|
+
import { type PaymentServiceConfig, type PaymentServiceInternalConfig, type PricingServiceSelection } from './payment.def.js';
|
|
7
|
+
export { PaymentServiceDefinition, type PaymentServiceConfig, type PaymentDetails, type LineItemAdditionalInfo, type PricingServiceSelection, } from './payment.def.js';
|
|
8
8
|
export type { PaymentServiceAPI, PaymentServiceInternalConfig, } from './payment.def.js';
|
|
9
9
|
export declare const PaymentService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
10
10
|
__api: import("./payment.def.js").PaymentServiceAPI;
|
|
@@ -23,10 +23,10 @@ export type ErrorPaymentConfigResult = {
|
|
|
23
23
|
* Load payment configuration for Server-Side Rendering (SSR).
|
|
24
24
|
* Calls the pricing APIs and returns pre-calculated payment details.
|
|
25
25
|
*
|
|
26
|
-
* @param params.
|
|
26
|
+
* @param params.pricingServiceSelections - Pricing service selections for calculation
|
|
27
27
|
* @param params.numberOfParticipants - Number of participants (default: 1)
|
|
28
28
|
*/
|
|
29
29
|
export declare function loadPaymentConfig(params: {
|
|
30
|
-
|
|
30
|
+
pricingServiceSelections: PricingServiceSelection[];
|
|
31
31
|
numberOfParticipants?: number;
|
|
32
32
|
}): Promise<SuccessPaymentConfigResult | ErrorPaymentConfigResult>;
|
|
@@ -30,9 +30,9 @@ export interface PaymentDetails {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* Input for calculating payment for a
|
|
33
|
+
* Input for calculating payment for a booking service
|
|
34
34
|
*/
|
|
35
|
-
export interface
|
|
35
|
+
export interface PricingServiceSelection {
|
|
36
36
|
service: Service;
|
|
37
37
|
/** Optional line item ID. If not provided, one will be generated. */
|
|
38
38
|
lineItemId?: string;
|
|
@@ -50,8 +50,8 @@ export interface PaymentServiceConfig {
|
|
|
50
50
|
* Not exposed publicly - Core merges this with PaymentServiceConfig
|
|
51
51
|
*/
|
|
52
52
|
export interface PaymentServiceInternalConfig extends PaymentServiceConfig {
|
|
53
|
-
/**
|
|
54
|
-
|
|
53
|
+
/** Booking services for lazy loading (internal use) */
|
|
54
|
+
pricingServiceSelections?: PricingServiceSelection[];
|
|
55
55
|
/** Number of participants for lazy loading (internal use) */
|
|
56
56
|
numberOfParticipants?: number;
|
|
57
57
|
}
|
|
@@ -60,11 +60,11 @@ function buildLineItem(service, numberOfParticipants, lineItemId) {
|
|
|
60
60
|
paymentOption,
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
async function calculatePaymentDetails(
|
|
64
|
-
// Ensure all
|
|
65
|
-
const data =
|
|
66
|
-
...
|
|
67
|
-
lineItemId:
|
|
63
|
+
async function calculatePaymentDetails(pricingServiceSelections, numberOfParticipants) {
|
|
64
|
+
// Ensure all booking services have a lineItemId
|
|
65
|
+
const data = pricingServiceSelections.map((selection) => ({
|
|
66
|
+
...selection,
|
|
67
|
+
lineItemId: selection.lineItemId || generateLineItemId(),
|
|
68
68
|
}));
|
|
69
69
|
const lineItems = data.map((item) => buildLineItem(item.service, numberOfParticipants, item.lineItemId));
|
|
70
70
|
const response = await calculateTotals({
|
|
@@ -96,15 +96,15 @@ export const PaymentService = implementService.withConfig()(PaymentServiceDefini
|
|
|
96
96
|
const isLoadingSignal = signalsService.signal(false);
|
|
97
97
|
const errorSignal = signalsService.signal(null);
|
|
98
98
|
// Internal calculate function
|
|
99
|
-
const calculate = async (
|
|
100
|
-
if (!
|
|
99
|
+
const calculate = async (pricingServiceSelections, numberOfParticipants) => {
|
|
100
|
+
if (!pricingServiceSelections.length) {
|
|
101
101
|
paymentDetailsSignal.set(null);
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
104
104
|
isLoadingSignal.set(true);
|
|
105
105
|
errorSignal.set(null);
|
|
106
106
|
try {
|
|
107
|
-
const paymentDetails = await calculatePaymentDetails(
|
|
107
|
+
const paymentDetails = await calculatePaymentDetails(pricingServiceSelections, numberOfParticipants);
|
|
108
108
|
paymentDetailsSignal.set(paymentDetails);
|
|
109
109
|
}
|
|
110
110
|
catch (error) {
|
|
@@ -122,22 +122,30 @@ export const PaymentService = implementService.withConfig()(PaymentServiceDefini
|
|
|
122
122
|
if (config.paymentDetails) {
|
|
123
123
|
// No-op - data is pre-fetched
|
|
124
124
|
}
|
|
125
|
-
// Mode 2: Lazy loading -
|
|
126
|
-
else if (config.
|
|
127
|
-
void calculate(config.
|
|
125
|
+
// Mode 2: Lazy loading - pricingServiceSelections provided via internal config
|
|
126
|
+
else if (config.pricingServiceSelections?.length) {
|
|
127
|
+
void calculate(config.pricingServiceSelections, config.numberOfParticipants ?? 1);
|
|
128
128
|
}
|
|
129
129
|
// Mode 3: Reactive - observe BookingService signals (client-side only)
|
|
130
130
|
else if (typeof window !== 'undefined' && bookingService) {
|
|
131
|
-
|
|
131
|
+
// Computed signal that only changes when services change (not participants)
|
|
132
|
+
const servicesKey = signalsService.computed(() => {
|
|
132
133
|
const selections = bookingService?.serviceSelections.get() || [];
|
|
134
|
+
return selections.map((s) => s.service._id).join(',');
|
|
135
|
+
});
|
|
136
|
+
signalsService.effect(() => {
|
|
137
|
+
// Subscribe to servicesKey to trigger effect only when services change
|
|
138
|
+
servicesKey.get();
|
|
139
|
+
// Read current selections without subscribing (peek)
|
|
140
|
+
const selections = bookingService?.serviceSelections.peek() || [];
|
|
133
141
|
// For single service mode, take the first selection
|
|
134
142
|
const firstSelection = selections[0];
|
|
135
143
|
const numParticipants = firstSelection?.totalParticipants || 1;
|
|
136
|
-
const
|
|
144
|
+
const pricingServiceSelections = selections.map((selection) => ({
|
|
137
145
|
service: selection.service,
|
|
138
146
|
lineItemId: selection.instanceId,
|
|
139
147
|
}));
|
|
140
|
-
void calculate(
|
|
148
|
+
void calculate(pricingServiceSelections, numParticipants);
|
|
141
149
|
});
|
|
142
150
|
}
|
|
143
151
|
return {
|
|
@@ -150,19 +158,19 @@ export const PaymentService = implementService.withConfig()(PaymentServiceDefini
|
|
|
150
158
|
* Load payment configuration for Server-Side Rendering (SSR).
|
|
151
159
|
* Calls the pricing APIs and returns pre-calculated payment details.
|
|
152
160
|
*
|
|
153
|
-
* @param params.
|
|
161
|
+
* @param params.pricingServiceSelections - Pricing service selections for calculation
|
|
154
162
|
* @param params.numberOfParticipants - Number of participants (default: 1)
|
|
155
163
|
*/
|
|
156
164
|
export async function loadPaymentConfig(params) {
|
|
157
165
|
try {
|
|
158
|
-
const {
|
|
159
|
-
if (!
|
|
166
|
+
const { pricingServiceSelections, numberOfParticipants = 1 } = params;
|
|
167
|
+
if (!pricingServiceSelections.length) {
|
|
160
168
|
return {
|
|
161
169
|
type: 'success',
|
|
162
170
|
config: { paymentDetails: undefined },
|
|
163
171
|
};
|
|
164
172
|
}
|
|
165
|
-
const paymentDetails = await calculatePaymentDetails(
|
|
173
|
+
const paymentDetails = await calculatePaymentDetails(pricingServiceSelections, numberOfParticipants);
|
|
166
174
|
return {
|
|
167
175
|
type: 'success',
|
|
168
176
|
config: { paymentDetails },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/headless-bookings",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.58",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"groupId": "com.wixpress.headless-components"
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
|
-
"falconPackageHash": "
|
|
75
|
+
"falconPackageHash": "ccd30f51c7b5e50deedb808077fe5dfaebe97ef4f66da71d4f246455"
|
|
76
76
|
}
|