@ticketboothapp/booking 1.2.122 → 1.2.124
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/CHANGE_BOOKING_BE_HANDOFF.md +15 -4
- package/package.json +1 -1
- package/src/components/booking/AdminChangeBookingContent.tsx +276 -0
- package/src/components/booking/AdminChangeBookingFlow.tsx +647 -6157
- package/src/components/booking/AdminChangeCheckoutDialogs.tsx +105 -0
- package/src/components/booking/AdminChangeCheckoutPanel.tsx +307 -0
- package/src/components/booking/AdminChangePricingPanel.tsx +244 -0
- package/src/components/booking/AdminChangeProductSwitcher.tsx +50 -0
- package/src/components/booking/AdminChangeReceiptComparison.tsx +167 -0
- package/src/components/booking/ChangeBookingCalendarPanel.tsx +126 -0
- package/src/components/booking/ChangeBookingCheckoutPanel.tsx +204 -0
- package/src/components/booking/ChangeBookingFlow.tsx +576 -4648
- package/src/components/booking/ChangeBookingItineraryPanel.tsx +115 -0
- package/src/components/booking/ChangeBookingQuoteStatusPlaceholder.tsx +57 -0
- package/src/components/booking/ChangeBookingSelectionControlsPanel.tsx +157 -0
- package/src/components/booking/ChangeBookingTicketsAndAddOnsPanel.tsx +102 -0
- package/src/components/booking/CheckoutModal.tsx +68 -49
- package/src/components/booking/NewBookingFlow.tsx +485 -3505
- package/src/components/booking/PriceBreakdown.tsx +17 -3
- package/src/components/booking/PriceSummary.tsx +21 -3
- package/src/components/booking/PrivateShuttleAddOnsSection.tsx +102 -0
- package/src/components/booking/PrivateShuttleBookingFlow.tsx +407 -2788
- package/src/components/booking/PrivateShuttleCheckoutDialogs.tsx +106 -0
- package/src/components/booking/PrivateShuttleCheckoutSection.tsx +333 -0
- package/src/components/booking/PrivateShuttleItinerarySection.tsx +95 -0
- package/src/components/booking/PrivateShuttleMediaIntro.tsx +62 -0
- package/src/components/booking/PrivateShuttleOptionSection.tsx +81 -0
- package/src/components/booking/PrivateShuttlePassengerSection.tsx +148 -0
- package/src/components/booking/PrivateShuttlePickupSection.tsx +91 -0
- package/src/components/booking/PrivateShuttlePreferencesSection.tsx +75 -0
- package/src/components/booking/PrivateShuttleStartTimeSection.tsx +88 -0
- package/src/components/booking/StandardBookingCheckoutDialogs.tsx +106 -0
- package/src/components/booking/StandardBookingCheckoutSection.tsx +185 -0
- package/src/components/booking/StandardBookingItineraryPanel.tsx +125 -0
- package/src/components/booking/StandardBookingMediaIntro.tsx +69 -0
- package/src/components/booking/StandardBookingSelectionControlsPanel.tsx +236 -0
- package/src/components/booking/admin-change-customer-quote-runner.ts +119 -0
- package/src/components/booking/admin-change-flow-state-helpers.ts +124 -0
- package/src/components/booking/admin-change-payment-choice-runner.ts +172 -0
- package/src/components/booking/admin-change-provider-payload.ts +101 -0
- package/src/components/booking/change-booking-checkout-builders.ts +185 -0
- package/src/components/booking/change-booking-checkout-quote-runner.ts +207 -0
- package/src/components/booking/change-booking-flow-helpers.ts +706 -0
- package/src/components/booking/change-booking-payment-modal-builders.ts +151 -0
- package/src/components/booking/change-booking-quote-guards.ts +223 -0
- package/src/components/booking/change-booking-quote-state.ts +64 -0
- package/src/components/booking/pricing-v2-checkout-summary.ts +144 -0
- package/src/components/booking/private-shuttle-availability.ts +111 -0
- package/src/components/booking/private-shuttle-checkout-builders.ts +264 -0
- package/src/components/booking/private-shuttle-checkout-controller.ts +744 -0
- package/src/components/booking/private-shuttle-payment-choice-runner.ts +271 -0
- package/src/components/booking/private-shuttle-provider-change-runner.ts +73 -0
- package/src/components/booking/private-shuttle-reservation-runner.ts +260 -0
- package/src/components/booking/standard-booking-availability.ts +305 -0
- package/src/components/booking/standard-booking-checkout-builders.ts +289 -0
- package/src/components/booking/standard-booking-checkout-controller.ts +659 -0
- package/src/components/booking/standard-booking-payment-choice-runner.ts +274 -0
- package/src/components/booking/standard-booking-reservation-runner.ts +229 -0
- package/src/components/booking/use-private-shuttle-availability.ts +602 -0
- package/src/components/booking/use-standard-booking-availability.ts +806 -0
- package/src/components/booking/useActiveProductOptions.ts +26 -0
- package/src/components/booking/useAdminChangeCheckoutController.ts +806 -0
- package/src/components/booking/useAdminChangeOrderSummaryModel.ts +246 -0
- package/src/components/booking/useAdminChangePriceSummary.ts +416 -0
- package/src/components/booking/useAdminChangePricingDebugPanel.tsx +178 -0
- package/src/components/booking/useAdminChangeProductReset.ts +60 -0
- package/src/components/booking/useAdminChangeProducts.ts +102 -0
- package/src/components/booking/useAdminChangePromoDiscount.ts +235 -0
- package/src/components/booking/useAdminChangeProtectedPricing.ts +280 -0
- package/src/components/booking/useAdminChangeQuoteDisplayState.tsx +437 -0
- package/src/components/booking/useAdminChangeQuotePreview.ts +506 -0
- package/src/components/booking/useAdminChangeReceiptDerivation.ts +203 -0
- package/src/components/booking/useAdminCustomReceiptLines.ts +57 -0
- package/src/components/booking/useAdminProviderPricingAdjustments.ts +146 -0
- package/src/components/booking/useBookingAvailabilityAddOns.ts +54 -0
- package/src/components/booking/useBookingPromoAndQuantityController.ts +163 -0
- package/src/components/booking/useBookingQuantityCapTrim.ts +56 -0
- package/src/components/booking/useBookingViewItemAnalytics.ts +30 -0
- package/src/components/booking/useChangeBookingAddOnFloorController.ts +109 -0
- package/src/components/booking/useChangeBookingAutoSelections.ts +148 -0
- package/src/components/booking/useChangeBookingAvailabilities.ts +692 -0
- package/src/components/booking/useChangeBookingCheckoutController.ts +461 -0
- package/src/components/booking/useChangeBookingInitialHydration.ts +204 -0
- package/src/components/booking/useChangeBookingItineraryUiState.ts +133 -0
- package/src/components/booking/useChangeBookingPickupItinerary.ts +472 -0
- package/src/components/booking/useChangeBookingPriceSummary.ts +199 -0
- package/src/components/booking/useChangeBookingPromoDiscount.ts +218 -0
- package/src/components/booking/useChangeBookingProtectedPricing.ts +256 -0
- package/src/components/booking/useChangeBookingQuotePreview.ts +442 -0
- package/src/components/booking/useChangeBookingReceiptDerivation.ts +128 -0
- package/src/components/booking/useChangeBookingReceiptFloorController.ts +449 -0
- package/src/components/booking/useChangeBookingSelection.ts +362 -0
- package/src/components/booking/useChangeBookingSelectionDetails.ts +200 -0
- package/src/components/booking/useChangeBookingSummaryLines.ts +169 -0
- package/src/components/booking/usePrivateShuttlePriceSummary.ts +513 -0
- package/src/components/booking/usePrivateShuttlePromoController.ts +143 -0
- package/src/components/booking/usePrivateShuttlePromoDiscount.ts +124 -0
- package/src/components/booking/useSeedPromoCodeInput.ts +13 -0
- package/src/components/booking/useStandardBookingAutoSelections.ts +224 -0
- package/src/components/booking/useStandardBookingPickupItinerary.ts +473 -0
- package/src/components/booking/useStandardBookingPriceSummary.ts +438 -0
- package/src/components/booking/useStandardBookingPromoController.ts +258 -0
- package/src/components/booking/useStandardBookingPromoDiscount.ts +203 -0
- package/src/data/products-config.json +1 -1
- package/src/lib/booking/change-booking-server-preview.ts +134 -20
- package/src/lib/booking/change-flow-pricing.ts +31 -11
- package/src/lib/booking/checkout-breakdown.ts +66 -1
- package/src/lib/booking/pricing-config.ts +10 -0
- package/src/lib/booking/source-metadata.ts +58 -0
- package/src/lib/booking-api.ts +154 -3
- package/src/lib/pricing-v2-shadow.ts +272 -0
- package/test/change-booking-helpers.test.ts +206 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import {
|
|
2
|
+
confirmBookingWithoutPayment,
|
|
3
|
+
type CheckoutBreakdown,
|
|
4
|
+
type ItineraryDisplayStep,
|
|
5
|
+
} from '../../lib/booking-api';
|
|
6
|
+
import type { OrderSummary } from '../../lib/booking/pricing';
|
|
7
|
+
import {
|
|
8
|
+
buildBookingSourceContext,
|
|
9
|
+
inferClientBookingSourceFromProductIds,
|
|
10
|
+
type BookingSourceMetadata,
|
|
11
|
+
} from '../../lib/booking/source-metadata';
|
|
12
|
+
import { formatBookingRefForDisplay } from '../../lib/booking-ref';
|
|
13
|
+
import type { CheckoutModalLineItem } from './CheckoutModal';
|
|
14
|
+
import type { Currency } from './CurrencySwitcher';
|
|
15
|
+
import type { ChangeBookingPaidCheckoutModalData } from './change-booking-payment-modal-builders';
|
|
16
|
+
|
|
17
|
+
export type AdminChangeCheckoutModalData = ChangeBookingPaidCheckoutModalData;
|
|
18
|
+
|
|
19
|
+
export interface AdminChangePaymentChoiceData {
|
|
20
|
+
reservationReference: string;
|
|
21
|
+
reservationExpiration?: string;
|
|
22
|
+
checkoutBreakdown: CheckoutBreakdown;
|
|
23
|
+
totalAmount: number;
|
|
24
|
+
datePart: string;
|
|
25
|
+
timePart: string;
|
|
26
|
+
availabilityProductOptionId: string;
|
|
27
|
+
itineraryDisplay?: ItineraryDisplayStep[] | null;
|
|
28
|
+
clientSecret: string;
|
|
29
|
+
ticketLinesForModal: CheckoutModalLineItem[];
|
|
30
|
+
feeLineItems: OrderSummary['feeLineItems'];
|
|
31
|
+
returnPriceAdjustment: number;
|
|
32
|
+
cancellationPolicyFee: number;
|
|
33
|
+
cancellationPolicyLabel?: string;
|
|
34
|
+
subtotal: number;
|
|
35
|
+
tax: number;
|
|
36
|
+
totalQuantity: number;
|
|
37
|
+
isTaxIncludedInPrice: boolean;
|
|
38
|
+
taxRate: number;
|
|
39
|
+
promoDiscountAmount: number;
|
|
40
|
+
discountLabel?: string | null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface BuildAdminChangePaymentChoiceDataParams {
|
|
44
|
+
reservationReference: string;
|
|
45
|
+
checkoutBreakdown: CheckoutBreakdown;
|
|
46
|
+
totalAmount: number;
|
|
47
|
+
datePart: string;
|
|
48
|
+
timePart: string;
|
|
49
|
+
availabilityProductOptionId: string;
|
|
50
|
+
itineraryDisplay?: ItineraryDisplayStep[] | null;
|
|
51
|
+
clientSecret: string;
|
|
52
|
+
ticketLinesForModal: CheckoutModalLineItem[];
|
|
53
|
+
feeLineItems: OrderSummary['feeLineItems'];
|
|
54
|
+
returnPriceAdjustment: number;
|
|
55
|
+
cancellationPolicyFee: number;
|
|
56
|
+
cancellationPolicyLabel?: string;
|
|
57
|
+
subtotal: number;
|
|
58
|
+
tax: number;
|
|
59
|
+
totalQuantity: number;
|
|
60
|
+
isTaxIncludedInPrice: boolean;
|
|
61
|
+
taxRate: number;
|
|
62
|
+
promoDiscountAmount: number;
|
|
63
|
+
discountLabel?: string | null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function buildAdminChangePaymentChoiceData(
|
|
67
|
+
params: BuildAdminChangePaymentChoiceDataParams
|
|
68
|
+
): AdminChangePaymentChoiceData {
|
|
69
|
+
return {
|
|
70
|
+
reservationExpiration: undefined,
|
|
71
|
+
...params,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function buildAdminChangePayNowCheckoutModalData(
|
|
76
|
+
adminChoiceData: AdminChangePaymentChoiceData,
|
|
77
|
+
lastName: string
|
|
78
|
+
): AdminChangeCheckoutModalData {
|
|
79
|
+
return {
|
|
80
|
+
reservationReference: adminChoiceData.reservationReference,
|
|
81
|
+
reservationExpiration: adminChoiceData.reservationExpiration,
|
|
82
|
+
customerLastName: lastName.trim(),
|
|
83
|
+
ticketLines: adminChoiceData.ticketLinesForModal,
|
|
84
|
+
feeLineItems: adminChoiceData.feeLineItems,
|
|
85
|
+
returnPriceAdjustment: adminChoiceData.returnPriceAdjustment,
|
|
86
|
+
cancellationPolicyFee: adminChoiceData.cancellationPolicyFee,
|
|
87
|
+
cancellationPolicyLabel: adminChoiceData.cancellationPolicyLabel,
|
|
88
|
+
subtotal: adminChoiceData.subtotal,
|
|
89
|
+
tax: adminChoiceData.tax,
|
|
90
|
+
total: adminChoiceData.totalAmount,
|
|
91
|
+
totalQuantity: adminChoiceData.totalQuantity,
|
|
92
|
+
isTaxIncludedInPrice: adminChoiceData.isTaxIncludedInPrice,
|
|
93
|
+
taxRate: adminChoiceData.taxRate,
|
|
94
|
+
promoDiscountAmount: adminChoiceData.promoDiscountAmount,
|
|
95
|
+
discountLabel: adminChoiceData.discountLabel,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface ConfirmAdminChangeBookingWithoutPaymentParams {
|
|
100
|
+
adminChoiceData: AdminChangePaymentChoiceData;
|
|
101
|
+
bookingSourceAttribution: Partial<BookingSourceMetadata>;
|
|
102
|
+
partnerPortalBooking: boolean;
|
|
103
|
+
forceDashboardSource: boolean;
|
|
104
|
+
productId: string;
|
|
105
|
+
email: string;
|
|
106
|
+
firstName: string;
|
|
107
|
+
lastName: string;
|
|
108
|
+
currency: Currency;
|
|
109
|
+
travelerHotel?: string;
|
|
110
|
+
pickupLocationId?: string;
|
|
111
|
+
termsAcceptedAt?: string | null;
|
|
112
|
+
skipConfirmationCommunications: boolean;
|
|
113
|
+
disableAutoCommunications: boolean;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export async function confirmAdminChangeBookingWithoutPayment({
|
|
117
|
+
adminChoiceData,
|
|
118
|
+
bookingSourceAttribution,
|
|
119
|
+
partnerPortalBooking,
|
|
120
|
+
forceDashboardSource,
|
|
121
|
+
productId,
|
|
122
|
+
email,
|
|
123
|
+
firstName,
|
|
124
|
+
lastName,
|
|
125
|
+
currency,
|
|
126
|
+
travelerHotel,
|
|
127
|
+
pickupLocationId,
|
|
128
|
+
termsAcceptedAt,
|
|
129
|
+
skipConfirmationCommunications,
|
|
130
|
+
disableAutoCommunications,
|
|
131
|
+
}: ConfirmAdminChangeBookingWithoutPaymentParams): Promise<{
|
|
132
|
+
bookingReference: string;
|
|
133
|
+
displayReference: string;
|
|
134
|
+
lastName: string;
|
|
135
|
+
}> {
|
|
136
|
+
const bookingSourceContext = buildBookingSourceContext(bookingSourceAttribution, {
|
|
137
|
+
clientChannelSource: inferClientBookingSourceFromProductIds(
|
|
138
|
+
productId,
|
|
139
|
+
adminChoiceData.availabilityProductOptionId,
|
|
140
|
+
),
|
|
141
|
+
forcePartnerPortalChannel: partnerPortalBooking,
|
|
142
|
+
forceDashboardSource,
|
|
143
|
+
});
|
|
144
|
+
const result = await confirmBookingWithoutPayment({
|
|
145
|
+
reservationReference: adminChoiceData.reservationReference,
|
|
146
|
+
productId,
|
|
147
|
+
optionId: adminChoiceData.availabilityProductOptionId,
|
|
148
|
+
date: adminChoiceData.datePart,
|
|
149
|
+
time: adminChoiceData.timePart,
|
|
150
|
+
customerEmail: email || undefined,
|
|
151
|
+
customerFirstName: firstName.trim() || undefined,
|
|
152
|
+
customerLastName: lastName.trim() || undefined,
|
|
153
|
+
currency,
|
|
154
|
+
travelerHotel,
|
|
155
|
+
pickupLocationId,
|
|
156
|
+
itineraryDisplay: adminChoiceData.itineraryDisplay ?? undefined,
|
|
157
|
+
termsAcceptedAt: termsAcceptedAt ?? undefined,
|
|
158
|
+
skipConfirmationCommunications: skipConfirmationCommunications ? true : undefined,
|
|
159
|
+
disableAutoCommunications: disableAutoCommunications ? true : undefined,
|
|
160
|
+
checkoutBreakdown: adminChoiceData.checkoutBreakdown,
|
|
161
|
+
depositAmount: 0,
|
|
162
|
+
balanceAmount: adminChoiceData.totalAmount,
|
|
163
|
+
totalAmount: adminChoiceData.totalAmount,
|
|
164
|
+
...bookingSourceContext,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
bookingReference: result.bookingReference,
|
|
169
|
+
displayReference: formatBookingRefForDisplay(result.bookingReference),
|
|
170
|
+
lastName: lastName.trim(),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { Availability, Product, ReturnOption } from '../../lib/booking-api';
|
|
2
|
+
import type { ProviderDashboardChangeBookingPayload } from './provider-dashboard-change-booking';
|
|
3
|
+
|
|
4
|
+
export type AdminChangeBookingItem = { category: string; count: number };
|
|
5
|
+
export type AdminChangeAddOnSelection = { addOnId: string; variantId?: string; quantity?: number };
|
|
6
|
+
export type AdminChangeProviderLineOverride = NonNullable<
|
|
7
|
+
NonNullable<ProviderDashboardChangeBookingPayload['pricingAdjustment']>['lineOverrides']
|
|
8
|
+
>[number];
|
|
9
|
+
export type AdminChangeProviderAdditionalAdjustment = NonNullable<
|
|
10
|
+
NonNullable<ProviderDashboardChangeBookingPayload['pricingAdjustment']>['additionalAdjustments']
|
|
11
|
+
>[number];
|
|
12
|
+
|
|
13
|
+
export function bookingItemsFromQuantities(
|
|
14
|
+
quantities: Record<string, number>
|
|
15
|
+
): AdminChangeBookingItem[] {
|
|
16
|
+
return Object.entries(quantities)
|
|
17
|
+
.filter(([, count]) => count > 0)
|
|
18
|
+
.map(([category, count]) => ({ category, count }));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface BuildAdminChangeProviderPayloadParams {
|
|
22
|
+
selectedAvailability: Availability | null;
|
|
23
|
+
availabilityProductOptionId: string;
|
|
24
|
+
bookingItems: AdminChangeBookingItem[];
|
|
25
|
+
product: Product;
|
|
26
|
+
pickupLocationId: string | null;
|
|
27
|
+
selectedReturnOption: ReturnOption | null;
|
|
28
|
+
addOnSelections: AdminChangeAddOnSelection[];
|
|
29
|
+
cancellationPolicyId: string | null;
|
|
30
|
+
initialCancellationPolicyId?: string | null;
|
|
31
|
+
appliedPromoCode: string | null;
|
|
32
|
+
newTotalAmount: number;
|
|
33
|
+
providerPricingOverrides: AdminChangeProviderLineOverride[];
|
|
34
|
+
mergedProviderAdditionalAdjustments: AdminChangeProviderAdditionalAdjustment[];
|
|
35
|
+
providerApplyAuthoritativeReceipt?: ProviderDashboardChangeBookingPayload['authoritativeReceipt'];
|
|
36
|
+
previousPassengerCount: number;
|
|
37
|
+
previousAvailabilityId?: string | null;
|
|
38
|
+
previousReturnAvailabilityId?: string | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function buildAdminChangeProviderPayload({
|
|
42
|
+
selectedAvailability,
|
|
43
|
+
availabilityProductOptionId,
|
|
44
|
+
bookingItems,
|
|
45
|
+
product,
|
|
46
|
+
pickupLocationId,
|
|
47
|
+
selectedReturnOption,
|
|
48
|
+
addOnSelections,
|
|
49
|
+
cancellationPolicyId,
|
|
50
|
+
initialCancellationPolicyId,
|
|
51
|
+
appliedPromoCode,
|
|
52
|
+
newTotalAmount,
|
|
53
|
+
providerPricingOverrides,
|
|
54
|
+
mergedProviderAdditionalAdjustments,
|
|
55
|
+
providerApplyAuthoritativeReceipt,
|
|
56
|
+
previousPassengerCount,
|
|
57
|
+
previousAvailabilityId,
|
|
58
|
+
previousReturnAvailabilityId,
|
|
59
|
+
}: BuildAdminChangeProviderPayloadParams): ProviderDashboardChangeBookingPayload | null {
|
|
60
|
+
if (!selectedAvailability) return null;
|
|
61
|
+
const pickupForChange = pickupLocationId
|
|
62
|
+
? product.pickupLocations?.find((loc) => loc.id === pickupLocationId)
|
|
63
|
+
: null;
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
productId: availabilityProductOptionId,
|
|
67
|
+
parentProductId: product.productId,
|
|
68
|
+
dateTime: selectedAvailability.dateTime,
|
|
69
|
+
bookingItems,
|
|
70
|
+
returnAvailabilityId: selectedReturnOption?.returnAvailabilityId ?? null,
|
|
71
|
+
pickupLocationId: pickupLocationId ?? null,
|
|
72
|
+
travelerHotel: pickupForChange?.name ?? null,
|
|
73
|
+
startTime: selectedAvailability.dateTime ?? null,
|
|
74
|
+
passengerCount: null,
|
|
75
|
+
childSafetySeatsCount: null,
|
|
76
|
+
foodRestrictions: null,
|
|
77
|
+
addOnSelections: addOnSelections.length > 0 ? addOnSelections : null,
|
|
78
|
+
cancellationPolicyId: cancellationPolicyId ?? initialCancellationPolicyId ?? null,
|
|
79
|
+
promoCode: appliedPromoCode ?? null,
|
|
80
|
+
newTotalAmount,
|
|
81
|
+
additionalHoursCount: null,
|
|
82
|
+
pricingAdjustment:
|
|
83
|
+
providerPricingOverrides.length > 0 || mergedProviderAdditionalAdjustments.length > 0
|
|
84
|
+
? {
|
|
85
|
+
mode: 'MANUAL_LINES',
|
|
86
|
+
...(providerPricingOverrides.length > 0 ? { lineOverrides: providerPricingOverrides } : {}),
|
|
87
|
+
...(mergedProviderAdditionalAdjustments.length > 0
|
|
88
|
+
? { additionalAdjustments: mergedProviderAdditionalAdjustments }
|
|
89
|
+
: {}),
|
|
90
|
+
}
|
|
91
|
+
: undefined,
|
|
92
|
+
authoritativeReceipt: providerApplyAuthoritativeReceipt,
|
|
93
|
+
capacitySeatCredit: {
|
|
94
|
+
enabled: true,
|
|
95
|
+
previousPassengerCount,
|
|
96
|
+
previousAvailabilityId: previousAvailabilityId ?? null,
|
|
97
|
+
previousReturnAvailabilityId: previousReturnAvailabilityId ?? null,
|
|
98
|
+
},
|
|
99
|
+
deferPaymentToBalance: true,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type { AddOn, CheckoutBreakdown } from '../../lib/booking-api';
|
|
2
|
+
import type { CheckoutLineInput } from '../../lib/booking/checkout-breakdown';
|
|
3
|
+
import { buildCheckoutBreakdown } from '../../lib/booking/checkout-breakdown';
|
|
4
|
+
import type { OrderSummaryFeeLine, OrderSummaryTicketLine } from '../../lib/booking/pricing';
|
|
5
|
+
|
|
6
|
+
export type ChangeBookingAddOnSelection = {
|
|
7
|
+
addOnId: string;
|
|
8
|
+
variantId?: string;
|
|
9
|
+
quantity?: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type ChangeBookingCustomReceiptLineInput = {
|
|
13
|
+
label: string;
|
|
14
|
+
amountInput: string;
|
|
15
|
+
amountSign?: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export interface BuildChangeBookingCheckoutBreakdownParams {
|
|
19
|
+
ticketLineItems: OrderSummaryTicketLine[];
|
|
20
|
+
totalQuantity: number;
|
|
21
|
+
checkoutReturnLineAmount: number;
|
|
22
|
+
returnOptionLabel: string;
|
|
23
|
+
personLabel: string;
|
|
24
|
+
peopleLabel: string;
|
|
25
|
+
cancellationPolicyFee: number;
|
|
26
|
+
cancellationPolicyLabel: string;
|
|
27
|
+
addOnSelections: ChangeBookingAddOnSelection[];
|
|
28
|
+
addOns: AddOn[];
|
|
29
|
+
feeLineItems: OrderSummaryFeeLine[];
|
|
30
|
+
customReceiptLines?: ChangeBookingCustomReceiptLineInput[];
|
|
31
|
+
isTaxIncludedInPrice: boolean;
|
|
32
|
+
taxForBreakdown: number;
|
|
33
|
+
taxLabel: string;
|
|
34
|
+
effectivePromoDiscountAmount: number;
|
|
35
|
+
appliedPromoCode?: string | null;
|
|
36
|
+
discountLabel: string;
|
|
37
|
+
promoLineType: string;
|
|
38
|
+
amountDueForCheckout: number;
|
|
39
|
+
currency: string;
|
|
40
|
+
roundingLabel: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function buildChangeBookingAddOnCheckoutLines(
|
|
44
|
+
addOnSelections: ChangeBookingAddOnSelection[],
|
|
45
|
+
addOns: AddOn[]
|
|
46
|
+
): CheckoutLineInput[] {
|
|
47
|
+
const lines: CheckoutLineInput[] = [];
|
|
48
|
+
|
|
49
|
+
for (const selection of addOnSelections) {
|
|
50
|
+
const addOn = addOns.find((candidate) => candidate.addOnId === selection.addOnId);
|
|
51
|
+
if (!addOn) continue;
|
|
52
|
+
|
|
53
|
+
const hasVariant =
|
|
54
|
+
(addOn.variantType === 'single_choice' || addOn.variantType === 'multi_quantity') &&
|
|
55
|
+
selection.variantId;
|
|
56
|
+
const variant = hasVariant
|
|
57
|
+
? addOn.variants?.find((candidate) => candidate.id === selection.variantId)
|
|
58
|
+
: null;
|
|
59
|
+
const quantity = selection.quantity ?? 1;
|
|
60
|
+
const amount = ((addOn.price ?? 0) + (variant?.priceAdjustment ?? 0)) * quantity;
|
|
61
|
+
const label = variant?.label
|
|
62
|
+
? `${addOn.name} (${variant.label})${quantity > 1 ? ` \u00d7 ${quantity}` : ''}`
|
|
63
|
+
: addOn.name;
|
|
64
|
+
|
|
65
|
+
lines.push({
|
|
66
|
+
label,
|
|
67
|
+
amount,
|
|
68
|
+
type: 'FEE',
|
|
69
|
+
quantity,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return lines;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function buildCustomReceiptCheckoutLines(
|
|
77
|
+
customReceiptLines: ChangeBookingCustomReceiptLineInput[] | undefined
|
|
78
|
+
): CheckoutLineInput[] {
|
|
79
|
+
return (
|
|
80
|
+
customReceiptLines?.flatMap((line) => {
|
|
81
|
+
const raw = line.amountInput.trim();
|
|
82
|
+
if (raw === '' || raw === '+' || raw === '-') return [];
|
|
83
|
+
const amountInput = Number(raw);
|
|
84
|
+
if (!Number.isFinite(amountInput) || Math.abs(amountInput) < 0.0005) return [];
|
|
85
|
+
const sign = line.amountSign ?? 1;
|
|
86
|
+
return [
|
|
87
|
+
{
|
|
88
|
+
label: line.label.trim() || 'Adjustment',
|
|
89
|
+
amount: sign * Math.abs(amountInput),
|
|
90
|
+
type: 'FEE',
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
}) ?? []
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function buildChangeBookingCheckoutBreakdown(
|
|
98
|
+
params: BuildChangeBookingCheckoutBreakdownParams
|
|
99
|
+
): CheckoutBreakdown {
|
|
100
|
+
const {
|
|
101
|
+
ticketLineItems,
|
|
102
|
+
totalQuantity,
|
|
103
|
+
checkoutReturnLineAmount,
|
|
104
|
+
returnOptionLabel,
|
|
105
|
+
personLabel,
|
|
106
|
+
peopleLabel,
|
|
107
|
+
cancellationPolicyFee,
|
|
108
|
+
cancellationPolicyLabel,
|
|
109
|
+
addOnSelections,
|
|
110
|
+
addOns,
|
|
111
|
+
feeLineItems,
|
|
112
|
+
customReceiptLines,
|
|
113
|
+
isTaxIncludedInPrice,
|
|
114
|
+
taxForBreakdown,
|
|
115
|
+
taxLabel,
|
|
116
|
+
effectivePromoDiscountAmount,
|
|
117
|
+
appliedPromoCode,
|
|
118
|
+
discountLabel,
|
|
119
|
+
promoLineType,
|
|
120
|
+
amountDueForCheckout,
|
|
121
|
+
currency,
|
|
122
|
+
roundingLabel,
|
|
123
|
+
} = params;
|
|
124
|
+
const personCountLabel = totalQuantity === 1 ? personLabel : peopleLabel;
|
|
125
|
+
const lines: CheckoutLineInput[] = [
|
|
126
|
+
...ticketLineItems.map((line) => ({
|
|
127
|
+
label: line.category,
|
|
128
|
+
amount: line.itemTotal,
|
|
129
|
+
type: 'TICKET',
|
|
130
|
+
quantity: line.qty,
|
|
131
|
+
})),
|
|
132
|
+
...(checkoutReturnLineAmount !== 0
|
|
133
|
+
? [
|
|
134
|
+
{
|
|
135
|
+
label: `${returnOptionLabel} (${totalQuantity} ${personCountLabel})`,
|
|
136
|
+
amount: checkoutReturnLineAmount,
|
|
137
|
+
type: 'RETURN_OPTION',
|
|
138
|
+
quantity: totalQuantity,
|
|
139
|
+
},
|
|
140
|
+
]
|
|
141
|
+
: []),
|
|
142
|
+
...(cancellationPolicyFee > 0
|
|
143
|
+
? [
|
|
144
|
+
{
|
|
145
|
+
label: cancellationPolicyLabel,
|
|
146
|
+
amount: cancellationPolicyFee,
|
|
147
|
+
type: 'CANCELLATION_UPGRADE',
|
|
148
|
+
},
|
|
149
|
+
]
|
|
150
|
+
: []),
|
|
151
|
+
...buildChangeBookingAddOnCheckoutLines(addOnSelections, addOns),
|
|
152
|
+
...feeLineItems.map((fee) => ({
|
|
153
|
+
label: `${fee.name} (${totalQuantity} ${personCountLabel})`,
|
|
154
|
+
amount: fee.totalAmount,
|
|
155
|
+
type: 'FEE',
|
|
156
|
+
quantity: totalQuantity,
|
|
157
|
+
})),
|
|
158
|
+
...buildCustomReceiptCheckoutLines(customReceiptLines),
|
|
159
|
+
...(!isTaxIncludedInPrice && taxForBreakdown > 0
|
|
160
|
+
? [
|
|
161
|
+
{
|
|
162
|
+
label: taxLabel,
|
|
163
|
+
amount: taxForBreakdown,
|
|
164
|
+
type: 'TAX',
|
|
165
|
+
},
|
|
166
|
+
]
|
|
167
|
+
: []),
|
|
168
|
+
...(effectivePromoDiscountAmount > 0
|
|
169
|
+
? [
|
|
170
|
+
{
|
|
171
|
+
label: appliedPromoCode ? `Promo: ${appliedPromoCode}` : discountLabel,
|
|
172
|
+
amount: -effectivePromoDiscountAmount,
|
|
173
|
+
type: promoLineType,
|
|
174
|
+
},
|
|
175
|
+
]
|
|
176
|
+
: []),
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
return buildCheckoutBreakdown({
|
|
180
|
+
lines,
|
|
181
|
+
totalAmount: amountDueForCheckout,
|
|
182
|
+
currency,
|
|
183
|
+
roundingLabel,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import {
|
|
2
|
+
quoteChangeBooking,
|
|
3
|
+
quoteChangeBookingAdminFeReceipt,
|
|
4
|
+
type AdminFeAuthoritativeReceipt,
|
|
5
|
+
type ChangeBookingQuoteRequest,
|
|
6
|
+
} from '../../lib/booking-api';
|
|
7
|
+
import type { Currency } from './CurrencySwitcher';
|
|
8
|
+
import {
|
|
9
|
+
evaluateChangeBookingQuoteForCheckout,
|
|
10
|
+
type ChangeBookingCheckoutQuoteDecision,
|
|
11
|
+
} from './change-booking-quote-guards';
|
|
12
|
+
import {
|
|
13
|
+
resolveConfirmedChangeNewTotalForCheckout,
|
|
14
|
+
sliceAndMergeChangeQuoteForUi,
|
|
15
|
+
type ChangeBookingMergedQuoteState,
|
|
16
|
+
} from './change-booking-quote-state';
|
|
17
|
+
|
|
18
|
+
type FallbackCart = { total: number; subtotal: number; tax: number };
|
|
19
|
+
type PassengerCounts = NonNullable<ChangeBookingQuoteRequest['newPassengerCounts']>;
|
|
20
|
+
type AddOnSelections = NonNullable<ChangeBookingQuoteRequest['newAddOnSelections']>;
|
|
21
|
+
type ManualLineAdjustments = NonNullable<ChangeBookingQuoteRequest['manualLineAdjustments']>;
|
|
22
|
+
type CapacitySeatCredit = NonNullable<ChangeBookingQuoteRequest['capacitySeatCredit']>;
|
|
23
|
+
|
|
24
|
+
export interface ChangeCheckoutQuoteResult {
|
|
25
|
+
bookingReference: string;
|
|
26
|
+
decision: ChangeBookingCheckoutQuoteDecision;
|
|
27
|
+
mergedQuote: ChangeBookingMergedQuoteState;
|
|
28
|
+
confirmedNewTotalForCheckout: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface QuoteCustomerChangeForCheckoutParams {
|
|
32
|
+
bookingReference?: string | null;
|
|
33
|
+
lastName: string;
|
|
34
|
+
availabilityProductOptionId: string;
|
|
35
|
+
dateTime: string;
|
|
36
|
+
availabilityId?: string | null;
|
|
37
|
+
pickupLocationId?: string | null;
|
|
38
|
+
returnAvailabilityId?: string | null;
|
|
39
|
+
bookingItems: PassengerCounts;
|
|
40
|
+
addOnSelections?: AddOnSelections;
|
|
41
|
+
clientProposedTotal: number;
|
|
42
|
+
fallbackCart: FallbackCart;
|
|
43
|
+
currency: Currency;
|
|
44
|
+
originalReceiptTotal: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function quoteCustomerChangeForCheckout({
|
|
48
|
+
bookingReference,
|
|
49
|
+
lastName,
|
|
50
|
+
availabilityProductOptionId,
|
|
51
|
+
dateTime,
|
|
52
|
+
availabilityId,
|
|
53
|
+
pickupLocationId,
|
|
54
|
+
returnAvailabilityId,
|
|
55
|
+
bookingItems,
|
|
56
|
+
addOnSelections,
|
|
57
|
+
clientProposedTotal,
|
|
58
|
+
fallbackCart,
|
|
59
|
+
currency,
|
|
60
|
+
originalReceiptTotal,
|
|
61
|
+
}: QuoteCustomerChangeForCheckoutParams): Promise<ChangeCheckoutQuoteResult> {
|
|
62
|
+
const changeBookingReference = bookingReference?.trim();
|
|
63
|
+
const changeLastName = lastName.trim();
|
|
64
|
+
if (!changeBookingReference || !changeLastName) {
|
|
65
|
+
throw new Error('Missing booking reference or last name for change quote');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const quote = await quoteChangeBooking({
|
|
69
|
+
bookingReference: changeBookingReference,
|
|
70
|
+
lastName: changeLastName,
|
|
71
|
+
newProductId: availabilityProductOptionId,
|
|
72
|
+
newDateTime: dateTime,
|
|
73
|
+
newAvailabilityId: availabilityId || null,
|
|
74
|
+
newPickupLocationId: pickupLocationId || null,
|
|
75
|
+
newReturnAvailabilityId: returnAvailabilityId ?? null,
|
|
76
|
+
newPassengerCounts: bookingItems,
|
|
77
|
+
...(addOnSelections && addOnSelections.length > 0
|
|
78
|
+
? { newAddOnSelections: addOnSelections }
|
|
79
|
+
: {}),
|
|
80
|
+
clientProposedTotal,
|
|
81
|
+
});
|
|
82
|
+
const { quoteSlice, mergedQuote } = sliceAndMergeChangeQuoteForUi(
|
|
83
|
+
quote,
|
|
84
|
+
fallbackCart,
|
|
85
|
+
currency
|
|
86
|
+
);
|
|
87
|
+
const decision = evaluateChangeBookingQuoteForCheckout({
|
|
88
|
+
quote,
|
|
89
|
+
quoteSlice,
|
|
90
|
+
fallbackNewBookingTotal: fallbackCart.total,
|
|
91
|
+
originalReceiptTotal,
|
|
92
|
+
audience: 'customer',
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
bookingReference: changeBookingReference,
|
|
97
|
+
decision,
|
|
98
|
+
mergedQuote,
|
|
99
|
+
confirmedNewTotalForCheckout: resolveConfirmedChangeNewTotalForCheckout({
|
|
100
|
+
quote,
|
|
101
|
+
quoteSlice,
|
|
102
|
+
fallbackNewBookingTotal: fallbackCart.total,
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface QuoteAdminChangeForCheckoutParams {
|
|
108
|
+
bookingReference?: string | null;
|
|
109
|
+
lastName: string;
|
|
110
|
+
parentProductId: string;
|
|
111
|
+
availabilityProductOptionId: string;
|
|
112
|
+
dateTime: string;
|
|
113
|
+
availabilityId?: string | null;
|
|
114
|
+
pickupLocationId?: string | null;
|
|
115
|
+
returnAvailabilityId?: string | null;
|
|
116
|
+
bookingItems: PassengerCounts;
|
|
117
|
+
addOnSelections?: AddOnSelections;
|
|
118
|
+
manualLineAdjustments?: ManualLineAdjustments;
|
|
119
|
+
clientProposedTotal: number;
|
|
120
|
+
capacitySeatCredit?: CapacitySeatCredit;
|
|
121
|
+
fallbackCart: FallbackCart;
|
|
122
|
+
currency: Currency;
|
|
123
|
+
originalReceiptTotal: number;
|
|
124
|
+
useAdminFeAuthoritativeQuote: boolean;
|
|
125
|
+
adminFeAuthoritativeReceipt: AdminFeAuthoritativeReceipt;
|
|
126
|
+
adminFeAmountDueMajorUnits: number;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function quoteAdminChangeForCheckout({
|
|
130
|
+
bookingReference,
|
|
131
|
+
lastName,
|
|
132
|
+
parentProductId,
|
|
133
|
+
availabilityProductOptionId,
|
|
134
|
+
dateTime,
|
|
135
|
+
availabilityId,
|
|
136
|
+
pickupLocationId,
|
|
137
|
+
returnAvailabilityId,
|
|
138
|
+
bookingItems,
|
|
139
|
+
addOnSelections,
|
|
140
|
+
manualLineAdjustments,
|
|
141
|
+
clientProposedTotal,
|
|
142
|
+
capacitySeatCredit,
|
|
143
|
+
fallbackCart,
|
|
144
|
+
currency,
|
|
145
|
+
originalReceiptTotal,
|
|
146
|
+
useAdminFeAuthoritativeQuote,
|
|
147
|
+
adminFeAuthoritativeReceipt,
|
|
148
|
+
adminFeAmountDueMajorUnits,
|
|
149
|
+
}: QuoteAdminChangeForCheckoutParams): Promise<ChangeCheckoutQuoteResult> {
|
|
150
|
+
const changeBookingReference = bookingReference?.trim();
|
|
151
|
+
const changeLastName = lastName.trim();
|
|
152
|
+
if (!changeBookingReference || !changeLastName) {
|
|
153
|
+
throw new Error('Missing booking reference or last name for change quote');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const quoteRequestBase: ChangeBookingQuoteRequest = {
|
|
157
|
+
bookingReference: changeBookingReference,
|
|
158
|
+
lastName: changeLastName,
|
|
159
|
+
newProductId: availabilityProductOptionId,
|
|
160
|
+
newParentProductId: parentProductId,
|
|
161
|
+
newDateTime: dateTime,
|
|
162
|
+
newAvailabilityId: availabilityId || null,
|
|
163
|
+
newPickupLocationId: pickupLocationId || null,
|
|
164
|
+
newReturnAvailabilityId: returnAvailabilityId ?? null,
|
|
165
|
+
newPassengerCounts: bookingItems,
|
|
166
|
+
...(addOnSelections && addOnSelections.length > 0
|
|
167
|
+
? { newAddOnSelections: addOnSelections }
|
|
168
|
+
: {}),
|
|
169
|
+
...(manualLineAdjustments && manualLineAdjustments.length > 0
|
|
170
|
+
? { manualLineAdjustments }
|
|
171
|
+
: {}),
|
|
172
|
+
clientProposedTotal,
|
|
173
|
+
...(capacitySeatCredit ? { capacitySeatCredit } : {}),
|
|
174
|
+
};
|
|
175
|
+
const quote = useAdminFeAuthoritativeQuote
|
|
176
|
+
? await quoteChangeBookingAdminFeReceipt({
|
|
177
|
+
...quoteRequestBase,
|
|
178
|
+
feReceipt: adminFeAuthoritativeReceipt,
|
|
179
|
+
feAmountDueMajorUnits: adminFeAmountDueMajorUnits,
|
|
180
|
+
})
|
|
181
|
+
: await quoteChangeBooking(quoteRequestBase);
|
|
182
|
+
const { quoteSlice, mergedQuote } = sliceAndMergeChangeQuoteForUi(
|
|
183
|
+
quote,
|
|
184
|
+
fallbackCart,
|
|
185
|
+
currency
|
|
186
|
+
);
|
|
187
|
+
const decision = evaluateChangeBookingQuoteForCheckout({
|
|
188
|
+
quote,
|
|
189
|
+
quoteSlice,
|
|
190
|
+
fallbackNewBookingTotal: fallbackCart.total,
|
|
191
|
+
originalReceiptTotal,
|
|
192
|
+
audience: 'admin',
|
|
193
|
+
useAdminFeAuthoritativeQuote,
|
|
194
|
+
adminFeAmountDueMajorUnits,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
bookingReference: changeBookingReference,
|
|
199
|
+
decision,
|
|
200
|
+
mergedQuote,
|
|
201
|
+
confirmedNewTotalForCheckout: resolveConfirmedChangeNewTotalForCheckout({
|
|
202
|
+
quote,
|
|
203
|
+
quoteSlice,
|
|
204
|
+
fallbackNewBookingTotal: fallbackCart.total,
|
|
205
|
+
}),
|
|
206
|
+
};
|
|
207
|
+
}
|