@wix/himalaya-cli 0.1659.0 → 0.1661.0
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/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/attendance-classifier.d.ts +3 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/delivery-contract.d.ts +3 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/index.d.ts +7 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/wix-payments-contract.d.ts +19 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/wix-payments-wire.d.ts +2 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/sdk-types/src/capabilities.generated.d.ts +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/apple-iap-contract.d.ts +33 -7
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/commerce-contract.d.ts +4 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-order-backend.d.ts +5 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/attendance-orders.d.ts +10 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/attendance.d.ts +4 -5
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/index.d.ts +13 -3
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/online-programs-orders.d.ts +2 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/online-programs.d.ts +2 -2
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/pricing-plans-orders.d.ts +2 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/pricing-plans.d.ts +4 -2
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/shared.d.ts +3 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/order-refs.d.ts +8 -4
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/audio-record.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/calendar.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/calls.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/contacts.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap-checkout.mjs +622 -197
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap.mjs +52 -8
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/location.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/motion.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/photos.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +500 -119
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdk-types.mjs +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/tasks.mjs +1 -1
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{c04dd5fc5ad48e6b19678d4313159302e9a513ada94bfe515d8dfd5a54d46f5d.bin → fcafca348b6b973cfc2eadc938ddec3c515c641874cbca1667a43b22e1bf7a39.bin} +1 -1
- package/dist/browser-plane/sw.js +1 -1
- package/dist/cli.mjs +203 -56
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/himi-json-output.md +26 -1
- package/guides/qa-builds.md +27 -4
- package/guides/sdk-reference.json +82 -12
- package/guides/skill.md +2 -2
- package/guides/web-page-sdk-reference.md +1 -1
- package/package.json +2 -2
- package/templates/beauty-salon/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
- package/templates/beauty-salon/tier5-src/_shared/iap-worker.ts +2 -0
- package/templates/branded-lite/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
- package/templates/branded-lite/tier5-src/_shared/iap-worker.ts +2 -0
- package/templates/community-club/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
- package/templates/community-club/tier5-src/_shared/iap-worker.ts +2 -0
- package/templates/conference/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
- package/templates/conference/tier5-src/_shared/iap-worker.ts +2 -0
- package/templates/events-meetups/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
- package/templates/events-meetups/tier5-src/_shared/iap-worker.ts +2 -0
- package/templates/gym-fitness/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
- package/templates/gym-fitness/tier5-src/_shared/iap-worker.ts +2 -0
- package/templates/nonprofit-cause/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
- package/templates/nonprofit-cause/tier5-src/_shared/iap-worker.ts +2 -0
- package/templates/podcast-creator/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
- package/templates/podcast-creator/tier5-src/_shared/iap-worker.ts +2 -0
- package/templates/portfolio-creative/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
- package/templates/portfolio-creative/tier5-src/_shared/iap-worker.ts +2 -0
- package/templates/restaurant/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
- package/templates/restaurant/tier5-src/_shared/iap-worker.ts +2 -0
- package/templates/retail-store/tier5-src/_shared/iap-worker.ts +2 -0
- package/templates/salon-spa/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
- package/templates/salon-spa/tier5-src/_shared/iap-worker.ts +2 -0
- package/templates/wholesale-store/tier5-src/_shared/iap-worker.ts +2 -0
- package/templates/yoga-studio/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
- package/templates/yoga-studio/tier5-src/_shared/iap-worker.ts +2 -0
|
@@ -1784,9 +1784,18 @@ function createPurchaseCoordinator(deps) {
|
|
|
1784
1784
|
else if (result.status === "failed") failStore(result.code, false);
|
|
1785
1785
|
else if (result.status === "pending") {
|
|
1786
1786
|
if (!await awaitApproval(session, context)) return !disposed;
|
|
1787
|
-
} else
|
|
1787
|
+
} else {
|
|
1788
|
+
setOutcome("cancelled");
|
|
1789
|
+
void abandon(session, catalogRef);
|
|
1790
|
+
}
|
|
1788
1791
|
return false;
|
|
1789
1792
|
}
|
|
1793
|
+
async function abandon(session, catalogRef) {
|
|
1794
|
+
try {
|
|
1795
|
+
await deps.backend.abandonPurchase?.(session, catalogRef);
|
|
1796
|
+
} catch {
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1790
1799
|
async function deliverPurchase(session, transaction, context) {
|
|
1791
1800
|
const item = upsert2(transaction, null);
|
|
1792
1801
|
applyDelivered(await deliver(session, [item], context));
|
|
@@ -1801,9 +1810,9 @@ function createPurchaseCoordinator(deps) {
|
|
|
1801
1810
|
if (session.kind !== "member") return requireSignIn();
|
|
1802
1811
|
if (listing === "listed") clearReconcileProblem();
|
|
1803
1812
|
const now = deps.clock.now();
|
|
1804
|
-
const
|
|
1805
|
-
|
|
1806
|
-
await settleDelivery(session, await deliver(session,
|
|
1813
|
+
const eligible3 = itemsWhere((item) => isAwaitingDelivery(item) && (item.state.nextAttemptAt === null || item.state.nextAttemptAt <= now));
|
|
1814
|
+
eligible3.forEach(restartAttemptBudget);
|
|
1815
|
+
await settleDelivery(session, await deliver(session, eligible3));
|
|
1807
1816
|
}
|
|
1808
1817
|
async function settleDelivery(session, delivered) {
|
|
1809
1818
|
applyDelivered(delivered);
|
|
@@ -2362,6 +2371,8 @@ var ONLINE_PROGRAM_SALE_RULE = { appProductId: (id2) => id2, productType: "NON_C
|
|
|
2362
2371
|
var PRICING_PLAN_APPLE_SALES_ENABLED = true;
|
|
2363
2372
|
var PRICING_PLAN_SALE_RULE = { appProductId: (id2) => id2, productType: "NON_CONSUMABLE" };
|
|
2364
2373
|
var VIDEOS_APPLE_SALES_ENABLED = false;
|
|
2374
|
+
var PRICING_PLAN_ITEM_PAYMENT_ENABLED = false;
|
|
2375
|
+
var CANCEL_PAYMENT_ENABLED = false;
|
|
2365
2376
|
var VIDEO_SALE_RULE = { appProductId: (id2) => id2, productType: "NON_CONSUMABLE" };
|
|
2366
2377
|
function appleSaleRules(options = {}) {
|
|
2367
2378
|
return {
|
|
@@ -2793,10 +2804,21 @@ function decodeStartedItem(raw, expected) {
|
|
|
2793
2804
|
if (!isObject3(raw)) return null;
|
|
2794
2805
|
const ecomOrderId = optionalId(raw.ecomOrderId);
|
|
2795
2806
|
const joinApplicationId = optionalId(raw.joinApplicationId);
|
|
2796
|
-
|
|
2807
|
+
const eventsOrderNumber = optionalOrderNumber(raw.eventsOrderNumber);
|
|
2808
|
+
if (ecomOrderId === null || joinApplicationId === null || eventsOrderNumber === null) return null;
|
|
2809
|
+
if (!ecomOrderId && !joinApplicationId && !eventsOrderNumber) return null;
|
|
2797
2810
|
const started = decodeStarted(raw, expected);
|
|
2798
2811
|
if (!started || started.payment.appProductId !== expected.catalogItemId) return null;
|
|
2799
|
-
return {
|
|
2812
|
+
return {
|
|
2813
|
+
...started,
|
|
2814
|
+
...ecomOrderId ? { ecomOrderId } : {},
|
|
2815
|
+
...joinApplicationId ? { joinApplicationId } : {},
|
|
2816
|
+
...eventsOrderNumber ? { eventsOrderNumber } : {}
|
|
2817
|
+
};
|
|
2818
|
+
}
|
|
2819
|
+
function optionalOrderNumber(value) {
|
|
2820
|
+
if (value === void 0 || value === "") return void 0;
|
|
2821
|
+
return typeof value === "string" && value.length <= 36 ? value : null;
|
|
2800
2822
|
}
|
|
2801
2823
|
function optionalId(value) {
|
|
2802
2824
|
if (value === void 0 || value === "") return void 0;
|
|
@@ -3097,7 +3119,8 @@ var START_ITEM_PAYMENT_CODES = [
|
|
|
3097
3119
|
"BILLING_COUNTRY_REQUIRED",
|
|
3098
3120
|
"APP_NOT_CONFIGURED",
|
|
3099
3121
|
"NOT_BOOKING_OWNER",
|
|
3100
|
-
"BOOKING_PAYMENT_PENDING"
|
|
3122
|
+
"BOOKING_PAYMENT_PENDING",
|
|
3123
|
+
"MEMBER_DETAILS_REQUIRED"
|
|
3101
3124
|
];
|
|
3102
3125
|
var CANCEL_PAYMENT_CODES = ["NOT_PENDING", "APP_NOT_CONFIGURED", "NOT_FOUND"];
|
|
3103
3126
|
var UNDECIDED = /* @__PURE__ */ new Set(["unavailable", "sessionChanged", "invalidResponse"]);
|
|
@@ -3211,15 +3234,18 @@ function ticketAttendanceOf(event, definition) {
|
|
|
3211
3234
|
function availableTicketAttendanceOf(event, ticket) {
|
|
3212
3235
|
const e = object3(event);
|
|
3213
3236
|
const t = object3(ticket);
|
|
3214
|
-
const
|
|
3237
|
+
const v3 = t.pricingMethod !== void 0;
|
|
3238
|
+
const pricing = object3(v3 ? t.pricingMethod : t.pricing);
|
|
3215
3239
|
const fixed = object3(pricing.fixedPrice);
|
|
3240
|
+
const amount = v3 ? fixed.value : fixed.amount;
|
|
3216
3241
|
const price = object3(t.price);
|
|
3217
|
-
const
|
|
3218
|
-
const
|
|
3242
|
+
const listed = v3 ? t.hidden === false && t.state === void 0 : Array.isArray(t.state) && t.state.length === 0;
|
|
3243
|
+
const visible = listed && object3(t.dashboard).hidden !== true && typeof t.id === "string" && t.id.length > 0 && typeof e.id === "string" && e.id.length > 0 && t.eventId === e.id;
|
|
3244
|
+
const fixedPrice = t.free === false && (!v3 || pricing.free === false) && pricing.pricingType === "STANDARD" && sameTicketAmount(amount, price.amount) && fixed.currency === price.currency;
|
|
3219
3245
|
return ticketAttendanceOf(e, {
|
|
3220
3246
|
hidden: visible ? false : void 0,
|
|
3221
3247
|
saleStatus: t.saleStatus,
|
|
3222
|
-
pricingMethod: { pricingType: fixedPrice ? "STANDARD" : void 0, fixedPrice: { value:
|
|
3248
|
+
pricingMethod: { pricingType: fixedPrice ? "STANDARD" : void 0, fixedPrice: { value: amount, currency: fixed.currency } }
|
|
3223
3249
|
});
|
|
3224
3250
|
}
|
|
3225
3251
|
function sameTicketAmount(left, right) {
|
|
@@ -3236,6 +3262,15 @@ var boolean = (value) => typeof value === "boolean" ? value : void 0;
|
|
|
3236
3262
|
var zeroPrice = (value) => typeof value === "string" && /^0+(?:\.0+)?$/.test(value);
|
|
3237
3263
|
|
|
3238
3264
|
// ../../core/sdk/iap/src/index.ts
|
|
3265
|
+
async function storefrontCountryCode() {
|
|
3266
|
+
try {
|
|
3267
|
+
const r = await dispatch("capability.iap.storefront");
|
|
3268
|
+
const code = r?.countryCode;
|
|
3269
|
+
return typeof code === "string" && /^[A-Z]{3}$/.test(code) ? code : null;
|
|
3270
|
+
} catch {
|
|
3271
|
+
return null;
|
|
3272
|
+
}
|
|
3273
|
+
}
|
|
3239
3274
|
async function getProducts(productIds) {
|
|
3240
3275
|
if (!productIds || productIds.length === 0) return [];
|
|
3241
3276
|
const r = await dispatch("capability.iap.getProducts", {
|
|
@@ -3447,7 +3482,8 @@ var NEEDS_SUPPORT_HOLD_MS = 6048e5;
|
|
|
3447
3482
|
var ITEM_START_HOLD_MS = 36e5;
|
|
3448
3483
|
function pruneExpiredHolds(partition, now) {
|
|
3449
3484
|
const expired = partition.refs().filter((ref) => now - ref.updatedAt >= (HOLD_MS[ref.stage] ?? Infinity) || released(ref, now));
|
|
3450
|
-
|
|
3485
|
+
const removed = (ref) => ref.stage === "openingOrder" ? partition.removeGuard(ref) === "written" : partition.remove(ref.key);
|
|
3486
|
+
return expired.filter(removed).map((ref) => ref.key);
|
|
3451
3487
|
}
|
|
3452
3488
|
var OPENING_SETTLE_MS = 3e5;
|
|
3453
3489
|
async function settleOpening(partition, adapter, guard, item, bridge, now) {
|
|
@@ -3455,23 +3491,36 @@ async function settleOpening(partition, adapter, guard, item, bridge, now) {
|
|
|
3455
3491
|
if (!resolve) return "held";
|
|
3456
3492
|
let current = guard;
|
|
3457
3493
|
const claim = () => {
|
|
3458
|
-
const next = { ...current, updatedAt: now };
|
|
3459
|
-
if (
|
|
3494
|
+
const next = { ...current, guardToken: newGuardToken(), updatedAt: now };
|
|
3495
|
+
if (partition.replaceGuard(current, next) !== "written") return false;
|
|
3460
3496
|
current = next;
|
|
3461
3497
|
return true;
|
|
3462
3498
|
};
|
|
3463
3499
|
const resolution = await resolve(guard, item, bridge, { settled: now - guard.updatedAt >= OPENING_SETTLE_MS, claim });
|
|
3464
|
-
if (
|
|
3465
|
-
|
|
3466
|
-
|
|
3500
|
+
if (resolution === "released") {
|
|
3501
|
+
const removed = partition.removeGuard(current);
|
|
3502
|
+
if (removed !== "replaced") return removed === "written" ? "released" : "storageUnavailable";
|
|
3503
|
+
} else if (isStoredGuard(partition, current)) {
|
|
3504
|
+
return resolution;
|
|
3467
3505
|
}
|
|
3468
3506
|
const stored = partition.refs().find((ref) => ref.key === guard.key);
|
|
3469
3507
|
if (!stored) return "released";
|
|
3470
3508
|
return stored.stage === "openingOrder" ? resolve(stored, item, bridge, { settled: false, claim: () => false }) : "held";
|
|
3471
3509
|
}
|
|
3472
3510
|
function isStoredGuard(partition, guard) {
|
|
3473
|
-
|
|
3474
|
-
|
|
3511
|
+
return holdsGuard(partition.refs(), guard);
|
|
3512
|
+
}
|
|
3513
|
+
function holdsGuard(refs, expected) {
|
|
3514
|
+
const stored = refs.find((ref) => ref.key === expected.key);
|
|
3515
|
+
if (stored?.stage !== "openingOrder") return false;
|
|
3516
|
+
return expected.guardToken === void 0 ? stored.guardToken === void 0 && stored.updatedAt === expected.updatedAt : stored.guardToken === expected.guardToken;
|
|
3517
|
+
}
|
|
3518
|
+
var guardTokens = 0;
|
|
3519
|
+
function newGuardToken() {
|
|
3520
|
+
const crypto = globalThis.crypto;
|
|
3521
|
+
if (typeof crypto?.randomUUID === "function") return crypto.randomUUID();
|
|
3522
|
+
const random = () => Math.random().toString(36).slice(2, 12);
|
|
3523
|
+
return `${Date.now().toString(36)}-${(guardTokens++).toString(36)}-${random()}${random()}`;
|
|
3475
3524
|
}
|
|
3476
3525
|
var MAX_ORDER_REFS = 16;
|
|
3477
3526
|
function createWorkerOrderRefStore(storage) {
|
|
@@ -3483,19 +3532,34 @@ function createWorkerOrderRefStore(storage) {
|
|
|
3483
3532
|
return {
|
|
3484
3533
|
refs: () => readRefs(kv(), location) ?? [],
|
|
3485
3534
|
put: (ref) => writeWith(location, key, (refs) => upsert(refs, ref)),
|
|
3486
|
-
remove: (refKey) => writeWith(location, key, (refs) => refs.filter((stored) => stored.key !== refKey))
|
|
3535
|
+
remove: (refKey) => writeWith(location, key, (refs) => refs.filter((stored) => stored.key !== refKey)),
|
|
3536
|
+
replaceGuard: (expected, next) => guardedWrite(location, key, expected, (refs) => upsert(refs, next)),
|
|
3537
|
+
removeGuard: (expected) => guardedWrite(location, key, expected, (refs) => refs.filter((stored) => stored.key !== expected.key))
|
|
3487
3538
|
};
|
|
3488
3539
|
}
|
|
3540
|
+
function guardedWrite(location, key, expected, change) {
|
|
3541
|
+
let replaced = false;
|
|
3542
|
+
const written = writeWith(location, key, (refs) => {
|
|
3543
|
+
replaced = !holdsGuard(refs, expected);
|
|
3544
|
+
return replaced ? null : change(refs);
|
|
3545
|
+
});
|
|
3546
|
+
return written ? "written" : replaced ? "replaced" : "unavailable";
|
|
3547
|
+
}
|
|
3489
3548
|
function writeWith(location, key, change) {
|
|
3490
3549
|
const store = kv();
|
|
3491
3550
|
if (!store) return false;
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3551
|
+
for (let attempt4 = 0; attempt4 < WRITE_ATTEMPTS; attempt4++) {
|
|
3552
|
+
const raw = safely(() => store.getItem(location));
|
|
3553
|
+
const current = parseRefs(raw);
|
|
3554
|
+
const next = current && change(current);
|
|
3555
|
+
if (!next) return false;
|
|
3556
|
+
if (next.length > 0 && !updateIndex(store, key, true)) return false;
|
|
3557
|
+
if (safely(() => store.getItem(location)) !== raw) continue;
|
|
3558
|
+
if (!writeVerified(store, location, serialize({ v: VERSION, refs: next }))) return false;
|
|
3559
|
+
if (next.length === 0) updateIndex(store, key, false);
|
|
3560
|
+
return true;
|
|
3561
|
+
}
|
|
3562
|
+
return false;
|
|
3499
3563
|
}
|
|
3500
3564
|
function hasRefs(app) {
|
|
3501
3565
|
if (!isUUID3(app.purchasesAppId) || !isUUID3(app.siteId)) return null;
|
|
@@ -3520,7 +3584,10 @@ function updateIndex(store, key, holdsRefs) {
|
|
|
3520
3584
|
return next.length === members.length && next.every((m, i) => m === members[i]) || writeVerified(store, location, serialize({ v: VERSION, members: next }));
|
|
3521
3585
|
}
|
|
3522
3586
|
function readRefs(store, location) {
|
|
3523
|
-
|
|
3587
|
+
return store ? parseRefs(safely(() => store.getItem(location))) : null;
|
|
3588
|
+
}
|
|
3589
|
+
function parseRefs(raw) {
|
|
3590
|
+
const parsed = parseVersioned(raw);
|
|
3524
3591
|
if (parsed === "empty") return [];
|
|
3525
3592
|
if (!parsed || !Array.isArray(parsed.refs) || !parsed.refs.every(isOrderRef)) return null;
|
|
3526
3593
|
return parsed.refs;
|
|
@@ -3532,8 +3599,9 @@ function readIndex(store, location) {
|
|
|
3532
3599
|
return parsed.members;
|
|
3533
3600
|
}
|
|
3534
3601
|
function readVersioned(store, location) {
|
|
3535
|
-
|
|
3536
|
-
|
|
3602
|
+
return store ? parseVersioned(safely(() => store.getItem(location))) : null;
|
|
3603
|
+
}
|
|
3604
|
+
function parseVersioned(raw) {
|
|
3537
3605
|
if (raw === void 0) return null;
|
|
3538
3606
|
if (raw === null || raw === "") return "empty";
|
|
3539
3607
|
const parsed = safely(() => JSON.parse(raw));
|
|
@@ -3550,7 +3618,7 @@ function isOrderRef(value) {
|
|
|
3550
3618
|
if (!isObject6(value) || typeof value.key !== "string" || !STAGES.has(value.stage)) return false;
|
|
3551
3619
|
if (typeof value.updatedAt !== "number") return false;
|
|
3552
3620
|
if (value.releaseAt !== void 0 && typeof value.releaseAt !== "number") return false;
|
|
3553
|
-
const optional = ["kind", "cashierOrderId", "wixTransactionId", "paymentId", "storeProductId", "appProductId", "appleTransactionId", "appAccountToken"];
|
|
3621
|
+
const optional = ["kind", "cashierOrderId", "wixTransactionId", "paymentId", "storeProductId", "appProductId", "appleTransactionId", "appAccountToken", "guardToken"];
|
|
3554
3622
|
if (!optional.every((field) => value[field] === void 0 || typeof value[field] === "string")) return false;
|
|
3555
3623
|
return value.verticalRef === void 0 || isStringMap(value.verticalRef);
|
|
3556
3624
|
}
|
|
@@ -3606,6 +3674,7 @@ function isUUID3(value) {
|
|
|
3606
3674
|
return typeof value === "string" && /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(value);
|
|
3607
3675
|
}
|
|
3608
3676
|
var VERSION = 1;
|
|
3677
|
+
var WRITE_ATTEMPTS = 3;
|
|
3609
3678
|
var PREFIX = "himi.iap.wix-checkout.v1";
|
|
3610
3679
|
var STAGES = /* @__PURE__ */ new Set(["startingItem", "openingOrder", "ordered", "charged", "started", "submitted", "fulfilled", "held", "needsSupport"]);
|
|
3611
3680
|
var HOLD_MS = { held: NEEDS_SUPPORT_HOLD_MS, needsSupport: NEEDS_SUPPORT_HOLD_MS, startingItem: ITEM_START_HOLD_MS };
|
|
@@ -3698,7 +3767,26 @@ function createWixOrderBackend(deps) {
|
|
|
3698
3767
|
const blocked = saleBlocked(sale);
|
|
3699
3768
|
if (blocked) return contextResult(catalogRef, blocked);
|
|
3700
3769
|
const { adapter } = sale;
|
|
3701
|
-
|
|
3770
|
+
if (!paidByItem(adapter)) return startOrderFor({ ...sale, adapter });
|
|
3771
|
+
const country = await readStoreCountry();
|
|
3772
|
+
if (!sale.bridge.isCurrent()) return contextResult(catalogRef, STALE2);
|
|
3773
|
+
const { state, beforeCreate, afterCreate } = creationGuards(sale, void 0);
|
|
3774
|
+
const prepared = await adapter.itemPayment(sale.item, sale.bridge, beforeCreate, afterCreate);
|
|
3775
|
+
if (state.prevented) return contextResult(catalogRef, state.prevented);
|
|
3776
|
+
if (state.orphan) return contextResult(catalogRef, await releaseOrphan(sale, state.orphan));
|
|
3777
|
+
if (!sale.bridge.isCurrent()) return contextResult(catalogRef, STALE2);
|
|
3778
|
+
if ("status" in prepared) return contextResult(catalogRef, preparationStop(sale, prepared, state.guarded));
|
|
3779
|
+
if (state.guarded && !isStoredGuard(sale.partition, state.guarded)) return contextResult(catalogRef, retry("unavailable"));
|
|
3780
|
+
const stillBlocked = state.guarded === void 0 ? saleBlocked(sale) : null;
|
|
3781
|
+
if (stillBlocked) return contextResult(catalogRef, stillBlocked);
|
|
3782
|
+
return startItemFor(sale, prepared, country, state.guarded);
|
|
3783
|
+
}
|
|
3784
|
+
function preparationStop(sale, refusal, guarded) {
|
|
3785
|
+
if (refusal.noOrderCreated && guarded && sale.partition.removeGuard(guarded) === "unavailable") {
|
|
3786
|
+
return stopWith("rejected", "storageUnavailable");
|
|
3787
|
+
}
|
|
3788
|
+
if (refusal.status === "refused") return stopWith("rejected", refusal.reason);
|
|
3789
|
+
return refusal.status === "sessionChanged" ? STALE2 : retry("unavailable");
|
|
3702
3790
|
}
|
|
3703
3791
|
async function startOrderFor(sale) {
|
|
3704
3792
|
const ordered = await orderFor(sale);
|
|
@@ -3757,59 +3845,60 @@ function createWixOrderBackend(deps) {
|
|
|
3757
3845
|
unrelated: /* @__PURE__ */ new Set()
|
|
3758
3846
|
};
|
|
3759
3847
|
}
|
|
3760
|
-
|
|
3761
|
-
const
|
|
3762
|
-
let prevented;
|
|
3763
|
-
let guarded;
|
|
3848
|
+
function creationGuards(sale, existing) {
|
|
3849
|
+
const state = {};
|
|
3764
3850
|
const beforeCreate = (guard = {}) => {
|
|
3765
3851
|
if (!sale.adapter.repeatable || existing) return true;
|
|
3766
3852
|
if (!sale.bridge.isCurrent()) {
|
|
3767
|
-
prevented = STALE2;
|
|
3853
|
+
state.prevented = STALE2;
|
|
3768
3854
|
return false;
|
|
3769
3855
|
}
|
|
3770
3856
|
const blocked = saleBlocked(sale);
|
|
3771
3857
|
if (blocked) {
|
|
3772
|
-
prevented = blocked;
|
|
3858
|
+
state.prevented = blocked;
|
|
3773
3859
|
return false;
|
|
3774
3860
|
}
|
|
3775
|
-
const opening = persist(sale, { ...guard, key: sale.catalogRef, kind: sale.adapter.kind, stage: "openingOrder", updatedAt: now() });
|
|
3861
|
+
const opening = persist(sale, { ...guard, key: sale.catalogRef, kind: sale.adapter.kind, stage: "openingOrder", guardToken: newGuardToken(), updatedAt: now() });
|
|
3776
3862
|
if (isStop(opening)) {
|
|
3777
|
-
prevented = opening;
|
|
3863
|
+
state.prevented = opening;
|
|
3778
3864
|
return false;
|
|
3779
3865
|
}
|
|
3780
|
-
guarded = opening
|
|
3866
|
+
state.guarded = opening;
|
|
3781
3867
|
return true;
|
|
3782
3868
|
};
|
|
3783
3869
|
const afterCreate = (guard) => {
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
const
|
|
3787
|
-
if (
|
|
3870
|
+
if (!state.guarded || !sale.bridge.isCurrent()) return true;
|
|
3871
|
+
const recorded = { ...state.guarded, ...guard, verticalRef: { ...state.guarded.verticalRef, ...guard.verticalRef }, updatedAt: now() };
|
|
3872
|
+
const written = sale.partition.replaceGuard(state.guarded, recorded);
|
|
3873
|
+
if (written === "written") state.guarded = recorded;
|
|
3874
|
+
if (written === "replaced") state.orphan = recorded;
|
|
3875
|
+
return written !== "replaced";
|
|
3788
3876
|
};
|
|
3877
|
+
return { state, beforeCreate, afterCreate };
|
|
3878
|
+
}
|
|
3879
|
+
async function orderFor(sale) {
|
|
3880
|
+
const existing = refAt(sale.partition, sale.catalogRef);
|
|
3881
|
+
const { state, beforeCreate, afterCreate } = creationGuards(sale, existing);
|
|
3789
3882
|
const attempt4 = existing?.cashierOrderId && existing.verticalRef ? await reopenOrOpen(sale, { cashierOrderId: existing.cashierOrderId, verticalRef: existing.verticalRef }) : await sale.adapter.openOrder(sale.item, sale.bridge, beforeCreate, afterCreate);
|
|
3790
|
-
if (prevented) return prevented;
|
|
3791
|
-
if (
|
|
3792
|
-
const ref = recordOrder(sale, existing, attempt4, guarded);
|
|
3883
|
+
if (state.prevented) return state.prevented;
|
|
3884
|
+
if (state.orphan) return releaseOrphan(sale, state.orphan);
|
|
3885
|
+
const ref = recordOrder(sale, existing, attempt4, state.guarded);
|
|
3793
3886
|
return isStop(ref) ? ref : { ref, placed: isPlaced(attempt4) };
|
|
3794
3887
|
}
|
|
3795
|
-
function stillGuarded(sale, guarded) {
|
|
3796
|
-
const stored = refAt(sale.partition, sale.catalogRef);
|
|
3797
|
-
return stored?.stage === "openingOrder" && stored.updatedAt === guarded;
|
|
3798
|
-
}
|
|
3799
3888
|
async function reopenOrOpen(sale, order) {
|
|
3800
3889
|
const reopened = await sale.adapter.reopenOrder(order, sale.bridge);
|
|
3801
3890
|
const closed = reopened.status === "refused" && reopened.reason === "orderClosed";
|
|
3802
3891
|
return closed && !sale.adapter.repeatable ? sale.adapter.openOrder(sale.item, sale.bridge) : reopened;
|
|
3803
3892
|
}
|
|
3804
3893
|
function recordOrder(sale, existing, attempt4, guarded) {
|
|
3805
|
-
if (attempt4.noOrderCreated && guarded
|
|
3894
|
+
if (attempt4.noOrderCreated && guarded && sale.partition.removeGuard(guarded) === "unavailable") {
|
|
3806
3895
|
return stopWith("rejected", "storageUnavailable");
|
|
3807
3896
|
}
|
|
3808
3897
|
if (attempt4.status === "granted") return alreadyOwned(sale);
|
|
3809
3898
|
if (attempt4.status === "refused") return stopWith("rejected", attempt4.reason);
|
|
3810
3899
|
if (attempt4.status !== "open") return attempt4.status === "sessionChanged" ? STALE2 : retry("unavailable");
|
|
3811
3900
|
const kept = existing && existing.cashierOrderId === attempt4.cashierOrderId ? existing : { key: sale.catalogRef, updatedAt: 0 };
|
|
3812
|
-
|
|
3901
|
+
const ordered = {
|
|
3813
3902
|
...kept,
|
|
3814
3903
|
key: sale.catalogRef,
|
|
3815
3904
|
stage: "ordered",
|
|
@@ -3817,7 +3906,18 @@ function createWixOrderBackend(deps) {
|
|
|
3817
3906
|
verticalRef: attempt4.verticalRef,
|
|
3818
3907
|
cashierOrderId: attempt4.cashierOrderId,
|
|
3819
3908
|
updatedAt: now()
|
|
3820
|
-
}
|
|
3909
|
+
};
|
|
3910
|
+
return guarded ? persistGuarded(sale, guarded, ordered) : persist(sale, ordered);
|
|
3911
|
+
}
|
|
3912
|
+
async function releaseOrphan(sale, made) {
|
|
3913
|
+
const released2 = await sale.adapter.resolveOpening?.(made, sale.item, sale.bridge, { settled: true, claim: () => true });
|
|
3914
|
+
return released2 === "sessionChanged" || !sale.bridge.isCurrent() ? STALE2 : retry("unavailable");
|
|
3915
|
+
}
|
|
3916
|
+
function persistGuarded(sale, guarded, ref) {
|
|
3917
|
+
if (!sale.bridge.isCurrent()) return STALE2;
|
|
3918
|
+
const written = sale.partition.replaceGuard(guarded, ref);
|
|
3919
|
+
if (written === "replaced") return retry("unavailable");
|
|
3920
|
+
return written === "written" ? ref : stopWith("rejected", "storageUnavailable");
|
|
3821
3921
|
}
|
|
3822
3922
|
async function chargeFor(sale, ref, options) {
|
|
3823
3923
|
const charge = await (options.placed ? chargePlacedOrder : ensureAppleIapCharge)(sale.bridge, deps.cashier, ref.cashierOrderId ?? "");
|
|
@@ -3873,24 +3973,39 @@ function createWixOrderBackend(deps) {
|
|
|
3873
3973
|
if (isStop(recorded)) return contextResult(sale.catalogRef, recorded);
|
|
3874
3974
|
return { status: "ok", context: { productId: started.storeProductId, appAccountToken: started.appAccountToken, scopeKey: sale.member.scopeKey } };
|
|
3875
3975
|
}
|
|
3876
|
-
async function startItemFor(sale,
|
|
3877
|
-
const
|
|
3976
|
+
async function startItemFor(sale, itemPayment2, country, owned) {
|
|
3977
|
+
const made = refAt(sale.partition, sale.catalogRef);
|
|
3978
|
+
const guarded = made?.stage === "openingOrder" ? { verticalRef: made.verticalRef, releaseAt: made.releaseAt } : {};
|
|
3979
|
+
const next = {
|
|
3980
|
+
key: sale.catalogRef,
|
|
3981
|
+
stage: "startingItem",
|
|
3982
|
+
kind: sale.adapter.kind,
|
|
3983
|
+
storeProductId: sale.appleProduct.productId,
|
|
3984
|
+
...guarded.verticalRef ? { verticalRef: guarded.verticalRef } : {},
|
|
3985
|
+
...guarded.releaseAt !== void 0 ? { releaseAt: guarded.releaseAt } : {},
|
|
3986
|
+
updatedAt: now()
|
|
3987
|
+
};
|
|
3988
|
+
const attempt4 = owned ? persistGuarded(sale, owned, next) : persist(sale, next);
|
|
3878
3989
|
if (isStop(attempt4)) return contextResult(sale.catalogRef, attempt4);
|
|
3879
|
-
const started = await deps.wixIap.startItemPayment({ item:
|
|
3990
|
+
const started = await deps.wixIap.startItemPayment({ item: itemPayment2.catalogItem, ...country ? { storeCountryCode: country } : {} });
|
|
3880
3991
|
if (started.status === "outcomeUnknown") return contextResult(sale.catalogRef, sale.bridge.isCurrent() ? OUTCOME_UNKNOWN : STALE2);
|
|
3881
3992
|
if (started.status !== "started") return contextResult(sale.catalogRef, itemRefusal(sale, started));
|
|
3882
|
-
return startedItem(sale,
|
|
3883
|
-
}
|
|
3884
|
-
function startedItem(sale,
|
|
3885
|
-
if (started.storeProductId !== sale.appleProduct.productId) return contextResult(sale.catalogRef, stopWith("rejected", "productChanged"));
|
|
3886
|
-
const
|
|
3887
|
-
if (!
|
|
3993
|
+
return startedItem(sale, itemPayment2, started);
|
|
3994
|
+
}
|
|
3995
|
+
function startedItem(sale, itemPayment2, started) {
|
|
3996
|
+
if (started.storeProductId !== sale.appleProduct.productId) return contextResult(sale.catalogRef, unsold(sale, stopWith("rejected", "productChanged")));
|
|
3997
|
+
const placed = itemPayment2.verticalRefOf(started);
|
|
3998
|
+
if (!placed) return contextResult(sale.catalogRef, unsold(sale, OUTCOME_UNKNOWN));
|
|
3999
|
+
const attempt4 = refAt(sale.partition, sale.catalogRef);
|
|
4000
|
+
const guarded = attempt4?.stage === "startingItem" ? attempt4 : void 0;
|
|
4001
|
+
const verticalRef = guarded?.verticalRef ? { ...guarded.verticalRef, ...placed } : placed;
|
|
3888
4002
|
const { payment, storeProductId, appAccountToken } = started;
|
|
3889
4003
|
const recorded = persist(sale, {
|
|
3890
4004
|
key: sale.catalogRef,
|
|
3891
4005
|
stage: "started",
|
|
3892
4006
|
kind: sale.adapter.kind,
|
|
3893
4007
|
verticalRef,
|
|
4008
|
+
...guarded?.releaseAt !== void 0 ? { releaseAt: guarded.releaseAt } : {},
|
|
3894
4009
|
wixTransactionId: payment.wixTransactionId,
|
|
3895
4010
|
paymentId: payment.paymentId,
|
|
3896
4011
|
storeProductId,
|
|
@@ -3901,11 +4016,31 @@ function createWixOrderBackend(deps) {
|
|
|
3901
4016
|
if (isStop(recorded)) return contextResult(sale.catalogRef, recorded);
|
|
3902
4017
|
return { status: "ok", context: { productId: storeProductId, appAccountToken, scopeKey: sale.member.scopeKey } };
|
|
3903
4018
|
}
|
|
4019
|
+
function unsold(sale, stop) {
|
|
4020
|
+
handBackToGuard(sale.partition, sale.adapter, refAt(sale.partition, sale.catalogRef));
|
|
4021
|
+
return stop;
|
|
4022
|
+
}
|
|
3904
4023
|
function itemRefusal(sale, failure4) {
|
|
4024
|
+
if (failure4.kind === "application" && failure4.code === "NOT_BOOKING_OWNER") return dropAttempt(sale, retry("bookingNotOwned"));
|
|
3905
4025
|
if (failure4.kind === "application") return undoAttempt(sale, stopWith("rejected", ITEM_REFUSALS[failure4.code]));
|
|
3906
4026
|
return undoAttempt(sale, failure4.kind === "unrecognized" ? NOT_CONFIGURED : failureStop(failure4));
|
|
3907
4027
|
}
|
|
3908
4028
|
function undoAttempt(sale, stop) {
|
|
4029
|
+
return handBackToGuard(sale.partition, sale.adapter, refAt(sale.partition, sale.catalogRef)) ? stop : dropAttempt(sale, stop);
|
|
4030
|
+
}
|
|
4031
|
+
function handBackToGuard(partition, adapter, attempt4) {
|
|
4032
|
+
if (!attempt4?.verticalRef || !adapter.resolveOpening) return false;
|
|
4033
|
+
return partition.put({
|
|
4034
|
+
key: attempt4.key,
|
|
4035
|
+
kind: adapter.kind,
|
|
4036
|
+
stage: "openingOrder",
|
|
4037
|
+
guardToken: newGuardToken(),
|
|
4038
|
+
verticalRef: attempt4.verticalRef,
|
|
4039
|
+
...attempt4.releaseAt !== void 0 ? { releaseAt: attempt4.releaseAt } : {},
|
|
4040
|
+
updatedAt: now() - OPENING_SETTLE_MS
|
|
4041
|
+
});
|
|
4042
|
+
}
|
|
4043
|
+
function dropAttempt(sale, stop) {
|
|
3909
4044
|
sale.partition.remove(sale.catalogRef);
|
|
3910
4045
|
return stop;
|
|
3911
4046
|
}
|
|
@@ -3914,9 +4049,8 @@ function createWixOrderBackend(deps) {
|
|
|
3914
4049
|
}
|
|
3915
4050
|
async function startRefusal(sale, ref, failure4) {
|
|
3916
4051
|
if (failure4.kind !== "application") return failureStop(failure4);
|
|
3917
|
-
if (failure4.code === "SUBSCRIPTION_NOT_IN_APP"
|
|
3918
|
-
|
|
3919
|
-
}
|
|
4052
|
+
if (failure4.code === "SUBSCRIPTION_NOT_IN_APP") return stopWith("rejected", "unsupportedItem");
|
|
4053
|
+
if (failure4.code === "ALREADY_SUBSCRIBED") return stopWith("rejected", "alreadySubscribed");
|
|
3920
4054
|
if (failure4.code === "ALREADY_OWNED") return alreadyPaid(sale, ref);
|
|
3921
4055
|
if (failure4.code === "NOT_PENDING" || failure4.code === "NOT_ORDER_BUYER") forget(sale, sale.catalogRef);
|
|
3922
4056
|
return stopWith("rejected", failure4.code === "NOT_PENDING" ? "orderClosed" : "paymentRefused");
|
|
@@ -4013,12 +4147,37 @@ function createWixOrderBackend(deps) {
|
|
|
4013
4147
|
if (proof.transaction.appAccountToken) return refByToken(refs, proof.transaction);
|
|
4014
4148
|
return refs.filter((ref) => ref.stage === "started" && ref.storeProductId === productId).reduce((newest, ref) => !newest || ref.updatedAt >= newest.updatedAt ? ref : newest, void 0);
|
|
4015
4149
|
}
|
|
4150
|
+
async function readStoreCountry() {
|
|
4151
|
+
try {
|
|
4152
|
+
return await deps.storeCountry?.() ?? null;
|
|
4153
|
+
} catch {
|
|
4154
|
+
return null;
|
|
4155
|
+
}
|
|
4156
|
+
}
|
|
4157
|
+
async function abandonPurchase(session, catalogRef) {
|
|
4158
|
+
const member = await memberOf(session);
|
|
4159
|
+
const partition = isStop(member) ? null : member.partition;
|
|
4160
|
+
if (!partition || !isCurrent(session)) return;
|
|
4161
|
+
const ref = refAt(partition, catalogRef);
|
|
4162
|
+
if (ref?.stage !== "started" || !ref.paymentId) return;
|
|
4163
|
+
const adapter = adapterFor(ref.kind);
|
|
4164
|
+
if (!adapter || !paidByItem(adapter)) return;
|
|
4165
|
+
if (!(deps.cancelPaymentEnabled ?? CANCEL_PAYMENT_ENABLED) || adapter.reusesPayment) {
|
|
4166
|
+
const current = refAt(partition, catalogRef);
|
|
4167
|
+
if (current?.stage === "started" && current.paymentId === ref.paymentId && current.updatedAt === ref.updatedAt) handBackToGuard(partition, adapter, ref);
|
|
4168
|
+
return;
|
|
4169
|
+
}
|
|
4170
|
+
const canceled = await deps.wixIap.cancelPayment({ paymentId: ref.paymentId });
|
|
4171
|
+
if (canceled.status !== "answered" || !isCurrent(session)) return;
|
|
4172
|
+
if (canceled.payment.status !== "canceled") return;
|
|
4173
|
+
if (refAt(partition, catalogRef)?.paymentId === ref.paymentId) partition.remove(catalogRef);
|
|
4174
|
+
}
|
|
4016
4175
|
async function getMemberContext(session) {
|
|
4017
4176
|
const member = await memberOf(session);
|
|
4018
4177
|
if (isStop(member)) return { status: member.result };
|
|
4019
4178
|
return { status: "ok", context: { scopeKey: member.scopeKey } };
|
|
4020
4179
|
}
|
|
4021
|
-
return { getPurchaseContext, getMemberContext, submitProof };
|
|
4180
|
+
return { getPurchaseContext, getMemberContext, submitProof, abandonPurchase };
|
|
4022
4181
|
}
|
|
4023
4182
|
function paidByItem(adapter) {
|
|
4024
4183
|
return typeof adapter.itemPayment === "function";
|
|
@@ -4058,12 +4217,15 @@ var ITEM_REFUSALS = {
|
|
|
4058
4217
|
UNSUPPORTED_ORDER: "orderRefused",
|
|
4059
4218
|
CATALOG_NOT_SUPPORTED: "unsupportedItem",
|
|
4060
4219
|
EVENT_CHECKOUT_NOT_ECOM: "unsupportedItem",
|
|
4220
|
+
SUBSCRIPTION_NOT_IN_APP: "unsupportedItem",
|
|
4221
|
+
// The site or the store cannot sell it, and a tap would be refused again: Buy stays disabled.
|
|
4061
4222
|
VERTICAL_ACCESS_DENIED: "notConfigured",
|
|
4223
|
+
BILLING_COUNTRY_REQUIRED: "notConfigured",
|
|
4062
4224
|
APP_NOT_CONFIGURED: "notConfigured",
|
|
4063
|
-
ALREADY_SUBSCRIBED: "
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
NOT_BOOKING_OWNER: "
|
|
4225
|
+
ALREADY_SUBSCRIBED: "alreadySubscribed",
|
|
4226
|
+
MEMBER_DETAILS_REQUIRED: "memberDetailsRequired",
|
|
4227
|
+
// The booking is not this member's: itemRefusal drops the attempt and a new tap makes a new booking.
|
|
4228
|
+
NOT_BOOKING_OWNER: "bookingNotOwned",
|
|
4067
4229
|
BOOKING_PAYMENT_PENDING: "paymentInProgress"
|
|
4068
4230
|
};
|
|
4069
4231
|
var KIND_STOPS = {
|
|
@@ -4150,7 +4312,8 @@ function enabledCheckout(deps) {
|
|
|
4150
4312
|
bridge,
|
|
4151
4313
|
itemFor: (key) => sales.get(key),
|
|
4152
4314
|
productBusy,
|
|
4153
|
-
report: onEvent
|
|
4315
|
+
report: onEvent,
|
|
4316
|
+
storeCountry: deps.storeCountry ?? storefrontCountryCode
|
|
4154
4317
|
});
|
|
4155
4318
|
const coordinator = createPurchaseCoordinator({
|
|
4156
4319
|
store: deps.store ?? appleManagedStore,
|
|
@@ -4533,8 +4696,12 @@ function outcomeAction(state, copy) {
|
|
|
4533
4696
|
function refusalAction(failure4, copy) {
|
|
4534
4697
|
if (failure4 === "sitePaymentUnavailable") return action(copy, "enabled", copy.sitePaymentUnavailable ?? copy.retry);
|
|
4535
4698
|
const [mode, note] = REFUSALS[failure4 ?? "unavailable"] ?? ["enabled", "retry"];
|
|
4536
|
-
return action(copy, mode, note ? copy[note] ?? "" : "");
|
|
4699
|
+
return action(copy, mode, note ? copy[note] ?? copy[OPTIONAL_COPY_FALLBACK[note] ?? "retry"] ?? "" : "");
|
|
4537
4700
|
}
|
|
4701
|
+
var OPTIONAL_COPY_FALLBACK = {
|
|
4702
|
+
memberDetailsRequired: "retry",
|
|
4703
|
+
alreadySubscribed: "unavailable"
|
|
4704
|
+
};
|
|
4538
4705
|
function action(copy, mode, note) {
|
|
4539
4706
|
return { appleRoute: true, accessReady: false, buyLabel: copy.buy, buyDisabled: mode !== "enabled", buyBusy: mode === "busy", buyNote: note };
|
|
4540
4707
|
}
|
|
@@ -4553,6 +4720,11 @@ var REFUSALS = {
|
|
|
4553
4720
|
approvalRequired: ["disabled", "awaitingApproval"],
|
|
4554
4721
|
signInRequired: ["disabled", "signInRequired"],
|
|
4555
4722
|
notConfigured: ["disabled", "unavailable"],
|
|
4723
|
+
// The member can fix this: completing the profile and tapping again sells.
|
|
4724
|
+
memberDetailsRequired: ["enabled", "memberDetailsRequired"],
|
|
4725
|
+
alreadySubscribed: ["disabled", "alreadySubscribed"],
|
|
4726
|
+
// The booking was dropped: a tap (after fixing the details) books afresh.
|
|
4727
|
+
bookingNotOwned: ["enabled", "retry"],
|
|
4556
4728
|
notEnabled: ["disabled", "unavailable"],
|
|
4557
4729
|
storageUnavailable: ["disabled", "unavailable"],
|
|
4558
4730
|
unsupportedItem: ["disabled", "unavailable"],
|
|
@@ -4884,14 +5056,66 @@ var UNSUPPORTED = { eligible: false, reason: "unsupportedItem" };
|
|
|
4884
5056
|
var ORDER_REFUSED = { status: "refused", reason: "orderRefused" };
|
|
4885
5057
|
var ORDER_CLOSED = { status: "refused", reason: "orderClosed" };
|
|
4886
5058
|
var GRANTED = { status: "granted" };
|
|
5059
|
+
async function ecomOrderAccess(orderId, bridge) {
|
|
5060
|
+
if (!isNonEmpty3(orderId)) return "unavailable";
|
|
5061
|
+
const answer = await bridge.call("GET", `/ecom/v1/orders/${encodeURIComponent(orderId)}`);
|
|
5062
|
+
if (isRefusal(answer)) return accessRefused(answer);
|
|
5063
|
+
const status = String(bodyObject(answer, "order")?.paymentStatus);
|
|
5064
|
+
if (status === "PAID") return "granted";
|
|
5065
|
+
if (ECOM_PAYMENT_UNDER_WAY.has(status)) return "pending";
|
|
5066
|
+
return ECOM_NO_ACCESS.has(status) ? "none" : "unavailable";
|
|
5067
|
+
}
|
|
5068
|
+
var ECOM_PAYMENT_UNDER_WAY = /* @__PURE__ */ new Set(["NOT_PAID", "PENDING", "PENDING_MERCHANT", "PARTIALLY_PAID"]);
|
|
5069
|
+
var ECOM_NO_ACCESS = /* @__PURE__ */ new Set(["FULLY_REFUNDED", "PARTIALLY_REFUNDED", "CANCELED", "DECLINED", "VOIDED"]);
|
|
4887
5070
|
|
|
4888
5071
|
// ../../stdlib/flows/iap-checkout/src/iap-verticals/pricing-plans.ts
|
|
4889
5072
|
var KIND = "pricingPlan";
|
|
4890
|
-
var
|
|
5073
|
+
var PRICING_PLANS_APP = "1522827f-c56c-a5c9-2ac9-00f9e6ae12d3";
|
|
4891
5074
|
var MEMBER_ORDERS = "/pricing-plans/v2/member/orders";
|
|
4892
|
-
var
|
|
5075
|
+
var pricingPlanItemPayments = {
|
|
4893
5076
|
kind: KIND,
|
|
4894
5077
|
eligibility: (item) => singleUnitOf(KIND, item),
|
|
5078
|
+
itemPayment,
|
|
5079
|
+
readAccess: (verticalRef, bridge) => isNonEmpty3(verticalRef.planId) ? planAccess(verticalRef.planId, bridge) : Promise.resolve("unavailable"),
|
|
5080
|
+
currentAccess: (item, bridge) => planAccess(item.reference.id, bridge)
|
|
5081
|
+
};
|
|
5082
|
+
async function itemPayment(item, bridge) {
|
|
5083
|
+
const planId = item.reference.id;
|
|
5084
|
+
const read2 = await bridge.call("GET", `/pricing-plans/v3/plans/${encodeURIComponent(planId)}`);
|
|
5085
|
+
if (isRefusal(read2)) return attemptRefused(read2);
|
|
5086
|
+
const variants = bodyObject(read2, "plan")?.pricingVariants;
|
|
5087
|
+
const only = Array.isArray(variants) && variants.length === 1 && isObject7(variants[0]) ? variants[0].id : void 0;
|
|
5088
|
+
if (!isNonEmpty3(only)) return { status: "refused", reason: "unsupportedItem" };
|
|
5089
|
+
return {
|
|
5090
|
+
catalogItem: { catalogItemId: planId, catalogAppId: PRICING_PLANS_APP, options: { type: "PLAN", planOptions: { pricingVariantId: only } } },
|
|
5091
|
+
verticalRefOf: ({ ecomOrderId }) => ecomOrderId ? { ecomOrderId, planId } : null
|
|
5092
|
+
};
|
|
5093
|
+
}
|
|
5094
|
+
async function planAccess(planId, bridge) {
|
|
5095
|
+
let pending = false;
|
|
5096
|
+
const pages = /* @__PURE__ */ new Set();
|
|
5097
|
+
for (let offset = 0; ; offset += 50) {
|
|
5098
|
+
const answer = await bridge.call("GET", `${MEMBER_ORDERS}?orderStatuses=ACTIVE&orderStatuses=PENDING&orderStatuses=DRAFT&limit=50&offset=${offset}`);
|
|
5099
|
+
if (isRefusal(answer)) return accessRefused(answer);
|
|
5100
|
+
const orders = answer.body?.orders;
|
|
5101
|
+
if (!Array.isArray(orders)) return "unavailable";
|
|
5102
|
+
const page = JSON.stringify(orders.map((order) => [order.id, order.planId, order.status]));
|
|
5103
|
+
if (orders.length === 50 && pages.has(page)) return "unavailable";
|
|
5104
|
+
pages.add(page);
|
|
5105
|
+
const selected = orders.filter((order) => order.planId === planId);
|
|
5106
|
+
if (selected.some((order) => order.status === "ACTIVE")) return "granted";
|
|
5107
|
+
pending || (pending = selected.some((order) => order.status === "PENDING" || order.status === "DRAFT"));
|
|
5108
|
+
if (orders.length < 50) return pending ? "pending" : "none";
|
|
5109
|
+
}
|
|
5110
|
+
}
|
|
5111
|
+
|
|
5112
|
+
// ../../stdlib/flows/iap-checkout/src/iap-verticals/pricing-plans-orders.ts
|
|
5113
|
+
var KIND2 = "pricingPlan";
|
|
5114
|
+
var CHECKOUT = "/pricing-plans/v2/checkout/orders";
|
|
5115
|
+
var MEMBER_ORDERS2 = "/pricing-plans/v2/member/orders";
|
|
5116
|
+
var pricingPlanClientOrders = {
|
|
5117
|
+
kind: KIND2,
|
|
5118
|
+
eligibility: (item) => singleUnitOf(KIND2, item),
|
|
4895
5119
|
openOrder,
|
|
4896
5120
|
reopenOrder,
|
|
4897
5121
|
readAccess,
|
|
@@ -4901,7 +5125,7 @@ async function currentAccess(item, bridge) {
|
|
|
4901
5125
|
let pending = false;
|
|
4902
5126
|
const pages = /* @__PURE__ */ new Set();
|
|
4903
5127
|
for (let offset = 0; ; offset += 50) {
|
|
4904
|
-
const answer = await bridge.call("GET", `${
|
|
5128
|
+
const answer = await bridge.call("GET", `${MEMBER_ORDERS2}?orderStatuses=ACTIVE&orderStatuses=PENDING&orderStatuses=DRAFT&limit=50&offset=${offset}`);
|
|
4905
5129
|
if (isRefusal(answer)) return accessRefused(answer);
|
|
4906
5130
|
const orders = answer.body?.orders;
|
|
4907
5131
|
if (!Array.isArray(orders)) return "unavailable";
|
|
@@ -4930,8 +5154,8 @@ async function reopenOrder(order, bridge) {
|
|
|
4930
5154
|
return attempt4.status === "open" && attempt4.cashierOrderId !== order.cashierOrderId ? ORDER_CLOSED : attempt4;
|
|
4931
5155
|
}
|
|
4932
5156
|
async function readAccess(verticalRef, bridge) {
|
|
4933
|
-
if (!isNonEmpty3(verticalRef.orderId)) return "unavailable";
|
|
4934
|
-
const answer = await bridge.call("GET", `${
|
|
5157
|
+
if (!isNonEmpty3(verticalRef.orderId)) return isNonEmpty3(verticalRef.planId) ? planAccess(verticalRef.planId, bridge) : "unavailable";
|
|
5158
|
+
const answer = await bridge.call("GET", `${MEMBER_ORDERS2}/${encodeURIComponent(verticalRef.orderId)}`);
|
|
4935
5159
|
if (isRefusal(answer)) return accessRefused(answer);
|
|
4936
5160
|
const order = bodyObject(answer, "order");
|
|
4937
5161
|
return order ? accessOf(order) : "unavailable";
|
|
@@ -4953,7 +5177,7 @@ function orderOf(order, planId) {
|
|
|
4953
5177
|
}
|
|
4954
5178
|
async function memberOrder(orderId, bridge) {
|
|
4955
5179
|
if (!isNonEmpty3(orderId)) return { attempt: ORDER_CLOSED };
|
|
4956
|
-
const answer = await bridge.call("GET", `${
|
|
5180
|
+
const answer = await bridge.call("GET", `${MEMBER_ORDERS2}/${encodeURIComponent(orderId)}`);
|
|
4957
5181
|
if (isRefusal(answer)) return { attempt: answer.status === "http" && answer.httpStatus === 404 ? ORDER_CLOSED : attemptRefused(answer) };
|
|
4958
5182
|
return { order: bodyObject(answer, "order") };
|
|
4959
5183
|
}
|
|
@@ -4966,43 +5190,40 @@ function isOneTimeUnlimited(order) {
|
|
|
4966
5190
|
var BOOKING = "bookingsService";
|
|
4967
5191
|
var TICKET = "eventsTicket";
|
|
4968
5192
|
var NOT_ENABLED = { status: "refused", reason: "notEnabled" };
|
|
5193
|
+
var WIX_BOOKINGS_APP = "13d21c63-b5ec-5912-8397-c3a5ddb27a97";
|
|
4969
5194
|
var CHANGED = { status: "refused", reason: "productChanged" };
|
|
4970
|
-
var
|
|
5195
|
+
var WIX_EVENTS_APP = "140603ad-af8d-84a5-2c80-a0f60cb47351";
|
|
4971
5196
|
var RELEASE_MARGIN_MS = 3e5;
|
|
4972
|
-
var DEFAULT_RESERVATION_MINUTES = 60;
|
|
4973
5197
|
var PAYMENT_TAKEN = ["PAID", "PARTIALLY_PAID", "EXEMPT", "REFUNDED"];
|
|
4974
5198
|
var HAS_OFFSET = /(?:Z|[+-]\d{2}:?\d{2})$/i;
|
|
4975
5199
|
var LATEST_ZONE_MS = 432e5;
|
|
4976
5200
|
function attendanceOrdersWith(options) {
|
|
4977
|
-
const now = options.now ?? Date.now;
|
|
4978
5201
|
return {
|
|
4979
5202
|
bookingOrders: {
|
|
4980
5203
|
kind: BOOKING,
|
|
4981
5204
|
repeatable: true,
|
|
4982
5205
|
eligibility: (item) => eligible(item, BOOKING, options.bookingsEnabled),
|
|
4983
|
-
|
|
5206
|
+
itemPayment: (item, bridge, beforeCreate, afterCreate) => options.bookingsEnabled ? bookingPayment(item, bridge, beforeCreate, afterCreate) : NOT_ENABLED,
|
|
4984
5207
|
resolveOpening: resolveBookingOpening,
|
|
4985
|
-
readAccess: bookingAccess
|
|
4986
|
-
reopenOrder: (order, bridge) => reopen(order, bridge, bookingAccess)
|
|
5208
|
+
readAccess: bookingAccess
|
|
4987
5209
|
},
|
|
4988
5210
|
eventTicketOrders: {
|
|
4989
5211
|
kind: TICKET,
|
|
4990
5212
|
repeatable: true,
|
|
4991
5213
|
eligibility: (item) => eligible(item, TICKET, options.eventsEnabled),
|
|
4992
|
-
|
|
4993
|
-
readAccess: ticketAccess
|
|
4994
|
-
reopenOrder: (order, bridge) => reopen(order, bridge, ticketAccess, now)
|
|
5214
|
+
itemPayment: ticketPayment,
|
|
5215
|
+
readAccess: ticketAccess
|
|
4995
5216
|
}
|
|
4996
5217
|
};
|
|
4997
5218
|
}
|
|
4998
|
-
var { bookingOrders, eventTicketOrders } = /* @__PURE__ */ attendanceOrdersWith({ bookingsEnabled: BOOKINGS_APPLE_SALES_ENABLED, eventsEnabled: EVENTS_APPLE_SALES_ENABLED });
|
|
5219
|
+
var { bookingOrders: bookingItemPayments, eventTicketOrders: eventTicketItemPayments } = /* @__PURE__ */ attendanceOrdersWith({ bookingsEnabled: BOOKINGS_APPLE_SALES_ENABLED, eventsEnabled: EVENTS_APPLE_SALES_ENABLED });
|
|
4999
5220
|
function eligible(item, kind, enabled) {
|
|
5000
5221
|
if (!enabled) return { eligible: false, reason: "notEnabled" };
|
|
5001
5222
|
if (!singleUnitOf(kind, item).eligible || !isNonEmpty3(item.attemptId) || !item.attendance) return UNSUPPORTED;
|
|
5002
|
-
|
|
5003
|
-
return
|
|
5223
|
+
if (kind === TICKET) return isNonEmpty3(item.attendance.ticket?.eventId) ? { eligible: true } : UNSUPPORTED;
|
|
5224
|
+
return item.attendance.booking ? { eligible: true } : UNSUPPORTED;
|
|
5004
5225
|
}
|
|
5005
|
-
async function
|
|
5226
|
+
async function bookingPayment(item, bridge, beforeCreate, afterCreate) {
|
|
5006
5227
|
if (!eligible(item, BOOKING, true).eligible) return notCreated(ORDER_REFUSED);
|
|
5007
5228
|
const selected = item.attendance.booking;
|
|
5008
5229
|
if (selected.slot.serviceId !== item.reference.id || !isNonEmpty3(selected.slot.startDate) || !isNonEmpty3(selected.slot.endDate)) return notCreated(ORDER_REFUSED);
|
|
@@ -5021,8 +5242,12 @@ async function openBooking(item, bridge, beforeCreate, afterCreate) {
|
|
|
5021
5242
|
if (isRefusal(created)) return creationRefused(created);
|
|
5022
5243
|
const bookingId = bodyObject(created, "booking")?.id;
|
|
5023
5244
|
if (!isNonEmpty3(bookingId)) return ORDER_REFUSED;
|
|
5024
|
-
afterCreate?.({ verticalRef: { bookingId } });
|
|
5025
|
-
|
|
5245
|
+
if (afterCreate?.({ verticalRef: { bookingId } }) === false) return { status: "unavailable" };
|
|
5246
|
+
const serviceId = item.reference.id;
|
|
5247
|
+
return {
|
|
5248
|
+
catalogItem: { catalogItemId: serviceId, catalogAppId: WIX_BOOKINGS_APP, options: { bookingId } },
|
|
5249
|
+
verticalRefOf: ({ ecomOrderId }) => ecomOrderId ? { serviceId, bookingId, orderId: ecomOrderId } : null
|
|
5250
|
+
};
|
|
5026
5251
|
}
|
|
5027
5252
|
function slotGuard(slot) {
|
|
5028
5253
|
const verticalRef = {};
|
|
@@ -5060,12 +5285,164 @@ function sameSlot(guarded, slot) {
|
|
|
5060
5285
|
if (!guarded || !slot) return true;
|
|
5061
5286
|
return guarded.sessionId === slot.sessionId && Date.parse(guarded.startDate ?? "") === Date.parse(String(slot.startDate));
|
|
5062
5287
|
}
|
|
5288
|
+
async function bookingAccess(ref, bridge) {
|
|
5289
|
+
if (!ref.bookingId || !ref.orderId) return "unavailable";
|
|
5290
|
+
const order = await bridge.call("GET", `/ecom/v1/orders/${encodeURIComponent(ref.orderId)}`);
|
|
5291
|
+
if (isRefusal(order)) return accessRefused(order);
|
|
5292
|
+
const payment = bodyObject(order, "order")?.paymentStatus;
|
|
5293
|
+
if (payment === "FULLY_REFUNDED" || payment === "PARTIALLY_REFUNDED") return "none";
|
|
5294
|
+
const read2 = await bridge.call("POST", "/bookings/v2/bookings/query", { query: { filter: { id: { $eq: ref.bookingId } } } });
|
|
5295
|
+
if (isRefusal(read2)) return accessRefused(read2);
|
|
5296
|
+
const rows = isObject7(read2.body) ? read2.body.bookings : void 0;
|
|
5297
|
+
const booking = Array.isArray(rows) ? rows.find((b) => isObject7(b) && b.id === ref.bookingId) : void 0;
|
|
5298
|
+
if (!isObject7(booking)) return "unavailable";
|
|
5299
|
+
if (booking.status === "CANCELED" || booking.status === "CANCELLED" || booking.status === "DECLINED") return "none";
|
|
5300
|
+
return payment === "PAID" && booking.status === "CONFIRMED" && booking.paymentStatus === "PAID" ? "granted" : "pending";
|
|
5301
|
+
}
|
|
5302
|
+
async function ticketAccess(ref, bridge) {
|
|
5303
|
+
if (isNonEmpty3(ref.orderId)) return ecomOrderAccess(ref.orderId, bridge);
|
|
5304
|
+
if (!ref.eventId || !ref.orderNumber || !ref.ticketDefinitionId) return "unavailable";
|
|
5305
|
+
const read2 = await bridge.call("GET", `/events/v1/events/${encodeURIComponent(ref.eventId)}/orders/${encodeURIComponent(ref.orderNumber)}?fieldset=DETAILS&fieldset=TICKETS`);
|
|
5306
|
+
if (isRefusal(read2)) return accessRefused(read2);
|
|
5307
|
+
const order = bodyObject(read2, "order");
|
|
5308
|
+
if (order?.status === "CANCELED" || order?.status === "CANCELLED" || order?.status === "REFUNDED") return "none";
|
|
5309
|
+
const issued = Array.isArray(order?.tickets) && order.tickets.some((t) => isObject7(t) && isNonEmpty3(t.ticketNumber) && t.orderStatus === "PAID" && t.ticketDefinitionId === ref.ticketDefinitionId);
|
|
5310
|
+
return order?.status === "PAID" && issued ? "granted" : order ? "pending" : "unavailable";
|
|
5311
|
+
}
|
|
5312
|
+
function ticketPayment(item) {
|
|
5313
|
+
const eventId = item.attendance.ticket.eventId;
|
|
5314
|
+
const ticketDefinitionId = item.reference.id;
|
|
5315
|
+
return {
|
|
5316
|
+
catalogItem: { catalogItemId: ticketDefinitionId, catalogAppId: WIX_EVENTS_APP, options: { eventId } },
|
|
5317
|
+
// eCom checkout: the eCom order. Classic checkout (catalyst-server #24882): the Events order number.
|
|
5318
|
+
verticalRefOf: ({ ecomOrderId, eventsOrderNumber }) => {
|
|
5319
|
+
if (ecomOrderId) return { orderId: ecomOrderId, eventId, ticketDefinitionId };
|
|
5320
|
+
return eventsOrderNumber ? { orderNumber: eventsOrderNumber, eventId, ticketDefinitionId } : null;
|
|
5321
|
+
}
|
|
5322
|
+
};
|
|
5323
|
+
}
|
|
5324
|
+
function samePrice(value, item) {
|
|
5325
|
+
return isObject7(value) && value.currency === item.attendance?.currency && decimal(value.amount) !== null && decimal(value.amount) === decimal(item.attendance?.amount);
|
|
5326
|
+
}
|
|
5327
|
+
function decimal(value) {
|
|
5328
|
+
if (typeof value !== "string" || !/^\d+(?:\.\d+)?$/.test(value)) return null;
|
|
5329
|
+
return value.replace(/^0+(?=\d)/, "").replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
|
|
5330
|
+
}
|
|
5331
|
+
function matchesSlot(value, selected) {
|
|
5332
|
+
return isObject7(value) && ["serviceId", "sessionId"].every((key) => value[key] === selected[key]) && ["startDate", "endDate"].every((key) => typeof value[key] === "string" && Date.parse(value[key]) === Date.parse(String(selected[key])));
|
|
5333
|
+
}
|
|
5334
|
+
function creationRefused(refusal) {
|
|
5335
|
+
const attempt4 = attemptRefused(refusal);
|
|
5336
|
+
return refusal.status === "http" && [400, 401, 403, 404, 405, 409, 410, 415, 422].includes(refusal.httpStatus) ? notCreated(attempt4) : attempt4;
|
|
5337
|
+
}
|
|
5338
|
+
function notCreated(attempt4) {
|
|
5339
|
+
return { ...attempt4, noOrderCreated: true };
|
|
5340
|
+
}
|
|
5341
|
+
|
|
5342
|
+
// ../../stdlib/flows/iap-checkout/src/iap-verticals/attendance-orders.ts
|
|
5343
|
+
var BOOKING2 = "bookingsService";
|
|
5344
|
+
var TICKET2 = "eventsTicket";
|
|
5345
|
+
var NOT_ENABLED2 = { status: "refused", reason: "notEnabled" };
|
|
5346
|
+
var CHANGED2 = { status: "refused", reason: "productChanged" };
|
|
5347
|
+
var MINUTE_MS = 6e4;
|
|
5348
|
+
var RELEASE_MARGIN_MS2 = 3e5;
|
|
5349
|
+
var DEFAULT_RESERVATION_MINUTES = 60;
|
|
5350
|
+
var PAYMENT_TAKEN2 = ["PAID", "PARTIALLY_PAID", "EXEMPT", "REFUNDED"];
|
|
5351
|
+
var HAS_OFFSET2 = /(?:Z|[+-]\d{2}:?\d{2})$/i;
|
|
5352
|
+
var LATEST_ZONE_MS2 = 432e5;
|
|
5353
|
+
function attendanceClientOrdersWith(options) {
|
|
5354
|
+
const now = options.now ?? Date.now;
|
|
5355
|
+
return {
|
|
5356
|
+
bookingOrders: {
|
|
5357
|
+
kind: BOOKING2,
|
|
5358
|
+
repeatable: true,
|
|
5359
|
+
eligibility: (item) => eligible2(item, BOOKING2, options.bookingsEnabled),
|
|
5360
|
+
openOrder: (item, bridge, beforeCreate, afterCreate) => options.bookingsEnabled ? openBooking(item, bridge, beforeCreate, afterCreate) : Promise.resolve(NOT_ENABLED2),
|
|
5361
|
+
resolveOpening: resolveBookingOpening2,
|
|
5362
|
+
readAccess: bookingAccess2,
|
|
5363
|
+
reopenOrder: (order, bridge) => reopen(order, bridge, bookingAccess2)
|
|
5364
|
+
},
|
|
5365
|
+
eventTicketOrders: {
|
|
5366
|
+
kind: TICKET2,
|
|
5367
|
+
repeatable: true,
|
|
5368
|
+
eligibility: (item) => eligible2(item, TICKET2, options.eventsEnabled),
|
|
5369
|
+
openOrder: (item, bridge, beforeCreate, afterCreate) => options.eventsEnabled ? openTicket(item, bridge, now, beforeCreate, afterCreate) : Promise.resolve(NOT_ENABLED2),
|
|
5370
|
+
readAccess: ticketAccess2,
|
|
5371
|
+
reopenOrder: (order, bridge) => reopen(order, bridge, ticketAccess2, now)
|
|
5372
|
+
}
|
|
5373
|
+
};
|
|
5374
|
+
}
|
|
5375
|
+
var { bookingOrders: bookingClientOrders, eventTicketOrders: eventTicketClientOrders } = /* @__PURE__ */ attendanceClientOrdersWith({ bookingsEnabled: BOOKINGS_APPLE_SALES_ENABLED, eventsEnabled: EVENTS_APPLE_SALES_ENABLED });
|
|
5376
|
+
function eligible2(item, kind, enabled) {
|
|
5377
|
+
if (!enabled) return { eligible: false, reason: "notEnabled" };
|
|
5378
|
+
if (!singleUnitOf(kind, item).eligible || !isNonEmpty3(item.attemptId) || !item.attendance) return UNSUPPORTED;
|
|
5379
|
+
const selection = kind === BOOKING2 ? item.attendance.booking : item.attendance.ticket;
|
|
5380
|
+
return selection ? { eligible: true } : UNSUPPORTED;
|
|
5381
|
+
}
|
|
5382
|
+
async function openBooking(item, bridge, beforeCreate, afterCreate) {
|
|
5383
|
+
if (!eligible2(item, BOOKING2, true).eligible) return notCreated2(ORDER_REFUSED);
|
|
5384
|
+
const selected = item.attendance.booking;
|
|
5385
|
+
if (selected.slot.serviceId !== item.reference.id || !isNonEmpty3(selected.slot.startDate) || !isNonEmpty3(selected.slot.endDate)) return notCreated2(ORDER_REFUSED);
|
|
5386
|
+
const read2 = await bridge.call("GET", `/bookings/v2/services/${encodeURIComponent(item.reference.id)}`);
|
|
5387
|
+
if (isRefusal(read2)) return notCreated2(attemptRefused(read2));
|
|
5388
|
+
const service = bodyObject(read2, "service");
|
|
5389
|
+
const metadata = bookingAttendanceOf(service);
|
|
5390
|
+
if (classifyForApple(metadata, item.attendance.currency) !== "appleIap" || !samePrice2({ amount: metadata.amount, currency: metadata.currency }, item)) return notCreated2(CHANGED2);
|
|
5391
|
+
if (isObject7(service?.onlineBooking) && service.onlineBooking.requireManualApproval === true) return notCreated2({ status: "refused", reason: "approvalRequired" });
|
|
5392
|
+
const availability2 = await bridge.call("POST", "/bookings/v1/availability/query", { query: { filter: { serviceId: [item.reference.id], startDate: selected.slot.startDate, endDate: selected.slot.endDate, bookable: true } } });
|
|
5393
|
+
if (isRefusal(availability2)) return notCreated2(attemptRefused(availability2));
|
|
5394
|
+
const entries = isObject7(availability2.body) ? availability2.body.availabilityEntries : void 0;
|
|
5395
|
+
if (!Array.isArray(entries) || !entries.some((entry) => isObject7(entry) && entry.bookable === true && matchesSlot2(entry.slot, selected.slot))) return notCreated2(CHANGED2);
|
|
5396
|
+
if (beforeCreate && !beforeCreate(slotGuard2(selected.slot))) return notCreated2({ status: "refused", reason: "storageUnavailable" });
|
|
5397
|
+
const created = await bridge.call("POST", "/bookings/v2/bookings", { booking: { bookedEntity: { slot: selected.slot }, contactDetails: selected.contactDetails, totalParticipants: 1, selectedPaymentOption: "ONLINE", ...selected.formInfo ? { formInfo: selected.formInfo } : {} } });
|
|
5398
|
+
if (isRefusal(created)) return creationRefused2(created);
|
|
5399
|
+
const bookingId = bodyObject(created, "booking")?.id;
|
|
5400
|
+
if (!isNonEmpty3(bookingId)) return ORDER_REFUSED;
|
|
5401
|
+
if (afterCreate?.({ verticalRef: { bookingId } }) === false) return { status: "unavailable" };
|
|
5402
|
+
return bookingCheckout(item, bookingId, bridge);
|
|
5403
|
+
}
|
|
5404
|
+
function slotGuard2(slot) {
|
|
5405
|
+
const verticalRef = {};
|
|
5406
|
+
for (const key of ["sessionId", "startDate"]) if (isNonEmpty3(slot[key])) verticalRef[key] = slot[key];
|
|
5407
|
+
const ends = latestInstant2(String(slot.endDate));
|
|
5408
|
+
return Number.isFinite(ends) ? { verticalRef, releaseAt: ends + RELEASE_MARGIN_MS2 } : { verticalRef };
|
|
5409
|
+
}
|
|
5410
|
+
function latestInstant2(value) {
|
|
5411
|
+
if (HAS_OFFSET2.test(value)) return Date.parse(value);
|
|
5412
|
+
return Date.parse(`${value}Z`) + LATEST_ZONE_MS2;
|
|
5413
|
+
}
|
|
5414
|
+
async function resolveBookingOpening2(guard, item, bridge, options) {
|
|
5415
|
+
const scope = sameSlot2(guard.verticalRef, item?.attendance?.booking?.slot) ? "held" : "unrelated";
|
|
5416
|
+
const bookingId = guard.verticalRef?.bookingId;
|
|
5417
|
+
if (!bookingId || !options.settled) return scope;
|
|
5418
|
+
const released2 = await releaseBooking2(bookingId, bridge, options.claim);
|
|
5419
|
+
return released2 === "held" || released2 === "unavailable" && scope === "unrelated" ? scope : released2;
|
|
5420
|
+
}
|
|
5421
|
+
async function releaseBooking2(bookingId, bridge, claim) {
|
|
5422
|
+
const read2 = await bridge.call("POST", "/bookings/v2/bookings/query", { query: { filter: { id: { $eq: bookingId } } } });
|
|
5423
|
+
if (isRefusal(read2)) return read2.status === "http" && read2.httpStatus === 404 ? "released" : openingRefused2(read2);
|
|
5424
|
+
const rows = isObject7(read2.body) ? read2.body.bookings : void 0;
|
|
5425
|
+
const booking = Array.isArray(rows) ? rows.find((b) => isObject7(b) && b.id === bookingId) : void 0;
|
|
5426
|
+
if (!isObject7(booking)) return "held";
|
|
5427
|
+
if (["CANCELED", "CANCELLED", "DECLINED"].includes(String(booking.status)) || PAYMENT_TAKEN2.includes(String(booking.paymentStatus))) return "released";
|
|
5428
|
+
if (booking.status !== "CREATED" || !claim()) return "held";
|
|
5429
|
+
const cancelled = await bridge.call("POST", `/bookings/v2/bookings/${encodeURIComponent(bookingId)}/cancel`, { participantNotification: { notifyParticipants: false }, revision: booking.revision });
|
|
5430
|
+
return isRefusal(cancelled) ? openingRefused2(cancelled) : "released";
|
|
5431
|
+
}
|
|
5432
|
+
function openingRefused2(refusal) {
|
|
5433
|
+
if (refusal.status === "sessionChanged") return "sessionChanged";
|
|
5434
|
+
return refusal.status === "unavailable" ? "unavailable" : "held";
|
|
5435
|
+
}
|
|
5436
|
+
function sameSlot2(guarded, slot) {
|
|
5437
|
+
if (!guarded || !slot) return true;
|
|
5438
|
+
return guarded.sessionId === slot.sessionId && Date.parse(guarded.startDate ?? "") === Date.parse(String(slot.startDate));
|
|
5439
|
+
}
|
|
5063
5440
|
async function bookingCheckout(item, bookingId, bridge) {
|
|
5064
5441
|
const checkout = await bridge.call("POST", "/ecom/v1/checkouts", { lineItems: [{ quantity: 1, catalogReference: { appId: "13d21c63-b5ec-5912-8397-c3a5ddb27a97", catalogItemId: bookingId } }], channelType: "OTHER_PLATFORM" });
|
|
5065
5442
|
if (isRefusal(checkout)) return attemptRefused(checkout);
|
|
5066
5443
|
const entity = bodyObject(checkout, "checkout");
|
|
5067
5444
|
const total = isObject7(entity?.priceSummary) ? entity.priceSummary.total : void 0;
|
|
5068
|
-
if (!isObject7(total) || !
|
|
5445
|
+
if (!isObject7(total) || !samePrice2({ amount: total.amount, currency: entity?.currency }, item)) return CHANGED2;
|
|
5069
5446
|
if (!isNonEmpty3(entity?.id)) return ORDER_REFUSED;
|
|
5070
5447
|
const placed = await bridge.call("POST", `/ecom/v1/checkouts/${encodeURIComponent(entity.id)}/create-order`, {});
|
|
5071
5448
|
if (isRefusal(placed)) return attemptRefused(placed);
|
|
@@ -5073,7 +5450,7 @@ async function bookingCheckout(item, bookingId, bridge) {
|
|
|
5073
5450
|
if (!isObject7(body) || !isNonEmpty3(body.orderId) || !isNonEmpty3(body.paymentGatewayOrderId)) return ORDER_REFUSED;
|
|
5074
5451
|
return { status: "open", cashierOrderId: body.paymentGatewayOrderId, verticalRef: { serviceId: item.reference.id, bookingId, orderId: body.orderId } };
|
|
5075
5452
|
}
|
|
5076
|
-
async function
|
|
5453
|
+
async function bookingAccess2(ref, bridge) {
|
|
5077
5454
|
if (!ref.bookingId || !ref.orderId) return "unavailable";
|
|
5078
5455
|
const order = await bridge.call("GET", `/ecom/v1/orders/${encodeURIComponent(ref.orderId)}`);
|
|
5079
5456
|
if (isRefusal(order)) return accessRefused(order);
|
|
@@ -5088,19 +5465,19 @@ async function bookingAccess(ref, bridge) {
|
|
|
5088
5465
|
return payment === "PAID" && booking.status === "CONFIRMED" && booking.paymentStatus === "PAID" ? "granted" : "pending";
|
|
5089
5466
|
}
|
|
5090
5467
|
async function openTicket(item, bridge, now, beforeCreate, afterCreate) {
|
|
5091
|
-
if (!
|
|
5468
|
+
if (!eligible2(item, TICKET2, true).eligible) return notCreated2(ORDER_REFUSED);
|
|
5092
5469
|
const selected = item.attendance.ticket;
|
|
5093
|
-
if (!isNonEmpty3(selected.eventId)) return
|
|
5470
|
+
if (!isNonEmpty3(selected.eventId)) return notCreated2(ORDER_REFUSED);
|
|
5094
5471
|
const read2 = await bridge.call("GET", `/events/v3/events/${encodeURIComponent(selected.eventId)}?fields=REGISTRATION&fields=DETAILS&fields=FORM`);
|
|
5095
|
-
if (isRefusal(read2)) return
|
|
5472
|
+
if (isRefusal(read2)) return notCreated2(attemptRefused(read2));
|
|
5096
5473
|
const available = await bridge.call("POST", "/events/v1/checkout/available-tickets/query", { filter: { eventId: selected.eventId }, limit: 100, offset: 0 });
|
|
5097
|
-
if (isRefusal(available)) return
|
|
5474
|
+
if (isRefusal(available)) return notCreated2(attemptRefused(available));
|
|
5098
5475
|
const definitions = isObject7(available.body) ? available.body.definitions : void 0;
|
|
5099
5476
|
const live = Array.isArray(definitions) ? definitions.find((t) => isObject7(t) && t.id === item.reference.id && t.saleStatus === "SALE_STARTED") : void 0;
|
|
5100
|
-
if (!isObject7(live) || !
|
|
5477
|
+
if (!isObject7(live) || !samePrice2(live.price, item)) return notCreated2(CHANGED2);
|
|
5101
5478
|
const event = bodyObject(read2, "event");
|
|
5102
|
-
if (live.eventId !== selected.eventId || classifyForApple(availableTicketAttendanceOf(event, live), item.attendance.currency) !== "appleIap") return
|
|
5103
|
-
if (beforeCreate && !beforeCreate({ releaseAt: now() + reservationMinutes(event) * MINUTE_MS +
|
|
5479
|
+
if (live.eventId !== selected.eventId || classifyForApple(availableTicketAttendanceOf(event, live), item.attendance.currency) !== "appleIap") return notCreated2(ORDER_REFUSED);
|
|
5480
|
+
if (beforeCreate && !beforeCreate({ releaseAt: now() + reservationMinutes(event) * MINUTE_MS + RELEASE_MARGIN_MS2 })) return notCreated2({ status: "refused", reason: "storageUnavailable" });
|
|
5104
5481
|
return reserveTicket(item, bridge, now, afterCreate);
|
|
5105
5482
|
}
|
|
5106
5483
|
function reservationMinutes(event) {
|
|
@@ -5111,20 +5488,21 @@ function reservationMinutes(event) {
|
|
|
5111
5488
|
async function reserveTicket(item, bridge, now, afterCreate) {
|
|
5112
5489
|
const selected = item.attendance.ticket;
|
|
5113
5490
|
const held = await bridge.call("POST", "/events/v1/checkout/reservations", { eventId: selected.eventId, ticketQuantities: [{ ticketDefinitionId: item.reference.id, quantity: 1 }], ignoreLimits: false, allowHiddenTickets: false });
|
|
5114
|
-
if (isRefusal(held)) return
|
|
5491
|
+
if (isRefusal(held)) return creationRefused2(held);
|
|
5115
5492
|
const reservation = held.body;
|
|
5116
5493
|
if (!isObject7(reservation) || !isNonEmpty3(reservation.id) || !future(reservation.expires, now)) return ORDER_CLOSED;
|
|
5117
|
-
afterCreate?.({ verticalRef: { reservationId: reservation.id }, releaseAt: Date.parse(reservation.expires) +
|
|
5118
|
-
if (!heldAsSelected(reservation, item)) return
|
|
5494
|
+
if (afterCreate?.({ verticalRef: { reservationId: reservation.id }, releaseAt: Date.parse(reservation.expires) + RELEASE_MARGIN_MS2 }) === false) return { status: "unavailable" };
|
|
5495
|
+
if (!heldAsSelected(reservation, item)) return CHANGED2;
|
|
5119
5496
|
const placed = await bridge.call("POST", "/events/v1/checkout", { eventId: selected.eventId, reservationId: reservation.id, buyer: selected.buyer, ...selected.guests ? { guests: selected.guests } : {}, ...selected.buyerSubmission ? { buyerSubmission: selected.buyerSubmission } : {}, ...selected.guestSubmissions ? { guestSubmissions: selected.guestSubmissions } : {}, options: { silent: false, payInPerson: false, ignoreFormValidation: false, markAsPaid: false } });
|
|
5120
5497
|
if (isRefusal(placed)) return attemptRefused(placed);
|
|
5121
5498
|
const order = bodyObject(placed, "order");
|
|
5122
|
-
if (!
|
|
5499
|
+
if (!samePrice2(order?.totalPrice, item)) return CHANGED2;
|
|
5123
5500
|
const expires = isObject7(placed.body) && placed.body.expires || reservation.expires;
|
|
5124
5501
|
if (!future(expires, now) || !isNonEmpty3(order?.snapshotId) || !isNonEmpty3(order?.orderNumber)) return ORDER_CLOSED;
|
|
5125
5502
|
return { status: "open", cashierOrderId: order.snapshotId, verticalRef: { eventId: selected.eventId, ticketDefinitionId: item.reference.id, reservationId: reservation.id, orderNumber: order.orderNumber, expires: String(expires) } };
|
|
5126
5503
|
}
|
|
5127
|
-
async function
|
|
5504
|
+
async function ticketAccess2(ref, bridge) {
|
|
5505
|
+
if (isNonEmpty3(ref.orderId)) return ecomOrderAccess(ref.orderId, bridge);
|
|
5128
5506
|
if (!ref.eventId || !ref.orderNumber || !ref.ticketDefinitionId) return "unavailable";
|
|
5129
5507
|
const read2 = await bridge.call("GET", `/events/v1/events/${encodeURIComponent(ref.eventId)}/orders/${encodeURIComponent(ref.orderNumber)}?fieldset=DETAILS&fieldset=TICKETS`);
|
|
5130
5508
|
if (isRefusal(read2)) return accessRefused(read2);
|
|
@@ -5141,33 +5519,36 @@ async function reopen(order, bridge, accessOf2, now) {
|
|
|
5141
5519
|
return { status: "open", ...order };
|
|
5142
5520
|
}
|
|
5143
5521
|
function heldAsSelected(reservation, item) {
|
|
5144
|
-
if (isObject7(reservation.invoice)) return
|
|
5522
|
+
if (isObject7(reservation.invoice)) return samePrice2(reservation.invoice.grandTotal ?? reservation.invoice.total, item);
|
|
5145
5523
|
const lines = reservation.reservations;
|
|
5146
5524
|
if (!Array.isArray(lines) || lines.length !== 1 || !isObject7(lines[0]) || lines[0].quantity !== 1) return false;
|
|
5147
5525
|
const held = lines[0].ticket;
|
|
5148
|
-
return isObject7(held) && held.id === item.reference.id &&
|
|
5526
|
+
return isObject7(held) && held.id === item.reference.id && samePrice2(held.price, item);
|
|
5149
5527
|
}
|
|
5150
|
-
function
|
|
5151
|
-
return isObject7(value) && value.currency === item.attendance?.currency &&
|
|
5528
|
+
function samePrice2(value, item) {
|
|
5529
|
+
return isObject7(value) && value.currency === item.attendance?.currency && decimal2(value.amount) !== null && decimal2(value.amount) === decimal2(item.attendance?.amount);
|
|
5152
5530
|
}
|
|
5153
|
-
function
|
|
5531
|
+
function decimal2(value) {
|
|
5154
5532
|
if (typeof value !== "string" || !/^\d+(?:\.\d+)?$/.test(value)) return null;
|
|
5155
5533
|
return value.replace(/^0+(?=\d)/, "").replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
|
|
5156
5534
|
}
|
|
5157
5535
|
function future(value, now) {
|
|
5158
5536
|
return typeof value === "string" && Number.isFinite(Date.parse(value)) && Date.parse(value) > now();
|
|
5159
5537
|
}
|
|
5160
|
-
function
|
|
5538
|
+
function matchesSlot2(value, selected) {
|
|
5161
5539
|
return isObject7(value) && ["serviceId", "sessionId"].every((key) => value[key] === selected[key]) && ["startDate", "endDate"].every((key) => typeof value[key] === "string" && Date.parse(value[key]) === Date.parse(String(selected[key])));
|
|
5162
5540
|
}
|
|
5163
|
-
function
|
|
5541
|
+
function creationRefused2(refusal) {
|
|
5164
5542
|
const attempt4 = attemptRefused(refusal);
|
|
5165
|
-
return refusal.status === "http" && [400, 401, 403, 404, 405, 409, 410, 415, 422].includes(refusal.httpStatus) ?
|
|
5543
|
+
return refusal.status === "http" && [400, 401, 403, 404, 405, 409, 410, 415, 422].includes(refusal.httpStatus) ? notCreated2(attempt4) : attempt4;
|
|
5166
5544
|
}
|
|
5167
|
-
function
|
|
5545
|
+
function notCreated2(attempt4) {
|
|
5168
5546
|
return { ...attempt4, noOrderCreated: true };
|
|
5169
5547
|
}
|
|
5170
5548
|
|
|
5549
|
+
// ../../stdlib/flows/iap-checkout/src/iap-verticals/index.ts
|
|
5550
|
+
var pricingPlanOrders = PRICING_PLAN_ITEM_PAYMENT_ENABLED ? pricingPlanItemPayments : pricingPlanClientOrders;
|
|
5551
|
+
|
|
5171
5552
|
// ../../stdlib/wix-sdk/redirects-v1/src/index.ts
|
|
5172
5553
|
function wixCallHeaders(opts) {
|
|
5173
5554
|
const site = opts?.site?.trim();
|
|
@@ -5506,7 +5887,7 @@ function createCheckoutService(opts = {}) {
|
|
|
5506
5887
|
const commerce = createIapCommerce({ adapters: [pricingPlanOrders], onChange: () => {
|
|
5507
5888
|
void svc.pricingPublish();
|
|
5508
5889
|
} });
|
|
5509
|
-
const purchaseCopy = { buy: c.joinCta ?? "Buy now", processing: c.pendingNotice ?? "Processing your purchase\u2026", awaitingApproval: "Waiting for approval", unavailable: c.failedNotice ?? "Purchasing is temporarily unavailable.", signInRequired: c.signInFirst ?? "Sign in to join a plan \u2014 memberships belong to a member account.", retry: c.failedNotice ?? "Something went wrong. Try again.", priceChanged: "The price changed. Check it and try again.", support: "We couldn't finish this purchase. Contact support." };
|
|
5890
|
+
const purchaseCopy = { buy: c.joinCta ?? "Buy now", processing: c.pendingNotice ?? "Processing your purchase\u2026", awaitingApproval: "Waiting for approval", unavailable: c.failedNotice ?? "Purchasing is temporarily unavailable.", signInRequired: c.signInFirst ?? "Sign in to join a plan \u2014 memberships belong to a member account.", retry: c.failedNotice ?? "Something went wrong. Try again.", priceChanged: "The price changed. Check it and try again.", support: "We couldn't finish this purchase. Contact support.", memberDetailsRequired: "Complete your profile, then try again.", alreadySubscribed: "You already have this subscription." };
|
|
5510
5891
|
let catalogRows = [];
|
|
5511
5892
|
let items = [];
|
|
5512
5893
|
let started = false;
|