riverbankcms 0.31.2 → 0.32.1
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/dist/acceptance/matrix.mjs +3 -3
- package/dist/cli/index.mjs +5424 -2769
- package/dist/cli/init-docs/content/cli-reference.md +24 -1
- package/dist/{entryCommands-BnfJSvqs.mjs → entryCommands-KmqgJ44o.mjs} +2142 -1066
- package/dist/{eventUpsertInputSchema-NGbAnXH1.mjs → eventUpsertInputSchema-DQd8P8BZ.mjs} +2 -2
- package/dist/load-config-CTqBfOO9.mjs +4 -0
- package/dist/{load-config-CMeJVHDQ.mjs → load-config-C_QmGbxS.mjs} +3 -2
- package/dist/{plan-CiwCwXPF.mjs → plan-BKUvYkD2.mjs} +1 -1
- package/dist/scaffold/index.mjs +2 -2
- package/dist/{sdk-event-upsert-BMYgDeSe.mjs → sdk-event-upsert-D6oZBDR5.mjs} +13299 -2591
- package/dist/{src-BXMUcFYN.mjs → src-gbODrFjm.mjs} +389 -329
- package/dist/testing.mjs +4 -4
- package/package.json +2 -1
- package/dist/load-config-B-bx73AK.mjs +0 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { $n as headerStyleIdValues,
|
|
3
|
-
import { $t as businessCancellationRefusalCodes,
|
|
4
|
-
import { n as CliSdkPeerError, t as loadConfigFile } from "./load-config-
|
|
2
|
+
import { $n as headerStyleIdValues, At as getMimeType, Bt as footerPreferencesSchema, Cr as makeBoundaryId, Et as slugifyMediaIdentifier, Ft as MAX_MANAGEMENT_MEDIA_UPLOAD_BYTES, I as footerModeSchema, Ir as createSiteCommandSiteRef, Jn as asHeaderLayoutId, Kn as SUPPORTED_LOADER_ENDPOINTS, Mt as normalizeAmbiguousStoragePathForSite, Nn as RESOLVED_INTERNAL_LINK_ENTITY_TYPES, Or as createCommandRef, Pt as FILE_SIZE_LIMITS, Qn as headerLayoutIdValues, Sn as eventBookingOfferIntentSchema, Sr as asSiteStyleId, St as buildMediaIdentifierFromFilename, Tt as resolveMediaIdentifier, Un as ICON_PICKER_PRESETS, V as themeSchema, Xt as buttonStyleSelectionSchema, Yn as asHeaderStyleId, Zn as footerLookIdValues, _r as asDesignBoundaryId, at as parseAspectRatioValue, b as getSiteCommandMetadata, bt as mediaTypeDiscriminants, ct as getDirectImageUrlForSiteScopedPath, fr as asAppearancePresetId, gr as asDesignBlockId, h as parseAndPlanCommandBatchForTypes, k as headerPreferencesSchema, kr as createContentEntryRef, kt as getExtensionForMimeType, l as resolvePageUpsertSeo, m as createDryRunReport, n as sdkCourseBookingSettingsSchema, p as stableStringify, qn as asFooterLookId, r as sdkEventOccurrenceInputSchema, rr as SYSTEM_BLOCK_KINDS, s as eventVisibilitySchema, v as evaluateSiteCommandBatchExposure, vt as PUBLIC_FILE_FIELD_KINDS, w as entryIdentifierForCommand, wr as bookingQuestionAttachmentSchema, xn as require_dist, xr as asPageFlowPresetId, y as evaluateSiteCommandExposure, yt as isDisplayMediaKind, zr as slugPart } from "./sdk-event-upsert-D6oZBDR5.mjs";
|
|
3
|
+
import { $t as businessCancellationRefusalCodes, At as formatLocalScheduleDate, Bn as parseDatedOfferingCapacityHoldId, C as getPublicReadCachePolicy, Cn as toNonNegativeCents, Dn as parseCurrencyCode, En as formatCurrencyAmount, G as parseMailingListProviderScope, Gt as validateBookingPaymentOptionKinds, In as parseMembershipId, It as parseBookingLocalDate, Jt as clampConfiguredAmount, K as parseFooterCompositionV1, Kt as isLiveOrderInstalmentPlanStatus, M as createSecret, Mn as unsafeAsAppointmentResourceId, N as exposeSecret, Nn as unsafeAsStaffMemberId, Nt as getLocalScheduleDate, On as assertNever, Ot as addLocalScheduleDays, P as parseManagementKey, Pn as parseCustomerId, Qt as splitAmountWithRemainderInFirst, Rn as unsafeAsPassId, S as PUBLIC_CONTENT_FRESHNESS_SECONDS, Sn as toCents, Sr as ok, T as publicReadFreshnessSeconds, Tn as unsafeAsPositiveCents, Ut as toUtcIsoDateTimeString, Yt as getBookingInstalmentDepositRefundability, Zt as omitZeroAmountFutureRows, _ as EVENT_PRESET_VALUES, _r as unsafeAsEventOfferingId, ar as parseEditorSessionGeneration, bn as parseNonNegativeCents, br as unsafeAsPricingOptionId, c as planTurningOnCourses, cr as parseApiKeyId, ct as locationValueSchema, d as areConfiguredBookingVerticalConfigsEqual, en as scheduleBookingReasonCodes, f as canonicalizeConfiguredBookingVerticalConfig, ft as publicLocationSchema, g as DEFAULT_EVENT_TYPE_PRESETS, gn as fromArray, gr as unsafeAsEventInstanceId, h as resolveSiteVerticalBookingConfig, ht as trimmedStringOrNull, ir as unsafeAsOrderPaymentPlanId, l as resolveEventCatalogue, lr as parseSiteId, m as parseVerticalPresetId, mr as parseRetiredCourseId, n as OFFLINE_PAYMENT_METHODS, nn as resolveFlexibleBalanceInitialPaymentCents, nr as unsafeAsCheckoutLineId, nt as assertAllowedPublicUrl, or as parsePageId, ot as stableJsonStringify, p as parseVerticalId, pr as parseEventSeriesId, qt as addIntervalPreservingMonthAnchor, r as committedWriteProofSchema, rr as unsafeAsOrderFlexibleBalanceContractId, tn as resolveFlexibleBalanceDueAt, ur as parseUserId, vr as unsafeAsEventSeriesId, vt as formatDate, w as isPublicReadEndpoint, wn as unsafeAsNonNegativeCents, x as PUBLIC_AVAILABILITY_FRESHNESS_SECONDS, xn as parsePositiveCents, xr as err, y as SURFACE_EVENT_PRESET_VALUES, yn as isNonNegativeWholeCents$1, yr as unsafeAsOccurrenceId, zn as parseDatedOfferingCapacityHoldAuditRef, zt as resolveBookingTimeZoneId } from "./src-gbODrFjm.mjs";
|
|
4
|
+
import { n as CliSdkPeerError, t as loadConfigFile } from "./load-config-C_QmGbxS.mjs";
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
import { safeParse, z } from "zod";
|
|
7
7
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
@@ -44,6 +44,7 @@ const API_ERROR_CODES = [
|
|
|
44
44
|
"auth:token_invalid",
|
|
45
45
|
"auth:forbidden",
|
|
46
46
|
"auth:mfa_required",
|
|
47
|
+
"auth:mfa_setup_required",
|
|
47
48
|
"auth:sudo_required",
|
|
48
49
|
"auth:insufficient_permissions",
|
|
49
50
|
"auth:impersonation_restricted",
|
|
@@ -1758,6 +1759,7 @@ const createClientArrangementSchema = z.object({
|
|
|
1758
1759
|
/** The UI selects the next N dates from get.dates, then retains this body for retry. */
|
|
1759
1760
|
const bookNextArrangementSchema = z.object({
|
|
1760
1761
|
...operation,
|
|
1762
|
+
confirmation: z.string().optional(),
|
|
1761
1763
|
occurrenceDates: z.array(localDate).min(1).max(52).refine((values) => new Set(values).size === values.length, "Choose each date once."),
|
|
1762
1764
|
bookShortfallAsOwed: z.boolean().default(false)
|
|
1763
1765
|
}).strict();
|
|
@@ -1926,7 +1928,6 @@ const arrangementDateResultSchema = z.intersection(z.object({ occurrenceDate: lo
|
|
|
1926
1928
|
z.object({ code: z.enum([
|
|
1927
1929
|
"package_shortfall",
|
|
1928
1930
|
"not_available",
|
|
1929
|
-
"needs_recorded_return",
|
|
1930
1931
|
"client_not_found"
|
|
1931
1932
|
]) }),
|
|
1932
1933
|
z.object({
|
|
@@ -2215,7 +2216,11 @@ const APPOINTMENT_ENDPOINT_DEFINITIONS = defineEndpointDefinitions({
|
|
|
2215
2216
|
method: "DELETE",
|
|
2216
2217
|
auth: "user",
|
|
2217
2218
|
responseKind: "json",
|
|
2218
|
-
errors: [
|
|
2219
|
+
errors: [
|
|
2220
|
+
"resource:not_found",
|
|
2221
|
+
"resource:conflict",
|
|
2222
|
+
"server:internal_error"
|
|
2223
|
+
]
|
|
2219
2224
|
},
|
|
2220
2225
|
createTeamMemberProfile: {
|
|
2221
2226
|
path: "/sites/{siteId}/bookings/resources/{resourceId}/profile",
|
|
@@ -2516,6 +2521,17 @@ const APPOINTMENT_ENDPOINT_DEFINITIONS = defineEndpointDefinitions({
|
|
|
2516
2521
|
"server:internal_error"
|
|
2517
2522
|
]
|
|
2518
2523
|
},
|
|
2524
|
+
previewWeeklyAvailabilityImpact: {
|
|
2525
|
+
path: "/sites/{siteId}/bookings/resources/{resourceId}/weekly-availability/impact",
|
|
2526
|
+
method: "POST",
|
|
2527
|
+
auth: "user",
|
|
2528
|
+
responseKind: "json",
|
|
2529
|
+
errors: [
|
|
2530
|
+
"validation:invalid_input",
|
|
2531
|
+
"resource:not_found",
|
|
2532
|
+
"server:internal_error"
|
|
2533
|
+
]
|
|
2534
|
+
},
|
|
2519
2535
|
setServiceSpecificAvailability: {
|
|
2520
2536
|
path: "/sites/{siteId}/bookings/resources/{resourceId}/service-availability",
|
|
2521
2537
|
method: "PUT",
|
|
@@ -2855,6 +2871,54 @@ const EVENT_SERIES_REGISTRATION_ENDPOINT_DEFINITIONS = defineEndpointDefinitions
|
|
|
2855
2871
|
"server:internal_error"
|
|
2856
2872
|
]
|
|
2857
2873
|
},
|
|
2874
|
+
listEventOfferingCombinationPrices: {
|
|
2875
|
+
path: "/sites/{siteId}/bookings/event-offerings/{eventOfferingId}/combination-prices",
|
|
2876
|
+
method: "GET",
|
|
2877
|
+
auth: "user",
|
|
2878
|
+
responseKind: "json",
|
|
2879
|
+
errors: [
|
|
2880
|
+
"validation:invalid_input",
|
|
2881
|
+
"auth:forbidden",
|
|
2882
|
+
"resource:not_found",
|
|
2883
|
+
"server:internal_error"
|
|
2884
|
+
]
|
|
2885
|
+
},
|
|
2886
|
+
createEventOfferingCombinationPrice: {
|
|
2887
|
+
path: "/sites/{siteId}/bookings/event-offerings/{eventOfferingId}/combination-prices",
|
|
2888
|
+
method: "POST",
|
|
2889
|
+
auth: "user",
|
|
2890
|
+
responseKind: "json",
|
|
2891
|
+
errors: [
|
|
2892
|
+
"validation:invalid_input",
|
|
2893
|
+
"auth:forbidden",
|
|
2894
|
+
"resource:not_found",
|
|
2895
|
+
"server:internal_error"
|
|
2896
|
+
]
|
|
2897
|
+
},
|
|
2898
|
+
updateEventOfferingCombinationPrice: {
|
|
2899
|
+
path: "/sites/{siteId}/bookings/event-offerings/{eventOfferingId}/combination-prices/{combinationPriceId}",
|
|
2900
|
+
method: "PUT",
|
|
2901
|
+
auth: "user",
|
|
2902
|
+
responseKind: "json",
|
|
2903
|
+
errors: [
|
|
2904
|
+
"validation:invalid_input",
|
|
2905
|
+
"auth:forbidden",
|
|
2906
|
+
"resource:not_found",
|
|
2907
|
+
"server:internal_error"
|
|
2908
|
+
]
|
|
2909
|
+
},
|
|
2910
|
+
deleteEventOfferingCombinationPrice: {
|
|
2911
|
+
path: "/sites/{siteId}/bookings/event-offerings/{eventOfferingId}/combination-prices/{combinationPriceId}",
|
|
2912
|
+
method: "DELETE",
|
|
2913
|
+
auth: "user",
|
|
2914
|
+
responseKind: "json",
|
|
2915
|
+
errors: [
|
|
2916
|
+
"validation:invalid_input",
|
|
2917
|
+
"auth:forbidden",
|
|
2918
|
+
"resource:not_found",
|
|
2919
|
+
"server:internal_error"
|
|
2920
|
+
]
|
|
2921
|
+
},
|
|
2858
2922
|
deleteEventOffering: {
|
|
2859
2923
|
path: "/sites/{siteId}/bookings/event-offerings/{eventOfferingId}",
|
|
2860
2924
|
method: "DELETE",
|
|
@@ -3871,6 +3935,22 @@ const publicVenueMapLocationSchema = publicLocationSchema.unwrap().extend({
|
|
|
3871
3935
|
addressWithBooking: z.boolean().optional()
|
|
3872
3936
|
}).readonly();
|
|
3873
3937
|
|
|
3938
|
+
//#endregion
|
|
3939
|
+
//#region ../site-contracts/src/siteData/mapLocation.ts
|
|
3940
|
+
/** Site and preview authority belong to transport, never to the selected source. */
|
|
3941
|
+
const publicMapLocationParamsSchema = z.discriminatedUnion("source", [z.object({
|
|
3942
|
+
source: z.literal("venue"),
|
|
3943
|
+
venueId: z.string().uuid()
|
|
3944
|
+
}), z.object({ source: z.literal("business_address") })]);
|
|
3945
|
+
const publicMapLocationResultSchema = z.discriminatedUnion("kind", [
|
|
3946
|
+
z.object({
|
|
3947
|
+
kind: z.literal("shown"),
|
|
3948
|
+
location: publicVenueMapLocationSchema
|
|
3949
|
+
}),
|
|
3950
|
+
z.object({ kind: z.literal("hidden") }),
|
|
3951
|
+
z.object({ kind: z.literal("not_found") })
|
|
3952
|
+
]);
|
|
3953
|
+
|
|
3874
3954
|
//#endregion
|
|
3875
3955
|
//#region ../site-contracts/src/siteData/eventVocabulary.ts
|
|
3876
3956
|
const eventCalendarDisplayModeValues = [
|
|
@@ -3889,6 +3969,11 @@ const eventCalendarListLayoutValues = [
|
|
|
3889
3969
|
];
|
|
3890
3970
|
const eventCalendarListLayoutCompatibleDisplayModeValues = ["combined", "list"];
|
|
3891
3971
|
|
|
3972
|
+
//#endregion
|
|
3973
|
+
//#region ../site-contracts/src/siteData/eventCheckoutTypes.ts
|
|
3974
|
+
/** The most dates or runs one booking request may name; the block stops ticking at the same number. */
|
|
3975
|
+
const MAX_EVENT_BOOKING_SELECTION_ITEMS = 20;
|
|
3976
|
+
|
|
3892
3977
|
//#endregion
|
|
3893
3978
|
//#region ../commerce/src/purchase/allocation.ts
|
|
3894
3979
|
/**
|
|
@@ -3930,6 +4015,7 @@ const ORDER_STATUSES = [
|
|
|
3930
4015
|
"failed",
|
|
3931
4016
|
"cancelled"
|
|
3932
4017
|
];
|
|
4018
|
+
const orderStatusSchema = z.enum(ORDER_STATUSES);
|
|
3933
4019
|
const orderStatusSet = new Set(ORDER_STATUSES);
|
|
3934
4020
|
function isOrderStatus(value) {
|
|
3935
4021
|
return orderStatusSet.has(value);
|
|
@@ -4109,6 +4195,320 @@ function getBookingLaterInstalments(schedule) {
|
|
|
4109
4195
|
return schedule.filter((row) => row.stateAtBooking === "scheduled");
|
|
4110
4196
|
}
|
|
4111
4197
|
|
|
4198
|
+
//#endregion
|
|
4199
|
+
//#region ../commerce/src/purchase/settlement.ts
|
|
4200
|
+
function normalizeCurrencyCode(raw) {
|
|
4201
|
+
const normalized = raw.trim().toUpperCase();
|
|
4202
|
+
if (!/^[A-Z]{3}$/.test(normalized)) {
|
|
4203
|
+
throw new Error(`Invalid currency code: ${raw}`);
|
|
4204
|
+
}
|
|
4205
|
+
return normalized;
|
|
4206
|
+
}
|
|
4207
|
+
function rebrandCents(amount) {
|
|
4208
|
+
return amount;
|
|
4209
|
+
}
|
|
4210
|
+
function toSubtotalCents(raw) {
|
|
4211
|
+
return rebrandCents(toNonNegativeCents(raw));
|
|
4212
|
+
}
|
|
4213
|
+
function toDiscountCents(raw) {
|
|
4214
|
+
return rebrandCents(toNonNegativeCents(raw));
|
|
4215
|
+
}
|
|
4216
|
+
function toCreditAppliedCents(raw) {
|
|
4217
|
+
return rebrandCents(toNonNegativeCents(raw));
|
|
4218
|
+
}
|
|
4219
|
+
function toStripeChargeCents(raw) {
|
|
4220
|
+
return rebrandCents(toNonNegativeCents(raw));
|
|
4221
|
+
}
|
|
4222
|
+
function toRefundedCents(raw) {
|
|
4223
|
+
return rebrandCents(toNonNegativeCents(raw));
|
|
4224
|
+
}
|
|
4225
|
+
function toRefundableTotalCents(raw) {
|
|
4226
|
+
return rebrandCents(toNonNegativeCents(raw));
|
|
4227
|
+
}
|
|
4228
|
+
function money(amountCents, currency) {
|
|
4229
|
+
return {
|
|
4230
|
+
amountCents: toNonNegativeCents(amountCents),
|
|
4231
|
+
currency
|
|
4232
|
+
};
|
|
4233
|
+
}
|
|
4234
|
+
function parseLineSettlementCents(lineId, raw, field) {
|
|
4235
|
+
const parsed = parseNonNegativeCents(raw);
|
|
4236
|
+
if (!parsed.ok) {
|
|
4237
|
+
return err({
|
|
4238
|
+
_tag: "invalid_line_money",
|
|
4239
|
+
lineId,
|
|
4240
|
+
field,
|
|
4241
|
+
message: `Line ${lineId} ${field} must be a non-negative whole number of cents`
|
|
4242
|
+
});
|
|
4243
|
+
}
|
|
4244
|
+
return parsed;
|
|
4245
|
+
}
|
|
4246
|
+
function buildLineSettlementBreakdown(options) {
|
|
4247
|
+
const subtotalResult = parseLineSettlementCents(options.lineId, options.subtotalCents, "subtotalCents");
|
|
4248
|
+
if (!subtotalResult.ok) return subtotalResult;
|
|
4249
|
+
const discountResult = parseLineSettlementCents(options.lineId, options.discountCents, "discountCents");
|
|
4250
|
+
if (!discountResult.ok) return discountResult;
|
|
4251
|
+
const creditAppliedResult = parseLineSettlementCents(options.lineId, options.creditAppliedCents, "creditAppliedCents");
|
|
4252
|
+
if (!creditAppliedResult.ok) return creditAppliedResult;
|
|
4253
|
+
const stripeChargeResult = parseLineSettlementCents(options.lineId, options.stripeChargeCents, "stripeChargeCents");
|
|
4254
|
+
if (!stripeChargeResult.ok) return stripeChargeResult;
|
|
4255
|
+
const subtotalCents = rebrandCents(subtotalResult.value);
|
|
4256
|
+
const discountCents = rebrandCents(discountResult.value);
|
|
4257
|
+
const creditAppliedCents = rebrandCents(creditAppliedResult.value);
|
|
4258
|
+
const stripeChargeCents = rebrandCents(stripeChargeResult.value);
|
|
4259
|
+
const expectedStripeCharge = subtotalCents - discountCents - creditAppliedCents;
|
|
4260
|
+
if (expectedStripeCharge < 0) {
|
|
4261
|
+
return err({
|
|
4262
|
+
_tag: "inconsistent_line_totals",
|
|
4263
|
+
lineId: options.lineId,
|
|
4264
|
+
message: `Settlement invariant failed for line ${options.lineId}: reductions exceed subtotal`
|
|
4265
|
+
});
|
|
4266
|
+
}
|
|
4267
|
+
if (stripeChargeCents !== expectedStripeCharge) {
|
|
4268
|
+
return err({
|
|
4269
|
+
_tag: "inconsistent_line_totals",
|
|
4270
|
+
lineId: options.lineId,
|
|
4271
|
+
message: `Settlement invariant failed for line ${options.lineId}: expected stripe charge ${expectedStripeCharge}, got ${stripeChargeCents}`
|
|
4272
|
+
});
|
|
4273
|
+
}
|
|
4274
|
+
return ok({
|
|
4275
|
+
subtotalCents,
|
|
4276
|
+
discountCents,
|
|
4277
|
+
creditAppliedCents,
|
|
4278
|
+
stripeChargeCents
|
|
4279
|
+
});
|
|
4280
|
+
}
|
|
4281
|
+
function buildRefundableLineSettlement(options) {
|
|
4282
|
+
const line = buildLineSettlementBreakdown(options);
|
|
4283
|
+
if (!line.ok) {
|
|
4284
|
+
return line;
|
|
4285
|
+
}
|
|
4286
|
+
const alreadyRefundedResult = parseLineSettlementCents(options.lineId, options.alreadyRefundedCents, "alreadyRefundedCents");
|
|
4287
|
+
if (!alreadyRefundedResult.ok) return alreadyRefundedResult;
|
|
4288
|
+
const refundableTotalCents = toRefundableTotalCents(line.value.creditAppliedCents + line.value.stripeChargeCents);
|
|
4289
|
+
const alreadyRefundedCents = rebrandCents(alreadyRefundedResult.value);
|
|
4290
|
+
if (alreadyRefundedCents > refundableTotalCents) {
|
|
4291
|
+
return err({
|
|
4292
|
+
_tag: "refunded_exceeds_refundable_total",
|
|
4293
|
+
lineId: options.lineId,
|
|
4294
|
+
message: `Order item ${options.lineId} refunded amount exceeds refundable total`
|
|
4295
|
+
});
|
|
4296
|
+
}
|
|
4297
|
+
return ok({
|
|
4298
|
+
line: line.value,
|
|
4299
|
+
refundableTotalCents,
|
|
4300
|
+
alreadyRefundedCents
|
|
4301
|
+
});
|
|
4302
|
+
}
|
|
4303
|
+
/**
|
|
4304
|
+
* Cash actually collected against one order line, summed from its payment
|
|
4305
|
+
* receipt allocations. Shared so every refundable-remainder caller measures
|
|
4306
|
+
* funding the same way.
|
|
4307
|
+
*/
|
|
4308
|
+
function orderItemCashFundedCents(allocations, orderItemId) {
|
|
4309
|
+
let total = 0;
|
|
4310
|
+
for (const allocation of allocations) {
|
|
4311
|
+
if (allocation.orderItemId === orderItemId) {
|
|
4312
|
+
total += allocation.amountCents;
|
|
4313
|
+
}
|
|
4314
|
+
}
|
|
4315
|
+
return total;
|
|
4316
|
+
}
|
|
4317
|
+
/**
|
|
4318
|
+
* The single authority on how much of an order line is still refundable.
|
|
4319
|
+
*
|
|
4320
|
+
* Every surface that shows or enforces a refundable remainder MUST go through
|
|
4321
|
+
* this function. Computing it from the line's net total instead of its actual
|
|
4322
|
+
* funding overstates the remainder on partially collected orders, which used to
|
|
4323
|
+
* let the dashboard offer a refund the runtime then refused.
|
|
4324
|
+
*/
|
|
4325
|
+
function orderItemRefundableRemainingCents(funding) {
|
|
4326
|
+
return toNonNegativeCents(funding.cashFundedCents + funding.creditAppliedCents - funding.refundedCents);
|
|
4327
|
+
}
|
|
4328
|
+
function refundableRemainingCents(settlement) {
|
|
4329
|
+
return orderItemRefundableRemainingCents({
|
|
4330
|
+
cashFundedCents: settlement.refundableTotalCents,
|
|
4331
|
+
creditAppliedCents: 0,
|
|
4332
|
+
refundedCents: settlement.alreadyRefundedCents
|
|
4333
|
+
});
|
|
4334
|
+
}
|
|
4335
|
+
function ensureSingleCurrency(lines) {
|
|
4336
|
+
if (lines.length === 0) {
|
|
4337
|
+
return {
|
|
4338
|
+
ok: false,
|
|
4339
|
+
reason: "empty_cart",
|
|
4340
|
+
currencies: []
|
|
4341
|
+
};
|
|
4342
|
+
}
|
|
4343
|
+
const uniqueCurrencies = Array.from(new Set(lines.map((line) => line.currency.trim().toUpperCase()))).sort();
|
|
4344
|
+
if (uniqueCurrencies.length !== 1) {
|
|
4345
|
+
return {
|
|
4346
|
+
ok: false,
|
|
4347
|
+
reason: "mixed_currency",
|
|
4348
|
+
currencies: uniqueCurrencies
|
|
4349
|
+
};
|
|
4350
|
+
}
|
|
4351
|
+
try {
|
|
4352
|
+
return {
|
|
4353
|
+
ok: true,
|
|
4354
|
+
currency: normalizeCurrencyCode(uniqueCurrencies[0] ?? "")
|
|
4355
|
+
};
|
|
4356
|
+
} catch {
|
|
4357
|
+
return {
|
|
4358
|
+
ok: false,
|
|
4359
|
+
reason: "invalid_currency",
|
|
4360
|
+
currencies: uniqueCurrencies
|
|
4361
|
+
};
|
|
4362
|
+
}
|
|
4363
|
+
}
|
|
4364
|
+
function allocateReductionCents(inputs, requestedCents) {
|
|
4365
|
+
const sanitizedInputs = inputs.map((input) => ({
|
|
4366
|
+
lineId: input.lineId,
|
|
4367
|
+
basisCents: toNonNegativeCents(input.basisCents),
|
|
4368
|
+
maxReducibleCents: toNonNegativeCents(input.maxReducibleCents)
|
|
4369
|
+
}));
|
|
4370
|
+
const totalReducibleCents = sanitizedInputs.reduce((sum, input) => sum + input.maxReducibleCents, 0);
|
|
4371
|
+
const targetCents = Math.max(0, Math.min(Math.trunc(requestedCents), totalReducibleCents));
|
|
4372
|
+
const allocations = sanitizedInputs.map((input) => ({
|
|
4373
|
+
lineId: input.lineId,
|
|
4374
|
+
amountCents: toNonNegativeCents(0)
|
|
4375
|
+
}));
|
|
4376
|
+
if (targetCents === 0 || sanitizedInputs.length === 0) {
|
|
4377
|
+
return {
|
|
4378
|
+
requestedCents: toNonNegativeCents(requestedCents),
|
|
4379
|
+
appliedCents: toNonNegativeCents(0),
|
|
4380
|
+
allocations
|
|
4381
|
+
};
|
|
4382
|
+
}
|
|
4383
|
+
const remainingCaps = sanitizedInputs.map((input) => input.maxReducibleCents);
|
|
4384
|
+
let remainingCents = targetCents;
|
|
4385
|
+
while (remainingCents > 0) {
|
|
4386
|
+
const eligibleIndexes = sanitizedInputs.map((input, index) => ({
|
|
4387
|
+
input,
|
|
4388
|
+
index
|
|
4389
|
+
})).filter(({ input, index }) => input.basisCents > 0 && (remainingCaps[index] ?? 0) > 0);
|
|
4390
|
+
if (eligibleIndexes.length === 0) break;
|
|
4391
|
+
const eligibleBasis = eligibleIndexes.reduce((sum, { input }) => sum + input.basisCents, 0);
|
|
4392
|
+
if (eligibleBasis <= 0) break;
|
|
4393
|
+
const roundCandidates = eligibleIndexes.map(({ input, index }) => {
|
|
4394
|
+
const exactShare = input.basisCents / eligibleBasis * remainingCents;
|
|
4395
|
+
const floorShare = Math.min(Math.floor(exactShare), remainingCaps[index] ?? 0);
|
|
4396
|
+
const remainder = exactShare - floorShare;
|
|
4397
|
+
return {
|
|
4398
|
+
index,
|
|
4399
|
+
floorShare,
|
|
4400
|
+
remainder
|
|
4401
|
+
};
|
|
4402
|
+
});
|
|
4403
|
+
let assignedThisRound = 0;
|
|
4404
|
+
for (const candidate of roundCandidates) {
|
|
4405
|
+
if (candidate.floorShare <= 0) continue;
|
|
4406
|
+
const allocation = allocations[candidate.index];
|
|
4407
|
+
if (!allocation) continue;
|
|
4408
|
+
allocation.amountCents = toNonNegativeCents(allocation.amountCents + candidate.floorShare);
|
|
4409
|
+
remainingCaps[candidate.index] = toNonNegativeCents((remainingCaps[candidate.index] ?? 0) - candidate.floorShare);
|
|
4410
|
+
assignedThisRound += candidate.floorShare;
|
|
4411
|
+
}
|
|
4412
|
+
remainingCents -= assignedThisRound;
|
|
4413
|
+
if (remainingCents <= 0) break;
|
|
4414
|
+
const remainderCandidates = roundCandidates.filter((candidate) => (remainingCaps[candidate.index] ?? 0) > 0).sort((a, b) => {
|
|
4415
|
+
if (b.remainder !== a.remainder) return b.remainder - a.remainder;
|
|
4416
|
+
return a.index - b.index;
|
|
4417
|
+
});
|
|
4418
|
+
if (remainderCandidates.length === 0) break;
|
|
4419
|
+
let remainderAssigned = 0;
|
|
4420
|
+
for (const candidate of remainderCandidates) {
|
|
4421
|
+
if (remainingCents <= 0) break;
|
|
4422
|
+
if ((remainingCaps[candidate.index] ?? 0) <= 0) continue;
|
|
4423
|
+
const allocation = allocations[candidate.index];
|
|
4424
|
+
if (!allocation) continue;
|
|
4425
|
+
allocation.amountCents = toNonNegativeCents(allocation.amountCents + 1);
|
|
4426
|
+
remainingCaps[candidate.index] = toNonNegativeCents((remainingCaps[candidate.index] ?? 0) - 1);
|
|
4427
|
+
remainingCents -= 1;
|
|
4428
|
+
remainderAssigned += 1;
|
|
4429
|
+
}
|
|
4430
|
+
if (assignedThisRound === 0 && remainderAssigned === 0) {
|
|
4431
|
+
break;
|
|
4432
|
+
}
|
|
4433
|
+
}
|
|
4434
|
+
const appliedCents = allocations.reduce((sum, allocation) => sum + allocation.amountCents, 0);
|
|
4435
|
+
return {
|
|
4436
|
+
requestedCents: toNonNegativeCents(requestedCents),
|
|
4437
|
+
appliedCents: toNonNegativeCents(appliedCents),
|
|
4438
|
+
allocations
|
|
4439
|
+
};
|
|
4440
|
+
}
|
|
4441
|
+
function assertSettledOrderLineInvariants(lines) {
|
|
4442
|
+
for (const line of lines) {
|
|
4443
|
+
if (line.discountCents < 0 || line.creditCents < 0 || line.netTotalCents < 0) {
|
|
4444
|
+
throw new Error(`Negative settlement values are not allowed for line ${line.lineId}`);
|
|
4445
|
+
}
|
|
4446
|
+
const expectedNet = line.subtotalCents - line.discountCents - line.creditCents;
|
|
4447
|
+
if (line.netTotalCents !== expectedNet) {
|
|
4448
|
+
throw new Error(`Settlement invariant failed for line ${line.lineId}: expected ${expectedNet}, got ${line.netTotalCents}`);
|
|
4449
|
+
}
|
|
4450
|
+
}
|
|
4451
|
+
}
|
|
4452
|
+
|
|
4453
|
+
//#endregion
|
|
4454
|
+
//#region ../commerce/src/purchase/stripeMinimumCharge.ts
|
|
4455
|
+
const STRIPE_MINIMUM_CHARGE_CENTS_BY_CURRENCY = {
|
|
4456
|
+
GBP: 30,
|
|
4457
|
+
USD: 50,
|
|
4458
|
+
EUR: 50,
|
|
4459
|
+
AED: 200,
|
|
4460
|
+
AUD: 50,
|
|
4461
|
+
BGN: 100,
|
|
4462
|
+
BRL: 50,
|
|
4463
|
+
CAD: 50,
|
|
4464
|
+
CHF: 50,
|
|
4465
|
+
CZK: 1500,
|
|
4466
|
+
DKK: 250,
|
|
4467
|
+
HKD: 400,
|
|
4468
|
+
HUF: 17500,
|
|
4469
|
+
JPY: 50,
|
|
4470
|
+
MXN: 1e3,
|
|
4471
|
+
MYR: 200,
|
|
4472
|
+
NOK: 300,
|
|
4473
|
+
NZD: 50,
|
|
4474
|
+
PLN: 200,
|
|
4475
|
+
RON: 200,
|
|
4476
|
+
SEK: 300,
|
|
4477
|
+
SGD: 50,
|
|
4478
|
+
THB: 1e3
|
|
4479
|
+
};
|
|
4480
|
+
function isStripeMinimumChargeCurrency(currency) {
|
|
4481
|
+
return currency in STRIPE_MINIMUM_CHARGE_CENTS_BY_CURRENCY;
|
|
4482
|
+
}
|
|
4483
|
+
function getStripeMinimumChargeRequirement(rawCurrency) {
|
|
4484
|
+
let currency;
|
|
4485
|
+
try {
|
|
4486
|
+
currency = normalizeCurrencyCode(rawCurrency);
|
|
4487
|
+
} catch {
|
|
4488
|
+
return null;
|
|
4489
|
+
}
|
|
4490
|
+
const currencyKey = currency;
|
|
4491
|
+
if (!isStripeMinimumChargeCurrency(currencyKey)) {
|
|
4492
|
+
return null;
|
|
4493
|
+
}
|
|
4494
|
+
return {
|
|
4495
|
+
currency,
|
|
4496
|
+
minimumAmountCents: STRIPE_MINIMUM_CHARGE_CENTS_BY_CURRENCY[currencyKey]
|
|
4497
|
+
};
|
|
4498
|
+
}
|
|
4499
|
+
function isStripeChargeBelowMinimum(options) {
|
|
4500
|
+
const requirement = getStripeMinimumChargeRequirement(options.currency);
|
|
4501
|
+
return Boolean(requirement && options.amountCents > 0 && options.amountCents < requirement.minimumAmountCents);
|
|
4502
|
+
}
|
|
4503
|
+
/**
|
|
4504
|
+
* The smallest deposit a plan that starts with one may ask for: the card
|
|
4505
|
+
* minimum for the currency, or any positive amount for a currency Stripe has
|
|
4506
|
+
* no minimum on record for.
|
|
4507
|
+
*/
|
|
4508
|
+
function getInstalmentDepositMinimumCents(currency) {
|
|
4509
|
+
return getStripeMinimumChargeRequirement(currency)?.minimumAmountCents ?? 1;
|
|
4510
|
+
}
|
|
4511
|
+
|
|
4112
4512
|
//#endregion
|
|
4113
4513
|
//#region ../commerce/src/purchase/bookingPaymentSelection.ts
|
|
4114
4514
|
function isBookingPlanOrContractSelection(selection) {
|
|
@@ -4145,17 +4545,15 @@ function resolveAvailableBookingCollectionOptions(input) {
|
|
|
4145
4545
|
option,
|
|
4146
4546
|
totalCents: input.totalCents,
|
|
4147
4547
|
anchorAt: input.now,
|
|
4148
|
-
bookingStartAt: input.bookingStartAt
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
deadline,
|
|
4152
|
-
schedule: option.schedule
|
|
4153
|
-
}));
|
|
4548
|
+
bookingStartAt: input.bookingStartAt,
|
|
4549
|
+
timeZone: input.timeZone
|
|
4550
|
+
})).filter((option) => canOfferBookingCollectionOption(option, input.currency ?? "USD", deadline));
|
|
4154
4551
|
const upfront = resolveBookingCollectionOptionFacts({
|
|
4155
4552
|
option: { kind: "upfront" },
|
|
4156
4553
|
totalCents: input.totalCents,
|
|
4157
4554
|
anchorAt: input.now,
|
|
4158
|
-
bookingStartAt: input.bookingStartAt
|
|
4555
|
+
bookingStartAt: input.bookingStartAt,
|
|
4556
|
+
timeZone: input.timeZone
|
|
4159
4557
|
});
|
|
4160
4558
|
const collapsed = available.map((option) => isBookingCollectionEquivalentToUpfront(option) ? upfront : option);
|
|
4161
4559
|
const unique = collapsed.filter((option, index) => collapsed.findIndex((other) => other.kind === option.kind) === index);
|
|
@@ -4174,7 +4572,8 @@ function resolveBookingCollectionOptionFacts(input) {
|
|
|
4174
4572
|
const money$1 = {
|
|
4175
4573
|
totalCents: input.totalCents,
|
|
4176
4574
|
anchorAt: input.anchorAt,
|
|
4177
|
-
bookingStartAt: input.bookingStartAt
|
|
4575
|
+
bookingStartAt: input.bookingStartAt,
|
|
4576
|
+
timeZone: input.timeZone ?? "UTC"
|
|
4178
4577
|
};
|
|
4179
4578
|
switch (input.option.kind) {
|
|
4180
4579
|
case "upfront": return {
|
|
@@ -4213,10 +4612,7 @@ function resolveBookingCollectionOptionFacts(input) {
|
|
|
4213
4612
|
config: input.option.config,
|
|
4214
4613
|
dueNowCents,
|
|
4215
4614
|
remainingBalanceCents: Math.max(0, input.totalCents - dueNowCents),
|
|
4216
|
-
|
|
4217
|
-
bookingStartAt: input.bookingStartAt ?? input.anchorAt,
|
|
4218
|
-
dueDateRule: input.option.config.dueDateRule
|
|
4219
|
-
})
|
|
4615
|
+
balanceDueDay: flexibleBalanceDueDay(input.option.config, input.bookingStartAt ?? input.anchorAt, money$1.timeZone)
|
|
4220
4616
|
};
|
|
4221
4617
|
}
|
|
4222
4618
|
default: return assertNever$3(input.option);
|
|
@@ -4224,30 +4620,64 @@ function resolveBookingCollectionOptionFacts(input) {
|
|
|
4224
4620
|
}
|
|
4225
4621
|
/** Discounts change preview money, never an already admitted collection identity. */
|
|
4226
4622
|
function repriceBookingCollectionOptions(input) {
|
|
4227
|
-
|
|
4623
|
+
const repriced = input.options.map((option) => option.totalCents === input.totalCents ? option : resolveBookingCollectionOptionFacts({
|
|
4228
4624
|
option,
|
|
4229
4625
|
totalCents: input.totalCents,
|
|
4230
4626
|
anchorAt: option.anchorAt,
|
|
4231
|
-
bookingStartAt: option.bookingStartAt
|
|
4627
|
+
bookingStartAt: option.bookingStartAt,
|
|
4628
|
+
timeZone: option.timeZone
|
|
4232
4629
|
}));
|
|
4630
|
+
const available = repriced.filter((option) => canOfferBookingCollectionOption(option, input.currency, input.instalmentCollectionDeadlineAt));
|
|
4631
|
+
const first = repriced[0];
|
|
4632
|
+
return available.length > 0 || !first ? available : [resolveBookingCollectionOptionFacts({
|
|
4633
|
+
option: { kind: "upfront" },
|
|
4634
|
+
totalCents: input.totalCents,
|
|
4635
|
+
anchorAt: first.anchorAt,
|
|
4636
|
+
bookingStartAt: first.bookingStartAt,
|
|
4637
|
+
timeZone: first.timeZone
|
|
4638
|
+
})];
|
|
4639
|
+
}
|
|
4640
|
+
/** The same admission is used for the offer and the submitted selection. */
|
|
4641
|
+
function canOfferBookingCollectionOption(option, currency, deadline = option.bookingStartAt) {
|
|
4642
|
+
if (option.kind === "upfront" || option.kind === "deferred_manual") return true;
|
|
4643
|
+
const window$1 = bookingCollectionWindow(option);
|
|
4644
|
+
if (!window$1) return false;
|
|
4645
|
+
const { now, start } = window$1;
|
|
4646
|
+
if (option.kind === "flexible_balance") {
|
|
4647
|
+
return flexibleBalanceCanBeCollected(option, currency, now, start);
|
|
4648
|
+
}
|
|
4649
|
+
return deadline !== null && canInstalmentPlanCompleteBefore({
|
|
4650
|
+
now: option.anchorAt,
|
|
4651
|
+
deadline,
|
|
4652
|
+
schedule: option.schedule
|
|
4653
|
+
}) && laterInstalmentsCanBeCollected(option, currency, now);
|
|
4233
4654
|
}
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4655
|
+
function laterInstalmentsCanBeCollected(option, currency, now) {
|
|
4656
|
+
return option.schedule.filter((row) => row.stateAtBooking === "scheduled").every((row) => Date.parse(row.dueAt) > now && !isStripeChargeBelowMinimum({
|
|
4657
|
+
amountCents: row.amountCents,
|
|
4658
|
+
currency
|
|
4659
|
+
}));
|
|
4660
|
+
}
|
|
4661
|
+
function flexibleBalanceCanBeCollected(option, currency, now, start) {
|
|
4662
|
+
const today = formatLocalScheduleDate(getLocalScheduleDate(new Date(now), option.timeZone));
|
|
4663
|
+
const startDay = formatLocalScheduleDate(getLocalScheduleDate(new Date(start), option.timeZone));
|
|
4664
|
+
return option.balanceDueDay >= today && option.balanceDueDay < startDay && !isStripeChargeBelowMinimum({
|
|
4665
|
+
amountCents: option.remainingBalanceCents,
|
|
4666
|
+
currency
|
|
4667
|
+
});
|
|
4668
|
+
}
|
|
4669
|
+
function bookingCollectionWindow(option) {
|
|
4670
|
+
const now = Date.parse(option.anchorAt);
|
|
4671
|
+
const start = Date.parse(option.bookingStartAt ?? "");
|
|
4672
|
+
return Number.isFinite(now) && Number.isFinite(start) && start > now ? {
|
|
4673
|
+
now,
|
|
4674
|
+
start
|
|
4675
|
+
} : null;
|
|
4676
|
+
}
|
|
4677
|
+
/** Mirrors private.flexible_balance_due_day: fixed civil date, or local start minus calendar days. */
|
|
4678
|
+
function flexibleBalanceDueDay(config, bookingStartAt, timeZone) {
|
|
4679
|
+
const rule = config.dueDateRule;
|
|
4680
|
+
return formatLocalScheduleDate(rule.kind === "fixed_calendar_date" ? parseBookingLocalDate(rule.dueAt.slice(0, 10)) : addLocalScheduleDays(getLocalScheduleDate(new Date(bookingStartAt), timeZone), -rule.daysBeforeStart));
|
|
4251
4681
|
}
|
|
4252
4682
|
|
|
4253
4683
|
//#endregion
|
|
@@ -4425,13 +4855,14 @@ function formatUnexpectedValue(value) {
|
|
|
4425
4855
|
|
|
4426
4856
|
//#endregion
|
|
4427
4857
|
//#region ../commerce/src/purchase/checkoutDiscountContextPlanning.ts
|
|
4858
|
+
/** Group ticket lines within a date, keeping places per booking rather than adding dates. */
|
|
4428
4859
|
function collectCheckoutDiscountContexts(items) {
|
|
4429
4860
|
const contextsByIdentity = items.reduce((map, item) => {
|
|
4430
|
-
const candidate = toCheckoutDiscountContextCandidate(item
|
|
4861
|
+
const candidate = toCheckoutDiscountContextCandidate(item);
|
|
4431
4862
|
const existing = map.get(candidate.identityKey);
|
|
4432
4863
|
const nextEntry = existing ? {
|
|
4433
4864
|
identityKey: candidate.identityKey,
|
|
4434
|
-
context:
|
|
4865
|
+
context: mergeBookingDiscountContext(existing.context, candidate.context),
|
|
4435
4866
|
subtotalCents: existing.subtotalCents + item.subtotalCents,
|
|
4436
4867
|
lineIds: [...existing.lineIds, item.lineId]
|
|
4437
4868
|
} : {
|
|
@@ -4454,7 +4885,7 @@ function collectCheckoutDiscountContexts(items) {
|
|
|
4454
4885
|
function subtotalForCheckoutDiscountContexts(applicableContexts) {
|
|
4455
4886
|
return applicableContexts.reduce((sum, entry) => sum + entry.subtotalCents, 0);
|
|
4456
4887
|
}
|
|
4457
|
-
function rankCheckoutAutoDiscountCandidates(candidates) {
|
|
4888
|
+
function rankCheckoutAutoDiscountCandidates(candidates, options = { includeZeroDiscounts: false }) {
|
|
4458
4889
|
return candidates.map((candidate) => {
|
|
4459
4890
|
const subtotalCents = subtotalForCheckoutDiscountContexts(candidate.applicableContexts);
|
|
4460
4891
|
return {
|
|
@@ -4467,23 +4898,34 @@ function rankCheckoutAutoDiscountCandidates(candidates) {
|
|
|
4467
4898
|
subtotalCents: toNonNegativeCents(subtotalCents)
|
|
4468
4899
|
})
|
|
4469
4900
|
};
|
|
4470
|
-
}).filter((candidate) => candidate.computedDiscountCents > 0).sort((a, b) => {
|
|
4901
|
+
}).filter((candidate) => options.includeZeroDiscounts || candidate.computedDiscountCents > 0).sort((a, b) => {
|
|
4902
|
+
if (options.pricedTotalCents) {
|
|
4903
|
+
return options.pricedTotalCents(a) - options.pricedTotalCents(b) || a.code.id.localeCompare(b.code.id);
|
|
4904
|
+
}
|
|
4471
4905
|
if (b.computedDiscountCents !== a.computedDiscountCents) {
|
|
4472
4906
|
return b.computedDiscountCents - a.computedDiscountCents;
|
|
4473
4907
|
}
|
|
4474
4908
|
return a.code.id.localeCompare(b.code.id);
|
|
4475
4909
|
});
|
|
4476
4910
|
}
|
|
4477
|
-
function toCheckoutDiscountContextCandidate(
|
|
4478
|
-
const context = checkoutDiscountContext(
|
|
4911
|
+
function toCheckoutDiscountContextCandidate(item) {
|
|
4912
|
+
const context = checkoutDiscountContext(item.validated);
|
|
4913
|
+
const bookingId = item.validated.type === "event_ticket" ? item.validated.occurrenceId ?? item.lineId : item.lineId;
|
|
4479
4914
|
return {
|
|
4480
|
-
identityKey: checkoutDiscountContextIdentity(context),
|
|
4915
|
+
identityKey: checkoutDiscountContextIdentity(context, bookingId),
|
|
4481
4916
|
context
|
|
4482
4917
|
};
|
|
4483
4918
|
}
|
|
4484
|
-
|
|
4919
|
+
/** Price lines in the same booking (one date, or one run) add up their places; separate bookings never do. */
|
|
4920
|
+
function mergeBookingDiscountContext(existing, next) {
|
|
4921
|
+
return existing.type === "event" && next.type === "event" || existing.type === "whole_series" && next.type === "whole_series" ? {
|
|
4922
|
+
...existing,
|
|
4923
|
+
ticketsCount: (existing.ticketsCount ?? 0) + (next.ticketsCount ?? 0)
|
|
4924
|
+
} : existing;
|
|
4925
|
+
}
|
|
4926
|
+
function checkoutDiscountContextIdentity(context, bookingId) {
|
|
4485
4927
|
switch (context.type) {
|
|
4486
|
-
case "event": return `event:${context.eventSeriesId}`;
|
|
4928
|
+
case "event": return `event:${context.eventSeriesId}:${bookingId}`;
|
|
4487
4929
|
case "whole_series": return `whole-series:${context.eventSeriesId}`;
|
|
4488
4930
|
case "product": return `product:${context.productId}`;
|
|
4489
4931
|
case "pass": return `pass:${context.passId}`;
|
|
@@ -4495,12 +4937,14 @@ function checkoutDiscountContext(source) {
|
|
|
4495
4937
|
case "event_ticket": return {
|
|
4496
4938
|
type: "event",
|
|
4497
4939
|
eventSeriesId: source.eventSeries.id,
|
|
4940
|
+
eventOfferingId: source.eventSeries.eventOfferingId,
|
|
4498
4941
|
eventCategoryId: source.eventSeries.eventCategoryId,
|
|
4499
4942
|
ticketsCount: source.ticketCount
|
|
4500
4943
|
};
|
|
4501
4944
|
case "whole_series_enrollment": return {
|
|
4502
4945
|
type: "whole_series",
|
|
4503
4946
|
eventSeriesId: source.eventSeries.id,
|
|
4947
|
+
eventOfferingId: source.eventSeries.eventOfferingId,
|
|
4504
4948
|
eventCategoryId: source.eventSeries.eventCategoryId,
|
|
4505
4949
|
ticketsCount: source.participantCount
|
|
4506
4950
|
};
|
|
@@ -4519,15 +4963,6 @@ function checkoutDiscountContext(source) {
|
|
|
4519
4963
|
};
|
|
4520
4964
|
}
|
|
4521
4965
|
}
|
|
4522
|
-
function mergeCheckoutDiscountContexts(existing, next) {
|
|
4523
|
-
if (existing.type === "event" && next.type === "event" || existing.type === "whole_series" && next.type === "whole_series") {
|
|
4524
|
-
return {
|
|
4525
|
-
...existing,
|
|
4526
|
-
ticketsCount: (existing.ticketsCount ?? 0) + (next.ticketsCount ?? 0)
|
|
4527
|
-
};
|
|
4528
|
-
}
|
|
4529
|
-
return existing;
|
|
4530
|
-
}
|
|
4531
4966
|
function computeCheckoutDiscountCents(options) {
|
|
4532
4967
|
const subtotal = options.subtotalCents;
|
|
4533
4968
|
if (subtotal === 0) return toNonNegativeCents(0);
|
|
@@ -4662,6 +5097,7 @@ function planCheckoutPaymentObligation(input) {
|
|
|
4662
5097
|
};
|
|
4663
5098
|
case "flexible_balance": return {
|
|
4664
5099
|
kind: "flexible_balance",
|
|
5100
|
+
...selection.timeZone === undefined ? {} : { timeZone: selection.timeZone },
|
|
4665
5101
|
config: selection.config,
|
|
4666
5102
|
configuredPaymentDueNowCents: resolveFlexibleBalanceInitialPaymentCents({
|
|
4667
5103
|
totalAmountCents: input.totalAfterDiscountCents,
|
|
@@ -4751,261 +5187,6 @@ function unsafeAsPositiveCheckoutQuantity(quantity) {
|
|
|
4751
5187
|
return quantity;
|
|
4752
5188
|
}
|
|
4753
5189
|
|
|
4754
|
-
//#endregion
|
|
4755
|
-
//#region ../commerce/src/purchase/settlement.ts
|
|
4756
|
-
function normalizeCurrencyCode(raw) {
|
|
4757
|
-
const normalized = raw.trim().toUpperCase();
|
|
4758
|
-
if (!/^[A-Z]{3}$/.test(normalized)) {
|
|
4759
|
-
throw new Error(`Invalid currency code: ${raw}`);
|
|
4760
|
-
}
|
|
4761
|
-
return normalized;
|
|
4762
|
-
}
|
|
4763
|
-
function rebrandCents(amount) {
|
|
4764
|
-
return amount;
|
|
4765
|
-
}
|
|
4766
|
-
function toSubtotalCents(raw) {
|
|
4767
|
-
return rebrandCents(toNonNegativeCents(raw));
|
|
4768
|
-
}
|
|
4769
|
-
function toDiscountCents(raw) {
|
|
4770
|
-
return rebrandCents(toNonNegativeCents(raw));
|
|
4771
|
-
}
|
|
4772
|
-
function toCreditAppliedCents(raw) {
|
|
4773
|
-
return rebrandCents(toNonNegativeCents(raw));
|
|
4774
|
-
}
|
|
4775
|
-
function toStripeChargeCents(raw) {
|
|
4776
|
-
return rebrandCents(toNonNegativeCents(raw));
|
|
4777
|
-
}
|
|
4778
|
-
function toRefundedCents(raw) {
|
|
4779
|
-
return rebrandCents(toNonNegativeCents(raw));
|
|
4780
|
-
}
|
|
4781
|
-
function toRefundableTotalCents(raw) {
|
|
4782
|
-
return rebrandCents(toNonNegativeCents(raw));
|
|
4783
|
-
}
|
|
4784
|
-
function money(amountCents, currency) {
|
|
4785
|
-
return {
|
|
4786
|
-
amountCents: toNonNegativeCents(amountCents),
|
|
4787
|
-
currency
|
|
4788
|
-
};
|
|
4789
|
-
}
|
|
4790
|
-
function parseLineSettlementCents(lineId, raw, field) {
|
|
4791
|
-
const parsed = parseNonNegativeCents(raw);
|
|
4792
|
-
if (!parsed.ok) {
|
|
4793
|
-
return err({
|
|
4794
|
-
_tag: "invalid_line_money",
|
|
4795
|
-
lineId,
|
|
4796
|
-
field,
|
|
4797
|
-
message: `Line ${lineId} ${field} must be a non-negative whole number of cents`
|
|
4798
|
-
});
|
|
4799
|
-
}
|
|
4800
|
-
return parsed;
|
|
4801
|
-
}
|
|
4802
|
-
function buildLineSettlementBreakdown(options) {
|
|
4803
|
-
const subtotalResult = parseLineSettlementCents(options.lineId, options.subtotalCents, "subtotalCents");
|
|
4804
|
-
if (!subtotalResult.ok) return subtotalResult;
|
|
4805
|
-
const discountResult = parseLineSettlementCents(options.lineId, options.discountCents, "discountCents");
|
|
4806
|
-
if (!discountResult.ok) return discountResult;
|
|
4807
|
-
const creditAppliedResult = parseLineSettlementCents(options.lineId, options.creditAppliedCents, "creditAppliedCents");
|
|
4808
|
-
if (!creditAppliedResult.ok) return creditAppliedResult;
|
|
4809
|
-
const stripeChargeResult = parseLineSettlementCents(options.lineId, options.stripeChargeCents, "stripeChargeCents");
|
|
4810
|
-
if (!stripeChargeResult.ok) return stripeChargeResult;
|
|
4811
|
-
const subtotalCents = rebrandCents(subtotalResult.value);
|
|
4812
|
-
const discountCents = rebrandCents(discountResult.value);
|
|
4813
|
-
const creditAppliedCents = rebrandCents(creditAppliedResult.value);
|
|
4814
|
-
const stripeChargeCents = rebrandCents(stripeChargeResult.value);
|
|
4815
|
-
const expectedStripeCharge = subtotalCents - discountCents - creditAppliedCents;
|
|
4816
|
-
if (expectedStripeCharge < 0) {
|
|
4817
|
-
return err({
|
|
4818
|
-
_tag: "inconsistent_line_totals",
|
|
4819
|
-
lineId: options.lineId,
|
|
4820
|
-
message: `Settlement invariant failed for line ${options.lineId}: reductions exceed subtotal`
|
|
4821
|
-
});
|
|
4822
|
-
}
|
|
4823
|
-
if (stripeChargeCents !== expectedStripeCharge) {
|
|
4824
|
-
return err({
|
|
4825
|
-
_tag: "inconsistent_line_totals",
|
|
4826
|
-
lineId: options.lineId,
|
|
4827
|
-
message: `Settlement invariant failed for line ${options.lineId}: expected stripe charge ${expectedStripeCharge}, got ${stripeChargeCents}`
|
|
4828
|
-
});
|
|
4829
|
-
}
|
|
4830
|
-
return ok({
|
|
4831
|
-
subtotalCents,
|
|
4832
|
-
discountCents,
|
|
4833
|
-
creditAppliedCents,
|
|
4834
|
-
stripeChargeCents
|
|
4835
|
-
});
|
|
4836
|
-
}
|
|
4837
|
-
function buildRefundableLineSettlement(options) {
|
|
4838
|
-
const line = buildLineSettlementBreakdown(options);
|
|
4839
|
-
if (!line.ok) {
|
|
4840
|
-
return line;
|
|
4841
|
-
}
|
|
4842
|
-
const alreadyRefundedResult = parseLineSettlementCents(options.lineId, options.alreadyRefundedCents, "alreadyRefundedCents");
|
|
4843
|
-
if (!alreadyRefundedResult.ok) return alreadyRefundedResult;
|
|
4844
|
-
const refundableTotalCents = toRefundableTotalCents(line.value.creditAppliedCents + line.value.stripeChargeCents);
|
|
4845
|
-
const alreadyRefundedCents = rebrandCents(alreadyRefundedResult.value);
|
|
4846
|
-
if (alreadyRefundedCents > refundableTotalCents) {
|
|
4847
|
-
return err({
|
|
4848
|
-
_tag: "refunded_exceeds_refundable_total",
|
|
4849
|
-
lineId: options.lineId,
|
|
4850
|
-
message: `Order item ${options.lineId} refunded amount exceeds refundable total`
|
|
4851
|
-
});
|
|
4852
|
-
}
|
|
4853
|
-
return ok({
|
|
4854
|
-
line: line.value,
|
|
4855
|
-
refundableTotalCents,
|
|
4856
|
-
alreadyRefundedCents
|
|
4857
|
-
});
|
|
4858
|
-
}
|
|
4859
|
-
/**
|
|
4860
|
-
* Cash actually collected against one order line, summed from its payment
|
|
4861
|
-
* receipt allocations. Shared so every refundable-remainder caller measures
|
|
4862
|
-
* funding the same way.
|
|
4863
|
-
*/
|
|
4864
|
-
function orderItemCashFundedCents(allocations, orderItemId) {
|
|
4865
|
-
let total = 0;
|
|
4866
|
-
for (const allocation of allocations) {
|
|
4867
|
-
if (allocation.orderItemId === orderItemId) {
|
|
4868
|
-
total += allocation.amountCents;
|
|
4869
|
-
}
|
|
4870
|
-
}
|
|
4871
|
-
return total;
|
|
4872
|
-
}
|
|
4873
|
-
/**
|
|
4874
|
-
* The single authority on how much of an order line is still refundable.
|
|
4875
|
-
*
|
|
4876
|
-
* Every surface that shows or enforces a refundable remainder MUST go through
|
|
4877
|
-
* this function. Computing it from the line's net total instead of its actual
|
|
4878
|
-
* funding overstates the remainder on partially collected orders, which used to
|
|
4879
|
-
* let the dashboard offer a refund the runtime then refused.
|
|
4880
|
-
*/
|
|
4881
|
-
function orderItemRefundableRemainingCents(funding) {
|
|
4882
|
-
return toNonNegativeCents(funding.cashFundedCents + funding.creditAppliedCents - funding.refundedCents);
|
|
4883
|
-
}
|
|
4884
|
-
function refundableRemainingCents(settlement) {
|
|
4885
|
-
return orderItemRefundableRemainingCents({
|
|
4886
|
-
cashFundedCents: settlement.refundableTotalCents,
|
|
4887
|
-
creditAppliedCents: 0,
|
|
4888
|
-
refundedCents: settlement.alreadyRefundedCents
|
|
4889
|
-
});
|
|
4890
|
-
}
|
|
4891
|
-
function ensureSingleCurrency(lines) {
|
|
4892
|
-
if (lines.length === 0) {
|
|
4893
|
-
return {
|
|
4894
|
-
ok: false,
|
|
4895
|
-
reason: "empty_cart",
|
|
4896
|
-
currencies: []
|
|
4897
|
-
};
|
|
4898
|
-
}
|
|
4899
|
-
const uniqueCurrencies = Array.from(new Set(lines.map((line) => line.currency.trim().toUpperCase()))).sort();
|
|
4900
|
-
if (uniqueCurrencies.length !== 1) {
|
|
4901
|
-
return {
|
|
4902
|
-
ok: false,
|
|
4903
|
-
reason: "mixed_currency",
|
|
4904
|
-
currencies: uniqueCurrencies
|
|
4905
|
-
};
|
|
4906
|
-
}
|
|
4907
|
-
try {
|
|
4908
|
-
return {
|
|
4909
|
-
ok: true,
|
|
4910
|
-
currency: normalizeCurrencyCode(uniqueCurrencies[0] ?? "")
|
|
4911
|
-
};
|
|
4912
|
-
} catch {
|
|
4913
|
-
return {
|
|
4914
|
-
ok: false,
|
|
4915
|
-
reason: "invalid_currency",
|
|
4916
|
-
currencies: uniqueCurrencies
|
|
4917
|
-
};
|
|
4918
|
-
}
|
|
4919
|
-
}
|
|
4920
|
-
function allocateReductionCents(inputs, requestedCents) {
|
|
4921
|
-
const sanitizedInputs = inputs.map((input) => ({
|
|
4922
|
-
lineId: input.lineId,
|
|
4923
|
-
basisCents: toNonNegativeCents(input.basisCents),
|
|
4924
|
-
maxReducibleCents: toNonNegativeCents(input.maxReducibleCents)
|
|
4925
|
-
}));
|
|
4926
|
-
const totalReducibleCents = sanitizedInputs.reduce((sum, input) => sum + input.maxReducibleCents, 0);
|
|
4927
|
-
const targetCents = Math.max(0, Math.min(Math.trunc(requestedCents), totalReducibleCents));
|
|
4928
|
-
const allocations = sanitizedInputs.map((input) => ({
|
|
4929
|
-
lineId: input.lineId,
|
|
4930
|
-
amountCents: toNonNegativeCents(0)
|
|
4931
|
-
}));
|
|
4932
|
-
if (targetCents === 0 || sanitizedInputs.length === 0) {
|
|
4933
|
-
return {
|
|
4934
|
-
requestedCents: toNonNegativeCents(requestedCents),
|
|
4935
|
-
appliedCents: toNonNegativeCents(0),
|
|
4936
|
-
allocations
|
|
4937
|
-
};
|
|
4938
|
-
}
|
|
4939
|
-
const remainingCaps = sanitizedInputs.map((input) => input.maxReducibleCents);
|
|
4940
|
-
let remainingCents = targetCents;
|
|
4941
|
-
while (remainingCents > 0) {
|
|
4942
|
-
const eligibleIndexes = sanitizedInputs.map((input, index) => ({
|
|
4943
|
-
input,
|
|
4944
|
-
index
|
|
4945
|
-
})).filter(({ input, index }) => input.basisCents > 0 && (remainingCaps[index] ?? 0) > 0);
|
|
4946
|
-
if (eligibleIndexes.length === 0) break;
|
|
4947
|
-
const eligibleBasis = eligibleIndexes.reduce((sum, { input }) => sum + input.basisCents, 0);
|
|
4948
|
-
if (eligibleBasis <= 0) break;
|
|
4949
|
-
const roundCandidates = eligibleIndexes.map(({ input, index }) => {
|
|
4950
|
-
const exactShare = input.basisCents / eligibleBasis * remainingCents;
|
|
4951
|
-
const floorShare = Math.min(Math.floor(exactShare), remainingCaps[index] ?? 0);
|
|
4952
|
-
const remainder = exactShare - floorShare;
|
|
4953
|
-
return {
|
|
4954
|
-
index,
|
|
4955
|
-
floorShare,
|
|
4956
|
-
remainder
|
|
4957
|
-
};
|
|
4958
|
-
});
|
|
4959
|
-
let assignedThisRound = 0;
|
|
4960
|
-
for (const candidate of roundCandidates) {
|
|
4961
|
-
if (candidate.floorShare <= 0) continue;
|
|
4962
|
-
const allocation = allocations[candidate.index];
|
|
4963
|
-
if (!allocation) continue;
|
|
4964
|
-
allocation.amountCents = toNonNegativeCents(allocation.amountCents + candidate.floorShare);
|
|
4965
|
-
remainingCaps[candidate.index] = toNonNegativeCents((remainingCaps[candidate.index] ?? 0) - candidate.floorShare);
|
|
4966
|
-
assignedThisRound += candidate.floorShare;
|
|
4967
|
-
}
|
|
4968
|
-
remainingCents -= assignedThisRound;
|
|
4969
|
-
if (remainingCents <= 0) break;
|
|
4970
|
-
const remainderCandidates = roundCandidates.filter((candidate) => (remainingCaps[candidate.index] ?? 0) > 0).sort((a, b) => {
|
|
4971
|
-
if (b.remainder !== a.remainder) return b.remainder - a.remainder;
|
|
4972
|
-
return a.index - b.index;
|
|
4973
|
-
});
|
|
4974
|
-
if (remainderCandidates.length === 0) break;
|
|
4975
|
-
let remainderAssigned = 0;
|
|
4976
|
-
for (const candidate of remainderCandidates) {
|
|
4977
|
-
if (remainingCents <= 0) break;
|
|
4978
|
-
if ((remainingCaps[candidate.index] ?? 0) <= 0) continue;
|
|
4979
|
-
const allocation = allocations[candidate.index];
|
|
4980
|
-
if (!allocation) continue;
|
|
4981
|
-
allocation.amountCents = toNonNegativeCents(allocation.amountCents + 1);
|
|
4982
|
-
remainingCaps[candidate.index] = toNonNegativeCents((remainingCaps[candidate.index] ?? 0) - 1);
|
|
4983
|
-
remainingCents -= 1;
|
|
4984
|
-
remainderAssigned += 1;
|
|
4985
|
-
}
|
|
4986
|
-
if (assignedThisRound === 0 && remainderAssigned === 0) {
|
|
4987
|
-
break;
|
|
4988
|
-
}
|
|
4989
|
-
}
|
|
4990
|
-
const appliedCents = allocations.reduce((sum, allocation) => sum + allocation.amountCents, 0);
|
|
4991
|
-
return {
|
|
4992
|
-
requestedCents: toNonNegativeCents(requestedCents),
|
|
4993
|
-
appliedCents: toNonNegativeCents(appliedCents),
|
|
4994
|
-
allocations
|
|
4995
|
-
};
|
|
4996
|
-
}
|
|
4997
|
-
function assertSettledOrderLineInvariants(lines) {
|
|
4998
|
-
for (const line of lines) {
|
|
4999
|
-
if (line.discountCents < 0 || line.creditCents < 0 || line.netTotalCents < 0) {
|
|
5000
|
-
throw new Error(`Negative settlement values are not allowed for line ${line.lineId}`);
|
|
5001
|
-
}
|
|
5002
|
-
const expectedNet = line.subtotalCents - line.discountCents - line.creditCents;
|
|
5003
|
-
if (line.netTotalCents !== expectedNet) {
|
|
5004
|
-
throw new Error(`Settlement invariant failed for line ${line.lineId}: expected ${expectedNet}, got ${line.netTotalCents}`);
|
|
5005
|
-
}
|
|
5006
|
-
}
|
|
5007
|
-
}
|
|
5008
|
-
|
|
5009
5190
|
//#endregion
|
|
5010
5191
|
//#region ../commerce/src/purchase/result.ts
|
|
5011
5192
|
function traverseResult(results) {
|
|
@@ -5155,7 +5336,7 @@ function planCheckoutStripeSessionMetadata(options) {
|
|
|
5155
5336
|
metadata.discount_code_id = options.discount.discountCodeId;
|
|
5156
5337
|
metadata.discount_code = options.discount.discountCode;
|
|
5157
5338
|
metadata.discount_public_label = options.discount.discountPublicLabel;
|
|
5158
|
-
metadata.discount_code_amount_cents = String(options.
|
|
5339
|
+
metadata.discount_code_amount_cents = String(options.discount.amountDiscountCents);
|
|
5159
5340
|
}
|
|
5160
5341
|
if (options.orderReferences.orderPaymentPlanId) {
|
|
5161
5342
|
metadata.order_payment_plan_id = options.orderReferences.orderPaymentPlanId;
|
|
@@ -5351,7 +5532,31 @@ const SharedDatedOfferingOrderCheckoutSessionMetadataSchema = z.object({
|
|
|
5351
5532
|
...orderCheckoutSessionMetadataBaseShape,
|
|
5352
5533
|
...datedOfferingSharedEngineMetadataShape
|
|
5353
5534
|
});
|
|
5354
|
-
|
|
5535
|
+
/** Several whole-series bookings are owned by one attempt, never a representative hold. */
|
|
5536
|
+
const WholeSeriesSelectionOrderCheckoutSessionMetadataSchema = z.object({
|
|
5537
|
+
...orderCheckoutSessionMetadataBaseShape,
|
|
5538
|
+
order_id: z.string().uuid(),
|
|
5539
|
+
datedOfferingEngineContractVersion: z.literal("shared_v1"),
|
|
5540
|
+
datedOfferingEngineRouteKind: z.literal("shared_whole_series_registration"),
|
|
5541
|
+
customerId: z.string().uuid(),
|
|
5542
|
+
checkout_attempt_id: z.string().uuid(),
|
|
5543
|
+
datedOfferingCapacityHoldId: z.never().optional(),
|
|
5544
|
+
datedOfferingCapacityHoldAuditRef: z.never().optional(),
|
|
5545
|
+
eventSeriesId: z.never().optional()
|
|
5546
|
+
});
|
|
5547
|
+
const OrderCheckoutSessionMetadataSchema = z.union([
|
|
5548
|
+
z.object({
|
|
5549
|
+
...orderCheckoutSessionMetadataBaseShape,
|
|
5550
|
+
...absentDatedOfferingSharedEngineMetadataShape,
|
|
5551
|
+
order_id: z.string().uuid(),
|
|
5552
|
+
checkout_attempt_id: z.string().uuid(),
|
|
5553
|
+
attendee_id: z.never().optional(),
|
|
5554
|
+
occurrence_id: z.never().optional()
|
|
5555
|
+
}),
|
|
5556
|
+
WholeSeriesSelectionOrderCheckoutSessionMetadataSchema,
|
|
5557
|
+
SharedDatedOfferingOrderCheckoutSessionMetadataSchema,
|
|
5558
|
+
LegacyOrderCheckoutSessionMetadataSchema
|
|
5559
|
+
]);
|
|
5355
5560
|
|
|
5356
5561
|
//#endregion
|
|
5357
5562
|
//#region ../commerce/src/purchase/canonicalRefundPlanner.ts
|
|
@@ -5506,8 +5711,8 @@ const settledBalanceSchema = z.strictObject({ kind: z.literal("settled") });
|
|
|
5506
5711
|
const dueBalanceSchema = z.strictObject({
|
|
5507
5712
|
kind: z.literal("due"),
|
|
5508
5713
|
amountCents: z.number().int().positive().transform((value, ctx) => {
|
|
5509
|
-
const cents = parsePositiveCents(value);
|
|
5510
|
-
if (cents.ok) return cents.value;
|
|
5714
|
+
const cents$2 = parsePositiveCents(value);
|
|
5715
|
+
if (cents$2.ok) return cents$2.value;
|
|
5511
5716
|
ctx.addIssue({
|
|
5512
5717
|
code: "custom",
|
|
5513
5718
|
message: "Expected positive whole cents"
|
|
@@ -5645,7 +5850,6 @@ function fallbackOrderItemDisplayName(kind) {
|
|
|
5645
5850
|
|
|
5646
5851
|
//#endregion
|
|
5647
5852
|
//#region ../commerce/src/purchase/orderPaymentState.ts
|
|
5648
|
-
const ZERO_CENTS = toNonNegativeCents(0);
|
|
5649
5853
|
/** Amount arithmetic shared by strict payment evidence and tolerant email snapshots.
|
|
5650
5854
|
* Snapshots historically clamp overcollection to zero; the strict decision below
|
|
5651
5855
|
* checks collectability before using the same calculation.
|
|
@@ -5663,219 +5867,13 @@ function calculateOrderBalanceDueCents(input) {
|
|
|
5663
5867
|
settledCents
|
|
5664
5868
|
})));
|
|
5665
5869
|
}
|
|
5666
|
-
|
|
5667
|
-
if (input.flexibleBalance && input.instalmentPlan) {
|
|
5668
|
-
return err({ kind: "conflicting_payment_terms" });
|
|
5669
|
-
}
|
|
5670
|
-
const isNonMonetary = input.paymentMethod === "free" || input.paymentMethod === "waived" || input.paymentMethod === "pass_redemption" || input.paymentMethod === "membership_access";
|
|
5671
|
-
if (isNonMonetary && (input.flexibleBalance || input.instalmentPlan)) {
|
|
5672
|
-
return err({ kind: "managed_terms_for_non_monetary_order" });
|
|
5673
|
-
}
|
|
5674
|
-
if (input.flexibleBalance) {
|
|
5675
|
-
if (input.flexibleBalance.remainingBalanceCents !== outstandingCents) {
|
|
5676
|
-
return err({
|
|
5677
|
-
kind: "projection_receipt_mismatch",
|
|
5678
|
-
projection: "flexible_balance"
|
|
5679
|
-
});
|
|
5680
|
-
}
|
|
5681
|
-
return ok({
|
|
5682
|
-
kind: "flexible_balance",
|
|
5683
|
-
contractId: input.flexibleBalance.contractId,
|
|
5684
|
-
status: input.flexibleBalance.status,
|
|
5685
|
-
dueAt: input.flexibleBalance.dueAt,
|
|
5686
|
-
upfrontAmountCents: input.flexibleBalance.upfrontAmountCents
|
|
5687
|
-
});
|
|
5688
|
-
}
|
|
5689
|
-
if (input.instalmentPlan) {
|
|
5690
|
-
if (input.instalmentPlan.remainingBalanceCents !== outstandingCents) {
|
|
5691
|
-
return err({
|
|
5692
|
-
kind: "projection_receipt_mismatch",
|
|
5693
|
-
projection: "instalment_plan"
|
|
5694
|
-
});
|
|
5695
|
-
}
|
|
5696
|
-
return ok({
|
|
5697
|
-
kind: "instalment_plan",
|
|
5698
|
-
paymentPlanId: input.instalmentPlan.paymentPlanId,
|
|
5699
|
-
status: input.instalmentPlan.status,
|
|
5700
|
-
nextDueAt: input.instalmentPlan.nextDueAt,
|
|
5701
|
-
nextDueAmountCents: input.instalmentPlan.nextDueAmountCents
|
|
5702
|
-
});
|
|
5703
|
-
}
|
|
5704
|
-
return ok(input.paymentMethod === "manual" ? { kind: "manual" } : { kind: "immediate" });
|
|
5705
|
-
}
|
|
5706
|
-
function deriveOrderPaymentPosition(input) {
|
|
5707
|
-
const balance = calculateOrderBalanceDueCents(input);
|
|
5708
|
-
if (!balance.ok) return balance;
|
|
5709
|
-
if (input.refundedCents > input.paidCents) {
|
|
5710
|
-
return err({ kind: "refunded_exceeds_collected" });
|
|
5711
|
-
}
|
|
5712
|
-
const amounts = {
|
|
5713
|
-
totalCents: input.grandTotalCents,
|
|
5714
|
-
collectedCents: input.paidCents,
|
|
5715
|
-
refundedCents: input.refundedCents,
|
|
5716
|
-
outstandingCents: balance.value
|
|
5717
|
-
};
|
|
5718
|
-
const terms = derivePaymentTerms(input, balance.value);
|
|
5719
|
-
if (!terms.ok) return terms;
|
|
5720
|
-
if (input.status === "cancelled") {
|
|
5721
|
-
return ok({
|
|
5722
|
-
kind: "cancelled",
|
|
5723
|
-
...amounts,
|
|
5724
|
-
outstandingCents: ZERO_CENTS,
|
|
5725
|
-
terms: terms.value
|
|
5726
|
-
});
|
|
5727
|
-
}
|
|
5728
|
-
if (input.status === "refunded") {
|
|
5729
|
-
return ok({
|
|
5730
|
-
kind: "refunded",
|
|
5731
|
-
...amounts,
|
|
5732
|
-
outstandingCents: ZERO_CENTS,
|
|
5733
|
-
terms: terms.value
|
|
5734
|
-
});
|
|
5735
|
-
}
|
|
5736
|
-
if (input.waivedCents > 0) {
|
|
5737
|
-
return ok({
|
|
5738
|
-
kind: "waived",
|
|
5739
|
-
...amounts,
|
|
5740
|
-
waivedCents: input.waivedCents,
|
|
5741
|
-
outstandingCents: ZERO_CENTS,
|
|
5742
|
-
terms: terms.value
|
|
5743
|
-
});
|
|
5744
|
-
}
|
|
5745
|
-
switch (input.paymentMethod) {
|
|
5746
|
-
case "free": return ok({
|
|
5747
|
-
kind: "not_required",
|
|
5748
|
-
reason: "free",
|
|
5749
|
-
...amounts,
|
|
5750
|
-
outstandingCents: ZERO_CENTS
|
|
5751
|
-
});
|
|
5752
|
-
case "waived": return ok({
|
|
5753
|
-
kind: "not_required",
|
|
5754
|
-
reason: "waived",
|
|
5755
|
-
...amounts,
|
|
5756
|
-
outstandingCents: ZERO_CENTS
|
|
5757
|
-
});
|
|
5758
|
-
case "pass_redemption": return ok({
|
|
5759
|
-
kind: "not_required",
|
|
5760
|
-
reason: "pass",
|
|
5761
|
-
...amounts,
|
|
5762
|
-
outstandingCents: ZERO_CENTS
|
|
5763
|
-
});
|
|
5764
|
-
case "membership_access": return ok({
|
|
5765
|
-
kind: "not_required",
|
|
5766
|
-
reason: "membership",
|
|
5767
|
-
...amounts,
|
|
5768
|
-
outstandingCents: ZERO_CENTS
|
|
5769
|
-
});
|
|
5770
|
-
case "stripe":
|
|
5771
|
-
case "store_credit":
|
|
5772
|
-
case "mixed":
|
|
5773
|
-
case "manual": break;
|
|
5774
|
-
default: return assertNever$3(input.paymentMethod);
|
|
5775
|
-
}
|
|
5776
|
-
if (input.status === "failed" || input.hasCollectionFailure) {
|
|
5777
|
-
return ok({
|
|
5778
|
-
kind: "collection_failed",
|
|
5779
|
-
...amounts,
|
|
5780
|
-
terms: terms.value
|
|
5781
|
-
});
|
|
5782
|
-
}
|
|
5783
|
-
if (balance.value === 0) {
|
|
5784
|
-
return ok({
|
|
5785
|
-
kind: "paid",
|
|
5786
|
-
...amounts,
|
|
5787
|
-
outstandingCents: ZERO_CENTS,
|
|
5788
|
-
settledVia: input.paymentMethod,
|
|
5789
|
-
terms: terms.value
|
|
5790
|
-
});
|
|
5791
|
-
}
|
|
5792
|
-
if (input.paidCents > 0) return ok({
|
|
5793
|
-
kind: "partially_paid",
|
|
5794
|
-
...amounts,
|
|
5795
|
-
terms: terms.value
|
|
5796
|
-
});
|
|
5797
|
-
return ok({
|
|
5798
|
-
kind: "unpaid",
|
|
5799
|
-
...amounts,
|
|
5800
|
-
terms: terms.value
|
|
5801
|
-
});
|
|
5802
|
-
}
|
|
5803
|
-
function buildPaymentPresentation(position) {
|
|
5804
|
-
const shared = {
|
|
5805
|
-
collectedCents: position.collectedCents,
|
|
5806
|
-
refundedCents: position.refundedCents,
|
|
5807
|
-
outstandingCents: position.outstandingCents,
|
|
5808
|
-
dueAt: "terms" in position && position.terms.kind === "flexible_balance" ? position.terms.dueAt : null,
|
|
5809
|
-
nextDueAt: "terms" in position && position.terms.kind === "instalment_plan" ? position.terms.nextDueAt : null
|
|
5810
|
-
};
|
|
5811
|
-
switch (position.kind) {
|
|
5812
|
-
case "not_required": return {
|
|
5813
|
-
tone: "neutral",
|
|
5814
|
-
label: "Not required",
|
|
5815
|
-
...shared
|
|
5816
|
-
};
|
|
5817
|
-
case "waived": return {
|
|
5818
|
-
tone: "neutral",
|
|
5819
|
-
label: "Waived",
|
|
5820
|
-
...shared
|
|
5821
|
-
};
|
|
5822
|
-
case "unpaid": return {
|
|
5823
|
-
tone: "warning",
|
|
5824
|
-
label: "Unpaid",
|
|
5825
|
-
...shared
|
|
5826
|
-
};
|
|
5827
|
-
case "partially_paid": return {
|
|
5828
|
-
tone: "warning",
|
|
5829
|
-
label: "Partially paid",
|
|
5830
|
-
...shared
|
|
5831
|
-
};
|
|
5832
|
-
case "paid": return {
|
|
5833
|
-
tone: "positive",
|
|
5834
|
-
label: "Paid",
|
|
5835
|
-
...shared
|
|
5836
|
-
};
|
|
5837
|
-
case "collection_failed": return {
|
|
5838
|
-
tone: "critical",
|
|
5839
|
-
label: "Payment failed",
|
|
5840
|
-
...shared
|
|
5841
|
-
};
|
|
5842
|
-
case "refunded": return {
|
|
5843
|
-
tone: "neutral",
|
|
5844
|
-
label: "Refunded",
|
|
5845
|
-
...shared
|
|
5846
|
-
};
|
|
5847
|
-
case "cancelled": return {
|
|
5848
|
-
tone: "neutral",
|
|
5849
|
-
label: "Cancelled",
|
|
5850
|
-
...shared
|
|
5851
|
-
};
|
|
5852
|
-
default: return assertNever$3(position);
|
|
5853
|
-
}
|
|
5854
|
-
}
|
|
5870
|
+
/** Online rails are presentation/effect choices; SQL has already admitted collection. */
|
|
5855
5871
|
function hasOnlineOrderPaymentPath(input) {
|
|
5856
|
-
|
|
5857
|
-
if (input.position.outstandingCents === 0) return false;
|
|
5858
|
-
switch (input.position.terms.kind) {
|
|
5859
|
-
case "immediate": return input.paymentMethod === "stripe";
|
|
5860
|
-
case "manual": return ["manual", "mixed"].includes(input.paymentMethod);
|
|
5861
|
-
case "flexible_balance": return [
|
|
5862
|
-
"manual",
|
|
5863
|
-
"stripe",
|
|
5864
|
-
"mixed"
|
|
5865
|
-
].includes(input.paymentMethod) && isSettleableFlexibleBalanceContractStatus(input.position.terms.status);
|
|
5866
|
-
case "instalment_plan": return ["stripe", "mixed"].includes(input.paymentMethod) && isSettleableOrderInstalmentPlanStatus(input.position.terms.status);
|
|
5867
|
-
default: return assertNever$3(input.position.terms);
|
|
5868
|
-
}
|
|
5872
|
+
return input.position.admissions.paymentLinkPreparation.kind !== "refused";
|
|
5869
5873
|
}
|
|
5870
|
-
/** Executable outstanding card-payment path. Connection readiness is checked by the effect shell. */
|
|
5871
5874
|
function resolveOnlineOrderCheckoutMode(order) {
|
|
5872
|
-
if (
|
|
5873
|
-
|
|
5874
|
-
position: order.paymentState,
|
|
5875
|
-
paymentMethod: order.paymentMethod
|
|
5876
|
-
})) return null;
|
|
5877
|
-
if (!("terms" in order.paymentState)) return null;
|
|
5878
|
-
switch (order.paymentState.terms.kind) {
|
|
5875
|
+
if (!hasOnlineOrderPaymentPath({ position: order.paymentPosition })) return null;
|
|
5876
|
+
switch (order.paymentPosition.terms.kind) {
|
|
5879
5877
|
case "manual":
|
|
5880
5878
|
case "immediate": return { kind: "immediate" };
|
|
5881
5879
|
case "flexible_balance": return { kind: "flexible_balance" };
|
|
@@ -6058,94 +6056,102 @@ function buildTransferredAttendeeConfirmationEmailPaymentSummary(options) {
|
|
|
6058
6056
|
//#endregion
|
|
6059
6057
|
//#region ../commerce/src/purchase/discountApplication.ts
|
|
6060
6058
|
const CHECKOUT_DISCOUNT_ALLOCATION_RULE_VERSION = "proportional-v1";
|
|
6059
|
+
/** Preserve combination allocations; allocate a code against the remaining line bases. */
|
|
6061
6060
|
function planCheckoutDiscountApplication(input) {
|
|
6062
|
-
if (input.items.length === 0) {
|
|
6061
|
+
if (input.items.length === 0) return err({
|
|
6062
|
+
_tag: "empty_cart",
|
|
6063
|
+
message: "Cart is empty"
|
|
6064
|
+
});
|
|
6065
|
+
if (input.applications.filter((app) => app.kind === "discount_code").length > 1) {
|
|
6063
6066
|
return err({
|
|
6064
|
-
_tag: "
|
|
6065
|
-
message: "
|
|
6067
|
+
_tag: "invalid_discount_amount",
|
|
6068
|
+
message: "A checkout accepts at most one discount code"
|
|
6066
6069
|
});
|
|
6067
6070
|
}
|
|
6068
|
-
const
|
|
6069
|
-
item,
|
|
6070
|
-
subtotalCents: item.subtotalCents
|
|
6071
|
-
}));
|
|
6072
|
-
const subtotalCents = toNonNegativeCents(lines.reduce((sum, line) => sum + line.subtotalCents, 0));
|
|
6073
|
-
if (!input.selectedDiscount) {
|
|
6074
|
-
return ok(buildNoDiscountApplication({
|
|
6075
|
-
currency: input.currency,
|
|
6076
|
-
lines,
|
|
6077
|
-
subtotalCents
|
|
6078
|
-
}));
|
|
6079
|
-
}
|
|
6080
|
-
const selectedDiscount = input.selectedDiscount;
|
|
6081
|
-
const discountAllocation = allocateReductionCents(lines.map((line) => ({
|
|
6082
|
-
lineId: line.item.lineId,
|
|
6083
|
-
basisCents: line.subtotalCents,
|
|
6084
|
-
maxReducibleCents: selectedDiscount.eligibleLineIds.has(line.item.lineId) ? line.subtotalCents : toNonNegativeCents(0)
|
|
6085
|
-
})), selectedDiscount.discount.amountDiscountCents);
|
|
6086
|
-
const discountByLineId = new Map(discountAllocation.allocations.map((allocation) => [allocation.lineId, allocation.amountCents]));
|
|
6087
|
-
const items = lines.map((line) => {
|
|
6088
|
-
const discountCents = discountByLineId.get(line.item.lineId) ?? toNonNegativeCents(0);
|
|
6089
|
-
return {
|
|
6090
|
-
lineId: line.item.lineId,
|
|
6091
|
-
subtotalCents: line.subtotalCents,
|
|
6092
|
-
discountCents,
|
|
6093
|
-
totalAfterDiscountCents: toNonNegativeCents(line.subtotalCents - discountCents),
|
|
6094
|
-
payload: line.item.payload
|
|
6095
|
-
};
|
|
6096
|
-
});
|
|
6097
|
-
return ok({
|
|
6071
|
+
const initial = {
|
|
6098
6072
|
currency: input.currency,
|
|
6099
|
-
items
|
|
6100
|
-
|
|
6101
|
-
discountCents: discountAllocation.appliedCents,
|
|
6102
|
-
totalAfterDiscountCents: toNonNegativeCents(subtotalCents - discountAllocation.appliedCents),
|
|
6103
|
-
discount: selectedDiscount.discount,
|
|
6104
|
-
discountApplication: buildDiscountApplicationSnapshot({
|
|
6105
|
-
lines,
|
|
6106
|
-
selectedDiscount,
|
|
6107
|
-
discountByLineId,
|
|
6108
|
-
appliedCents: discountAllocation.appliedCents,
|
|
6109
|
-
currency: input.currency
|
|
6110
|
-
})
|
|
6111
|
-
});
|
|
6112
|
-
}
|
|
6113
|
-
function buildNoDiscountApplication(options) {
|
|
6114
|
-
return {
|
|
6115
|
-
currency: options.currency,
|
|
6116
|
-
items: options.lines.map((line) => ({
|
|
6117
|
-
lineId: line.item.lineId,
|
|
6118
|
-
subtotalCents: line.subtotalCents,
|
|
6073
|
+
items: input.items.map((item) => ({
|
|
6074
|
+
...item,
|
|
6119
6075
|
discountCents: toNonNegativeCents(0),
|
|
6120
|
-
totalAfterDiscountCents:
|
|
6121
|
-
payload: line.item.payload
|
|
6076
|
+
totalAfterDiscountCents: item.subtotalCents
|
|
6122
6077
|
})),
|
|
6123
|
-
subtotalCents:
|
|
6078
|
+
subtotalCents: toNonNegativeCents(input.items.reduce((sum, item) => sum + item.subtotalCents, 0)),
|
|
6124
6079
|
discountCents: toNonNegativeCents(0),
|
|
6125
|
-
totalAfterDiscountCents:
|
|
6080
|
+
totalAfterDiscountCents: toNonNegativeCents(input.items.reduce((sum, item) => sum + item.subtotalCents, 0)),
|
|
6126
6081
|
discount: null,
|
|
6127
|
-
|
|
6082
|
+
discountApplications: []
|
|
6083
|
+
};
|
|
6084
|
+
return ok(input.applications.reduce(applyReduction, initial));
|
|
6085
|
+
}
|
|
6086
|
+
function reductionIdentity(selected) {
|
|
6087
|
+
return selected.kind === "combination_price" ? {
|
|
6088
|
+
kind: selected.kind,
|
|
6089
|
+
combinationPriceId: selected.combinationPriceId,
|
|
6090
|
+
displayLabel: selected.displayLabel,
|
|
6091
|
+
discountCodeId: null,
|
|
6092
|
+
discountRedemptionId: null,
|
|
6093
|
+
code: null,
|
|
6094
|
+
source: "auto"
|
|
6095
|
+
} : {
|
|
6096
|
+
kind: selected.kind,
|
|
6097
|
+
combinationPriceId: null,
|
|
6098
|
+
discountCodeId: selected.discount.discountCodeId,
|
|
6099
|
+
discountRedemptionId: selected.discount.redemptionId,
|
|
6100
|
+
code: selected.discount.discountCode,
|
|
6101
|
+
displayLabel: selected.discount.discountPublicLabel,
|
|
6102
|
+
source: selected.discount.autoApplied ? "auto" : "manual"
|
|
6128
6103
|
};
|
|
6129
6104
|
}
|
|
6130
|
-
function
|
|
6105
|
+
function reductionAllocation(cart, selected) {
|
|
6106
|
+
if (selected.kind === "combination_price") {
|
|
6107
|
+
return {
|
|
6108
|
+
allocations: selected.allocations,
|
|
6109
|
+
appliedCents: toNonNegativeCents(selected.allocations.reduce((sum, row) => sum + row.amountCents, 0)),
|
|
6110
|
+
eligibleLineIds: new Set(selected.allocations.map((row) => row.lineId))
|
|
6111
|
+
};
|
|
6112
|
+
}
|
|
6113
|
+
const lineIds = selected.allocationLineIds ?? cart.items.map((item) => item.lineId);
|
|
6114
|
+
const order = new Map(lineIds.map((id, index) => [id, index]));
|
|
6115
|
+
const ordered = [...cart.items].sort((a, b) => (order.get(a.lineId) ?? Infinity) - (order.get(b.lineId) ?? Infinity));
|
|
6116
|
+
const allocation = allocateReductionCents(ordered.map((item) => ({
|
|
6117
|
+
lineId: item.lineId,
|
|
6118
|
+
basisCents: item.totalAfterDiscountCents,
|
|
6119
|
+
maxReducibleCents: selected.eligibleLineIds.has(item.lineId) ? item.totalAfterDiscountCents : toNonNegativeCents(0)
|
|
6120
|
+
})), selected.discount.amountDiscountCents);
|
|
6131
6121
|
return {
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6122
|
+
...allocation,
|
|
6123
|
+
eligibleLineIds: selected.eligibleLineIds
|
|
6124
|
+
};
|
|
6125
|
+
}
|
|
6126
|
+
function applyReduction(cart, selected) {
|
|
6127
|
+
const allocation = reductionAllocation(cart, selected);
|
|
6128
|
+
const amounts = new Map(allocation.allocations.map((row) => [row.lineId, row.amountCents]));
|
|
6129
|
+
const snapshot = {
|
|
6130
|
+
...reductionIdentity(selected),
|
|
6131
|
+
currency: cart.currency,
|
|
6132
|
+
totalDiscountCents: allocation.appliedCents,
|
|
6139
6133
|
allocationRuleVersion: CHECKOUT_DISCOUNT_ALLOCATION_RULE_VERSION,
|
|
6140
|
-
items:
|
|
6141
|
-
|
|
6134
|
+
items: cart.items.map((item) => ({
|
|
6135
|
+
lineId: item.lineId,
|
|
6136
|
+
eligible: allocation.eligibleLineIds.has(item.lineId),
|
|
6137
|
+
basisSubtotalCents: allocation.eligibleLineIds.has(item.lineId) ? item.totalAfterDiscountCents : toNonNegativeCents(0),
|
|
6138
|
+
discountCents: amounts.get(item.lineId) ?? toNonNegativeCents(0)
|
|
6139
|
+
}))
|
|
6140
|
+
};
|
|
6141
|
+
return {
|
|
6142
|
+
...cart,
|
|
6143
|
+
items: cart.items.map((item) => {
|
|
6144
|
+
const reduction = amounts.get(item.lineId) ?? 0;
|
|
6142
6145
|
return {
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
discountCents: options.discountByLineId.get(line.item.lineId) ?? toNonNegativeCents(0)
|
|
6146
|
+
...item,
|
|
6147
|
+
discountCents: toNonNegativeCents(item.discountCents + reduction),
|
|
6148
|
+
totalAfterDiscountCents: toNonNegativeCents(item.totalAfterDiscountCents - reduction)
|
|
6147
6149
|
};
|
|
6148
|
-
})
|
|
6150
|
+
}),
|
|
6151
|
+
discountCents: toNonNegativeCents(cart.discountCents + allocation.appliedCents),
|
|
6152
|
+
totalAfterDiscountCents: toNonNegativeCents(cart.totalAfterDiscountCents - allocation.appliedCents),
|
|
6153
|
+
discount: selected.kind === "discount_code" ? selected.discount : cart.discount,
|
|
6154
|
+
discountApplications: [...cart.discountApplications, snapshot]
|
|
6149
6155
|
};
|
|
6150
6156
|
}
|
|
6151
6157
|
|
|
@@ -6170,7 +6176,7 @@ function buildOneTimeCheckoutPlan(options) {
|
|
|
6170
6176
|
totalAfterDiscount: money(options.settledCart.totalAfterDiscountCents, currency),
|
|
6171
6177
|
totalAfterCredits: money(options.settledCart.totalAfterCreditsCents, currency),
|
|
6172
6178
|
discount: options.settledCart.discount,
|
|
6173
|
-
|
|
6179
|
+
discountApplications: options.settledCart.discountApplications
|
|
6174
6180
|
};
|
|
6175
6181
|
const chargeMismatch = findInstalmentChargeMismatch(options.paymentPlan, settlement.totalAfterCredits.amountCents);
|
|
6176
6182
|
if (chargeMismatch) return err(chargeMismatch);
|
|
@@ -6207,7 +6213,7 @@ function materializeSettledCart(plan) {
|
|
|
6207
6213
|
totalAfterCreditsCents: plan.settlement.totalAfterCredits.amountCents,
|
|
6208
6214
|
currency: plan.settlement.currency,
|
|
6209
6215
|
discount: plan.settlement.discount,
|
|
6210
|
-
|
|
6216
|
+
discountApplications: plan.settlement.discountApplications
|
|
6211
6217
|
};
|
|
6212
6218
|
}
|
|
6213
6219
|
function buildOrderDraftPlan(paymentPlan, settlement) {
|
|
@@ -6454,12 +6460,12 @@ function resolveOrderConfirmationPaymentMethodLabel(paymentMethod) {
|
|
|
6454
6460
|
}
|
|
6455
6461
|
return assertNever$3(paymentMethod);
|
|
6456
6462
|
}
|
|
6457
|
-
function resolveOrderConfirmationPaymentSummary(order, settlement, formatCurrencyAmount) {
|
|
6463
|
+
function resolveOrderConfirmationPaymentSummary(order, settlement, formatCurrencyAmount$1) {
|
|
6458
6464
|
switch (order.paymentMethod) {
|
|
6459
|
-
case "stripe": return settlement.collectedCents > 0 ? `${formatCurrencyAmount(settlement.collectedCents, order.currency)} charged to card` : null;
|
|
6460
|
-
case "mixed": return `${formatCurrencyAmount(settlement.collectedCents, order.currency)} charged to card and ${formatCurrencyAmount(order.creditCents, order.currency)} applied from site credit`;
|
|
6461
|
-
case "store_credit": return `${formatCurrencyAmount(order.creditCents, order.currency)} applied from site credit`;
|
|
6462
|
-
case "manual": return settlement.collectedCents > 0 ? "Marked paid manually" : `Payment of ${formatCurrencyAmount(computeOrderReceiptTotalCents(brandOrderReceiptTotalSource(order)), order.currency)} is still due`;
|
|
6465
|
+
case "stripe": return settlement.collectedCents > 0 ? `${formatCurrencyAmount$1(settlement.collectedCents, order.currency)} charged to card` : null;
|
|
6466
|
+
case "mixed": return `${formatCurrencyAmount$1(settlement.collectedCents, order.currency)} charged to card and ${formatCurrencyAmount$1(order.creditCents, order.currency)} applied from site credit`;
|
|
6467
|
+
case "store_credit": return `${formatCurrencyAmount$1(order.creditCents, order.currency)} applied from site credit`;
|
|
6468
|
+
case "manual": return settlement.collectedCents > 0 ? "Marked paid manually" : `Payment of ${formatCurrencyAmount$1(computeOrderReceiptTotalCents(brandOrderReceiptTotalSource(order)), order.currency)} is still due`;
|
|
6463
6469
|
case "pass_redemption": return "Covered by pass redemption";
|
|
6464
6470
|
case "membership_access": return "Covered by membership access";
|
|
6465
6471
|
case "waived": return "Payment was waived for this order";
|
|
@@ -6886,37 +6892,18 @@ function hasArchivedOrderHistorySource(record) {
|
|
|
6886
6892
|
|
|
6887
6893
|
//#endregion
|
|
6888
6894
|
//#region ../commerce/src/purchase/orderInstalmentAdminSettlement.ts
|
|
6889
|
-
const MANUALLY_SETTLEABLE_PLAN_STATUSES = ["active", "payment_failed"];
|
|
6890
|
-
const settleablePlanStatusSet = new Set(MANUALLY_SETTLEABLE_PLAN_STATUSES);
|
|
6891
6895
|
const MANUALLY_SETTLEABLE_INSTALMENT_STATUSES = ["scheduled", "failed"];
|
|
6892
6896
|
const settleableInstalmentStatusSet = new Set(MANUALLY_SETTLEABLE_INSTALMENT_STATUSES);
|
|
6893
|
-
function isManuallySettleablePlanStatus(status) {
|
|
6894
|
-
return settleablePlanStatusSet.has(status);
|
|
6895
|
-
}
|
|
6896
6897
|
function isManuallySettleableInstalmentStatus(status) {
|
|
6897
6898
|
return settleableInstalmentStatusSet.has(status);
|
|
6898
6899
|
}
|
|
6899
6900
|
function listCollectibleRecurringInstalments(instalments) {
|
|
6900
6901
|
return instalments.filter((instalment) => instalment.phaseKind === "scheduled" && isManuallySettleableInstalmentStatus(instalment.status)).sort((left, right) => left.sequence - right.sequence);
|
|
6901
6902
|
}
|
|
6902
|
-
function assertSupportedPlanStatus(paymentPlan) {
|
|
6903
|
-
if (paymentPlan.remainingBalanceCents <= 0 || paymentPlan.status === "completed" || paymentPlan.status === "cancelled_as_paid_early") {
|
|
6904
|
-
return;
|
|
6905
|
-
}
|
|
6906
|
-
if (!isManuallySettleablePlanStatus(paymentPlan.status)) {
|
|
6907
|
-
throw new Error(`Cannot settle instalment plan in status '${paymentPlan.status}'`);
|
|
6908
|
-
}
|
|
6909
|
-
}
|
|
6910
6903
|
function planOrderInstalmentManualPayment(input) {
|
|
6911
6904
|
if (input.paymentPlan.remainingBalanceCents <= 0) {
|
|
6912
6905
|
return { kind: "already_applied" };
|
|
6913
6906
|
}
|
|
6914
|
-
if (!isManuallySettleablePlanStatus(input.paymentPlan.status)) {
|
|
6915
|
-
return {
|
|
6916
|
-
kind: "refused",
|
|
6917
|
-
message: `Cannot settle instalment plan in status '${input.paymentPlan.status}'`
|
|
6918
|
-
};
|
|
6919
|
-
}
|
|
6920
6907
|
const collectibleInstalments = listCollectibleRecurringInstalments(input.instalments);
|
|
6921
6908
|
if (collectibleInstalments.length === 0) {
|
|
6922
6909
|
return {
|
|
@@ -6958,25 +6945,6 @@ function planOrderInstalmentManualPayment(input) {
|
|
|
6958
6945
|
instalmentUpdates: allocation.updates
|
|
6959
6946
|
};
|
|
6960
6947
|
}
|
|
6961
|
-
function planOrderInstalmentWaiver(input) {
|
|
6962
|
-
if (input.paymentPlan.remainingBalanceCents <= 0) {
|
|
6963
|
-
return { kind: "already_applied" };
|
|
6964
|
-
}
|
|
6965
|
-
assertSupportedPlanStatus(input.paymentPlan);
|
|
6966
|
-
const instalmentUpdates = listCollectibleRecurringInstalments(input.instalments).map((instalment) => ({
|
|
6967
|
-
instalmentId: instalment.id,
|
|
6968
|
-
nextStatus: "waived"
|
|
6969
|
-
}));
|
|
6970
|
-
if (instalmentUpdates.length === 0) {
|
|
6971
|
-
throw new Error("No recurring instalments are available to waive");
|
|
6972
|
-
}
|
|
6973
|
-
return {
|
|
6974
|
-
kind: "apply",
|
|
6975
|
-
nextPlanStatus: "completed",
|
|
6976
|
-
nextRemainingBalanceCents: toNonNegativeCents(0),
|
|
6977
|
-
instalmentUpdates
|
|
6978
|
-
};
|
|
6979
|
-
}
|
|
6980
6948
|
|
|
6981
6949
|
//#endregion
|
|
6982
6950
|
//#region ../commerce/src/purchase/orderInstalmentClosure.ts
|
|
@@ -7722,80 +7690,284 @@ function planUnappliedOrderPaymentReceiptAllocations(input) {
|
|
|
7722
7690
|
return attributedCents === input.amountCents ? ok(allocations) : err({ kind: "allocation_invariant_failed" });
|
|
7723
7691
|
}
|
|
7724
7692
|
|
|
7693
|
+
//#endregion
|
|
7694
|
+
//#region ../commerce/src/purchase/orderPaymentPositionDisplay.ts
|
|
7695
|
+
function settlementFlags(position) {
|
|
7696
|
+
const { collectedCents, refundedCents, waivedCents, remainderCents } = position.amounts;
|
|
7697
|
+
return {
|
|
7698
|
+
refunded: collectedCents > 0 && refundedCents === collectedCents,
|
|
7699
|
+
waived: waivedCents > 0 && remainderCents === 0
|
|
7700
|
+
};
|
|
7701
|
+
}
|
|
7702
|
+
/** Legacy customer display/wire mapping. No behavioural admission may consume its labels. */
|
|
7703
|
+
function paymentPositionContractStatus(position) {
|
|
7704
|
+
if (position.lifecycle.kind === "cancelled_non_payment") return "cancelled_due_to_non_payment";
|
|
7705
|
+
if (position.lifecycle.kind === "retired" && position.lifecycle.reason === "staff") return "closed_order_failed";
|
|
7706
|
+
if (settlementFlags(position).refunded) return "refunded";
|
|
7707
|
+
if (position.lifecycle.kind === "retired") return "closed_order_failed";
|
|
7708
|
+
if (settlementFlags(position).waived) return "waived";
|
|
7709
|
+
return contractCollectionStatus(position);
|
|
7710
|
+
}
|
|
7711
|
+
function contractCollectionStatus(position) {
|
|
7712
|
+
if (position.collection.kind === "closed" && position.collection.reason === "settled") return "completed";
|
|
7713
|
+
if (position.collection.kind === "in_progress") return "payment_pending";
|
|
7714
|
+
if (position.collection.kind === "closed" && position.collection.reason === "disputed") return position.deadline.kind === "overdue" ? "overdue" : "active";
|
|
7715
|
+
if (position.collection.kind === "closed" || position.collection.kind === "unresolved") return "closed_order_failed";
|
|
7716
|
+
return position.deadline.kind === "overdue" ? "overdue" : "active";
|
|
7717
|
+
}
|
|
7718
|
+
function paymentPositionDisplayTerms(position) {
|
|
7719
|
+
const terms = position.terms;
|
|
7720
|
+
switch (terms.kind) {
|
|
7721
|
+
case "immediate":
|
|
7722
|
+
case "manual": return terms;
|
|
7723
|
+
case "flexible_balance": return {
|
|
7724
|
+
...terms,
|
|
7725
|
+
dueAt: position.deadline.kind === "none" ? null : position.deadline.dueAt,
|
|
7726
|
+
status: paymentPositionContractStatus(position)
|
|
7727
|
+
};
|
|
7728
|
+
case "instalment_plan": return {
|
|
7729
|
+
kind: "instalment_plan",
|
|
7730
|
+
paymentPlanId: terms.paymentPlanId,
|
|
7731
|
+
status: terms.state.kind,
|
|
7732
|
+
nextDueAt: position.deadline.kind === "none" ? null : position.deadline.dueAt,
|
|
7733
|
+
nextDueAmountCents: terms.nextDueAmountCents
|
|
7734
|
+
};
|
|
7735
|
+
}
|
|
7736
|
+
}
|
|
7737
|
+
/** The old union survives only at presentation and wire boundaries for the stable customer wire. */
|
|
7738
|
+
function paymentPositionForDisplay(position) {
|
|
7739
|
+
const { totalCents, collectedCents, refundedCents, waivedCents, remainderCents } = position.amounts;
|
|
7740
|
+
const amounts = {
|
|
7741
|
+
totalCents,
|
|
7742
|
+
collectedCents,
|
|
7743
|
+
refundedCents,
|
|
7744
|
+
outstandingCents: remainderCents
|
|
7745
|
+
};
|
|
7746
|
+
const terms = paymentPositionDisplayTerms(position);
|
|
7747
|
+
const zero = toNonNegativeCents(0);
|
|
7748
|
+
if (settlementFlags(position).refunded) return {
|
|
7749
|
+
kind: "refunded",
|
|
7750
|
+
...amounts,
|
|
7751
|
+
outstandingCents: zero,
|
|
7752
|
+
terms
|
|
7753
|
+
};
|
|
7754
|
+
const retiredKind = retiredPaymentDisplayKind(position.lifecycle);
|
|
7755
|
+
if (retiredKind) return {
|
|
7756
|
+
kind: retiredKind,
|
|
7757
|
+
...amounts,
|
|
7758
|
+
outstandingCents: zero,
|
|
7759
|
+
terms
|
|
7760
|
+
};
|
|
7761
|
+
if (settlementFlags(position).waived) return {
|
|
7762
|
+
kind: "waived",
|
|
7763
|
+
...amounts,
|
|
7764
|
+
waivedCents,
|
|
7765
|
+
outstandingCents: zero,
|
|
7766
|
+
terms
|
|
7767
|
+
};
|
|
7768
|
+
switch (position.paymentMethod) {
|
|
7769
|
+
case "free": return {
|
|
7770
|
+
kind: "not_required",
|
|
7771
|
+
reason: "free",
|
|
7772
|
+
...amounts,
|
|
7773
|
+
outstandingCents: zero
|
|
7774
|
+
};
|
|
7775
|
+
case "waived": return {
|
|
7776
|
+
kind: "not_required",
|
|
7777
|
+
reason: "waived",
|
|
7778
|
+
...amounts,
|
|
7779
|
+
outstandingCents: zero
|
|
7780
|
+
};
|
|
7781
|
+
case "pass_redemption": return {
|
|
7782
|
+
kind: "not_required",
|
|
7783
|
+
reason: "pass",
|
|
7784
|
+
...amounts,
|
|
7785
|
+
outstandingCents: zero
|
|
7786
|
+
};
|
|
7787
|
+
case "membership_access": return {
|
|
7788
|
+
kind: "not_required",
|
|
7789
|
+
reason: "membership",
|
|
7790
|
+
...amounts,
|
|
7791
|
+
outstandingCents: zero
|
|
7792
|
+
};
|
|
7793
|
+
case "manual":
|
|
7794
|
+
case "mixed":
|
|
7795
|
+
case "store_credit":
|
|
7796
|
+
case "stripe": break;
|
|
7797
|
+
}
|
|
7798
|
+
if (hasFailedDisplayCollection(position)) return {
|
|
7799
|
+
kind: "collection_failed",
|
|
7800
|
+
...amounts,
|
|
7801
|
+
terms
|
|
7802
|
+
};
|
|
7803
|
+
if (remainderCents === 0) return {
|
|
7804
|
+
kind: "paid",
|
|
7805
|
+
...amounts,
|
|
7806
|
+
outstandingCents: zero,
|
|
7807
|
+
settledVia: position.paymentMethod,
|
|
7808
|
+
terms
|
|
7809
|
+
};
|
|
7810
|
+
return {
|
|
7811
|
+
kind: collectedCents > 0 ? "partially_paid" : "unpaid",
|
|
7812
|
+
...amounts,
|
|
7813
|
+
terms
|
|
7814
|
+
};
|
|
7815
|
+
}
|
|
7816
|
+
const RETIRED_PAYMENT_KINDS = {
|
|
7817
|
+
checkout_failed: "collection_failed",
|
|
7818
|
+
abandoned_failed: "collection_failed",
|
|
7819
|
+
dispute_lost: "collection_failed",
|
|
7820
|
+
staff: "cancelled",
|
|
7821
|
+
booking_cancelled: "cancelled",
|
|
7822
|
+
abandoned_cancelled: "cancelled"
|
|
7823
|
+
};
|
|
7824
|
+
function retiredPaymentDisplayKind(lifecycle) {
|
|
7825
|
+
switch (lifecycle.kind) {
|
|
7826
|
+
case "open": return null;
|
|
7827
|
+
case "cancelled_non_payment": return "cancelled";
|
|
7828
|
+
case "retired": return RETIRED_PAYMENT_KINDS[lifecycle.reason];
|
|
7829
|
+
default: return assertNever(lifecycle);
|
|
7830
|
+
}
|
|
7831
|
+
}
|
|
7832
|
+
function hasFailedDisplayCollection(position) {
|
|
7833
|
+
return position.collection.kind === "unresolved" || position.openDispute || position.terms.kind === "instalment_plan" && position.terms.state.kind === "payment_failed" || position.collection.kind === "closed" && position.collection.reason === "checkout_failed";
|
|
7834
|
+
}
|
|
7835
|
+
/** Wire adapter only: amount selection and admission have already been decided in SQL. */
|
|
7836
|
+
function paymentPositionFlexibleEligibility(position) {
|
|
7837
|
+
const verdict = position.admissions.paymentLink;
|
|
7838
|
+
if (verdict.kind === "refused") {
|
|
7839
|
+
switch (verdict.reason) {
|
|
7840
|
+
case "below_card_minimum": return {
|
|
7841
|
+
kind: "unavailable",
|
|
7842
|
+
reason: "below_card_minimum"
|
|
7843
|
+
};
|
|
7844
|
+
case "in_progress": return {
|
|
7845
|
+
kind: "unavailable",
|
|
7846
|
+
reason: "payment_pending"
|
|
7847
|
+
};
|
|
7848
|
+
case "identity":
|
|
7849
|
+
case "amounts":
|
|
7850
|
+
case "conflicting_terms":
|
|
7851
|
+
case "provider_reconciliation":
|
|
7852
|
+
case "missing_instalments": return {
|
|
7853
|
+
kind: "unavailable",
|
|
7854
|
+
reason: "unresolved"
|
|
7855
|
+
};
|
|
7856
|
+
case "refunded": return {
|
|
7857
|
+
kind: "unavailable",
|
|
7858
|
+
reason: "refunded"
|
|
7859
|
+
};
|
|
7860
|
+
case "settled":
|
|
7861
|
+
case "nothing_owed": return {
|
|
7862
|
+
kind: "unavailable",
|
|
7863
|
+
reason: position.amounts.waivedCents > 0 ? "waived" : "already_settled"
|
|
7864
|
+
};
|
|
7865
|
+
case "cancelled_non_payment": return {
|
|
7866
|
+
kind: "unavailable",
|
|
7867
|
+
reason: "cancelled_due_to_non_payment"
|
|
7868
|
+
};
|
|
7869
|
+
case "cancelled":
|
|
7870
|
+
case "disputed":
|
|
7871
|
+
case "not_committed":
|
|
7872
|
+
case "unsupported_payment_method":
|
|
7873
|
+
case "live_terms":
|
|
7874
|
+
case "not_applicable":
|
|
7875
|
+
case "terms_closed":
|
|
7876
|
+
case "partly_cancelled":
|
|
7877
|
+
case "retired":
|
|
7878
|
+
case "retirement_pending":
|
|
7879
|
+
case "recurring_collection_active":
|
|
7880
|
+
case "non_monetary":
|
|
7881
|
+
case "checkout_failed":
|
|
7882
|
+
case "archived": return {
|
|
7883
|
+
kind: "unavailable",
|
|
7884
|
+
reason: "booking_cancelled"
|
|
7885
|
+
};
|
|
7886
|
+
default: return assertNever(verdict.reason);
|
|
7887
|
+
}
|
|
7888
|
+
}
|
|
7889
|
+
if (verdict.kind === "requires_provider_check") return {
|
|
7890
|
+
kind: "unavailable",
|
|
7891
|
+
reason: "payment_pending"
|
|
7892
|
+
};
|
|
7893
|
+
const selection = position.paymentSelection;
|
|
7894
|
+
return selection.kind === "full" ? {
|
|
7895
|
+
kind: "full_balance_only",
|
|
7896
|
+
remainingBalanceCents: selection.maximumCents,
|
|
7897
|
+
reason: selection.reason
|
|
7898
|
+
} : {
|
|
7899
|
+
kind: "eligible",
|
|
7900
|
+
minimumAmountCents: selection.minimumCents,
|
|
7901
|
+
maximumCustomAmountCents: selection.maximumCustomCents,
|
|
7902
|
+
suggestedPayFullAmountCents: selection.maximumCents
|
|
7903
|
+
};
|
|
7904
|
+
}
|
|
7905
|
+
/** The SQL position owns the order filter/badge value; customer wire mappings above retain their separate contract. */
|
|
7906
|
+
function paymentPositionOrderStatus(position) {
|
|
7907
|
+
return position.orderStatus;
|
|
7908
|
+
}
|
|
7909
|
+
|
|
7725
7910
|
//#endregion
|
|
7726
7911
|
//#region ../commerce/src/purchase/orderPaymentLinkPlanning.ts
|
|
7727
7912
|
function buildOrderPaymentAdminProjection(facts) {
|
|
7728
|
-
const
|
|
7729
|
-
|
|
7730
|
-
|
|
7731
|
-
|
|
7732
|
-
paidCents: facts.paidCents,
|
|
7733
|
-
waivedCents: facts.waivedCents,
|
|
7734
|
-
refundedCents: facts.refundedCents,
|
|
7735
|
-
flexibleBalance: facts.flexibleBalance ? {
|
|
7736
|
-
contractId: facts.flexibleBalance.contractId,
|
|
7737
|
-
status: facts.flexibleBalance.status,
|
|
7738
|
-
remainingBalanceCents: facts.flexibleBalance.remainingBalanceCents,
|
|
7739
|
-
dueAt: facts.flexibleBalance.dueAt ?? null,
|
|
7740
|
-
upfrontAmountCents: facts.flexibleBalance.upfrontAmountCents ?? facts.paidCents
|
|
7741
|
-
} : null,
|
|
7742
|
-
instalmentPlan: facts.instalmentPlan ? {
|
|
7743
|
-
paymentPlanId: facts.instalmentPlan.paymentPlanId,
|
|
7744
|
-
status: facts.instalmentPlan.status,
|
|
7745
|
-
remainingBalanceCents: facts.instalmentPlan.remainingBalanceCents,
|
|
7746
|
-
nextDueAt: facts.instalmentPlan.nextDueAt ?? null,
|
|
7747
|
-
nextDueAmountCents: facts.instalmentPlan.nextDueAmountCents ?? null
|
|
7748
|
-
} : null,
|
|
7749
|
-
hasCollectionFailure: facts.instalmentPlan?.status === "payment_failed"
|
|
7750
|
-
});
|
|
7751
|
-
if (!paymentPosition.ok) return paymentPosition;
|
|
7752
|
-
const paymentState = paymentPosition.value;
|
|
7753
|
-
const balanceDueCents = paymentState.outstandingCents;
|
|
7754
|
-
const paymentLinkAvailability = resolvePaymentLinkAvailabilityFromFacts({
|
|
7755
|
-
...facts,
|
|
7913
|
+
const paymentState = paymentPositionForDisplay(facts.paymentPosition);
|
|
7914
|
+
const balanceDueCents = facts.paymentPosition.amounts.remainderCents;
|
|
7915
|
+
const paymentLinkAvailability = resolvePaymentLinkAvailabilityFromFacts(facts);
|
|
7916
|
+
return {
|
|
7756
7917
|
paymentState,
|
|
7757
|
-
balanceDueCents
|
|
7758
|
-
});
|
|
7759
|
-
const paymentReminderAvailability = resolvePaymentReminderAvailabilityFromFacts({
|
|
7918
|
+
balanceDueCents,
|
|
7760
7919
|
paymentLinkAvailability,
|
|
7761
|
-
|
|
7762
|
-
|
|
7763
|
-
|
|
7764
|
-
|
|
7765
|
-
value: {
|
|
7766
|
-
paymentState,
|
|
7767
|
-
balanceDueCents,
|
|
7768
|
-
paymentLinkAvailability,
|
|
7769
|
-
paymentReminderAvailability
|
|
7770
|
-
}
|
|
7920
|
+
paymentReminderAvailability: resolvePaymentReminderAvailabilityFromFacts({
|
|
7921
|
+
paymentLinkAvailability: resolvePaymentLinkAvailabilityFromFacts(facts, facts.paymentPosition.admissions.demand, false),
|
|
7922
|
+
customerEmail: facts.customerEmail
|
|
7923
|
+
})
|
|
7771
7924
|
};
|
|
7772
7925
|
}
|
|
7773
|
-
function resolvePaymentLinkAvailabilityFromFacts(input) {
|
|
7774
|
-
|
|
7775
|
-
|
|
7776
|
-
case "live": break;
|
|
7777
|
-
default: return assertNever$3(input.historySource);
|
|
7778
|
-
}
|
|
7779
|
-
if (input.status !== "pending") {
|
|
7780
|
-
return unavailable("order_not_pending", "Only pending orders can generate a customer payment link.", 422);
|
|
7781
|
-
}
|
|
7782
|
-
if (input.commitState !== "committed") {
|
|
7783
|
-
return unavailable("order_not_committed", "This order cannot generate a customer payment link right now.", 422);
|
|
7784
|
-
}
|
|
7785
|
-
if (input.balanceDueCents <= 0) {
|
|
7786
|
-
return unavailable("no_balance_due", "This order does not have a payable balance.", 422);
|
|
7787
|
-
}
|
|
7788
|
-
if (!resolveOnlineOrderCheckoutMode(input)) {
|
|
7789
|
-
return unavailable("payment_path_unavailable", "This order cannot generate a customer payment link right now.", 422);
|
|
7790
|
-
}
|
|
7926
|
+
function resolvePaymentLinkAvailabilityFromFacts(input, verdict = input.paymentPosition.admissions.paymentLinkPreparation, canCheckProvider = true) {
|
|
7927
|
+
const admission = operationAvailability(verdict, canCheckProvider);
|
|
7928
|
+
if (admission.kind === "unavailable") return admission;
|
|
7791
7929
|
if (!input.stripeConnected) {
|
|
7792
7930
|
return unavailable("stripe_not_connected", "Online payment is not available for this site.", 409);
|
|
7793
7931
|
}
|
|
7794
|
-
if (input.hasLiveCheckoutAttempt) {
|
|
7795
|
-
return unavailable("checkout_in_progress", "An online payment checkout is already in progress for this order.", 409);
|
|
7796
|
-
}
|
|
7797
7932
|
return { kind: "available" };
|
|
7798
7933
|
}
|
|
7934
|
+
function operationAvailability(verdict, canCheckProvider) {
|
|
7935
|
+
switch (verdict.kind) {
|
|
7936
|
+
case "admitted": return { kind: "available" };
|
|
7937
|
+
case "requires_provider_check": return canCheckProvider ? { kind: "available" } : unavailable("checkout_in_progress", "A scheduled payment needs to be checked before requesting another payment.", 409);
|
|
7938
|
+
case "refused": {
|
|
7939
|
+
switch (verdict.reason) {
|
|
7940
|
+
case "in_progress": return unavailable("checkout_in_progress", "An online payment checkout is already in progress for this order.", 409);
|
|
7941
|
+
case "refunded":
|
|
7942
|
+
case "nothing_owed":
|
|
7943
|
+
case "settled": return unavailable("no_balance_due", "This order does not have a payable balance.", 422);
|
|
7944
|
+
case "archived": return unavailable("archived_order", "Archived orders cannot generate customer payment links.", 422);
|
|
7945
|
+
case "below_card_minimum": return unavailable("payment_path_unavailable", "What's left is below the smallest card payment Stripe accepts, so it can't be paid by link. You can record it as paid or waive it.", 422);
|
|
7946
|
+
case "amounts":
|
|
7947
|
+
case "cancelled":
|
|
7948
|
+
case "cancelled_non_payment":
|
|
7949
|
+
case "checkout_failed":
|
|
7950
|
+
case "conflicting_terms":
|
|
7951
|
+
case "disputed":
|
|
7952
|
+
case "identity":
|
|
7953
|
+
case "live_terms":
|
|
7954
|
+
case "missing_instalments":
|
|
7955
|
+
case "non_monetary":
|
|
7956
|
+
case "not_applicable":
|
|
7957
|
+
case "not_committed":
|
|
7958
|
+
case "partly_cancelled":
|
|
7959
|
+
case "provider_reconciliation":
|
|
7960
|
+
case "retired":
|
|
7961
|
+
case "retirement_pending":
|
|
7962
|
+
case "terms_closed":
|
|
7963
|
+
case "unsupported_payment_method":
|
|
7964
|
+
case "recurring_collection_active": return unavailable("payment_path_unavailable", "This order cannot generate a customer payment link right now.", 422);
|
|
7965
|
+
default: return assertNever$3(verdict.reason);
|
|
7966
|
+
}
|
|
7967
|
+
}
|
|
7968
|
+
default: return assertNever$3(verdict);
|
|
7969
|
+
}
|
|
7970
|
+
}
|
|
7799
7971
|
function resolvePaymentReminderAvailabilityFromFacts(input) {
|
|
7800
7972
|
if (input.paymentLinkAvailability.kind === "unavailable") {
|
|
7801
7973
|
return input.paymentLinkAvailability;
|
|
@@ -7825,58 +7997,6 @@ function unavailable(reason, publicMessage, httpStatus) {
|
|
|
7825
7997
|
|
|
7826
7998
|
//#endregion
|
|
7827
7999
|
//#region ../commerce/src/purchase/orderRefundPlanning.ts
|
|
7828
|
-
function planOrderRefund(options) {
|
|
7829
|
-
const paidCents = options.paidCents;
|
|
7830
|
-
const currentRefundedCents = options.currentRefundedCents;
|
|
7831
|
-
if (currentRefundedCents > paidCents) {
|
|
7832
|
-
return err("Current refunded amount exceeds paid amount");
|
|
7833
|
-
}
|
|
7834
|
-
const linesById = new Map();
|
|
7835
|
-
for (const line of options.lines) {
|
|
7836
|
-
if (linesById.has(line.orderItemId)) {
|
|
7837
|
-
return err(`Duplicate refund line input: ${line.orderItemId}`);
|
|
7838
|
-
}
|
|
7839
|
-
linesById.set(line.orderItemId, line);
|
|
7840
|
-
}
|
|
7841
|
-
const plannedLines = [];
|
|
7842
|
-
let requestedTotalCents = 0;
|
|
7843
|
-
let appliedTotalCents = 0;
|
|
7844
|
-
for (const requested of options.requestedLineRefunds) {
|
|
7845
|
-
const line = linesById.get(requested.orderItemId);
|
|
7846
|
-
if (!line) {
|
|
7847
|
-
return err(`Unknown order item for refund planning: ${requested.orderItemId}`);
|
|
7848
|
-
}
|
|
7849
|
-
const netTotalCents = line.netTotalCents;
|
|
7850
|
-
const alreadyRefundedCents = line.alreadyRefundedCents ?? toNonNegativeCents(0);
|
|
7851
|
-
if (alreadyRefundedCents > netTotalCents) {
|
|
7852
|
-
return err(`Refunded amount exceeds line total for ${line.orderItemId}`);
|
|
7853
|
-
}
|
|
7854
|
-
const refundableRemainingCents$1 = orderItemRefundableRemainingCents({
|
|
7855
|
-
cashFundedCents: netTotalCents,
|
|
7856
|
-
creditAppliedCents: 0,
|
|
7857
|
-
refundedCents: alreadyRefundedCents
|
|
7858
|
-
});
|
|
7859
|
-
const requestedCents = requested.amountCents;
|
|
7860
|
-
const appliedCents = toNonNegativeCents(Math.min(requestedCents, refundableRemainingCents$1));
|
|
7861
|
-
requestedTotalCents += requestedCents;
|
|
7862
|
-
appliedTotalCents += appliedCents;
|
|
7863
|
-
plannedLines.push({
|
|
7864
|
-
orderItemId: requested.orderItemId,
|
|
7865
|
-
requestedCents,
|
|
7866
|
-
refundableRemainingCents: refundableRemainingCents$1,
|
|
7867
|
-
appliedCents
|
|
7868
|
-
});
|
|
7869
|
-
}
|
|
7870
|
-
const nextRefundedCents = toNonNegativeCents(currentRefundedCents + appliedTotalCents);
|
|
7871
|
-
const nextStatus = appliedTotalCents <= 0 ? null : nextRefundedCents >= paidCents ? "refunded" : "partially_refunded";
|
|
7872
|
-
return ok({
|
|
7873
|
-
lines: plannedLines,
|
|
7874
|
-
requestedTotalCents: toNonNegativeCents(requestedTotalCents),
|
|
7875
|
-
appliedTotalCents: toNonNegativeCents(appliedTotalCents),
|
|
7876
|
-
nextRefundedCents,
|
|
7877
|
-
nextStatus
|
|
7878
|
-
});
|
|
7879
|
-
}
|
|
7880
8000
|
function planOrderRefundSummaryUpdate(options) {
|
|
7881
8001
|
const paidCents = options.paidCents;
|
|
7882
8002
|
const currentRefundedCents = options.currentRefundedCents;
|
|
@@ -7887,30 +8007,7 @@ function planOrderRefundSummaryUpdate(options) {
|
|
|
7887
8007
|
if (nextRefundedCents < currentRefundedCents) {
|
|
7888
8008
|
return err("Refunded amount cannot decrease");
|
|
7889
8009
|
}
|
|
7890
|
-
|
|
7891
|
-
return ok({
|
|
7892
|
-
refundedCents: nextRefundedCents,
|
|
7893
|
-
nextStatus
|
|
7894
|
-
});
|
|
7895
|
-
}
|
|
7896
|
-
function settleOrderRefundPlan(options) {
|
|
7897
|
-
const actualRefundedCents = options.actualRefundedCents;
|
|
7898
|
-
if (actualRefundedCents > options.planned.appliedTotalCents) {
|
|
7899
|
-
return err("Actual refunded amount exceeds planned refundable amount");
|
|
7900
|
-
}
|
|
7901
|
-
const allocation = allocateReductionCents(options.planned.lines.map((line) => ({
|
|
7902
|
-
lineId: line.orderItemId,
|
|
7903
|
-
basisCents: line.appliedCents,
|
|
7904
|
-
maxReducibleCents: line.appliedCents
|
|
7905
|
-
})), actualRefundedCents);
|
|
7906
|
-
return ok({
|
|
7907
|
-
lines: options.planned.lines.map((line) => ({
|
|
7908
|
-
orderItemId: line.orderItemId,
|
|
7909
|
-
requestedCents: line.requestedCents,
|
|
7910
|
-
appliedCents: allocation.allocations.find((allocationLine) => allocationLine.lineId === line.orderItemId)?.amountCents ?? toNonNegativeCents(0)
|
|
7911
|
-
})),
|
|
7912
|
-
refundedTotalCents: allocation.appliedCents
|
|
7913
|
-
});
|
|
8010
|
+
return ok({ refundedCents: nextRefundedCents });
|
|
7914
8011
|
}
|
|
7915
8012
|
|
|
7916
8013
|
//#endregion
|
|
@@ -8007,80 +8104,6 @@ function fallbackDisplayName(kind) {
|
|
|
8007
8104
|
|
|
8008
8105
|
//#endregion
|
|
8009
8106
|
//#region ../commerce/src/purchase/protectedDepositRefundPolicy.ts
|
|
8010
|
-
function buildProtectedDepositPolicySubjectFromFlexibleBalance(input) {
|
|
8011
|
-
return {
|
|
8012
|
-
kind: "protected_deposit",
|
|
8013
|
-
sourceKind: "flexible_balance",
|
|
8014
|
-
protectedDepositAmountCents: input.upfrontAmountCents,
|
|
8015
|
-
depositRefundability: input.depositRefundability
|
|
8016
|
-
};
|
|
8017
|
-
}
|
|
8018
|
-
function buildProtectedDepositPolicySubjectFromInstalmentPlan(plan) {
|
|
8019
|
-
const protectedDepositAmountCents = getBookingInstalmentProtectedDepositAmountCents(plan);
|
|
8020
|
-
const depositRefundability = getBookingInstalmentDepositRefundability(plan);
|
|
8021
|
-
if (protectedDepositAmountCents == null || depositRefundability == null) {
|
|
8022
|
-
return { kind: "none" };
|
|
8023
|
-
}
|
|
8024
|
-
return {
|
|
8025
|
-
kind: "protected_deposit",
|
|
8026
|
-
sourceKind: "instalment_plan",
|
|
8027
|
-
protectedDepositAmountCents: unsafeAsNonNegativeCents(protectedDepositAmountCents),
|
|
8028
|
-
depositRefundability
|
|
8029
|
-
};
|
|
8030
|
-
}
|
|
8031
|
-
function calculateProtectedDepositRefundExposure(input) {
|
|
8032
|
-
const itemRemainingCents = toNonNegativeCents(input.itemTotalCents - input.itemRefundedCents);
|
|
8033
|
-
const totalRemainingRefundableCents = toNonNegativeCents(Math.min(itemRemainingCents, input.collectedRemainingCents));
|
|
8034
|
-
if (input.subject.kind === "none" || input.subject.depositRefundability === "refundable") {
|
|
8035
|
-
return {
|
|
8036
|
-
subject: input.subject,
|
|
8037
|
-
totalRemainingRefundableCents,
|
|
8038
|
-
policyRefundableCents: totalRemainingRefundableCents,
|
|
8039
|
-
protectedDepositRemainingCents: toNonNegativeCents(0)
|
|
8040
|
-
};
|
|
8041
|
-
}
|
|
8042
|
-
const protectedDepositOriginalCents = toNonNegativeCents(Math.min(input.subject.protectedDepositAmountCents, input.itemTotalCents));
|
|
8043
|
-
const nonDepositOriginalCents = toNonNegativeCents(input.itemTotalCents - protectedDepositOriginalCents);
|
|
8044
|
-
const refundedAgainstProtectedDepositCents = toNonNegativeCents(input.itemRefundedCents - nonDepositOriginalCents);
|
|
8045
|
-
const protectedDepositRemainingByItemCents = toNonNegativeCents(protectedDepositOriginalCents - refundedAgainstProtectedDepositCents);
|
|
8046
|
-
const nonDepositRemainingByItemCents = toNonNegativeCents(itemRemainingCents - protectedDepositRemainingByItemCents);
|
|
8047
|
-
const policyRefundableCents = toNonNegativeCents(Math.min(totalRemainingRefundableCents, nonDepositRemainingByItemCents));
|
|
8048
|
-
return {
|
|
8049
|
-
subject: input.subject,
|
|
8050
|
-
totalRemainingRefundableCents,
|
|
8051
|
-
policyRefundableCents,
|
|
8052
|
-
protectedDepositRemainingCents: toNonNegativeCents(totalRemainingRefundableCents - policyRefundableCents)
|
|
8053
|
-
};
|
|
8054
|
-
}
|
|
8055
|
-
/**
|
|
8056
|
-
* Calculates policy exposure for one receipt allocation.
|
|
8057
|
-
*
|
|
8058
|
-
* A protected deposit is collected by the initial-checkout receipt. Later
|
|
8059
|
-
* paydowns and instalments therefore remain independently refundable even
|
|
8060
|
-
* while the entity still has a non-refundable deposit balance.
|
|
8061
|
-
*/
|
|
8062
|
-
function calculateReceiptProtectedDepositRefundExposure(input) {
|
|
8063
|
-
const totalRemainingRefundableCents = toNonNegativeCents(input.allocatedCents - input.refundedCents);
|
|
8064
|
-
if (input.subject.kind === "none" || input.subject.depositRefundability === "refundable" || input.receiptPurpose !== "initial_checkout") {
|
|
8065
|
-
return {
|
|
8066
|
-
subject: input.subject,
|
|
8067
|
-
totalRemainingRefundableCents,
|
|
8068
|
-
policyRefundableCents: totalRemainingRefundableCents,
|
|
8069
|
-
protectedDepositRemainingCents: toNonNegativeCents(0)
|
|
8070
|
-
};
|
|
8071
|
-
}
|
|
8072
|
-
const protectedDepositOriginalCents = toNonNegativeCents(Math.min(input.subject.protectedDepositAmountCents, input.allocatedCents));
|
|
8073
|
-
const nonDepositOriginalCents = toNonNegativeCents(input.allocatedCents - protectedDepositOriginalCents);
|
|
8074
|
-
const refundedAgainstProtectedDepositCents = toNonNegativeCents(input.refundedCents - nonDepositOriginalCents);
|
|
8075
|
-
const protectedDepositRemainingCents = toNonNegativeCents(protectedDepositOriginalCents - refundedAgainstProtectedDepositCents);
|
|
8076
|
-
const policyRefundableCents = toNonNegativeCents(totalRemainingRefundableCents - protectedDepositRemainingCents);
|
|
8077
|
-
return {
|
|
8078
|
-
subject: input.subject,
|
|
8079
|
-
totalRemainingRefundableCents,
|
|
8080
|
-
policyRefundableCents,
|
|
8081
|
-
protectedDepositRemainingCents
|
|
8082
|
-
};
|
|
8083
|
-
}
|
|
8084
8107
|
function planAdminProtectedDepositRefund(input) {
|
|
8085
8108
|
const requestedAmountCents = resolveRequestedAmountCents(input.request, { fullRemainingCents: input.allowProtectedDepositOverride ? input.exposure.totalRemainingRefundableCents : input.exposure.policyRefundableCents });
|
|
8086
8109
|
if (input.exposure.totalRemainingRefundableCents <= 0 || requestedAmountCents <= 0) {
|
|
@@ -8271,65 +8294,6 @@ function planShopRefund(order, shopItems) {
|
|
|
8271
8294
|
};
|
|
8272
8295
|
}
|
|
8273
8296
|
|
|
8274
|
-
//#endregion
|
|
8275
|
-
//#region ../commerce/src/purchase/stripeMinimumCharge.ts
|
|
8276
|
-
const STRIPE_MINIMUM_CHARGE_CENTS_BY_CURRENCY = {
|
|
8277
|
-
GBP: 30,
|
|
8278
|
-
USD: 50,
|
|
8279
|
-
EUR: 50,
|
|
8280
|
-
AED: 200,
|
|
8281
|
-
AUD: 50,
|
|
8282
|
-
BGN: 100,
|
|
8283
|
-
BRL: 50,
|
|
8284
|
-
CAD: 50,
|
|
8285
|
-
CHF: 50,
|
|
8286
|
-
CZK: 1500,
|
|
8287
|
-
DKK: 250,
|
|
8288
|
-
HKD: 400,
|
|
8289
|
-
HUF: 17500,
|
|
8290
|
-
JPY: 50,
|
|
8291
|
-
MXN: 1e3,
|
|
8292
|
-
MYR: 200,
|
|
8293
|
-
NOK: 300,
|
|
8294
|
-
NZD: 50,
|
|
8295
|
-
PLN: 200,
|
|
8296
|
-
RON: 200,
|
|
8297
|
-
SEK: 300,
|
|
8298
|
-
SGD: 50,
|
|
8299
|
-
THB: 1e3
|
|
8300
|
-
};
|
|
8301
|
-
function isStripeMinimumChargeCurrency(currency) {
|
|
8302
|
-
return currency in STRIPE_MINIMUM_CHARGE_CENTS_BY_CURRENCY;
|
|
8303
|
-
}
|
|
8304
|
-
function getStripeMinimumChargeRequirement(rawCurrency) {
|
|
8305
|
-
let currency;
|
|
8306
|
-
try {
|
|
8307
|
-
currency = normalizeCurrencyCode(rawCurrency);
|
|
8308
|
-
} catch {
|
|
8309
|
-
return null;
|
|
8310
|
-
}
|
|
8311
|
-
const currencyKey = currency;
|
|
8312
|
-
if (!isStripeMinimumChargeCurrency(currencyKey)) {
|
|
8313
|
-
return null;
|
|
8314
|
-
}
|
|
8315
|
-
return {
|
|
8316
|
-
currency,
|
|
8317
|
-
minimumAmountCents: STRIPE_MINIMUM_CHARGE_CENTS_BY_CURRENCY[currencyKey]
|
|
8318
|
-
};
|
|
8319
|
-
}
|
|
8320
|
-
function isStripeChargeBelowMinimum(options) {
|
|
8321
|
-
const requirement = getStripeMinimumChargeRequirement(options.currency);
|
|
8322
|
-
return Boolean(requirement && options.amountCents > 0 && options.amountCents < requirement.minimumAmountCents);
|
|
8323
|
-
}
|
|
8324
|
-
/**
|
|
8325
|
-
* The smallest deposit a plan that starts with one may ask for: the card
|
|
8326
|
-
* minimum for the currency, or any positive amount for a currency Stripe has
|
|
8327
|
-
* no minimum on record for.
|
|
8328
|
-
*/
|
|
8329
|
-
function getInstalmentDepositMinimumCents(currency) {
|
|
8330
|
-
return getStripeMinimumChargeRequirement(currency)?.minimumAmountCents ?? 1;
|
|
8331
|
-
}
|
|
8332
|
-
|
|
8333
8297
|
//#endregion
|
|
8334
8298
|
//#region ../commerce/src/purchase/stripeCheckoutReturnUrl.ts
|
|
8335
8299
|
const STRIPE_CHECKOUT_SESSION_ID_PLACEHOLDER = "{CHECKOUT_SESSION_ID}";
|
|
@@ -8368,39 +8332,6 @@ const checkoutCopy = {
|
|
|
8368
8332
|
|
|
8369
8333
|
//#endregion
|
|
8370
8334
|
//#region ../commerce/src/purchase/stateTransitions.ts
|
|
8371
|
-
function advanceOrderStatus(from, event) {
|
|
8372
|
-
switch (event) {
|
|
8373
|
-
case "checkout_failed":
|
|
8374
|
-
if (from === "pending") return ok("failed");
|
|
8375
|
-
break;
|
|
8376
|
-
case "stripe_payment_completed":
|
|
8377
|
-
if (from === "pending") return ok("paid");
|
|
8378
|
-
break;
|
|
8379
|
-
case "cancel":
|
|
8380
|
-
if (from === "pending" || from === "failed") return ok("cancelled");
|
|
8381
|
-
if (from === "paid" || from === "partially_refunded" || from === "refunded") return ok("cancelled");
|
|
8382
|
-
break;
|
|
8383
|
-
case "partial_refund":
|
|
8384
|
-
if (from === "paid" || from === "partially_refunded") return ok("partially_refunded");
|
|
8385
|
-
break;
|
|
8386
|
-
case "full_refund":
|
|
8387
|
-
if (from === "paid" || from === "partially_refunded") return ok("refunded");
|
|
8388
|
-
break;
|
|
8389
|
-
}
|
|
8390
|
-
return err(`Illegal order status transition: ${from} -> ${event}`);
|
|
8391
|
-
}
|
|
8392
|
-
function transitionOrderStatusTo(from, to) {
|
|
8393
|
-
if (from === to) return ok(to);
|
|
8394
|
-
switch (to) {
|
|
8395
|
-
case "failed": return advanceOrderStatus(from, "checkout_failed");
|
|
8396
|
-
case "paid": return advanceOrderStatus(from, "stripe_payment_completed");
|
|
8397
|
-
case "cancelled": return advanceOrderStatus(from, "cancel");
|
|
8398
|
-
case "partially_refunded": return advanceOrderStatus(from, "partial_refund");
|
|
8399
|
-
case "refunded": return advanceOrderStatus(from, "full_refund");
|
|
8400
|
-
case "pending": break;
|
|
8401
|
-
}
|
|
8402
|
-
return err(`Illegal order status transition: ${from} -> ${to}`);
|
|
8403
|
-
}
|
|
8404
8335
|
function classifyCheckoutCompensationDecision(input) {
|
|
8405
8336
|
const sideEffects = checkoutCommitSideEffects(input.progress);
|
|
8406
8337
|
if (input.paymentRail === "bypass") {
|
|
@@ -8500,6 +8431,11 @@ const eventRegistrationErrors = {
|
|
|
8500
8431
|
message: "Booking is currently closed for this event. Please contact the organiser if you’d like to find out more.",
|
|
8501
8432
|
action: "none"
|
|
8502
8433
|
},
|
|
8434
|
+
siteNotTakingBookings: {
|
|
8435
|
+
endsCommand: false,
|
|
8436
|
+
message: "This business isn’t taking online bookings right now. Please contact them if you’d like to book.",
|
|
8437
|
+
action: "none"
|
|
8438
|
+
},
|
|
8503
8439
|
paymentInvestigationRequired: {
|
|
8504
8440
|
endsCommand: false,
|
|
8505
8441
|
message: "We still can’t confirm your payment. Please don’t make another payment. Contact the organiser so they can check your booking.",
|
|
@@ -8594,6 +8530,10 @@ function eventRegistrationErrorEndsCommand(value) {
|
|
|
8594
8530
|
//#region ../commerce/src/purchase/eventCheckoutRecoveryWindow.ts
|
|
8595
8531
|
const EVENT_CHECKOUT_HOLD_DURATION_MS = 35 * 60 * 1e3;
|
|
8596
8532
|
const EVENT_CHECKOUT_RECOVERY_GRACE_MS = 24 * 60 * 60 * 1e3;
|
|
8533
|
+
/** Admission deadlines close new bookings; an admitted payment gets the full hold window. */
|
|
8534
|
+
function eventCheckoutPaymentDeadlineEpoch(deadlineEpoch, nowMs) {
|
|
8535
|
+
return Math.max(deadlineEpoch, Math.floor((nowMs + EVENT_CHECKOUT_HOLD_DURATION_MS) / 1e3));
|
|
8536
|
+
}
|
|
8597
8537
|
function validInstant(value) {
|
|
8598
8538
|
const instant = Date.parse(value);
|
|
8599
8539
|
return Number.isFinite(instant) ? instant : null;
|
|
@@ -8639,6 +8579,942 @@ function checkBrowserStripeKey(publishableKey, livemode) {
|
|
|
8639
8579
|
};
|
|
8640
8580
|
}
|
|
8641
8581
|
|
|
8582
|
+
//#endregion
|
|
8583
|
+
//#region ../commerce/src/purchase/discountCodeApplicability.ts
|
|
8584
|
+
const DISCOUNT_EVENT_SCOPE_MODES = [
|
|
8585
|
+
"all_categories",
|
|
8586
|
+
"categories",
|
|
8587
|
+
"event_offerings"
|
|
8588
|
+
];
|
|
8589
|
+
function discountMinimumTickets(code) {
|
|
8590
|
+
if (!code.eventMinTicketsEnabled) return 1;
|
|
8591
|
+
const minimum = code.eventMinTickets ?? 0;
|
|
8592
|
+
return minimum >= 2 ? minimum : "misconfigured";
|
|
8593
|
+
}
|
|
8594
|
+
function meetsDiscountMinimumTickets(code, ticketsCount) {
|
|
8595
|
+
const minimum = discountMinimumTickets(code);
|
|
8596
|
+
return minimum !== "misconfigured" && ticketsCount >= minimum;
|
|
8597
|
+
}
|
|
8598
|
+
function matchesSelectedScope(mode, ids, id) {
|
|
8599
|
+
switch (mode) {
|
|
8600
|
+
case "all": return true;
|
|
8601
|
+
case "selected": return ids.includes(id);
|
|
8602
|
+
}
|
|
8603
|
+
}
|
|
8604
|
+
function matchesEventScope(mode, scopes, context) {
|
|
8605
|
+
switch (mode) {
|
|
8606
|
+
case "all_categories": return true;
|
|
8607
|
+
case "categories": return context.eventCategoryId !== null && scopes.eventCategoryIds.includes(context.eventCategoryId);
|
|
8608
|
+
case "event_offerings": return scopes.eventOfferingIds.includes(context.eventOfferingId);
|
|
8609
|
+
}
|
|
8610
|
+
}
|
|
8611
|
+
function matchesProductScope(mode, scopes, context) {
|
|
8612
|
+
switch (mode) {
|
|
8613
|
+
case "all": return true;
|
|
8614
|
+
case "categories": return context.productCategoryId !== null && scopes.productCategoryIds.includes(context.productCategoryId);
|
|
8615
|
+
case "selected": return scopes.productIds.includes(context.productId);
|
|
8616
|
+
}
|
|
8617
|
+
}
|
|
8618
|
+
/** All applicability rules, evaluated against loaded facts and an explicit clock. */
|
|
8619
|
+
function discountCodeAppliesTo(code, scopes, context, now) {
|
|
8620
|
+
const enabled = {
|
|
8621
|
+
event: code.appliesToEvents,
|
|
8622
|
+
whole_series: code.appliesToEvents,
|
|
8623
|
+
appointment: code.appliesToAppointments,
|
|
8624
|
+
pass: code.appliesToPasses,
|
|
8625
|
+
membership: code.appliesToMemberships,
|
|
8626
|
+
product: code.appliesToProducts
|
|
8627
|
+
}[context.type];
|
|
8628
|
+
return enabled && code.isActive && isWithinDiscountWindow(code, now) && matchesDiscountContext(code, scopes, context);
|
|
8629
|
+
}
|
|
8630
|
+
function isWithinDiscountWindow(code, now) {
|
|
8631
|
+
return !(code.startsAt !== null && code.startsAt > now) && !(code.endsAt !== null && code.endsAt < now);
|
|
8632
|
+
}
|
|
8633
|
+
function matchesDiscountContext(code, scopes, context) {
|
|
8634
|
+
switch (context.type) {
|
|
8635
|
+
case "event":
|
|
8636
|
+
case "whole_series": return meetsDiscountMinimumTickets(code, context.ticketsCount ?? 1) && matchesEventScope(code.eventsScopeMode, scopes, context);
|
|
8637
|
+
case "appointment": return matchesSelectedScope(code.appointmentsScopeMode, scopes.appointmentServiceIds, context.serviceId);
|
|
8638
|
+
case "pass": return matchesSelectedScope(code.passesScopeMode, scopes.passIds, context.passId);
|
|
8639
|
+
case "membership": return matchesSelectedScope(code.membershipsScopeMode, scopes.membershipIds, context.membershipId);
|
|
8640
|
+
case "product": return matchesProductScope(code.productsScopeMode, scopes, context);
|
|
8641
|
+
}
|
|
8642
|
+
}
|
|
8643
|
+
|
|
8644
|
+
//#endregion
|
|
8645
|
+
//#region ../commerce/src/purchase/combinationPricing.ts
|
|
8646
|
+
const cents$1 = toNonNegativeCents;
|
|
8647
|
+
const compareText = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
8648
|
+
const compareLine = (a, b) => compareText(a.date, b.date) || compareText(a.lineId, b.lineId);
|
|
8649
|
+
const compareOffer = (a, b) => a.sortOrder - b.sortOrder || compareText(a.id, b.id);
|
|
8650
|
+
const sumPrices = (lines) => lines.reduce((sum, line) => sum + line.unitPriceCents, 0);
|
|
8651
|
+
function application(offer, lines, places) {
|
|
8652
|
+
const ordered = [...lines].sort(compareLine);
|
|
8653
|
+
const savingCents = cents$1((sumPrices(lines) - offer.priceCents) * places);
|
|
8654
|
+
const allocation = allocateReductionCents(ordered.map((line) => ({
|
|
8655
|
+
lineId: line.lineId,
|
|
8656
|
+
basisCents: cents$1(line.unitPriceCents * places),
|
|
8657
|
+
maxReducibleCents: cents$1(line.unitPriceCents * places)
|
|
8658
|
+
})), savingCents);
|
|
8659
|
+
return {
|
|
8660
|
+
offer,
|
|
8661
|
+
lines: ordered,
|
|
8662
|
+
totalCents: cents$1(offer.priceCents * places),
|
|
8663
|
+
savingCents,
|
|
8664
|
+
allocations: allocation.allocations.map((row, index) => ({
|
|
8665
|
+
lineId: row.lineId,
|
|
8666
|
+
reductionCents: row.amountCents,
|
|
8667
|
+
totalCents: cents$1((ordered[index]?.unitPriceCents ?? 0) * places - row.amountCents)
|
|
8668
|
+
}))
|
|
8669
|
+
};
|
|
8670
|
+
}
|
|
8671
|
+
const compareApplication = (a, b) => compareOffer(a.offer, b.offer) || compareText(JSON.stringify(a.lines.map((line) => [line.date, line.lineId])), JSON.stringify(b.lines.map((line) => [line.date, line.lineId])));
|
|
8672
|
+
const saving = (apps) => apps.reduce((sum, app) => sum + app.savingCents, 0);
|
|
8673
|
+
function prefer(a, b) {
|
|
8674
|
+
const money$1 = saving(b) - saving(a);
|
|
8675
|
+
if (money$1 !== 0) return money$1 < 0 ? a : b;
|
|
8676
|
+
if (a.length !== b.length) return a.length < b.length ? a : b;
|
|
8677
|
+
const left = [...a].sort(compareApplication);
|
|
8678
|
+
const right = [...b].sort(compareApplication);
|
|
8679
|
+
const offerDifference = left.map((app, index) => right[index] ? compareOffer(app.offer, right[index].offer) : 0).find((value) => value !== 0) ?? 0;
|
|
8680
|
+
if (offerDifference !== 0) return offerDifference < 0 ? left : right;
|
|
8681
|
+
const difference = left.map((app, index) => right[index] ? compareApplication(app, right[index]) : 0).find((value) => value !== 0) ?? 0;
|
|
8682
|
+
return difference <= 0 ? left : right;
|
|
8683
|
+
}
|
|
8684
|
+
function cheaperSelection(a, b) {
|
|
8685
|
+
if (!a) return b;
|
|
8686
|
+
if (a.priceCents !== b.priceCents) return a.priceCents < b.priceCents ? a : b;
|
|
8687
|
+
if (a.offers.length !== b.offers.length) return a.offers.length < b.offers.length ? a : b;
|
|
8688
|
+
const difference = a.offers.map((offer, index) => b.offers[index] ? compareOffer(offer, b.offers[index]) : 0).find((value) => value !== 0) ?? 0;
|
|
8689
|
+
return difference <= 0 ? a : b;
|
|
8690
|
+
}
|
|
8691
|
+
/** Cheapest exact cover of each count, independent of which dates fill it. */
|
|
8692
|
+
function anySelections(count, offers) {
|
|
8693
|
+
const memo = new Map([[0, {
|
|
8694
|
+
offers: [],
|
|
8695
|
+
priceCents: 0
|
|
8696
|
+
}]]);
|
|
8697
|
+
const visit = (size) => {
|
|
8698
|
+
if (memo.has(size)) return memo.get(size) ?? null;
|
|
8699
|
+
const best = offers.reduce((best$1, offer) => {
|
|
8700
|
+
if (offer.itemCount > size) return best$1;
|
|
8701
|
+
const previous = visit(size - offer.itemCount);
|
|
8702
|
+
return previous ? cheaperSelection(best$1, {
|
|
8703
|
+
offers: [...previous.offers, offer].sort(compareOffer),
|
|
8704
|
+
priceCents: previous.priceCents + offer.priceCents
|
|
8705
|
+
}) : best$1;
|
|
8706
|
+
}, null);
|
|
8707
|
+
memo.set(size, best);
|
|
8708
|
+
return best;
|
|
8709
|
+
};
|
|
8710
|
+
return Array.from({ length: count + 1 }, (_, size) => visit(size));
|
|
8711
|
+
}
|
|
8712
|
+
/**
|
|
8713
|
+
* Covering k items always uses the k highest list prices (earliest dates on ties).
|
|
8714
|
+
* Once offer counts are fixed, grouping cannot change the total. A globally best
|
|
8715
|
+
* candidate cannot contain a non-saving group: dropping it would improve the
|
|
8716
|
+
* total or the application-count tie. So canonical date grouping is sufficient.
|
|
8717
|
+
*/
|
|
8718
|
+
function planAny(lines, offers, places) {
|
|
8719
|
+
const ranked = [...lines].sort((a, b) => b.unitPriceCents - a.unitPriceCents || compareLine(a, b));
|
|
8720
|
+
return anySelections(lines.length, offers.filter((offer) => offer.kind === "any")).reduce((best, selected, count) => {
|
|
8721
|
+
if (!selected) return best;
|
|
8722
|
+
const chosen = ranked.slice(0, count).sort(compareLine);
|
|
8723
|
+
const grouped = selected.offers.reduce((state, offer) => {
|
|
8724
|
+
const size = offer.itemCount;
|
|
8725
|
+
const group = chosen.slice(state.offset, state.offset + size);
|
|
8726
|
+
return {
|
|
8727
|
+
offset: state.offset + size,
|
|
8728
|
+
apps: [...state.apps, application(offer, group, places)]
|
|
8729
|
+
};
|
|
8730
|
+
}, {
|
|
8731
|
+
offset: 0,
|
|
8732
|
+
apps: []
|
|
8733
|
+
});
|
|
8734
|
+
return grouped.apps.every((app) => app.savingCents > 0) ? prefer(best, grouped.apps) : best;
|
|
8735
|
+
}, []);
|
|
8736
|
+
}
|
|
8737
|
+
/** Search particular-set subsets; memoised masks collapse different application orders. */
|
|
8738
|
+
function search(input) {
|
|
8739
|
+
const memo = new Map();
|
|
8740
|
+
const visit = (mask) => {
|
|
8741
|
+
const cached = memo.get(mask);
|
|
8742
|
+
if (cached) return cached;
|
|
8743
|
+
const remaining = input.lines.filter((_, index) => (mask & 1 << index) !== 0);
|
|
8744
|
+
const best = input.offers.reduce((best$1, offer) => {
|
|
8745
|
+
if (offer.kind !== "particular") return best$1;
|
|
8746
|
+
const group = remaining.filter((line) => offer.lineIds.includes(line.lineId));
|
|
8747
|
+
if (group.length !== offer.lineIds.length || sumPrices(group) <= offer.priceCents) return best$1;
|
|
8748
|
+
const used = input.lines.reduce((bits, line, index) => group.includes(line) ? bits | 1 << index : bits, 0);
|
|
8749
|
+
return prefer(best$1, [application(offer, group, input.places), ...visit(mask ^ used)]);
|
|
8750
|
+
}, planAny(remaining, input.offers, input.places));
|
|
8751
|
+
memo.set(mask, best);
|
|
8752
|
+
return best;
|
|
8753
|
+
};
|
|
8754
|
+
return visit((1 << input.lines.length) - 1);
|
|
8755
|
+
}
|
|
8756
|
+
function validate(input) {
|
|
8757
|
+
if (input.lines.length > 20 || new Set(input.lines.map((line) => line.lineId)).size !== input.lines.length) throw new Error("Combination pricing requires at most 20 distinct lines");
|
|
8758
|
+
if (input.offers.some((offer) => offer.kind === "any" ? offer.itemCount < 2 : offer.lineIds.length < 2 || new Set(offer.lineIds).size !== offer.lineIds.length)) throw new Error("Combination offers require at least two distinct items");
|
|
8759
|
+
}
|
|
8760
|
+
function planCombinationPrices(input) {
|
|
8761
|
+
validate(input);
|
|
8762
|
+
const applications = [...search(input)].sort(compareApplication);
|
|
8763
|
+
const lines = [...input.lines].sort(compareLine).map((line) => {
|
|
8764
|
+
const allocated = applications.flatMap((app) => app.allocations).find((row) => row.lineId === line.lineId);
|
|
8765
|
+
const listCents = cents$1(line.unitPriceCents * input.places);
|
|
8766
|
+
return {
|
|
8767
|
+
line,
|
|
8768
|
+
listCents,
|
|
8769
|
+
totalCents: allocated?.totalCents ?? listCents,
|
|
8770
|
+
combined: allocated !== undefined
|
|
8771
|
+
};
|
|
8772
|
+
});
|
|
8773
|
+
return {
|
|
8774
|
+
places: input.places,
|
|
8775
|
+
applications,
|
|
8776
|
+
lines,
|
|
8777
|
+
totalCents: cents$1(lines.reduce((sum, line) => sum + line.totalCents, 0)),
|
|
8778
|
+
listTotalCents: cents$1(sumPrices(input.lines) * input.places)
|
|
8779
|
+
};
|
|
8780
|
+
}
|
|
8781
|
+
/**
|
|
8782
|
+
* The offers a selection can use, with particular offers mapped from the item
|
|
8783
|
+
* ids they name to this basket's line ids. A particular offer applies only
|
|
8784
|
+
* when every item it names is selected. Which items an offer may cover at all
|
|
8785
|
+
* (fixed-price ones) is decided when offers are stored and published, so the
|
|
8786
|
+
* offers arriving here already exclude ticket types and sliding scales.
|
|
8787
|
+
*/
|
|
8788
|
+
function combinationOffersForSelection(offers, items) {
|
|
8789
|
+
const lineIds = new Map(items.map((item) => [item.itemId, item.lineId]));
|
|
8790
|
+
return offers.flatMap((offer) => {
|
|
8791
|
+
if (offer.kind === "any") return [offer];
|
|
8792
|
+
const selected = offer.lineIds.map((id) => lineIds.get(id));
|
|
8793
|
+
return selected.every((id) => id !== undefined) ? [{
|
|
8794
|
+
...offer,
|
|
8795
|
+
lineIds: selected
|
|
8796
|
+
}] : [];
|
|
8797
|
+
});
|
|
8798
|
+
}
|
|
8799
|
+
/**
|
|
8800
|
+
* Checkout and the booking block price a selection here (issue 1725). Every
|
|
8801
|
+
* item enters at its resolved price, so an item no offer covers (a run with
|
|
8802
|
+
* ticket types next to "Part 1 and Part 2 for £120") stays at the price
|
|
8803
|
+
* chosen for it and still counts in the total.
|
|
8804
|
+
*/
|
|
8805
|
+
function planSelectionCombinationPrices(input) {
|
|
8806
|
+
const plan = planCombinationPrices({
|
|
8807
|
+
lines: input.items.map(({ lineId, date, label, unitPriceCents }) => ({
|
|
8808
|
+
lineId,
|
|
8809
|
+
date,
|
|
8810
|
+
label,
|
|
8811
|
+
unitPriceCents
|
|
8812
|
+
})),
|
|
8813
|
+
offers: combinationOffersForSelection(input.offers, input.items),
|
|
8814
|
+
places: input.places
|
|
8815
|
+
});
|
|
8816
|
+
const uncovered = (input.uncovered ?? []).map(({ line, subtotalCents }) => ({
|
|
8817
|
+
line,
|
|
8818
|
+
listCents: subtotalCents,
|
|
8819
|
+
totalCents: subtotalCents,
|
|
8820
|
+
combined: false
|
|
8821
|
+
}));
|
|
8822
|
+
const extra = uncovered.reduce((sum, row) => sum + row.totalCents, 0);
|
|
8823
|
+
return {
|
|
8824
|
+
...plan,
|
|
8825
|
+
lines: [...plan.lines, ...uncovered],
|
|
8826
|
+
totalCents: cents$1(plan.totalCents + extra),
|
|
8827
|
+
listTotalCents: cents$1(plan.listTotalCents + extra)
|
|
8828
|
+
};
|
|
8829
|
+
}
|
|
8830
|
+
/** One completion per offer, never arbitrary subsets of the available items. */
|
|
8831
|
+
function missingOfferLines(input, offer) {
|
|
8832
|
+
const selected = new Set(input.lines.map((line) => line.lineId));
|
|
8833
|
+
if (offer.kind === "particular") {
|
|
8834
|
+
const missing = offer.lineIds.filter((id) => !selected.has(id));
|
|
8835
|
+
const added = missing.flatMap((id) => input.addable.filter((line) => line.lineId === id));
|
|
8836
|
+
return added.length === missing.length ? added.sort(compareLine) : null;
|
|
8837
|
+
}
|
|
8838
|
+
const count = Math.max(0, offer.itemCount - input.lines.length);
|
|
8839
|
+
return [...input.addable].sort((a, b) => a.unitPriceCents - b.unitPriceCents || compareLine(a, b)).slice(0, count);
|
|
8840
|
+
}
|
|
8841
|
+
function nextCombinationHint(input) {
|
|
8842
|
+
const current = planCombinationPrices(input);
|
|
8843
|
+
const used = new Set(current.applications.map((app) => app.offer.id));
|
|
8844
|
+
const candidates = input.offers.filter((offer) => !used.has(offer.id)).flatMap((offer) => {
|
|
8845
|
+
const added = missingOfferLines(input, offer);
|
|
8846
|
+
if (!added?.length || input.lines.length + added.length > 20) return [];
|
|
8847
|
+
const plan = planCombinationPrices({
|
|
8848
|
+
...input,
|
|
8849
|
+
lines: [...input.lines, ...added]
|
|
8850
|
+
});
|
|
8851
|
+
const fresh = plan.applications.find((app) => !used.has(app.offer.id) && app.lines.some((line) => added.some((item) => item.lineId === line.lineId)));
|
|
8852
|
+
return fresh ? [{
|
|
8853
|
+
added,
|
|
8854
|
+
offer: fresh.offer,
|
|
8855
|
+
plan,
|
|
8856
|
+
savingCents: cents$1(plan.listTotalCents - plan.totalCents)
|
|
8857
|
+
}] : [];
|
|
8858
|
+
});
|
|
8859
|
+
return candidates.sort((a, b) => a.added.length - b.added.length || a.plan.totalCents - b.plan.totalCents || compareOffer(a.offer, b.offer))[0] ?? null;
|
|
8860
|
+
}
|
|
8861
|
+
function codeCandidate(plan, code, kind) {
|
|
8862
|
+
const bases = plan.lines.map((row) => ({
|
|
8863
|
+
lineId: row.line.lineId,
|
|
8864
|
+
basisCents: kind === "code_only" ? row.listCents : row.totalCents,
|
|
8865
|
+
eligible: code.eligibleLineIds.includes(row.line.lineId) && (kind === "code_only" || code.combinesWithCombinationPrices || !row.combined)
|
|
8866
|
+
}));
|
|
8867
|
+
const reductions = code.reductions(bases);
|
|
8868
|
+
if (new Set(reductions.map((row) => row.lineId)).size !== reductions.length || reductions.some((row) => !bases.some((base) => base.lineId === row.lineId && (base.eligible || row.reductionCents === 0) && row.reductionCents <= base.basisCents))) throw new Error("Invalid discount code allocation");
|
|
8869
|
+
const lines = bases.map((base, index) => {
|
|
8870
|
+
const codeReductionCents = reductions.find((row) => row.lineId === base.lineId)?.reductionCents ?? cents$1(0);
|
|
8871
|
+
return {
|
|
8872
|
+
lineId: base.lineId,
|
|
8873
|
+
combinationReductionCents: cents$1((plan.lines[index]?.listCents ?? 0) - base.basisCents),
|
|
8874
|
+
codeReductionCents,
|
|
8875
|
+
totalCents: cents$1(base.basisCents - codeReductionCents)
|
|
8876
|
+
};
|
|
8877
|
+
});
|
|
8878
|
+
return {
|
|
8879
|
+
kind,
|
|
8880
|
+
applications: kind === "code_only" ? [] : plan.applications,
|
|
8881
|
+
lines,
|
|
8882
|
+
totalCents: cents$1(lines.reduce((sum, row) => sum + row.totalCents, 0)),
|
|
8883
|
+
listTotalCents: plan.listTotalCents
|
|
8884
|
+
};
|
|
8885
|
+
}
|
|
8886
|
+
/** Deliberately compares two candidates; this is not a joint combinations/code optimiser. */
|
|
8887
|
+
function compareCombinationPriceCode(plan, code) {
|
|
8888
|
+
const combined = codeCandidate(plan, code, "combinations_and_code");
|
|
8889
|
+
const alone = codeCandidate(plan, code, "code_only");
|
|
8890
|
+
return alone.totalCents < combined.totalCents ? alone : combined;
|
|
8891
|
+
}
|
|
8892
|
+
|
|
8893
|
+
//#endregion
|
|
8894
|
+
//#region ../commerce/src/purchase/flexibleBalanceCollection.ts
|
|
8895
|
+
function flexibleBalanceCollectionIsAvailable(collection) {
|
|
8896
|
+
return collection?.kind === "available";
|
|
8897
|
+
}
|
|
8898
|
+
const flexibleBalanceUnavailableCopy = "You can’t pay this balance online at the moment. Please contact us to arrange payment.";
|
|
8899
|
+
const flexibleBalanceProcessingCopy = "A payment for this booking is already being processed. Please check back in a few minutes.";
|
|
8900
|
+
|
|
8901
|
+
//#endregion
|
|
8902
|
+
//#region ../commerce/src/purchase/orderPaymentPosition.ts
|
|
8903
|
+
const cents = z.number().int().nonnegative().transform(toNonNegativeCents);
|
|
8904
|
+
const orderPaymentAdmissionSchema = z.discriminatedUnion("kind", [
|
|
8905
|
+
z.object({ kind: z.literal("admitted") }),
|
|
8906
|
+
z.object({ kind: z.literal("requires_provider_check") }),
|
|
8907
|
+
z.object({
|
|
8908
|
+
kind: z.literal("refused"),
|
|
8909
|
+
reason: z.enum([
|
|
8910
|
+
"in_progress",
|
|
8911
|
+
"cancelled",
|
|
8912
|
+
"disputed",
|
|
8913
|
+
"identity",
|
|
8914
|
+
"amounts",
|
|
8915
|
+
"conflicting_terms",
|
|
8916
|
+
"provider_reconciliation",
|
|
8917
|
+
"missing_instalments",
|
|
8918
|
+
"nothing_owed",
|
|
8919
|
+
"not_committed",
|
|
8920
|
+
"unsupported_payment_method",
|
|
8921
|
+
"live_terms",
|
|
8922
|
+
"not_applicable",
|
|
8923
|
+
"terms_closed",
|
|
8924
|
+
"refunded",
|
|
8925
|
+
"partly_cancelled",
|
|
8926
|
+
"retired",
|
|
8927
|
+
"retirement_pending",
|
|
8928
|
+
"cancelled_non_payment",
|
|
8929
|
+
"non_monetary",
|
|
8930
|
+
"settled",
|
|
8931
|
+
"checkout_failed",
|
|
8932
|
+
"archived",
|
|
8933
|
+
"recurring_collection_active",
|
|
8934
|
+
"below_card_minimum"
|
|
8935
|
+
])
|
|
8936
|
+
})
|
|
8937
|
+
]).readonly();
|
|
8938
|
+
const orderPaymentOperationKeys = [
|
|
8939
|
+
"manualReceipt",
|
|
8940
|
+
"waiver",
|
|
8941
|
+
"paymentLink",
|
|
8942
|
+
"demand",
|
|
8943
|
+
"partialRefund",
|
|
8944
|
+
"closeBalance",
|
|
8945
|
+
"instalmentSetup",
|
|
8946
|
+
"cashlessCompletion",
|
|
8947
|
+
"initialCheckout",
|
|
8948
|
+
"checkoutResume",
|
|
8949
|
+
"providerReceipt",
|
|
8950
|
+
"recovery",
|
|
8951
|
+
"closePlan",
|
|
8952
|
+
"partialManualReceipt",
|
|
8953
|
+
"expiryRelease",
|
|
8954
|
+
"manualReceiptPreparation",
|
|
8955
|
+
"waiverPreparation",
|
|
8956
|
+
"paymentLinkPreparation",
|
|
8957
|
+
"bookingRestore",
|
|
8958
|
+
"staffCancellation"
|
|
8959
|
+
];
|
|
8960
|
+
const retirementScope = z.discriminatedUnion("kind", [
|
|
8961
|
+
z.object({ kind: z.literal("pending") }),
|
|
8962
|
+
z.object({ kind: z.literal("whole_order") }),
|
|
8963
|
+
z.object({ kind: z.literal("terms_only") }),
|
|
8964
|
+
z.object({
|
|
8965
|
+
kind: z.literal("items"),
|
|
8966
|
+
itemIds: z.array(z.string().uuid()).readonly()
|
|
8967
|
+
})
|
|
8968
|
+
]).readonly();
|
|
8969
|
+
const orderRefundProtectionSchema = z.object({
|
|
8970
|
+
subject: z.discriminatedUnion("kind", [z.object({ kind: z.literal("none") }), z.object({
|
|
8971
|
+
kind: z.literal("protected_deposit"),
|
|
8972
|
+
sourceKind: z.enum(["flexible_balance", "instalment_plan"]),
|
|
8973
|
+
protectedDepositAmountCents: cents,
|
|
8974
|
+
depositRefundability: z.enum(["refundable", "non_refundable"])
|
|
8975
|
+
})]).readonly(),
|
|
8976
|
+
funding: z.array(z.object({
|
|
8977
|
+
orderItemId: z.string().uuid(),
|
|
8978
|
+
paymentReceiptId: z.string().uuid().nullable(),
|
|
8979
|
+
originalCents: cents,
|
|
8980
|
+
totalRemainingRefundableCents: cents,
|
|
8981
|
+
policyRefundableCents: cents,
|
|
8982
|
+
protectedDepositRemainingCents: cents
|
|
8983
|
+
}).readonly()).readonly()
|
|
8984
|
+
}).readonly();
|
|
8985
|
+
/** SQL owns the decision. This schema only parses its closed result. */
|
|
8986
|
+
const orderPaymentPositionSchema = z.object({
|
|
8987
|
+
orderStatus: z.enum([
|
|
8988
|
+
"pending",
|
|
8989
|
+
"paid",
|
|
8990
|
+
"partially_refunded",
|
|
8991
|
+
"refunded",
|
|
8992
|
+
"cancelled",
|
|
8993
|
+
"failed"
|
|
8994
|
+
]),
|
|
8995
|
+
refundProtection: orderRefundProtectionSchema,
|
|
8996
|
+
amounts: z.object({
|
|
8997
|
+
totalCents: cents,
|
|
8998
|
+
collectedCents: cents,
|
|
8999
|
+
refundedCents: cents,
|
|
9000
|
+
waivedCents: cents,
|
|
9001
|
+
remainderCents: cents
|
|
9002
|
+
}).readonly(),
|
|
9003
|
+
lifecycle: z.discriminatedUnion("kind", [
|
|
9004
|
+
z.object({ kind: z.literal("open") }),
|
|
9005
|
+
z.object({
|
|
9006
|
+
kind: z.literal("retired"),
|
|
9007
|
+
scope: retirementScope,
|
|
9008
|
+
reason: z.enum([
|
|
9009
|
+
"staff",
|
|
9010
|
+
"checkout_failed",
|
|
9011
|
+
"abandoned_failed",
|
|
9012
|
+
"abandoned_cancelled",
|
|
9013
|
+
"dispute_lost",
|
|
9014
|
+
"booking_cancelled"
|
|
9015
|
+
])
|
|
9016
|
+
}),
|
|
9017
|
+
z.object({ kind: z.literal("cancelled_non_payment") })
|
|
9018
|
+
]).readonly(),
|
|
9019
|
+
openDispute: z.boolean(),
|
|
9020
|
+
termsLive: z.boolean(),
|
|
9021
|
+
admissions: z.object({
|
|
9022
|
+
bookingRestore: orderPaymentAdmissionSchema,
|
|
9023
|
+
staffCancellation: orderPaymentAdmissionSchema,
|
|
9024
|
+
manualReceipt: orderPaymentAdmissionSchema,
|
|
9025
|
+
waiver: orderPaymentAdmissionSchema,
|
|
9026
|
+
paymentLink: orderPaymentAdmissionSchema,
|
|
9027
|
+
demand: orderPaymentAdmissionSchema,
|
|
9028
|
+
partialRefund: orderPaymentAdmissionSchema,
|
|
9029
|
+
closeBalance: orderPaymentAdmissionSchema,
|
|
9030
|
+
instalmentSetup: orderPaymentAdmissionSchema,
|
|
9031
|
+
cashlessCompletion: orderPaymentAdmissionSchema,
|
|
9032
|
+
initialCheckout: orderPaymentAdmissionSchema,
|
|
9033
|
+
checkoutResume: orderPaymentAdmissionSchema,
|
|
9034
|
+
providerReceipt: orderPaymentAdmissionSchema,
|
|
9035
|
+
recovery: orderPaymentAdmissionSchema,
|
|
9036
|
+
closePlan: orderPaymentAdmissionSchema,
|
|
9037
|
+
partialManualReceipt: orderPaymentAdmissionSchema,
|
|
9038
|
+
expiryRelease: orderPaymentAdmissionSchema,
|
|
9039
|
+
manualReceiptPreparation: orderPaymentAdmissionSchema,
|
|
9040
|
+
waiverPreparation: orderPaymentAdmissionSchema,
|
|
9041
|
+
paymentLinkPreparation: orderPaymentAdmissionSchema
|
|
9042
|
+
}).readonly(),
|
|
9043
|
+
paymentSelection: z.object({
|
|
9044
|
+
kind: z.enum(["full", "custom"]),
|
|
9045
|
+
minimumCents: cents,
|
|
9046
|
+
maximumCents: cents,
|
|
9047
|
+
maximumCustomCents: cents,
|
|
9048
|
+
reason: z.enum(["overdue", "dust_balance"])
|
|
9049
|
+
}).readonly(),
|
|
9050
|
+
collection: z.discriminatedUnion("kind", [
|
|
9051
|
+
z.object({ kind: z.literal("available") }),
|
|
9052
|
+
z.object({ kind: z.literal("in_progress") }),
|
|
9053
|
+
z.object({
|
|
9054
|
+
kind: z.literal("closed"),
|
|
9055
|
+
reason: z.enum([
|
|
9056
|
+
"archived",
|
|
9057
|
+
"partly_cancelled",
|
|
9058
|
+
"retired",
|
|
9059
|
+
"retirement_pending",
|
|
9060
|
+
"cancelled_non_payment",
|
|
9061
|
+
"disputed",
|
|
9062
|
+
"non_monetary",
|
|
9063
|
+
"settled",
|
|
9064
|
+
"terms_closed",
|
|
9065
|
+
"refunded",
|
|
9066
|
+
"not_committed",
|
|
9067
|
+
"checkout_failed"
|
|
9068
|
+
])
|
|
9069
|
+
}),
|
|
9070
|
+
z.object({
|
|
9071
|
+
kind: z.literal("unresolved"),
|
|
9072
|
+
reason: z.enum([
|
|
9073
|
+
"identity",
|
|
9074
|
+
"amounts",
|
|
9075
|
+
"conflicting_terms",
|
|
9076
|
+
"provider_reconciliation",
|
|
9077
|
+
"missing_instalments"
|
|
9078
|
+
])
|
|
9079
|
+
})
|
|
9080
|
+
]).readonly(),
|
|
9081
|
+
deadline: z.discriminatedUnion("kind", [
|
|
9082
|
+
z.object({ kind: z.literal("none") }),
|
|
9083
|
+
z.object({
|
|
9084
|
+
kind: z.literal("not_yet_due"),
|
|
9085
|
+
dueAt: z.string().datetime({ offset: true }),
|
|
9086
|
+
dueDay: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
|
|
9087
|
+
timezone: z.string().optional()
|
|
9088
|
+
}),
|
|
9089
|
+
z.object({
|
|
9090
|
+
kind: z.literal("overdue"),
|
|
9091
|
+
dueAt: z.string().datetime({ offset: true }),
|
|
9092
|
+
dueDay: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
|
|
9093
|
+
timezone: z.string().optional()
|
|
9094
|
+
})
|
|
9095
|
+
]).readonly(),
|
|
9096
|
+
terms: z.discriminatedUnion("kind", [
|
|
9097
|
+
z.object({ kind: z.literal("immediate") }),
|
|
9098
|
+
z.object({ kind: z.literal("manual") }),
|
|
9099
|
+
z.object({
|
|
9100
|
+
kind: z.literal("flexible_balance"),
|
|
9101
|
+
contractId: z.string().uuid().transform(unsafeAsOrderFlexibleBalanceContractId),
|
|
9102
|
+
upfrontAmountCents: cents
|
|
9103
|
+
}),
|
|
9104
|
+
z.object({
|
|
9105
|
+
kind: z.literal("instalment_plan"),
|
|
9106
|
+
paymentPlanId: z.string().uuid().transform(unsafeAsOrderPaymentPlanId),
|
|
9107
|
+
nextDueAmountCents: cents.nullable(),
|
|
9108
|
+
collectionStopped: z.boolean(),
|
|
9109
|
+
state: z.object({ kind: z.enum([
|
|
9110
|
+
"active",
|
|
9111
|
+
"payment_failed",
|
|
9112
|
+
"pending_initial_payment",
|
|
9113
|
+
"reconciliation_required",
|
|
9114
|
+
"cancelled",
|
|
9115
|
+
"refunded",
|
|
9116
|
+
"completed"
|
|
9117
|
+
]) }).readonly()
|
|
9118
|
+
})
|
|
9119
|
+
]).readonly(),
|
|
9120
|
+
paymentMethod: z.enum([
|
|
9121
|
+
"free",
|
|
9122
|
+
"waived",
|
|
9123
|
+
"pass_redemption",
|
|
9124
|
+
"membership_access",
|
|
9125
|
+
"stripe",
|
|
9126
|
+
"store_credit",
|
|
9127
|
+
"mixed",
|
|
9128
|
+
"manual"
|
|
9129
|
+
]),
|
|
9130
|
+
currency: z.string().transform((value, ctx) => {
|
|
9131
|
+
const currency = parseCurrencyCode(value);
|
|
9132
|
+
if (currency) return currency;
|
|
9133
|
+
ctx.addIssue({
|
|
9134
|
+
code: "custom",
|
|
9135
|
+
message: "Invalid currency code"
|
|
9136
|
+
});
|
|
9137
|
+
return z.NEVER;
|
|
9138
|
+
})
|
|
9139
|
+
}).superRefine((position, ctx) => {
|
|
9140
|
+
const { totalCents, collectedCents, waivedCents, refundedCents, remainderCents } = position.amounts;
|
|
9141
|
+
if (remainderCents !== Math.max(0, totalCents - collectedCents - waivedCents)) ctx.addIssue({
|
|
9142
|
+
code: "custom",
|
|
9143
|
+
path: ["amounts", "remainderCents"],
|
|
9144
|
+
message: "Payment remainder does not match its facts"
|
|
9145
|
+
});
|
|
9146
|
+
if (refundedCents > collectedCents) ctx.addIssue({
|
|
9147
|
+
code: "custom",
|
|
9148
|
+
path: ["amounts", "refundedCents"],
|
|
9149
|
+
message: "Refund exceeds collection"
|
|
9150
|
+
});
|
|
9151
|
+
if (position.collection.kind === "available" && (position.lifecycle.kind !== "open" || position.openDispute)) ctx.addIssue({
|
|
9152
|
+
code: "custom",
|
|
9153
|
+
path: ["collection"],
|
|
9154
|
+
message: "Available collection requires an open undisputed order"
|
|
9155
|
+
});
|
|
9156
|
+
if (position.deadline.kind !== "none" && position.terms.kind !== "flexible_balance" && position.terms.kind !== "instalment_plan") ctx.addIssue({
|
|
9157
|
+
code: "custom",
|
|
9158
|
+
path: ["deadline"],
|
|
9159
|
+
message: "A deadline requires agreed payment terms"
|
|
9160
|
+
});
|
|
9161
|
+
}).readonly();
|
|
9162
|
+
const parseOrderPaymentPosition = (value) => orderPaymentPositionSchema.parse(value);
|
|
9163
|
+
/** History snapshots have totals, not live collection evidence. Never reopen them. */
|
|
9164
|
+
function parseArchivedOrderPaymentPosition(snapshot) {
|
|
9165
|
+
return parseOrderPaymentPosition({
|
|
9166
|
+
orderStatus: snapshot.status,
|
|
9167
|
+
amounts: {
|
|
9168
|
+
...snapshot,
|
|
9169
|
+
remainderCents: calculateOutstandingOrderAmountCents({
|
|
9170
|
+
totalCents: snapshot.totalCents,
|
|
9171
|
+
settledCents: snapshot.collectedCents + snapshot.waivedCents
|
|
9172
|
+
})
|
|
9173
|
+
},
|
|
9174
|
+
lifecycle: snapshot.status === "cancelled" ? {
|
|
9175
|
+
kind: "retired",
|
|
9176
|
+
scope: { kind: "whole_order" },
|
|
9177
|
+
reason: "booking_cancelled"
|
|
9178
|
+
} : snapshot.status === "failed" ? {
|
|
9179
|
+
kind: "retired",
|
|
9180
|
+
scope: { kind: "terms_only" },
|
|
9181
|
+
reason: "checkout_failed"
|
|
9182
|
+
} : { kind: "open" },
|
|
9183
|
+
termsLive: false,
|
|
9184
|
+
admissions: Object.fromEntries(orderPaymentOperationKeys.map((key) => [key, {
|
|
9185
|
+
kind: "refused",
|
|
9186
|
+
reason: "archived"
|
|
9187
|
+
}])),
|
|
9188
|
+
refundProtection: {
|
|
9189
|
+
subject: { kind: "none" },
|
|
9190
|
+
funding: []
|
|
9191
|
+
},
|
|
9192
|
+
paymentSelection: {
|
|
9193
|
+
kind: "full",
|
|
9194
|
+
minimumCents: 0,
|
|
9195
|
+
maximumCents: 0,
|
|
9196
|
+
maximumCustomCents: 0,
|
|
9197
|
+
reason: "dust_balance"
|
|
9198
|
+
},
|
|
9199
|
+
openDispute: false,
|
|
9200
|
+
collection: {
|
|
9201
|
+
kind: "closed",
|
|
9202
|
+
reason: "archived"
|
|
9203
|
+
},
|
|
9204
|
+
deadline: { kind: "none" },
|
|
9205
|
+
terms: { kind: snapshot.paymentMethod === "manual" ? "manual" : "immediate" },
|
|
9206
|
+
paymentMethod: snapshot.paymentMethod,
|
|
9207
|
+
currency: snapshot.currency
|
|
9208
|
+
});
|
|
9209
|
+
}
|
|
9210
|
+
/** Retain per-item SQL caps alongside their source totals; allocators never rebuild them. */
|
|
9211
|
+
function projectOrderRefundExposure(protection, paymentReceiptId, orderItemIds) {
|
|
9212
|
+
const funding = protection.funding.filter((line) => line.paymentReceiptId === paymentReceiptId && orderItemIds.includes(line.orderItemId));
|
|
9213
|
+
return {
|
|
9214
|
+
subject: protection.subject,
|
|
9215
|
+
policyLineRemaining: funding.map((line) => ({
|
|
9216
|
+
orderItemId: line.orderItemId,
|
|
9217
|
+
remainingCents: line.policyRefundableCents
|
|
9218
|
+
})),
|
|
9219
|
+
unrestrictedLineRemaining: funding.map((line) => ({
|
|
9220
|
+
orderItemId: line.orderItemId,
|
|
9221
|
+
remainingCents: line.totalRemainingRefundableCents
|
|
9222
|
+
})),
|
|
9223
|
+
totalRemainingRefundableCents: toNonNegativeCents(funding.reduce((sum, line) => sum + line.totalRemainingRefundableCents, 0)),
|
|
9224
|
+
policyRefundableCents: toNonNegativeCents(funding.reduce((sum, line) => sum + line.policyRefundableCents, 0)),
|
|
9225
|
+
protectedDepositRemainingCents: toNonNegativeCents(funding.reduce((sum, line) => sum + line.protectedDepositRemainingCents, 0))
|
|
9226
|
+
};
|
|
9227
|
+
}
|
|
9228
|
+
|
|
9229
|
+
//#endregion
|
|
9230
|
+
//#region ../commerce/src/purchase/orderPaymentLabels.ts
|
|
9231
|
+
const NEEDS_CHECKING_OWNER_HINT = "We couldn't work out what's still owed on this booking, so we've paused payment requests. Contact us and we'll sort it out.";
|
|
9232
|
+
function orderPaymentLabelFormatters(currency, context) {
|
|
9233
|
+
return {
|
|
9234
|
+
money: (cents$2) => formatCurrencyAmount(cents$2, currency, { decimals: "auto" }),
|
|
9235
|
+
day: (day) => formatDate(day, context, {
|
|
9236
|
+
date: "short",
|
|
9237
|
+
year: "omit"
|
|
9238
|
+
})
|
|
9239
|
+
};
|
|
9240
|
+
}
|
|
9241
|
+
function effectiveDueDay(deadline) {
|
|
9242
|
+
return deadline.dueDay ? {
|
|
9243
|
+
kind: "civil",
|
|
9244
|
+
value: parseBookingLocalDate(deadline.dueDay)
|
|
9245
|
+
} : {
|
|
9246
|
+
kind: "instant",
|
|
9247
|
+
value: toUtcIsoDateTimeString(new Date(deadline.dueAt).toISOString())
|
|
9248
|
+
};
|
|
9249
|
+
}
|
|
9250
|
+
function decideBookingOutcome({ lifecycle, collection }) {
|
|
9251
|
+
switch (lifecycle.kind) {
|
|
9252
|
+
case "open": return collection.kind === "closed" && (collection.reason === "checkout_failed" || collection.reason === "not_committed") ? "checkout_not_finished" : "booked";
|
|
9253
|
+
case "cancelled_non_payment": return "cancelled_non_payment";
|
|
9254
|
+
case "retired":
|
|
9255
|
+
if (lifecycle.scope.kind === "whole_order") return "cancelled";
|
|
9256
|
+
switch (lifecycle.reason) {
|
|
9257
|
+
case "checkout_failed":
|
|
9258
|
+
case "abandoned_failed":
|
|
9259
|
+
case "abandoned_cancelled": return "checkout_not_finished";
|
|
9260
|
+
case "dispute_lost": return "dispute_lost";
|
|
9261
|
+
case "staff":
|
|
9262
|
+
case "booking_cancelled": return collection.kind === "closed" && collection.reason === "partly_cancelled" ? "partly_cancelled" : "cancelled";
|
|
9263
|
+
default: return assertNever(lifecycle.reason);
|
|
9264
|
+
}
|
|
9265
|
+
default: return assertNever(lifecycle);
|
|
9266
|
+
}
|
|
9267
|
+
}
|
|
9268
|
+
function decideStillToPay({ amounts, collection, deadline }) {
|
|
9269
|
+
if (collection.kind !== "available" || amounts.remainderCents === 0) return { kind: "nothing" };
|
|
9270
|
+
const cents$2 = amounts.remainderCents;
|
|
9271
|
+
return deadline.kind === "none" ? {
|
|
9272
|
+
kind: "no_deadline",
|
|
9273
|
+
cents: cents$2
|
|
9274
|
+
} : {
|
|
9275
|
+
kind: deadline.kind,
|
|
9276
|
+
cents: cents$2,
|
|
9277
|
+
day: effectiveDueDay(deadline)
|
|
9278
|
+
};
|
|
9279
|
+
}
|
|
9280
|
+
function decidePaidInFull(position, outcome) {
|
|
9281
|
+
const { collectedCents, refundedCents, waivedCents, remainderCents } = position.amounts;
|
|
9282
|
+
if (outcome !== "booked" || remainderCents > 0 || refundedCents > 0 || waivedCents > 0) return null;
|
|
9283
|
+
switch (position.paymentMethod) {
|
|
9284
|
+
case "store_credit": return {
|
|
9285
|
+
kind: "paid_in_full",
|
|
9286
|
+
via: "credit"
|
|
9287
|
+
};
|
|
9288
|
+
case "manual": return collectedCents > 0 ? {
|
|
9289
|
+
kind: "paid_in_full",
|
|
9290
|
+
via: "offline"
|
|
9291
|
+
} : null;
|
|
9292
|
+
case "stripe":
|
|
9293
|
+
case "mixed": return collectedCents > 0 ? {
|
|
9294
|
+
kind: "paid_in_full",
|
|
9295
|
+
via: "online"
|
|
9296
|
+
} : null;
|
|
9297
|
+
case "waived":
|
|
9298
|
+
case "free":
|
|
9299
|
+
case "pass_redemption":
|
|
9300
|
+
case "membership_access": return null;
|
|
9301
|
+
default: return assertNever(position.paymentMethod);
|
|
9302
|
+
}
|
|
9303
|
+
}
|
|
9304
|
+
function decideInstalmentStanding(position) {
|
|
9305
|
+
const { terms, deadline, collection, amounts } = position;
|
|
9306
|
+
if (terms.kind !== "instalment_plan" || collection.kind !== "available") return null;
|
|
9307
|
+
switch (terms.state.kind) {
|
|
9308
|
+
case "payment_failed": return {
|
|
9309
|
+
kind: "instalment_failed",
|
|
9310
|
+
canPayNow: position.admissions.paymentLink.kind === "admitted"
|
|
9311
|
+
};
|
|
9312
|
+
case "active":
|
|
9313
|
+
if (amounts.collectedCents === 0 || deadline.kind === "overdue") return null;
|
|
9314
|
+
return {
|
|
9315
|
+
kind: "instalments_running",
|
|
9316
|
+
next: deadline.kind === "not_yet_due" && terms.nextDueAmountCents !== null ? {
|
|
9317
|
+
cents: terms.nextDueAmountCents,
|
|
9318
|
+
day: effectiveDueDay(deadline)
|
|
9319
|
+
} : null
|
|
9320
|
+
};
|
|
9321
|
+
case "pending_initial_payment":
|
|
9322
|
+
case "reconciliation_required":
|
|
9323
|
+
case "cancelled":
|
|
9324
|
+
case "refunded":
|
|
9325
|
+
case "completed": return null;
|
|
9326
|
+
default: return assertNever(terms.state.kind);
|
|
9327
|
+
}
|
|
9328
|
+
}
|
|
9329
|
+
function decideMoneyStanding(position, outcome) {
|
|
9330
|
+
const { terms, collection } = position;
|
|
9331
|
+
const planState = terms.kind === "instalment_plan" ? terms.state.kind : null;
|
|
9332
|
+
if (collection.kind === "unresolved" || planState === "reconciliation_required") return { kind: "needs_checking" };
|
|
9333
|
+
switch (position.paymentMethod) {
|
|
9334
|
+
case "free": return {
|
|
9335
|
+
kind: "covered",
|
|
9336
|
+
by: "free"
|
|
9337
|
+
};
|
|
9338
|
+
case "pass_redemption": return {
|
|
9339
|
+
kind: "covered",
|
|
9340
|
+
by: "pass"
|
|
9341
|
+
};
|
|
9342
|
+
case "membership_access": return {
|
|
9343
|
+
kind: "covered",
|
|
9344
|
+
by: "membership"
|
|
9345
|
+
};
|
|
9346
|
+
case "waived":
|
|
9347
|
+
case "stripe":
|
|
9348
|
+
case "store_credit":
|
|
9349
|
+
case "mixed":
|
|
9350
|
+
case "manual": break;
|
|
9351
|
+
default: return assertNever(position.paymentMethod);
|
|
9352
|
+
}
|
|
9353
|
+
if (planState === "pending_initial_payment" && collection.kind !== "closed") return { kind: "first_instalment_pending" };
|
|
9354
|
+
if (collection.kind === "in_progress") return { kind: "in_progress" };
|
|
9355
|
+
return decideInstalmentStanding(position) ?? decidePaidInFull(position, outcome) ?? {
|
|
9356
|
+
kind: "amounts",
|
|
9357
|
+
stillToPay: decideStillToPay(position)
|
|
9358
|
+
};
|
|
9359
|
+
}
|
|
9360
|
+
const OWNER_COPY = {
|
|
9361
|
+
noPaymentDue: "No payment due",
|
|
9362
|
+
nothingPaid: "Nothing paid",
|
|
9363
|
+
credit: "Paid with credit",
|
|
9364
|
+
pass: "Covered by pass or package",
|
|
9365
|
+
membership: "Covered by membership",
|
|
9366
|
+
paidOnline: "Paid",
|
|
9367
|
+
paidOffline: "Paid offline",
|
|
9368
|
+
inProgress: "Payment in progress",
|
|
9369
|
+
firstInstalmentPending: "Waiting for the first payment",
|
|
9370
|
+
instalmentFailed: "A payment didn't go through",
|
|
9371
|
+
waived: (amount) => `${amount} waived`,
|
|
9372
|
+
dueNoDeadline: (amount) => `${amount} due`,
|
|
9373
|
+
due: (amount, day) => `${amount} due by ${day}`,
|
|
9374
|
+
overdue: (amount, day) => `${amount} overdue (due ${day})`,
|
|
9375
|
+
instalments: ({ paid, refunded, next }) => [
|
|
9376
|
+
paid,
|
|
9377
|
+
refunded,
|
|
9378
|
+
next && `next ${next.amount} on ${next.day}`
|
|
9379
|
+
].filter((part) => part !== null).join(" · ")
|
|
9380
|
+
};
|
|
9381
|
+
const CUSTOMER_COPY = {
|
|
9382
|
+
noPaymentDue: "No payment due",
|
|
9383
|
+
nothingPaid: "Nothing paid",
|
|
9384
|
+
credit: "Paid with credit",
|
|
9385
|
+
pass: "Covered by pass or package",
|
|
9386
|
+
membership: "Covered by membership",
|
|
9387
|
+
paidOnline: "Paid",
|
|
9388
|
+
paidOffline: "Paid",
|
|
9389
|
+
inProgress: "Your payment is being processed",
|
|
9390
|
+
firstInstalmentPending: "Your first payment is being processed",
|
|
9391
|
+
instalmentFailed: "A payment didn't go through.",
|
|
9392
|
+
waived: () => null,
|
|
9393
|
+
dueNoDeadline: (amount) => `${amount} to pay`,
|
|
9394
|
+
due: (amount, day) => `${amount} to pay by ${day}`,
|
|
9395
|
+
overdue: (amount, day) => `${amount} to pay. It was due on ${day}.`,
|
|
9396
|
+
instalments: ({ paid, refunded, next }) => [
|
|
9397
|
+
paid,
|
|
9398
|
+
refunded,
|
|
9399
|
+
next && `Next payment of ${next.amount} on ${next.day}`
|
|
9400
|
+
].filter((part) => part !== null).join(". ") + (next || refunded ? "." : "")
|
|
9401
|
+
};
|
|
9402
|
+
function moneySegments(position, outcome, copy, format, stillToPay) {
|
|
9403
|
+
const { collectedCents, refundedCents, waivedCents } = position.amounts;
|
|
9404
|
+
const keptCents = collectedCents - refundedCents;
|
|
9405
|
+
const cancelled = outcome === "cancelled" || outcome === "cancelled_non_payment";
|
|
9406
|
+
const paid = collectedCents === 0 ? null : cancelled && refundedCents === 0 ? `${format.money(collectedCents)} paid, not refunded` : `${format.money(collectedCents)} paid`;
|
|
9407
|
+
return [
|
|
9408
|
+
paid,
|
|
9409
|
+
refundedCents > 0 ? `${format.money(refundedCents)} refunded` : null,
|
|
9410
|
+
cancelled && refundedCents > 0 && keptCents > 0 ? `${format.money(keptCents)} not refunded` : null,
|
|
9411
|
+
waivedCents > 0 ? copy.waived(format.money(waivedCents)) : null,
|
|
9412
|
+
stillToPaySegment(stillToPay, copy, format)
|
|
9413
|
+
].filter((segment) => segment !== null);
|
|
9414
|
+
}
|
|
9415
|
+
function stillToPaySegment(stillToPay, copy, format) {
|
|
9416
|
+
switch (stillToPay.kind) {
|
|
9417
|
+
case "nothing": return null;
|
|
9418
|
+
case "no_deadline": return copy.dueNoDeadline(format.money(stillToPay.cents));
|
|
9419
|
+
case "not_yet_due": return copy.due(format.money(stillToPay.cents), format.day(stillToPay.day));
|
|
9420
|
+
case "overdue": return copy.overdue(format.money(stillToPay.cents), format.day(stillToPay.day));
|
|
9421
|
+
default: return assertNever(stillToPay);
|
|
9422
|
+
}
|
|
9423
|
+
}
|
|
9424
|
+
function needsCheckingMoneyLine(position, outcome, audience, copy, format) {
|
|
9425
|
+
if (audience.audience === "owner") return "Needs checking";
|
|
9426
|
+
const checking = `We're checking what's left to pay. ${audience.siteName} will be in touch.`;
|
|
9427
|
+
const segments = moneySegments(position, outcome, copy, format, { kind: "nothing" });
|
|
9428
|
+
return segments.length > 0 ? `${segments.join(" · ")}. ${checking}` : checking;
|
|
9429
|
+
}
|
|
9430
|
+
function moneyLine(standing, position, outcome, audience, format) {
|
|
9431
|
+
const copy = audience.audience === "owner" ? OWNER_COPY : CUSTOMER_COPY;
|
|
9432
|
+
switch (standing.kind) {
|
|
9433
|
+
case "covered": return {
|
|
9434
|
+
free: copy.noPaymentDue,
|
|
9435
|
+
pass: copy.pass,
|
|
9436
|
+
membership: copy.membership
|
|
9437
|
+
}[standing.by];
|
|
9438
|
+
case "needs_checking": return needsCheckingMoneyLine(position, outcome, audience, copy, format);
|
|
9439
|
+
case "first_instalment_pending": return copy.firstInstalmentPending;
|
|
9440
|
+
case "in_progress": return copy.inProgress;
|
|
9441
|
+
case "instalment_failed": return audience.audience === "customer" && standing.canPayNow ? `${copy.instalmentFailed} You can pay the rest now.` : copy.instalmentFailed;
|
|
9442
|
+
case "instalments_running": {
|
|
9443
|
+
const { collectedCents, refundedCents, totalCents } = position.amounts;
|
|
9444
|
+
return copy.instalments({
|
|
9445
|
+
paid: `${format.money(collectedCents)} of ${format.money(totalCents)} paid`,
|
|
9446
|
+
refunded: refundedCents > 0 ? `${format.money(refundedCents)} refunded` : null,
|
|
9447
|
+
next: standing.next && {
|
|
9448
|
+
amount: format.money(standing.next.cents),
|
|
9449
|
+
day: format.day(standing.next.day)
|
|
9450
|
+
}
|
|
9451
|
+
});
|
|
9452
|
+
}
|
|
9453
|
+
case "paid_in_full": return {
|
|
9454
|
+
online: copy.paidOnline,
|
|
9455
|
+
credit: copy.credit,
|
|
9456
|
+
offline: copy.paidOffline
|
|
9457
|
+
}[standing.via];
|
|
9458
|
+
case "amounts": {
|
|
9459
|
+
const segments = moneySegments(position, outcome, copy, format, standing.stillToPay);
|
|
9460
|
+
if (segments.length > 0) return segments.join(" · ");
|
|
9461
|
+
return position.amounts.remainderCents === 0 ? copy.noPaymentDue : copy.nothingPaid;
|
|
9462
|
+
}
|
|
9463
|
+
default: return assertNever(standing);
|
|
9464
|
+
}
|
|
9465
|
+
}
|
|
9466
|
+
function moneyTone(standing, position, outcome) {
|
|
9467
|
+
switch (standing.kind) {
|
|
9468
|
+
case "needs_checking":
|
|
9469
|
+
case "instalment_failed": return "problem";
|
|
9470
|
+
case "paid_in_full": return "success";
|
|
9471
|
+
case "instalments_running": return "attention";
|
|
9472
|
+
case "covered":
|
|
9473
|
+
case "first_instalment_pending":
|
|
9474
|
+
case "in_progress": return "neutral";
|
|
9475
|
+
case "amounts": switch (standing.stillToPay.kind) {
|
|
9476
|
+
case "overdue": return "problem";
|
|
9477
|
+
case "not_yet_due":
|
|
9478
|
+
case "no_deadline": return "attention";
|
|
9479
|
+
case "nothing": return outcome === "booked" && position.amounts.remainderCents === 0 && position.amounts.collectedCents > position.amounts.refundedCents ? "success" : "neutral";
|
|
9480
|
+
default: return assertNever(standing.stillToPay);
|
|
9481
|
+
}
|
|
9482
|
+
default: return assertNever(standing);
|
|
9483
|
+
}
|
|
9484
|
+
}
|
|
9485
|
+
function bookingOutcomeLabel(outcome, audience) {
|
|
9486
|
+
switch (outcome) {
|
|
9487
|
+
case "booked": return null;
|
|
9488
|
+
case "cancelled": return "Cancelled";
|
|
9489
|
+
case "cancelled_non_payment": return audience === "owner" ? "Cancelled for non-payment" : "Cancelled";
|
|
9490
|
+
case "partly_cancelled": return "Partly cancelled";
|
|
9491
|
+
case "checkout_not_finished": return "Checkout not finished";
|
|
9492
|
+
case "dispute_lost": return audience === "owner" ? "Dispute lost" : null;
|
|
9493
|
+
default: return assertNever(outcome);
|
|
9494
|
+
}
|
|
9495
|
+
}
|
|
9496
|
+
function bookingLine(position, outcome, audience) {
|
|
9497
|
+
const archived = position.collection.kind === "closed" && position.collection.reason === "archived";
|
|
9498
|
+
const parts = [
|
|
9499
|
+
bookingOutcomeLabel(outcome, audience),
|
|
9500
|
+
audience === "owner" && position.openDispute ? "Payment disputed" : null,
|
|
9501
|
+
audience === "owner" && archived ? "Archived" : null
|
|
9502
|
+
].filter((part) => part !== null);
|
|
9503
|
+
return parts.length > 0 ? parts.join(" · ") : null;
|
|
9504
|
+
}
|
|
9505
|
+
/** The one owner of how a payment position reads, for site owners and their customers. */
|
|
9506
|
+
function describeOrderPayment(position, audience, format) {
|
|
9507
|
+
const outcome = decideBookingOutcome(position);
|
|
9508
|
+
const standing = decideMoneyStanding(position, outcome);
|
|
9509
|
+
const disputeShown = audience.audience === "owner" && (position.openDispute || outcome === "dispute_lost");
|
|
9510
|
+
return {
|
|
9511
|
+
booking: bookingLine(position, outcome, audience.audience),
|
|
9512
|
+
money: moneyLine(standing, position, outcome, audience, format),
|
|
9513
|
+
tone: disputeShown ? "problem" : moneyTone(standing, position, outcome),
|
|
9514
|
+
ownerHint: audience.audience === "owner" && standing.kind === "needs_checking" ? NEEDS_CHECKING_OWNER_HINT : null
|
|
9515
|
+
};
|
|
9516
|
+
}
|
|
9517
|
+
|
|
8642
9518
|
//#endregion
|
|
8643
9519
|
//#region ../site-contracts/src/siteData/eventCheckout.ts
|
|
8644
9520
|
const uuid = z.string().uuid();
|
|
@@ -8688,7 +9564,13 @@ const eventBookingOutcomeSchema = z.discriminatedUnion("kind", [z.object({
|
|
|
8688
9564
|
identity: confirmedBookingIdentitySchema,
|
|
8689
9565
|
...arrivalFields
|
|
8690
9566
|
}).strict()]);
|
|
9567
|
+
const priceReductionSummarySchema = z.object({
|
|
9568
|
+
kind: z.enum(["discount_code", "combination_price"]),
|
|
9569
|
+
label: z.string(),
|
|
9570
|
+
amountCents: z.number().int().nonnegative()
|
|
9571
|
+
}).strict();
|
|
8691
9572
|
const eventEmbeddedCheckoutSchema = z.object({
|
|
9573
|
+
priceReductions: z.tuple([priceReductionSummarySchema]).rest(priceReductionSummarySchema).readonly().optional(),
|
|
8692
9574
|
kind: z.literal("embedded"),
|
|
8693
9575
|
sessionId: z.string().min(1),
|
|
8694
9576
|
clientSecret: z.string().min(1),
|
|
@@ -8711,16 +9593,21 @@ const eventRegistrationSummarySchema = z.object({
|
|
|
8711
9593
|
message: z.string(),
|
|
8712
9594
|
passCreditsRemaining: z.number().int().nonnegative().optional()
|
|
8713
9595
|
}).strict();
|
|
9596
|
+
const bookingOutcomesSchema = z.tuple([eventBookingOutcomeSchema]).rest(eventBookingOutcomeSchema).readonly().refine((outcomes) => outcomes.length <= MAX_EVENT_BOOKING_SELECTION_ITEMS, "Too many booking outcomes");
|
|
9597
|
+
const bookingReferencesSchema = z.tuple([eventRegistrationStatusReferenceSchema]).rest(eventRegistrationStatusReferenceSchema).readonly().refine((references) => references.length <= MAX_EVENT_BOOKING_SELECTION_ITEMS, "Too many booking references");
|
|
9598
|
+
const registrationIdsSchema = z.tuple([uuid]).rest(uuid).readonly().refine((ids) => ids.length <= MAX_EVENT_BOOKING_SELECTION_ITEMS, "Too many registrations");
|
|
8714
9599
|
const eventRegisterResponseSchema = z.discriminatedUnion("kind", [
|
|
8715
9600
|
z.object({
|
|
8716
9601
|
kind: z.literal("bookingComplete"),
|
|
8717
9602
|
outcome: eventBookingOutcomeSchema,
|
|
9603
|
+
outcomes: bookingOutcomesSchema.optional(),
|
|
8718
9604
|
summary: eventRegistrationSummarySchema,
|
|
8719
9605
|
...decorations
|
|
8720
9606
|
}).strict(),
|
|
8721
9607
|
z.object({
|
|
8722
9608
|
kind: z.literal("checkoutRequired"),
|
|
8723
9609
|
reference: eventRegistrationStatusReferenceSchema,
|
|
9610
|
+
references: bookingReferencesSchema.optional(),
|
|
8724
9611
|
checkout: eventEmbeddedCheckoutSchema,
|
|
8725
9612
|
submissionId: uuid,
|
|
8726
9613
|
...decorations
|
|
@@ -8746,12 +9633,16 @@ const eventRegisterResponseSchema = z.discriminatedUnion("kind", [
|
|
|
8746
9633
|
}).strict(),
|
|
8747
9634
|
...decorations
|
|
8748
9635
|
}).strict()
|
|
8749
|
-
])
|
|
9636
|
+
]).superRefine((response, ctx) => {
|
|
9637
|
+
if (response.kind === "bookingComplete") validateOutcomeList(response, ctx);
|
|
9638
|
+
if (response.kind === "checkoutRequired") validateReferenceList(response, ctx);
|
|
9639
|
+
});
|
|
8750
9640
|
const checkoutStatusArms = [
|
|
8751
9641
|
z.object({
|
|
8752
9642
|
kind: z.literal("resolved"),
|
|
8753
|
-
outcome: eventBookingOutcomeSchema
|
|
8754
|
-
|
|
9643
|
+
outcome: eventBookingOutcomeSchema,
|
|
9644
|
+
outcomes: bookingOutcomesSchema.optional()
|
|
9645
|
+
}).strict().superRefine(validateOutcomeList),
|
|
8755
9646
|
z.object({ kind: z.literal("abandoned") }).strict(),
|
|
8756
9647
|
z.object({ kind: z.literal("reconciliationRequired") }).strict(),
|
|
8757
9648
|
z.object({
|
|
@@ -8760,6 +9651,7 @@ const checkoutStatusArms = [
|
|
|
8760
9651
|
}).strict(),
|
|
8761
9652
|
z.object({
|
|
8762
9653
|
kind: z.literal("paymentAvailable"),
|
|
9654
|
+
references: bookingReferencesSchema.optional(),
|
|
8763
9655
|
checkout: eventEmbeddedCheckoutSchema,
|
|
8764
9656
|
recoverableUntil: z.string().optional()
|
|
8765
9657
|
}).strict(),
|
|
@@ -8783,8 +9675,7 @@ const eventCheckoutReturnResponseSchema = z.discriminatedUnion("kind", [
|
|
|
8783
9675
|
z.object({ kind: z.literal("reconciliationRequired") }).strict()
|
|
8784
9676
|
]).superRefine((response, ctx) => {
|
|
8785
9677
|
if (response.kind !== "checkout" || response.outcome.kind !== "resolved") return;
|
|
8786
|
-
|
|
8787
|
-
if (identity.scope !== response.subject.scope || identity.submissionId !== response.subject.submissionId || identity.scope === "occurrence" && response.subject.scope === "occurrence" && identity.attendeeId !== response.subject.attendeeId) {
|
|
9678
|
+
if (!identityMatchesSubject(response.outcome.outcome.identity, response.subject)) {
|
|
8788
9679
|
ctx.addIssue({
|
|
8789
9680
|
code: "custom",
|
|
8790
9681
|
message: "Confirmed booking does not match checkout subject",
|
|
@@ -8804,6 +9695,7 @@ const eventCheckoutResponseSchema = z.union([
|
|
|
8804
9695
|
kind: z.literal("completed"),
|
|
8805
9696
|
scope: z.literal("wholeSeries"),
|
|
8806
9697
|
outcome: eventBookingOutcomeSchema,
|
|
9698
|
+
outcomes: bookingOutcomesSchema.optional(),
|
|
8807
9699
|
...checkoutDecorations
|
|
8808
9700
|
}).strict(),
|
|
8809
9701
|
z.object({
|
|
@@ -8817,6 +9709,7 @@ const eventCheckoutResponseSchema = z.union([
|
|
|
8817
9709
|
kind: z.literal("checkoutRequired"),
|
|
8818
9710
|
scope: z.literal("wholeSeries"),
|
|
8819
9711
|
registrationId: uuid,
|
|
9712
|
+
registrationIds: registrationIdsSchema.optional(),
|
|
8820
9713
|
checkoutAttemptId: uuid,
|
|
8821
9714
|
checkout: eventEmbeddedCheckoutSchema,
|
|
8822
9715
|
recoverableUntil: z.string().optional(),
|
|
@@ -8838,16 +9731,65 @@ const eventCheckoutResponseSchema = z.union([
|
|
|
8838
9731
|
...checkoutDecorations
|
|
8839
9732
|
}).strict()
|
|
8840
9733
|
]).superRefine((response, ctx) => {
|
|
8841
|
-
if ("kind" in response
|
|
9734
|
+
if (!("kind" in response)) return;
|
|
9735
|
+
if (response.kind === "completed") {
|
|
9736
|
+
if (response.scope !== response.outcome.identity.scope) ctx.addIssue({
|
|
9737
|
+
code: "custom",
|
|
9738
|
+
message: "Confirmed booking scope mismatch",
|
|
9739
|
+
path: [
|
|
9740
|
+
"outcome",
|
|
9741
|
+
"identity",
|
|
9742
|
+
"scope"
|
|
9743
|
+
]
|
|
9744
|
+
});
|
|
9745
|
+
validateOutcomeList(response, ctx);
|
|
9746
|
+
}
|
|
9747
|
+
if (response.kind === "checkoutRequired" && response.scope === "wholeSeries" && response.registrationIds) {
|
|
9748
|
+
if (response.registrationIds[0] !== response.registrationId || new Set(response.registrationIds).size !== response.registrationIds.length) ctx.addIssue({
|
|
9749
|
+
code: "custom",
|
|
9750
|
+
message: "Registration list does not match its first reference or repeats a booking",
|
|
9751
|
+
path: ["registrationIds"]
|
|
9752
|
+
});
|
|
9753
|
+
}
|
|
9754
|
+
});
|
|
9755
|
+
function bookingReferenceKey(reference) {
|
|
9756
|
+
return reference.scope === "wholeSeries" ? `run:${reference.registrationId}` : `date:${reference.attendeeId}`;
|
|
9757
|
+
}
|
|
9758
|
+
/** Singular fields are aliases of the first member; every member belongs to one submission. */
|
|
9759
|
+
function validateOutcomeList(response, ctx) {
|
|
9760
|
+
const outcomes = response.outcomes;
|
|
9761
|
+
if (!outcomes) return;
|
|
9762
|
+
if (stableJsonStringify(outcomes[0]) !== stableJsonStringify(response.outcome)) ctx.addIssue({
|
|
8842
9763
|
code: "custom",
|
|
8843
|
-
message: "
|
|
8844
|
-
path: [
|
|
8845
|
-
"outcome",
|
|
8846
|
-
"identity",
|
|
8847
|
-
"scope"
|
|
8848
|
-
]
|
|
9764
|
+
message: "First booking outcome does not match the single-booking alias",
|
|
9765
|
+
path: ["outcomes", 0]
|
|
8849
9766
|
});
|
|
8850
|
-
|
|
9767
|
+
const identity = response.outcome.identity;
|
|
9768
|
+
if (outcomes.some((outcome) => outcome.identity.scope !== identity.scope || outcome.identity.submissionId !== identity.submissionId)) ctx.addIssue({
|
|
9769
|
+
code: "custom",
|
|
9770
|
+
message: "Booking outcomes must belong to the same submission and scope",
|
|
9771
|
+
path: ["outcomes"]
|
|
9772
|
+
});
|
|
9773
|
+
const keys = outcomes.map((outcome) => bookingReferenceKey(outcome.identity));
|
|
9774
|
+
if (new Set(keys).size !== keys.length) ctx.addIssue({
|
|
9775
|
+
code: "custom",
|
|
9776
|
+
message: "Booking outcomes repeat a booking",
|
|
9777
|
+
path: ["outcomes"]
|
|
9778
|
+
});
|
|
9779
|
+
}
|
|
9780
|
+
function validateReferenceList(response, ctx) {
|
|
9781
|
+
const references = response.references;
|
|
9782
|
+
if (!references) return;
|
|
9783
|
+
const keys = references.map(bookingReferenceKey);
|
|
9784
|
+
if (keys[0] !== bookingReferenceKey(response.reference) || new Set(keys).size !== keys.length || references.some((reference) => reference.scope !== response.reference.scope)) ctx.addIssue({
|
|
9785
|
+
code: "custom",
|
|
9786
|
+
message: "Booking references must be distinct, share a scope and match the first reference",
|
|
9787
|
+
path: ["references"]
|
|
9788
|
+
});
|
|
9789
|
+
}
|
|
9790
|
+
function identityMatchesSubject(identity, subject) {
|
|
9791
|
+
return identity.scope === subject.scope && identity.submissionId === subject.submissionId && (identity.scope !== "occurrence" || subject.scope !== "occurrence" || identity.attendeeId === subject.attendeeId);
|
|
9792
|
+
}
|
|
8851
9793
|
|
|
8852
9794
|
//#endregion
|
|
8853
9795
|
//#region ../site-contracts/src/siteData/bookingQuestions.ts
|
|
@@ -8861,6 +9803,67 @@ const BEFORE_BOOKING_QUESTIONS_ROUTE = {
|
|
|
8861
9803
|
method: "POST"
|
|
8862
9804
|
};
|
|
8863
9805
|
|
|
9806
|
+
//#endregion
|
|
9807
|
+
//#region ../site-contracts/src/siteData/eventSelection.ts
|
|
9808
|
+
function isHybrid(item) {
|
|
9809
|
+
return item.deliveryMode === "hybrid";
|
|
9810
|
+
}
|
|
9811
|
+
function offeredModes(item) {
|
|
9812
|
+
const delivery = item.deliveryMode ?? "in_person";
|
|
9813
|
+
return delivery === "hybrid" ? (item.attendanceModes ?? []).map((row) => row.mode) : [delivery];
|
|
9814
|
+
}
|
|
9815
|
+
function decideSelectionAttendance(items) {
|
|
9816
|
+
const [first, ...rest] = items;
|
|
9817
|
+
if (!first) return { kind: "none" };
|
|
9818
|
+
const common = rest.reduce((modes, item) => modes.filter((mode) => offeredModes(item).includes(mode)), offeredModes(first));
|
|
9819
|
+
const [only, ...others] = common;
|
|
9820
|
+
if (!items.every(isHybrid)) return only && others.length === 0 ? {
|
|
9821
|
+
kind: "fixed",
|
|
9822
|
+
mode: only
|
|
9823
|
+
} : { kind: "incompatible" };
|
|
9824
|
+
return rest.length > 0 && common.length === 0 ? { kind: "incompatible" } : {
|
|
9825
|
+
kind: "choose",
|
|
9826
|
+
modes: common
|
|
9827
|
+
};
|
|
9828
|
+
}
|
|
9829
|
+
/** The way of attending the booking uses: the fixed one, or the visitor's choice while it's still offered. */
|
|
9830
|
+
function resolveSelectionAttendanceMode(attendance, selected) {
|
|
9831
|
+
switch (attendance.kind) {
|
|
9832
|
+
case "none":
|
|
9833
|
+
case "incompatible": return null;
|
|
9834
|
+
case "fixed": return attendance.mode;
|
|
9835
|
+
case "choose": return selected !== null && attendance.modes.includes(selected) ? selected : null;
|
|
9836
|
+
}
|
|
9837
|
+
}
|
|
9838
|
+
const INCOMPATIBLE_ATTENDANCE_MESSAGE = "These runs can’t be booked together, because they don’t share a way to attend. Book them one at a time.";
|
|
9839
|
+
|
|
9840
|
+
//#endregion
|
|
9841
|
+
//#region ../site-contracts/src/siteData/eventSelectionRequirements.ts
|
|
9842
|
+
/** The consent text is its version: attachment IDs alone do not change when copy is edited. */
|
|
9843
|
+
function eventBookingConsentContentKey(consent) {
|
|
9844
|
+
return stableJsonStringify({
|
|
9845
|
+
title: consent.title,
|
|
9846
|
+
agreement: consent.agreement,
|
|
9847
|
+
checkboxLabel: consent.checkboxLabel
|
|
9848
|
+
});
|
|
9849
|
+
}
|
|
9850
|
+
/** Unavailable or older question payloads cannot prove that sharing is safe. */
|
|
9851
|
+
function areEventBookingRequirementsIdentical(requirements) {
|
|
9852
|
+
const keys = requirements.map(requirementsKey);
|
|
9853
|
+
const first = keys[0];
|
|
9854
|
+
return first !== undefined && first !== null && keys.every((key) => key === first);
|
|
9855
|
+
}
|
|
9856
|
+
function requirementsKey(view) {
|
|
9857
|
+
const questions = view.bookingQuestions;
|
|
9858
|
+
if (questions.kind === "unavailable") return null;
|
|
9859
|
+
const questionKey = questions.kind === "none" ? null : questions.set.sharingKey;
|
|
9860
|
+
if (questionKey === undefined) return null;
|
|
9861
|
+
return stableJsonStringify({
|
|
9862
|
+
consent: view.consent ? eventBookingConsentContentKey(view.consent) : null,
|
|
9863
|
+
questions: questionKey
|
|
9864
|
+
});
|
|
9865
|
+
}
|
|
9866
|
+
|
|
8864
9867
|
//#endregion
|
|
8865
9868
|
//#region ../api/src/publicEventEndpointDefinitions.ts
|
|
8866
9869
|
const PUBLIC_EVENT_ENDPOINT_DEFINITIONS = defineEndpointDefinitions({
|
|
@@ -9191,6 +10194,13 @@ const EVENT_MANAGEMENT_ENDPOINT_DEFINITIONS = defineEndpointDefinitions({
|
|
|
9191
10194
|
"server:internal_error"
|
|
9192
10195
|
]
|
|
9193
10196
|
},
|
|
10197
|
+
getEventGoLivePage: {
|
|
10198
|
+
path: "/sites/{siteId}/bookings/events/{eventId}/go-live-page",
|
|
10199
|
+
method: "GET",
|
|
10200
|
+
auth: "user",
|
|
10201
|
+
responseKind: "json",
|
|
10202
|
+
errors: ["validation:invalid_input", "server:internal_error"]
|
|
10203
|
+
},
|
|
9194
10204
|
updateEventIdentity: {
|
|
9195
10205
|
path: "/sites/{siteId}/bookings/events/{eventId}",
|
|
9196
10206
|
method: "PATCH",
|
|
@@ -9787,6 +10797,30 @@ const PUBLIC_ONBOARDING_ATTEMPT_ENDPOINT_DEFINITIONS = defineEndpointDefinitions
|
|
|
9787
10797
|
//#endregion
|
|
9788
10798
|
//#region ../api/src/billingEndpointDefinitions.ts
|
|
9789
10799
|
const BILLING_ENDPOINT_DEFINITIONS = defineEndpointDefinitions({
|
|
10800
|
+
adminSendSiteHandover: {
|
|
10801
|
+
path: "/admin/sites/{siteId}/handover",
|
|
10802
|
+
method: "POST",
|
|
10803
|
+
tags: ["admin"],
|
|
10804
|
+
auth: "admin",
|
|
10805
|
+
responseKind: "json",
|
|
10806
|
+
errors: []
|
|
10807
|
+
},
|
|
10808
|
+
adminResendSiteHandover: {
|
|
10809
|
+
path: "/admin/sites/{siteId}/handover/resend",
|
|
10810
|
+
method: "POST",
|
|
10811
|
+
tags: ["admin"],
|
|
10812
|
+
auth: "admin",
|
|
10813
|
+
responseKind: "json",
|
|
10814
|
+
errors: []
|
|
10815
|
+
},
|
|
10816
|
+
adminWithdrawSiteHandover: {
|
|
10817
|
+
path: "/admin/sites/{siteId}/handover/withdraw",
|
|
10818
|
+
method: "POST",
|
|
10819
|
+
tags: ["admin"],
|
|
10820
|
+
auth: "admin",
|
|
10821
|
+
responseKind: "json",
|
|
10822
|
+
errors: []
|
|
10823
|
+
},
|
|
9790
10824
|
adminChangePlan: {
|
|
9791
10825
|
path: "/admin/billing/plan",
|
|
9792
10826
|
method: "POST",
|
|
@@ -10781,6 +11815,18 @@ const ENDPOINT_DEFINITIONS = {
|
|
|
10781
11815
|
"server:internal_error"
|
|
10782
11816
|
]
|
|
10783
11817
|
},
|
|
11818
|
+
turnOnCourses: {
|
|
11819
|
+
path: "/sites/{siteId}/bookings/settings/courses",
|
|
11820
|
+
method: "POST",
|
|
11821
|
+
tags: [TAG_TEMPLATES.site, TAG_TEMPLATES.siteBookingSettings],
|
|
11822
|
+
auth: "user",
|
|
11823
|
+
responseKind: "json",
|
|
11824
|
+
errors: [
|
|
11825
|
+
"auth:forbidden",
|
|
11826
|
+
"resource:conflict",
|
|
11827
|
+
"server:internal_error"
|
|
11828
|
+
]
|
|
11829
|
+
},
|
|
10784
11830
|
sendTestEmail: {
|
|
10785
11831
|
path: "/sites/{siteId}/settings/emails/test",
|
|
10786
11832
|
method: "POST",
|
|
@@ -10863,6 +11909,30 @@ const ENDPOINT_DEFINITIONS = {
|
|
|
10863
11909
|
responseKind: "json",
|
|
10864
11910
|
errors: ["auth:forbidden", "server:internal_error"]
|
|
10865
11911
|
},
|
|
11912
|
+
authEmailCodeSend: {
|
|
11913
|
+
path: "/auth/email-code/send",
|
|
11914
|
+
method: "POST",
|
|
11915
|
+
tags: ["auth"],
|
|
11916
|
+
auth: "public",
|
|
11917
|
+
responseKind: "json",
|
|
11918
|
+
errors: []
|
|
11919
|
+
},
|
|
11920
|
+
authEmailCodeVerify: {
|
|
11921
|
+
path: "/auth/email-code/verify",
|
|
11922
|
+
method: "POST",
|
|
11923
|
+
tags: ["auth"],
|
|
11924
|
+
auth: "public",
|
|
11925
|
+
responseKind: "json",
|
|
11926
|
+
errors: []
|
|
11927
|
+
},
|
|
11928
|
+
authForgetEmail: {
|
|
11929
|
+
path: "/auth/remembered-email/clear",
|
|
11930
|
+
method: "POST",
|
|
11931
|
+
tags: ["auth"],
|
|
11932
|
+
auth: "public",
|
|
11933
|
+
responseKind: "json",
|
|
11934
|
+
errors: []
|
|
11935
|
+
},
|
|
10866
11936
|
authLogin: {
|
|
10867
11937
|
path: "/auth/login/submit",
|
|
10868
11938
|
method: "POST",
|
|
@@ -10891,6 +11961,22 @@ const ENDPOINT_DEFINITIONS = {
|
|
|
10891
11961
|
auth: "public",
|
|
10892
11962
|
responseKind: "json"
|
|
10893
11963
|
},
|
|
11964
|
+
authReauthEmailCodeSend: {
|
|
11965
|
+
path: "/auth/reauth/email-code",
|
|
11966
|
+
method: "POST",
|
|
11967
|
+
tags: ["auth"],
|
|
11968
|
+
auth: "user",
|
|
11969
|
+
errors: [],
|
|
11970
|
+
responseKind: "json"
|
|
11971
|
+
},
|
|
11972
|
+
authReauthEmailCodeVerify: {
|
|
11973
|
+
path: "/auth/reauth/email-code/verify",
|
|
11974
|
+
method: "POST",
|
|
11975
|
+
tags: ["auth"],
|
|
11976
|
+
auth: "user",
|
|
11977
|
+
errors: [],
|
|
11978
|
+
responseKind: "json"
|
|
11979
|
+
},
|
|
10894
11980
|
authStatus: {
|
|
10895
11981
|
path: "/auth/status",
|
|
10896
11982
|
method: "GET",
|
|
@@ -10948,6 +12034,14 @@ const ENDPOINT_DEFINITIONS = {
|
|
|
10948
12034
|
auth: "user",
|
|
10949
12035
|
responseKind: "json"
|
|
10950
12036
|
},
|
|
12037
|
+
dismissSiteInviteWelcome: {
|
|
12038
|
+
path: "/sites/{siteId}/members/invite-welcome/dismiss",
|
|
12039
|
+
method: "POST",
|
|
12040
|
+
auth: "user",
|
|
12041
|
+
responseKind: "json",
|
|
12042
|
+
errors: ["auth:forbidden", "server:internal_error"],
|
|
12043
|
+
tags: ["site-{siteId}"]
|
|
12044
|
+
},
|
|
10951
12045
|
revokeSiteInvitation: {
|
|
10952
12046
|
path: "/sites/{siteId}/members/invitations/{invitationId}",
|
|
10953
12047
|
method: "DELETE",
|
|
@@ -12060,6 +13154,22 @@ const ENDPOINT_DEFINITIONS = {
|
|
|
12060
13154
|
auth: "user",
|
|
12061
13155
|
responseKind: "json"
|
|
12062
13156
|
},
|
|
13157
|
+
mfaRenameFactor: {
|
|
13158
|
+
path: "/auth/mfa/factors/{factorId}",
|
|
13159
|
+
method: "PATCH",
|
|
13160
|
+
tags: ["mfa"],
|
|
13161
|
+
auth: "user",
|
|
13162
|
+
errors: [],
|
|
13163
|
+
responseKind: "json"
|
|
13164
|
+
},
|
|
13165
|
+
mfaTurnOff: {
|
|
13166
|
+
path: "/auth/mfa/turn-off",
|
|
13167
|
+
method: "POST",
|
|
13168
|
+
tags: ["mfa"],
|
|
13169
|
+
auth: "user",
|
|
13170
|
+
errors: [],
|
|
13171
|
+
responseKind: "json"
|
|
13172
|
+
},
|
|
12063
13173
|
mfaBackupCodesGet: {
|
|
12064
13174
|
path: "/auth/mfa/backup-codes",
|
|
12065
13175
|
method: "GET",
|
|
@@ -12114,6 +13224,18 @@ const ENDPOINT_DEFINITIONS = {
|
|
|
12114
13224
|
],
|
|
12115
13225
|
responseKind: "json"
|
|
12116
13226
|
},
|
|
13227
|
+
accountDismissTwoStepPrompt: {
|
|
13228
|
+
path: "/account/two-step-prompt/dismiss",
|
|
13229
|
+
method: "POST",
|
|
13230
|
+
tags: ["account"],
|
|
13231
|
+
auth: "user",
|
|
13232
|
+
errors: [
|
|
13233
|
+
"auth:unauthenticated",
|
|
13234
|
+
"validation:invalid_input",
|
|
13235
|
+
"server:internal_error"
|
|
13236
|
+
],
|
|
13237
|
+
responseKind: "json"
|
|
13238
|
+
},
|
|
12117
13239
|
accountRevokeSessions: {
|
|
12118
13240
|
path: "/account/sessions/revoke",
|
|
12119
13241
|
method: "POST",
|
|
@@ -12121,6 +13243,22 @@ const ENDPOINT_DEFINITIONS = {
|
|
|
12121
13243
|
auth: "user",
|
|
12122
13244
|
responseKind: "json"
|
|
12123
13245
|
},
|
|
13246
|
+
accountRevokeSession: {
|
|
13247
|
+
path: "/account/sessions/{sessionId}",
|
|
13248
|
+
method: "DELETE",
|
|
13249
|
+
tags: ["account"],
|
|
13250
|
+
auth: "user",
|
|
13251
|
+
errors: [],
|
|
13252
|
+
responseKind: "json"
|
|
13253
|
+
},
|
|
13254
|
+
accountUnlinkGoogle: {
|
|
13255
|
+
path: "/account/identities/google",
|
|
13256
|
+
method: "DELETE",
|
|
13257
|
+
tags: ["account"],
|
|
13258
|
+
auth: "user",
|
|
13259
|
+
errors: [],
|
|
13260
|
+
responseKind: "json"
|
|
13261
|
+
},
|
|
12124
13262
|
adminListInvites: {
|
|
12125
13263
|
path: "/admin/invites",
|
|
12126
13264
|
method: "GET",
|
|
@@ -17729,6 +18867,13 @@ function resolveBookingSettingsEventCatalogue(settings) {
|
|
|
17729
18867
|
eventTypePresets: settings.eventTypePresets ?? DEFAULT_EVENT_TYPE_PRESETS
|
|
17730
18868
|
});
|
|
17731
18869
|
}
|
|
18870
|
+
/** Normalizes the same wire default as the catalogue before planning the change. */
|
|
18871
|
+
function planBookingSettingsCoursesTurnOn(settings) {
|
|
18872
|
+
return planTurningOnCourses({
|
|
18873
|
+
verticalConfig: settings.verticalConfig,
|
|
18874
|
+
eventTypePresets: settings.eventTypePresets ?? DEFAULT_EVENT_TYPE_PRESETS
|
|
18875
|
+
});
|
|
18876
|
+
}
|
|
17732
18877
|
|
|
17733
18878
|
//#endregion
|
|
17734
18879
|
//#region ../api/src/sdkManagementResponseSchemas.ts
|
|
@@ -19483,6 +20628,7 @@ const lookKnobBlocks = {
|
|
|
19483
20628
|
showPhotos: cardListKnobBlocks,
|
|
19484
20629
|
cardMarker: cardListFamilyBlocks,
|
|
19485
20630
|
dates: "block.offerings-preview",
|
|
20631
|
+
grouping: "block.offerings-preview",
|
|
19486
20632
|
columns: "block.feature-cards",
|
|
19487
20633
|
listColumns: "block.event-calendar",
|
|
19488
20634
|
blackAndWhite: "block.image-gallery",
|
|
@@ -21746,16 +22892,6 @@ async function confirmAction(message, options, isRemote) {
|
|
|
21746
22892
|
});
|
|
21747
22893
|
});
|
|
21748
22894
|
}
|
|
21749
|
-
/** Environment target/client helpers are backed by the execution boundary. */
|
|
21750
|
-
/**
|
|
21751
|
-
* Create a management client for a specific environment target.
|
|
21752
|
-
*
|
|
21753
|
-
* @param target - Environment target (local or remote)
|
|
21754
|
-
* @returns Management client configured for that environment
|
|
21755
|
-
*/
|
|
21756
|
-
function createClientForEnv(target) {
|
|
21757
|
-
return createManagementClient(managementClientConfigFor(loadSdkEnvironment(target)));
|
|
21758
|
-
}
|
|
21759
22895
|
/**
|
|
21760
22896
|
* Resolve the environment setting from global options.
|
|
21761
22897
|
* Handles --env flag and deprecated --remote flag.
|
|
@@ -22003,95 +23139,6 @@ function withConfirmation(getMessage, action) {
|
|
|
22003
23139
|
}
|
|
22004
23140
|
};
|
|
22005
23141
|
}
|
|
22006
|
-
/**
|
|
22007
|
-
* Capitalize the first letter of a string.
|
|
22008
|
-
*/
|
|
22009
|
-
function capitalize(str) {
|
|
22010
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
22011
|
-
}
|
|
22012
|
-
/**
|
|
22013
|
-
* Create a get command for a resource.
|
|
22014
|
-
*
|
|
22015
|
-
* @example
|
|
22016
|
-
* const getCommand = createGetCommand({
|
|
22017
|
-
* resourceName: 'entry',
|
|
22018
|
-
* args: ['type', 'identifier'],
|
|
22019
|
-
* get: (client, type, id) => client.entries.get(type, id),
|
|
22020
|
-
* formatOutput: (entry) => ({
|
|
22021
|
-
* id: entry.id,
|
|
22022
|
-
* status: entry.status,
|
|
22023
|
-
* }),
|
|
22024
|
-
* });
|
|
22025
|
-
*/
|
|
22026
|
-
function createGetCommand(config) {
|
|
22027
|
-
const cmd = new Command("get").description(`Get a single ${config.resourceName}`);
|
|
22028
|
-
for (const arg of config.args) {
|
|
22029
|
-
cmd.argument(`<${arg}>`, `${capitalize(arg.replace("-", " "))}`);
|
|
22030
|
-
}
|
|
22031
|
-
return cmd.action(withErrorHandling(async (...actionArgs) => {
|
|
22032
|
-
const args = actionArgs.slice(0, config.args.length);
|
|
22033
|
-
const command = actionArgs[actionArgs.length - 1];
|
|
22034
|
-
const { output, client, isJsonOutput } = createCommandContext(command);
|
|
22035
|
-
const label = args.join("/");
|
|
22036
|
-
const item = await config.get(client, ...args);
|
|
22037
|
-
if (!item) {
|
|
22038
|
-
return output.error(`${capitalize(config.resourceName)} not found: ${label}`, { suggestion: `Check that the ${config.args.join(" and ")} ${config.args.length > 1 ? "are" : "is"} correct` });
|
|
22039
|
-
}
|
|
22040
|
-
if (isJsonOutput) {
|
|
22041
|
-
output.json(item);
|
|
22042
|
-
} else {
|
|
22043
|
-
output.success(`${capitalize(config.resourceName)}: ${label}`, config.formatOutput(item));
|
|
22044
|
-
}
|
|
22045
|
-
}));
|
|
22046
|
-
}
|
|
22047
|
-
/**
|
|
22048
|
-
* Create a list command for a resource.
|
|
22049
|
-
*
|
|
22050
|
-
* @example
|
|
22051
|
-
* const listCommand = createListCommand({
|
|
22052
|
-
* resourceName: 'entry',
|
|
22053
|
-
* resourceNamePlural: 'entries',
|
|
22054
|
-
* args: ['type'],
|
|
22055
|
-
* hasPagination: true,
|
|
22056
|
-
* list: (client, [type], pagination) => client.entries.list(type, pagination),
|
|
22057
|
-
* tableHeaders: ['Identifier', 'Status', 'Updated'],
|
|
22058
|
-
* formatRow: (entry) => [entry.identifier, entry.status, entry.updatedAt],
|
|
22059
|
-
* });
|
|
22060
|
-
*/
|
|
22061
|
-
function createListCommand(config) {
|
|
22062
|
-
const cmd = new Command("list").description(`List ${config.resourceNamePlural}`);
|
|
22063
|
-
for (const arg of config.args) {
|
|
22064
|
-
cmd.argument(`<${arg}>`, `${capitalize(arg.replace("-", " "))}`);
|
|
22065
|
-
}
|
|
22066
|
-
if (config.hasPagination) {
|
|
22067
|
-
cmd.option("--limit <n>", "Number of items per page", "20");
|
|
22068
|
-
cmd.option("--page <n>", "Page number", "1");
|
|
22069
|
-
}
|
|
22070
|
-
return cmd.action(withErrorHandling(async (...actionArgs) => {
|
|
22071
|
-
const args = actionArgs.slice(0, config.args.length);
|
|
22072
|
-
const options = actionArgs[config.args.length];
|
|
22073
|
-
const command = actionArgs[actionArgs.length - 1];
|
|
22074
|
-
const { output, client, isJsonOutput } = createCommandContext(command);
|
|
22075
|
-
const pagination = config.hasPagination ? parsePaginationOptions(options) : undefined;
|
|
22076
|
-
const result = await config.list(client, args, pagination);
|
|
22077
|
-
if (isJsonOutput) {
|
|
22078
|
-
output.json({
|
|
22079
|
-
[config.resourceNamePlural]: result.items,
|
|
22080
|
-
...result.pagination && { pagination: result.pagination }
|
|
22081
|
-
});
|
|
22082
|
-
} else if (result.items.length === 0) {
|
|
22083
|
-
const context = args.length > 0 ? ` for ${args.join("/")}` : "";
|
|
22084
|
-
output.info(`No ${config.resourceNamePlural} found${context}`);
|
|
22085
|
-
} else {
|
|
22086
|
-
output.table(config.tableHeaders, result.items.map(config.formatRow));
|
|
22087
|
-
if (result.pagination) {
|
|
22088
|
-
output.info(`Showing ${result.items.length} of ${result.pagination.total} ${config.resourceNamePlural} (page ${result.pagination.page})`);
|
|
22089
|
-
} else {
|
|
22090
|
-
output.info(`${result.items.length} ${config.resourceNamePlural}`);
|
|
22091
|
-
}
|
|
22092
|
-
}
|
|
22093
|
-
}));
|
|
22094
|
-
}
|
|
22095
23142
|
|
|
22096
23143
|
//#endregion
|
|
22097
23144
|
//#region src/environment-outcome-json.ts
|
|
@@ -23576,7 +24623,7 @@ function buildPreviewSummary(sync) {
|
|
|
23576
24623
|
}
|
|
23577
24624
|
|
|
23578
24625
|
//#endregion
|
|
23579
|
-
//#region src/push-config.ts
|
|
24626
|
+
//#region src/legacy/push-config.ts
|
|
23580
24627
|
/**
|
|
23581
24628
|
* push-config CLI command
|
|
23582
24629
|
*
|
|
@@ -24737,7 +25784,7 @@ async function adminClearSitePublicCache(apiClient, siteId, options) {
|
|
|
24737
25784
|
//#region ../api/src/accessAdmin.ts
|
|
24738
25785
|
function getDefaultStaffCapabilities(surfaces) {
|
|
24739
25786
|
if (surfaces.events && !surfaces.appointments) return ["event_ops"];
|
|
24740
|
-
return ["appointments"];
|
|
25787
|
+
return surfaces.appointments ? ["appointments", "packages"] : ["appointments"];
|
|
24741
25788
|
}
|
|
24742
25789
|
const managedDomainAddOnPricingSnapshotSchema = z.object({
|
|
24743
25790
|
formulaVersion: z.literal("managed-domain-overage-v2"),
|
|
@@ -24817,7 +25864,7 @@ async function linkCurrentUserPractitioner(apiClient, { siteId, body, options })
|
|
|
24817
25864
|
options
|
|
24818
25865
|
}));
|
|
24819
25866
|
} catch (error) {
|
|
24820
|
-
return normalizeApiError(error, "
|
|
25867
|
+
return normalizeApiError(error, "We couldn’t link that profile.");
|
|
24821
25868
|
}
|
|
24822
25869
|
}
|
|
24823
25870
|
async function unlinkCurrentUserPractitioner(apiClient, { siteId, options }) {
|
|
@@ -24828,7 +25875,7 @@ async function unlinkCurrentUserPractitioner(apiClient, { siteId, options }) {
|
|
|
24828
25875
|
options
|
|
24829
25876
|
}));
|
|
24830
25877
|
} catch (error) {
|
|
24831
|
-
return normalizeApiError(error, "
|
|
25878
|
+
return normalizeApiError(error, "We couldn’t unlink that profile.");
|
|
24832
25879
|
}
|
|
24833
25880
|
}
|
|
24834
25881
|
async function removeSiteMember(apiClient, { siteId, memberId, options }) {
|
|
@@ -25451,7 +26498,7 @@ const SETTINGS_SURFACE_POLICIES = {
|
|
|
25451
26498
|
surfaceId: "settings.bookings",
|
|
25452
26499
|
navVisibilityPolicy: administratorPolicy,
|
|
25453
26500
|
pageAccessPolicy: administratorPolicy,
|
|
25454
|
-
actionIds: []
|
|
26501
|
+
actionIds: ["bookings.updateSettings", "bookings.turnOnCourses"]
|
|
25455
26502
|
},
|
|
25456
26503
|
"settings.redirects": {
|
|
25457
26504
|
surfaceId: "settings.redirects",
|
|
@@ -25538,6 +26585,8 @@ const SETTINGS_SURFACE_POLICIES = {
|
|
|
25538
26585
|
};
|
|
25539
26586
|
const SETTINGS_ACTION_POLICIES = {
|
|
25540
26587
|
"privacy.update": administratorPolicy,
|
|
26588
|
+
"bookings.updateSettings": editorPolicy,
|
|
26589
|
+
"bookings.turnOnCourses": editorPolicy,
|
|
25541
26590
|
"emails.read": editorPolicy,
|
|
25542
26591
|
"emails.update": administratorPolicy,
|
|
25543
26592
|
"emails.updateSendSetting": editorPolicy,
|
|
@@ -26284,13 +27333,13 @@ function createAccountApi(apiClient) {
|
|
|
26284
27333
|
return response;
|
|
26285
27334
|
},
|
|
26286
27335
|
async listSites(input = {}) {
|
|
26287
|
-
const search = input.query?.search?.trim();
|
|
27336
|
+
const search$1 = input.query?.search?.trim();
|
|
26288
27337
|
const response = parseSuccessfulData("accountListSites", await apiClient({
|
|
26289
27338
|
endpoint: "accountListSites",
|
|
26290
27339
|
...input.query ? { params: {
|
|
26291
27340
|
...input.query.cursor ? { cursor: input.query.cursor } : {},
|
|
26292
27341
|
...input.query.limit !== undefined ? { limit: String(input.query.limit) } : {},
|
|
26293
|
-
...search ? { search } : {}
|
|
27342
|
+
...search$1 ? { search: search$1 } : {}
|
|
26294
27343
|
} } : {},
|
|
26295
27344
|
options: input.options
|
|
26296
27345
|
}), listSitesResponseSchema);
|
|
@@ -27033,6 +28082,33 @@ async function reorderNavigationItems(apiClient, { siteId, menuId, items, option
|
|
|
27033
28082
|
normalizeApiError(error, "Failed to reorder navigation items");
|
|
27034
28083
|
}
|
|
27035
28084
|
}
|
|
28085
|
+
/** Resolved partitions own the navigation facts used by footer layout planning. */
|
|
28086
|
+
function footerNavigationFacts(menu) {
|
|
28087
|
+
return {
|
|
28088
|
+
hasFooterNavigation: menu.groups.length > 0 || menu.links.length > 0,
|
|
28089
|
+
navigationGroups: [...menu.groups, ...menu.links.length ? [{ label: null }] : []]
|
|
28090
|
+
};
|
|
28091
|
+
}
|
|
28092
|
+
/**
|
|
28093
|
+
* The one owner of the navigation facts a footer plans its layout with, read from the
|
|
28094
|
+
* stored menus' shape: a root item with children is a labelled group, any other root
|
|
28095
|
+
* link joins the unlabelled set. Route resolution plays no part, so the served site,
|
|
28096
|
+
* the SDK and the editor preview (which has no route map) all decide alike, and a link
|
|
28097
|
+
* that needs a route can't drop the whole links module.
|
|
28098
|
+
*/
|
|
28099
|
+
function footerMenuNavigationFacts(menus) {
|
|
28100
|
+
const items = menus.find((menu) => menu.location === "footer")?.items ?? [];
|
|
28101
|
+
const roots = items.filter((item) => !item.parentId);
|
|
28102
|
+
const groups = roots.filter((item) => items.some((child) => child.parentId === item.id));
|
|
28103
|
+
const links = roots.filter((item) => item.urlType !== "dropdown" && !groups.includes(item));
|
|
28104
|
+
return {
|
|
28105
|
+
...footerNavigationFacts({
|
|
28106
|
+
groups,
|
|
28107
|
+
links
|
|
28108
|
+
}),
|
|
28109
|
+
hasLegalPolicyNavigation: menus.some((menu) => menu.location === "legal" && menu.items.length > 0)
|
|
28110
|
+
};
|
|
28111
|
+
}
|
|
27036
28112
|
|
|
27037
28113
|
//#endregion
|
|
27038
28114
|
//#region src/sync/mapper.ts
|
|
@@ -33200,4 +34276,4 @@ function optionalTitle(data) {
|
|
|
33200
34276
|
}
|
|
33201
34277
|
|
|
33202
34278
|
//#endregion
|
|
33203
|
-
export { normalizeMediaValueToIdentifierOnly as $,
|
|
34279
|
+
export { normalizeMediaValueToIdentifierOnly as $, resolveRepeaterGridSpanFieldId as $n, ApiEnvelopeError as $r, bindRequestTimeout as $t, formatDiffDetail as A, getEnvPrefix as An, getStripeMinimumChargeRequirement as Ar, navigationIdentity as At, buildFieldChanges as B, NodeSchema as Bn, publicProductSchema as Br, ACCOUNT_SITE_LIST_LIMIT_MIN as Bt, reportFromOutcomes as C, requireEnvironmentWriteAuthorization as Cn, unsafeAsPositiveCheckoutQuantity as Cr, fileExists$1 as Ct, normalizeRemoteHomepageReference as D, transportSuggestion as Dn, repriceBookingCollectionOptions as Dr, writeJsonFileAtomic as Dt, createEmptySyncResult as E, formatError as En, isBookingCollectionEquivalentToUpfront as Er, writeJsonFile$1 as Et, calculatePullDiff as F, createManagementClient as Fn, eventCalendarListLayoutCompatibleDisplayModeValues as Fr, AccountApiMalformedResponseError as Ft, syncLocalMediaForPull as G, blockContentSourceSchema as Gn, calendarMonthWindowSchema as Gr, applyPushConfigPlan as Gt, formatFieldPath as H, bindingSchema as Hn, purchasablePublicPassProductSchema as Hr, ACCOUNT_SITE_TITLE_MAX_LENGTH as Ht, buildJsonDiff as I, cardListBlockParts as In, eventCalendarListLayoutValues as Ir, createBearerAccountApi as It, admitBinaryWriteDestination as J, MAX_REPEATER_GRID_COLUMNS as Jn, eventSurfacePresetValues as Jr, preparePushConfigTarget as Jt, applyLocalMediaPush as K, blockRequiredFeatureSchema as Kn, calendarSourceCursorSchema as Kr, createPushConfigCommand as Kt, hasPageOperations as L, cardListFamilyBlocks as Ln, publicVenueMapLocationSchema as Lr, ACCOUNT_SITE_CURSOR_MAX_LENGTH as Lt, hasPendingChanges as M, isLocalConfigured as Mn, MAX_EVENT_BOOKING_SELECTION_ITEMS as Mr, convertPulledFooterToLocal as Mt, findChangedFieldsWithValues as N, isRemoteConfigured as Nn, eventCalendarDefaultViewValues as Nr, convertPulledNavigationToLocal as Nt, calculateDiff as O, CliExit as On, resolveAvailableBookingCollectionOptions as Or, isMediaValue as Ot, formatHumanDiff as P, loadSdkEnvironment as Pn, eventCalendarDisplayModeValues as Pr, convertPulledPagesToLocal as Pt, normalizeMediaIdentifierInput as Q, resolveRepeaterGridRowFieldId as Qn, publicEventLoaderQuerySchemaShape as Qr, mapEnvironmentExecutionOutcomesJson as Qt, pageMetadataForUpsert as R, cardListKnobBlocks as Rn, publicMembershipProductSchema as Rr, ACCOUNT_SITE_LIST_LIMIT_DEFAULT as Rt, planCliCommandBatchForBindings as S, planEnvironmentWriteAuthorization as Sn, checkoutCopy as Sr, ensureDir$1 as St, executeResidualSettingsSyncPlan as T, ErrorCodes as Tn, planFlexibleBalanceCreditFirst as Tr, readJsonFile as Tt, revalidateLocalMediaPushPlan as U, DEFAULT_MEDIA_FIELD_KINDS as Un, CALENDAR_SSR_PAGE_SIZE as Ur, navigationCommandItemToManagementInput as Ut, formatFieldChange as V, NodeTreeSchema as Vn, purchasablePublicMembershipProductSchema as Vr, ACCOUNT_SITE_SEARCH_MAX_LENGTH as Vt, syncLocalMediaForPush as W, blockCategoryEnum as Wn, calendarMonthDate as Wr, normalizeNavigationConfigItemForCommand as Wt, writeBinaryFileAtomic as X, parseRepeaterGridInteger as Xn, monthNumber as Xr, createBearerAPIClient as Xt, readStableBinaryFile as Y, isAcceptedRepeaterGridSpan as Yn, eventSurfaceScopeValues as Yr, revalidatePushConfigPlan as Yt, sha256 as Z, resolveRepeaterGridColumnFieldId as Zn, normalizeCalendarFilterId as Zr, deriveCmsApiUrlFromDashboardUrl as Zt, commandExecutionToReport as _, withErrorHandling as _n, decideSelectionAttendance as _r, metadataFilePath as _t, executeEntryCommandPlanAsReport as a, getOutputContext as an, ApiRequestError as ar, readEntries as at, executeCompiledCliCommandPlanAsReport as b, parseEnvironmentSelection as bn, nextCombinationHint as br, writeMetadataFile as bt, titleFromEntryData as c, managementClientConfigFor as cn, linkPayloadSchema as cr, readEventsMeta as ct, unsafeAsCliEntryIdentifier as d, parseJsonData as dn, pageDesignIntentSchemaVersion as dr, readNavigationMeta as dt, unwrapResponse as ei, confirmAction as en, visibilityLevels as er, walkLocalContentMedia as et, unsafeAsCliFormSlug as f, parsePaginationOptions as fn, sdkConfiguredBookingVerticalConfigSchema as fr, readPagesMeta as ft, commandCompileFailureToReport as g, withConfirmation as gn, INCOMPATIBLE_ATTENDANCE_MESSAGE as gr, ensureMetadataDir as gt, mutationCounterForEffect as h, withCommandContext as hn, eventBookingConsentContentKey as hr, writeMediaManifest as ht, entrySiteCommandTypes as i, formatDateShort as in, isRecord$5 as ir, findLegacyEntryFiles as it, formatDiffSummary as j, getEnvironmentDebugInfo as jn, getBookingLaterInstalments as jr, navigationIdentityMap as jt, calculateFooterDiff as k, createOutput as kn, resolveBookingCollectionOptionFacts as kr, duplicateNavigationIdentityMessage as kt, unsafeAsCliBlockIdentifier as l, mapEntryForOutput as ln, portablePageDesignSchema as lr, readFooterMeta as lt, commandReportToSyncResult as m, runWithInvocation as mn, areEventBookingRequirementsIdentical as mr, readVenuesMeta as mt, entryCommandCompileErrorToReport as n, createOutputForCommand as nn, extractApiErrorMessage as nr, downloadMedia as nt, executeEntryCommandPlanAsSyncResult as o, getOutputOnlyContext as on, sdkEventScheduleSchema as or, readAllMeta as ot, unsafeAsCliPageIdentifier as p, resolveCommandPath as pn, API_ENDPOINTS as pr, readSettingsMeta as pt, prepareLocalMediaForPush as q, fieldSchema as qn, eventScheduleScopeValues as qr, loadPushConfigTarget as qt, entryCommandReportToSyncResult as r, currentInvocationEnvelope as rn, normalizeApiError as rr, extractMediaIdentifiers as rt, syncResultForEntryCommandCompileError as s, handleCommandError as sn, sdkSettingsUpdateSchema as sr, readEventCategoriesMeta as st, compileEntryPushCommands as t, createCommandContext as tn, ManagementApiError as tr, buildStorageUrl as tt, unsafeAsCliContentTypeKey as u, parseJsonArray as un, pageDesignDecisionsV2Schema as ur, readFormsMeta as ut, commandReportHasFailures as v, withOutputOnlyErrorHandling as vn, resolveSelectionAttendanceMode as vr, metadataTargetFromEnvironment as vt, mergeManySyncResults as w, withRiverbankEnv as wn, planCheckoutPaymentFlow as wr, listFiles as wt, formatManagementError as x, planEnvironmentExecution as xn, planSelectionCombinationPrices as xr, writeMetadataRecordMap as xt, executeCliCommandPlan as y, executeEnvironmentPlan as yn, checkoutStatusArms as yr, readMetadataFile as yt, calculateEntryDiffs as z, lookKnobBlocks as zn, publicPassProductSchema as zr, ACCOUNT_SITE_LIST_LIMIT_MAX as zt };
|