@wix/himalaya-cli 0.1659.0 → 0.1660.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.
Files changed (66) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/attendance-classifier.d.ts +3 -1
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/delivery-contract.d.ts +3 -0
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/index.d.ts +7 -0
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/wix-payments-contract.d.ts +19 -1
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/wix-payments-wire.d.ts +2 -0
  6. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/sdk-types/src/capabilities.generated.d.ts +1 -1
  7. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/apple-iap-contract.d.ts +22 -5
  8. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/commerce-contract.d.ts +4 -0
  9. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-order-backend.d.ts +5 -0
  10. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/attendance-orders.d.ts +10 -0
  11. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/attendance.d.ts +4 -5
  12. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/index.d.ts +13 -3
  13. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/online-programs-orders.d.ts +2 -0
  14. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/online-programs.d.ts +2 -2
  15. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/pricing-plans-orders.d.ts +2 -0
  16. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/pricing-plans.d.ts +4 -2
  17. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/shared.d.ts +3 -1
  18. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/audio-record.mjs +1 -1
  19. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/calendar.mjs +1 -1
  20. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/calls.mjs +1 -1
  21. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/contacts.mjs +1 -1
  22. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap-checkout.mjs +545 -166
  23. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap.mjs +52 -8
  24. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/location.mjs +1 -1
  25. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/motion.mjs +1 -1
  26. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/photos.mjs +1 -1
  27. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +423 -88
  28. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdk-types.mjs +1 -1
  29. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/tasks.mjs +1 -1
  30. package/dist/browser-plane/assets.json +5 -5
  31. package/dist/browser-plane/preview-deferred/{c04dd5fc5ad48e6b19678d4313159302e9a513ada94bfe515d8dfd5a54d46f5d.bin → fcafca348b6b973cfc2eadc938ddec3c515c641874cbca1667a43b22e1bf7a39.bin} +1 -1
  32. package/dist/browser-plane/sw.js +1 -1
  33. package/dist/cli.mjs +175 -52
  34. package/dist/preview-assets.generated.bin +0 -0
  35. package/guides/himi-json-output.md +26 -1
  36. package/guides/qa-builds.md +20 -0
  37. package/guides/sdk-reference.json +79 -9
  38. package/guides/skill.md +2 -2
  39. package/guides/web-page-sdk-reference.md +1 -1
  40. package/package.json +2 -2
  41. package/templates/beauty-salon/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  42. package/templates/beauty-salon/tier5-src/_shared/iap-worker.ts +2 -0
  43. package/templates/branded-lite/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  44. package/templates/branded-lite/tier5-src/_shared/iap-worker.ts +2 -0
  45. package/templates/community-club/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  46. package/templates/community-club/tier5-src/_shared/iap-worker.ts +2 -0
  47. package/templates/conference/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  48. package/templates/conference/tier5-src/_shared/iap-worker.ts +2 -0
  49. package/templates/events-meetups/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  50. package/templates/events-meetups/tier5-src/_shared/iap-worker.ts +2 -0
  51. package/templates/gym-fitness/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  52. package/templates/gym-fitness/tier5-src/_shared/iap-worker.ts +2 -0
  53. package/templates/nonprofit-cause/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  54. package/templates/nonprofit-cause/tier5-src/_shared/iap-worker.ts +2 -0
  55. package/templates/podcast-creator/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  56. package/templates/podcast-creator/tier5-src/_shared/iap-worker.ts +2 -0
  57. package/templates/portfolio-creative/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  58. package/templates/portfolio-creative/tier5-src/_shared/iap-worker.ts +2 -0
  59. package/templates/restaurant/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  60. package/templates/restaurant/tier5-src/_shared/iap-worker.ts +2 -0
  61. package/templates/retail-store/tier5-src/_shared/iap-worker.ts +2 -0
  62. package/templates/salon-spa/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  63. package/templates/salon-spa/tier5-src/_shared/iap-worker.ts +2 -0
  64. package/templates/wholesale-store/tier5-src/_shared/iap-worker.ts +2 -0
  65. package/templates/yoga-studio/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  66. package/templates/yoga-studio/tier5-src/_shared/iap-worker.ts +2 -0
@@ -135,9 +135,18 @@ function createPurchaseCoordinator(deps) {
135
135
  else if (result.status === "failed") failStore(result.code, false);
136
136
  else if (result.status === "pending") {
137
137
  if (!await awaitApproval(session, context)) return !disposed;
138
- } else setOutcome("cancelled");
138
+ } else {
139
+ setOutcome("cancelled");
140
+ void abandon(session, catalogRef);
141
+ }
139
142
  return false;
140
143
  }
144
+ async function abandon(session, catalogRef) {
145
+ try {
146
+ await deps.backend.abandonPurchase?.(session, catalogRef);
147
+ } catch {
148
+ }
149
+ }
141
150
  async function deliverPurchase(session, transaction, context) {
142
151
  const item = upsert2(transaction, null);
143
152
  applyDelivered(await deliver(session, [item], context));
@@ -152,9 +161,9 @@ function createPurchaseCoordinator(deps) {
152
161
  if (session.kind !== "member") return requireSignIn();
153
162
  if (listing === "listed") clearReconcileProblem();
154
163
  const now = deps.clock.now();
155
- const eligible2 = itemsWhere((item) => isAwaitingDelivery(item) && (item.state.nextAttemptAt === null || item.state.nextAttemptAt <= now));
156
- eligible2.forEach(restartAttemptBudget);
157
- await settleDelivery(session, await deliver(session, eligible2));
164
+ const eligible3 = itemsWhere((item) => isAwaitingDelivery(item) && (item.state.nextAttemptAt === null || item.state.nextAttemptAt <= now));
165
+ eligible3.forEach(restartAttemptBudget);
166
+ await settleDelivery(session, await deliver(session, eligible3));
158
167
  }
159
168
  async function settleDelivery(session, delivered) {
160
169
  applyDelivered(delivered);
@@ -713,6 +722,11 @@ var ONLINE_PROGRAM_SALE_RULE = { appProductId: (id) => id, productType: "NON_CON
713
722
  var PRICING_PLAN_APPLE_SALES_ENABLED = true;
714
723
  var PRICING_PLAN_SALE_RULE = { appProductId: (id) => id, productType: "NON_CONSUMABLE" };
715
724
  var VIDEOS_APPLE_SALES_ENABLED = false;
725
+ var PRICING_PLAN_ITEM_PAYMENT_ENABLED = false;
726
+ var ONLINE_PROGRAM_ITEM_PAYMENT_ENABLED = false;
727
+ var BOOKINGS_ITEM_PAYMENT_ENABLED = false;
728
+ var EVENTS_ITEM_PAYMENT_ENABLED = false;
729
+ var CANCEL_PAYMENT_ENABLED = false;
716
730
  var VIDEO_SALE_RULE = { appProductId: (id) => id, productType: "NON_CONSUMABLE" };
717
731
  function appleSaleRules(options = {}) {
718
732
  return {
@@ -1120,10 +1134,21 @@ function decodeStartedItem(raw, expected) {
1120
1134
  if (!isObject3(raw)) return null;
1121
1135
  const ecomOrderId = optionalId(raw.ecomOrderId);
1122
1136
  const joinApplicationId = optionalId(raw.joinApplicationId);
1123
- if (ecomOrderId === null || joinApplicationId === null || !ecomOrderId && !joinApplicationId) return null;
1137
+ const eventsOrderNumber = optionalOrderNumber(raw.eventsOrderNumber);
1138
+ if (ecomOrderId === null || joinApplicationId === null || eventsOrderNumber === null) return null;
1139
+ if (!ecomOrderId && !joinApplicationId && !eventsOrderNumber) return null;
1124
1140
  const started = decodeStarted(raw, expected);
1125
1141
  if (!started || started.payment.appProductId !== expected.catalogItemId) return null;
1126
- return { ...started, ...ecomOrderId ? { ecomOrderId } : {}, ...joinApplicationId ? { joinApplicationId } : {} };
1142
+ return {
1143
+ ...started,
1144
+ ...ecomOrderId ? { ecomOrderId } : {},
1145
+ ...joinApplicationId ? { joinApplicationId } : {},
1146
+ ...eventsOrderNumber ? { eventsOrderNumber } : {}
1147
+ };
1148
+ }
1149
+ function optionalOrderNumber(value) {
1150
+ if (value === void 0 || value === "") return void 0;
1151
+ return typeof value === "string" && value.length <= 36 ? value : null;
1127
1152
  }
1128
1153
  function optionalId(value) {
1129
1154
  if (value === void 0 || value === "") return void 0;
@@ -1424,7 +1449,8 @@ var START_ITEM_PAYMENT_CODES = [
1424
1449
  "BILLING_COUNTRY_REQUIRED",
1425
1450
  "APP_NOT_CONFIGURED",
1426
1451
  "NOT_BOOKING_OWNER",
1427
- "BOOKING_PAYMENT_PENDING"
1452
+ "BOOKING_PAYMENT_PENDING",
1453
+ "MEMBER_DETAILS_REQUIRED"
1428
1454
  ];
1429
1455
  var CANCEL_PAYMENT_CODES = ["NOT_PENDING", "APP_NOT_CONFIGURED", "NOT_FOUND"];
1430
1456
  var UNDECIDED = /* @__PURE__ */ new Set(["unavailable", "sessionChanged", "invalidResponse"]);
@@ -1538,15 +1564,18 @@ function ticketAttendanceOf(event, definition) {
1538
1564
  function availableTicketAttendanceOf(event, ticket) {
1539
1565
  const e = object(event);
1540
1566
  const t = object(ticket);
1541
- const pricing = object(t.pricing);
1567
+ const v3 = t.pricingMethod !== void 0;
1568
+ const pricing = object(v3 ? t.pricingMethod : t.pricing);
1542
1569
  const fixed = object(pricing.fixedPrice);
1570
+ const amount = v3 ? fixed.value : fixed.amount;
1543
1571
  const price = object(t.price);
1544
- const visible = Array.isArray(t.state) && t.state.length === 0 && object(t.dashboard).hidden !== true && typeof t.id === "string" && t.id.length > 0 && typeof e.id === "string" && e.id.length > 0 && t.eventId === e.id;
1545
- const fixedPrice = t.free === false && pricing.pricingType === "STANDARD" && sameTicketAmount(fixed.amount, price.amount) && fixed.currency === price.currency;
1572
+ const listed = v3 ? t.hidden === false && t.state === void 0 : Array.isArray(t.state) && t.state.length === 0;
1573
+ const visible = listed && object(t.dashboard).hidden !== true && typeof t.id === "string" && t.id.length > 0 && typeof e.id === "string" && e.id.length > 0 && t.eventId === e.id;
1574
+ const fixedPrice = t.free === false && (!v3 || pricing.free === false) && pricing.pricingType === "STANDARD" && sameTicketAmount(amount, price.amount) && fixed.currency === price.currency;
1546
1575
  return ticketAttendanceOf(e, {
1547
1576
  hidden: visible ? false : void 0,
1548
1577
  saleStatus: t.saleStatus,
1549
- pricingMethod: { pricingType: fixedPrice ? "STANDARD" : void 0, fixedPrice: { value: fixed.amount, currency: fixed.currency } }
1578
+ pricingMethod: { pricingType: fixedPrice ? "STANDARD" : void 0, fixedPrice: { value: amount, currency: fixed.currency } }
1550
1579
  });
1551
1580
  }
1552
1581
  function sameTicketAmount(left, right) {
@@ -1563,6 +1592,15 @@ var boolean = (value) => typeof value === "boolean" ? value : void 0;
1563
1592
  var zeroPrice = (value) => typeof value === "string" && /^0+(?:\.0+)?$/.test(value);
1564
1593
 
1565
1594
  // ../../core/sdk/iap/src/index.ts
1595
+ async function storefrontCountryCode() {
1596
+ try {
1597
+ const r = await dispatch("capability.iap.storefront");
1598
+ const code = r?.countryCode;
1599
+ return typeof code === "string" && /^[A-Z]{3}$/.test(code) ? code : null;
1600
+ } catch {
1601
+ return null;
1602
+ }
1603
+ }
1566
1604
  async function getProducts(productIds) {
1567
1605
  if (!productIds || productIds.length === 0) return [];
1568
1606
  const r = await dispatch("capability.iap.getProducts", {
@@ -2031,7 +2069,25 @@ function createWixOrderBackend(deps) {
2031
2069
  const blocked = saleBlocked(sale);
2032
2070
  if (blocked) return contextResult(catalogRef, blocked);
2033
2071
  const { adapter } = sale;
2034
- return paidByItem(adapter) ? startItemFor(sale, adapter.itemPayment(sale.item)) : startOrderFor({ ...sale, adapter });
2072
+ if (!paidByItem(adapter)) return startOrderFor({ ...sale, adapter });
2073
+ const country = await readStoreCountry();
2074
+ if (!sale.bridge.isCurrent()) return contextResult(catalogRef, STALE2);
2075
+ const { state, beforeCreate, afterCreate } = creationGuards(sale, void 0);
2076
+ const prepared = await adapter.itemPayment(sale.item, sale.bridge, beforeCreate, afterCreate);
2077
+ if (state.prevented) return contextResult(catalogRef, state.prevented);
2078
+ if (!sale.bridge.isCurrent()) return contextResult(catalogRef, STALE2);
2079
+ if ("status" in prepared) return contextResult(catalogRef, preparationStop(sale, prepared, state.guarded));
2080
+ if (state.guarded !== void 0 && !stillGuarded(sale, state.guarded)) return contextResult(catalogRef, retry("unavailable"));
2081
+ const stillBlocked = state.guarded === void 0 ? saleBlocked(sale) : null;
2082
+ if (stillBlocked) return contextResult(catalogRef, stillBlocked);
2083
+ return startItemFor(sale, prepared, country);
2084
+ }
2085
+ function preparationStop(sale, refusal, guarded) {
2086
+ if (refusal.noOrderCreated && guarded !== void 0 && stillGuarded(sale, guarded) && !sale.partition.remove(sale.catalogRef)) {
2087
+ return stopWith("rejected", "storageUnavailable");
2088
+ }
2089
+ if (refusal.status === "refused") return stopWith("rejected", refusal.reason);
2090
+ return refusal.status === "sessionChanged" ? STALE2 : retry("unavailable");
2035
2091
  }
2036
2092
  async function startOrderFor(sale) {
2037
2093
  const ordered = await orderFor(sale);
@@ -2090,39 +2146,42 @@ function createWixOrderBackend(deps) {
2090
2146
  unrelated: /* @__PURE__ */ new Set()
2091
2147
  };
2092
2148
  }
2093
- async function orderFor(sale) {
2094
- const existing = refAt(sale.partition, sale.catalogRef);
2095
- let prevented;
2096
- let guarded;
2149
+ function creationGuards(sale, existing) {
2150
+ const state = {};
2097
2151
  const beforeCreate = (guard = {}) => {
2098
2152
  if (!sale.adapter.repeatable || existing) return true;
2099
2153
  if (!sale.bridge.isCurrent()) {
2100
- prevented = STALE2;
2154
+ state.prevented = STALE2;
2101
2155
  return false;
2102
2156
  }
2103
2157
  const blocked = saleBlocked(sale);
2104
2158
  if (blocked) {
2105
- prevented = blocked;
2159
+ state.prevented = blocked;
2106
2160
  return false;
2107
2161
  }
2108
2162
  const opening = persist(sale, { ...guard, key: sale.catalogRef, kind: sale.adapter.kind, stage: "openingOrder", updatedAt: now() });
2109
2163
  if (isStop(opening)) {
2110
- prevented = opening;
2164
+ state.prevented = opening;
2111
2165
  return false;
2112
2166
  }
2113
- guarded = opening.updatedAt;
2167
+ state.guarded = opening.updatedAt;
2114
2168
  return true;
2115
2169
  };
2116
2170
  const afterCreate = (guard) => {
2117
2171
  const opening = refAt(sale.partition, sale.catalogRef);
2118
- if (opening?.stage !== "openingOrder" || opening.updatedAt !== guarded) return;
2172
+ if (opening?.stage !== "openingOrder" || opening.updatedAt !== state.guarded) return;
2119
2173
  const recorded = persist(sale, { ...opening, ...guard, verticalRef: { ...opening.verticalRef, ...guard.verticalRef }, updatedAt: now() });
2120
- if (!isStop(recorded)) guarded = recorded.updatedAt;
2174
+ if (!isStop(recorded)) state.guarded = recorded.updatedAt;
2121
2175
  };
2176
+ return { state, beforeCreate, afterCreate };
2177
+ }
2178
+ async function orderFor(sale) {
2179
+ const existing = refAt(sale.partition, sale.catalogRef);
2180
+ const { state, beforeCreate, afterCreate } = creationGuards(sale, existing);
2122
2181
  const attempt3 = existing?.cashierOrderId && existing.verticalRef ? await reopenOrOpen(sale, { cashierOrderId: existing.cashierOrderId, verticalRef: existing.verticalRef }) : await sale.adapter.openOrder(sale.item, sale.bridge, beforeCreate, afterCreate);
2123
- if (prevented) return prevented;
2124
- if (guarded !== void 0 && attempt3.status === "open" && !stillGuarded(sale, guarded)) return retry("unavailable");
2125
- const ref = recordOrder(sale, existing, attempt3, guarded);
2182
+ if (state.prevented) return state.prevented;
2183
+ if (state.guarded !== void 0 && attempt3.status === "open" && !stillGuarded(sale, state.guarded)) return retry("unavailable");
2184
+ const ref = recordOrder(sale, existing, attempt3, state.guarded);
2126
2185
  return isStop(ref) ? ref : { ref, placed: isPlaced(attempt3) };
2127
2186
  }
2128
2187
  function stillGuarded(sale, guarded) {
@@ -2206,24 +2265,38 @@ function createWixOrderBackend(deps) {
2206
2265
  if (isStop(recorded)) return contextResult(sale.catalogRef, recorded);
2207
2266
  return { status: "ok", context: { productId: started.storeProductId, appAccountToken: started.appAccountToken, scopeKey: sale.member.scopeKey } };
2208
2267
  }
2209
- async function startItemFor(sale, itemPayment2) {
2210
- const attempt3 = persist(sale, { key: sale.catalogRef, stage: "startingItem", kind: sale.adapter.kind, storeProductId: sale.appleProduct.productId, updatedAt: now() });
2268
+ async function startItemFor(sale, itemPayment4, country) {
2269
+ const made = refAt(sale.partition, sale.catalogRef);
2270
+ const guarded = made?.stage === "openingOrder" ? { verticalRef: made.verticalRef, releaseAt: made.releaseAt } : {};
2271
+ const attempt3 = persist(sale, {
2272
+ key: sale.catalogRef,
2273
+ stage: "startingItem",
2274
+ kind: sale.adapter.kind,
2275
+ storeProductId: sale.appleProduct.productId,
2276
+ ...guarded.verticalRef ? { verticalRef: guarded.verticalRef } : {},
2277
+ ...guarded.releaseAt !== void 0 ? { releaseAt: guarded.releaseAt } : {},
2278
+ updatedAt: now()
2279
+ });
2211
2280
  if (isStop(attempt3)) return contextResult(sale.catalogRef, attempt3);
2212
- const started = await deps.wixIap.startItemPayment({ item: itemPayment2.catalogItem });
2281
+ const started = await deps.wixIap.startItemPayment({ item: itemPayment4.catalogItem, ...country ? { storeCountryCode: country } : {} });
2213
2282
  if (started.status === "outcomeUnknown") return contextResult(sale.catalogRef, sale.bridge.isCurrent() ? OUTCOME_UNKNOWN : STALE2);
2214
2283
  if (started.status !== "started") return contextResult(sale.catalogRef, itemRefusal(sale, started));
2215
- return startedItem(sale, itemPayment2, started);
2216
- }
2217
- function startedItem(sale, itemPayment2, started) {
2218
- if (started.storeProductId !== sale.appleProduct.productId) return contextResult(sale.catalogRef, stopWith("rejected", "productChanged"));
2219
- const verticalRef = itemPayment2.verticalRefOf(started);
2220
- if (!verticalRef) return contextResult(sale.catalogRef, OUTCOME_UNKNOWN);
2284
+ return startedItem(sale, itemPayment4, started);
2285
+ }
2286
+ function startedItem(sale, itemPayment4, started) {
2287
+ if (started.storeProductId !== sale.appleProduct.productId) return contextResult(sale.catalogRef, unsold(sale, stopWith("rejected", "productChanged")));
2288
+ const placed = itemPayment4.verticalRefOf(started);
2289
+ if (!placed) return contextResult(sale.catalogRef, unsold(sale, OUTCOME_UNKNOWN));
2290
+ const attempt3 = refAt(sale.partition, sale.catalogRef);
2291
+ const guarded = attempt3?.stage === "startingItem" ? attempt3 : void 0;
2292
+ const verticalRef = guarded?.verticalRef ? { ...guarded.verticalRef, ...placed } : placed;
2221
2293
  const { payment, storeProductId, appAccountToken } = started;
2222
2294
  const recorded = persist(sale, {
2223
2295
  key: sale.catalogRef,
2224
2296
  stage: "started",
2225
2297
  kind: sale.adapter.kind,
2226
2298
  verticalRef,
2299
+ ...guarded?.releaseAt !== void 0 ? { releaseAt: guarded.releaseAt } : {},
2227
2300
  wixTransactionId: payment.wixTransactionId,
2228
2301
  paymentId: payment.paymentId,
2229
2302
  storeProductId,
@@ -2234,11 +2307,30 @@ function createWixOrderBackend(deps) {
2234
2307
  if (isStop(recorded)) return contextResult(sale.catalogRef, recorded);
2235
2308
  return { status: "ok", context: { productId: storeProductId, appAccountToken, scopeKey: sale.member.scopeKey } };
2236
2309
  }
2310
+ function unsold(sale, stop) {
2311
+ handBackToGuard(sale.partition, sale.adapter, refAt(sale.partition, sale.catalogRef));
2312
+ return stop;
2313
+ }
2237
2314
  function itemRefusal(sale, failure3) {
2315
+ if (failure3.kind === "application" && failure3.code === "NOT_BOOKING_OWNER") return dropAttempt(sale, retry("bookingNotOwned"));
2238
2316
  if (failure3.kind === "application") return undoAttempt(sale, stopWith("rejected", ITEM_REFUSALS[failure3.code]));
2239
2317
  return undoAttempt(sale, failure3.kind === "unrecognized" ? NOT_CONFIGURED : failureStop(failure3));
2240
2318
  }
2241
2319
  function undoAttempt(sale, stop) {
2320
+ return handBackToGuard(sale.partition, sale.adapter, refAt(sale.partition, sale.catalogRef)) ? stop : dropAttempt(sale, stop);
2321
+ }
2322
+ function handBackToGuard(partition, adapter, attempt3) {
2323
+ if (!attempt3?.verticalRef || !adapter.resolveOpening) return false;
2324
+ return partition.put({
2325
+ key: attempt3.key,
2326
+ kind: adapter.kind,
2327
+ stage: "openingOrder",
2328
+ verticalRef: attempt3.verticalRef,
2329
+ ...attempt3.releaseAt !== void 0 ? { releaseAt: attempt3.releaseAt } : {},
2330
+ updatedAt: now() - OPENING_SETTLE_MS
2331
+ });
2332
+ }
2333
+ function dropAttempt(sale, stop) {
2242
2334
  sale.partition.remove(sale.catalogRef);
2243
2335
  return stop;
2244
2336
  }
@@ -2247,9 +2339,8 @@ function createWixOrderBackend(deps) {
2247
2339
  }
2248
2340
  async function startRefusal(sale, ref, failure3) {
2249
2341
  if (failure3.kind !== "application") return failureStop(failure3);
2250
- if (failure3.code === "SUBSCRIPTION_NOT_IN_APP" || failure3.code === "ALREADY_SUBSCRIBED") {
2251
- return stopWith("rejected", "paymentRefused");
2252
- }
2342
+ if (failure3.code === "SUBSCRIPTION_NOT_IN_APP") return stopWith("rejected", "unsupportedItem");
2343
+ if (failure3.code === "ALREADY_SUBSCRIBED") return stopWith("rejected", "alreadySubscribed");
2253
2344
  if (failure3.code === "ALREADY_OWNED") return alreadyPaid(sale, ref);
2254
2345
  if (failure3.code === "NOT_PENDING" || failure3.code === "NOT_ORDER_BUYER") forget(sale, sale.catalogRef);
2255
2346
  return stopWith("rejected", failure3.code === "NOT_PENDING" ? "orderClosed" : "paymentRefused");
@@ -2346,12 +2437,37 @@ function createWixOrderBackend(deps) {
2346
2437
  if (proof.transaction.appAccountToken) return refByToken(refs, proof.transaction);
2347
2438
  return refs.filter((ref) => ref.stage === "started" && ref.storeProductId === productId).reduce((newest, ref) => !newest || ref.updatedAt >= newest.updatedAt ? ref : newest, void 0);
2348
2439
  }
2440
+ async function readStoreCountry() {
2441
+ try {
2442
+ return await deps.storeCountry?.() ?? null;
2443
+ } catch {
2444
+ return null;
2445
+ }
2446
+ }
2447
+ async function abandonPurchase(session, catalogRef) {
2448
+ const member = await memberOf(session);
2449
+ const partition = isStop(member) ? null : member.partition;
2450
+ if (!partition || !isCurrent(session)) return;
2451
+ const ref = refAt(partition, catalogRef);
2452
+ if (ref?.stage !== "started" || !ref.paymentId) return;
2453
+ const adapter = adapterFor(ref.kind);
2454
+ if (!adapter || !paidByItem(adapter)) return;
2455
+ if (!(deps.cancelPaymentEnabled ?? CANCEL_PAYMENT_ENABLED) || adapter.reusesPayment) {
2456
+ const current = refAt(partition, catalogRef);
2457
+ if (current?.stage === "started" && current.paymentId === ref.paymentId && current.updatedAt === ref.updatedAt) handBackToGuard(partition, adapter, ref);
2458
+ return;
2459
+ }
2460
+ const canceled = await deps.wixIap.cancelPayment({ paymentId: ref.paymentId });
2461
+ if (canceled.status !== "answered" || !isCurrent(session)) return;
2462
+ if (canceled.payment.status !== "canceled") return;
2463
+ if (refAt(partition, catalogRef)?.paymentId === ref.paymentId) partition.remove(catalogRef);
2464
+ }
2349
2465
  async function getMemberContext(session) {
2350
2466
  const member = await memberOf(session);
2351
2467
  if (isStop(member)) return { status: member.result };
2352
2468
  return { status: "ok", context: { scopeKey: member.scopeKey } };
2353
2469
  }
2354
- return { getPurchaseContext, getMemberContext, submitProof };
2470
+ return { getPurchaseContext, getMemberContext, submitProof, abandonPurchase };
2355
2471
  }
2356
2472
  function paidByItem(adapter) {
2357
2473
  return typeof adapter.itemPayment === "function";
@@ -2391,12 +2507,15 @@ var ITEM_REFUSALS = {
2391
2507
  UNSUPPORTED_ORDER: "orderRefused",
2392
2508
  CATALOG_NOT_SUPPORTED: "unsupportedItem",
2393
2509
  EVENT_CHECKOUT_NOT_ECOM: "unsupportedItem",
2510
+ SUBSCRIPTION_NOT_IN_APP: "unsupportedItem",
2511
+ // The site or the store cannot sell it, and a tap would be refused again: Buy stays disabled.
2394
2512
  VERTICAL_ACCESS_DENIED: "notConfigured",
2513
+ BILLING_COUNTRY_REQUIRED: "notConfigured",
2395
2514
  APP_NOT_CONFIGURED: "notConfigured",
2396
- ALREADY_SUBSCRIBED: "paymentRefused",
2397
- SUBSCRIPTION_NOT_IN_APP: "paymentRefused",
2398
- BILLING_COUNTRY_REQUIRED: "orderRefused",
2399
- NOT_BOOKING_OWNER: "orderRefused",
2515
+ ALREADY_SUBSCRIBED: "alreadySubscribed",
2516
+ MEMBER_DETAILS_REQUIRED: "memberDetailsRequired",
2517
+ // The booking is not this member's: itemRefusal drops the attempt and a new tap makes a new booking.
2518
+ NOT_BOOKING_OWNER: "bookingNotOwned",
2400
2519
  BOOKING_PAYMENT_PENDING: "paymentInProgress"
2401
2520
  };
2402
2521
  var KIND_STOPS = {
@@ -2483,7 +2602,8 @@ function enabledCheckout(deps) {
2483
2602
  bridge,
2484
2603
  itemFor: (key) => sales.get(key),
2485
2604
  productBusy,
2486
- report: onEvent
2605
+ report: onEvent,
2606
+ storeCountry: deps.storeCountry ?? storefrontCountryCode
2487
2607
  });
2488
2608
  const coordinator = createPurchaseCoordinator({
2489
2609
  store: deps.store ?? appleManagedStore,
@@ -2650,7 +2770,7 @@ function enabledCheckout(deps) {
2650
2770
  if (!isCurrent(session)) return;
2651
2771
  if (ref.stage === "needsSupport") setPayment(ref.key, "needsSupport");
2652
2772
  if (ref.stage === "fulfilled" && !options.dueOnly) {
2653
- const access = await accessOf3(session, ref);
2773
+ const access = await accessOf4(session, ref);
2654
2774
  if (!isCurrent(session)) return;
2655
2775
  if (access === "granted") setPayment(ref.key, "granted");
2656
2776
  else if (access === "none") payments.delete(ref.key);
@@ -2710,7 +2830,7 @@ function enabledCheckout(deps) {
2710
2830
  if (isFinalRefusal(payment.status)) return markNeedsSupport(partition, ref);
2711
2831
  if (payment.status !== "approved") return backOff(partition, ref, false);
2712
2832
  if (!ref.kind) return settleUnassociated(partition, ref);
2713
- const access = await accessOf3(session, ref);
2833
+ const access = await accessOf4(session, ref);
2714
2834
  if (!isCurrent(session)) return;
2715
2835
  if (access === "granted") return grant(partition, ref);
2716
2836
  backOff(partition, ref, access === "none");
@@ -2726,7 +2846,7 @@ function enabledCheckout(deps) {
2726
2846
  partition.remove(ref.key);
2727
2847
  setPayment(ref.key, "accessUnknown");
2728
2848
  }
2729
- async function accessOf3(session, ref) {
2849
+ async function accessOf4(session, ref) {
2730
2850
  const adapter = deps.adapters.find((candidate) => candidate.kind === ref.kind);
2731
2851
  if (!adapter || !ref.verticalRef) return "unavailable";
2732
2852
  return adapter.readAccess(ref.verticalRef, bindBridge(session, deps.session, bridge));
@@ -2866,8 +2986,12 @@ function outcomeAction(state, copy) {
2866
2986
  function refusalAction(failure3, copy) {
2867
2987
  if (failure3 === "sitePaymentUnavailable") return action(copy, "enabled", copy.sitePaymentUnavailable ?? copy.retry);
2868
2988
  const [mode, note] = REFUSALS[failure3 ?? "unavailable"] ?? ["enabled", "retry"];
2869
- return action(copy, mode, note ? copy[note] ?? "" : "");
2989
+ return action(copy, mode, note ? copy[note] ?? copy[OPTIONAL_COPY_FALLBACK[note] ?? "retry"] ?? "" : "");
2870
2990
  }
2991
+ var OPTIONAL_COPY_FALLBACK = {
2992
+ memberDetailsRequired: "retry",
2993
+ alreadySubscribed: "unavailable"
2994
+ };
2871
2995
  function action(copy, mode, note) {
2872
2996
  return { appleRoute: true, accessReady: false, buyLabel: copy.buy, buyDisabled: mode !== "enabled", buyBusy: mode === "busy", buyNote: note };
2873
2997
  }
@@ -2886,6 +3010,11 @@ var REFUSALS = {
2886
3010
  approvalRequired: ["disabled", "awaitingApproval"],
2887
3011
  signInRequired: ["disabled", "signInRequired"],
2888
3012
  notConfigured: ["disabled", "unavailable"],
3013
+ // The member can fix this: completing the profile and tapping again sells.
3014
+ memberDetailsRequired: ["enabled", "memberDetailsRequired"],
3015
+ alreadySubscribed: ["disabled", "alreadySubscribed"],
3016
+ // The booking was dropped: a tap (after fixing the details) books afresh.
3017
+ bookingNotOwned: ["enabled", "retry"],
2889
3018
  notEnabled: ["disabled", "unavailable"],
2890
3019
  storageUnavailable: ["disabled", "unavailable"],
2891
3020
  unsupportedItem: ["disabled", "unavailable"],
@@ -3225,17 +3354,74 @@ var UNSUPPORTED = { eligible: false, reason: "unsupportedItem" };
3225
3354
  var ORDER_REFUSED = { status: "refused", reason: "orderRefused" };
3226
3355
  var ORDER_CLOSED = { status: "refused", reason: "orderClosed" };
3227
3356
  var GRANTED = { status: "granted" };
3357
+ async function ecomOrderAccess(orderId, bridge) {
3358
+ if (!isNonEmpty3(orderId)) return "unavailable";
3359
+ const answer = await bridge.call("GET", `/ecom/v1/orders/${encodeURIComponent(orderId)}`);
3360
+ if (isRefusal(answer)) return accessRefused(answer);
3361
+ const status = String(bodyObject(answer, "order")?.paymentStatus);
3362
+ if (status === "PAID") return "granted";
3363
+ if (ECOM_PAYMENT_UNDER_WAY.has(status)) return "pending";
3364
+ return ECOM_NO_ACCESS.has(status) ? "none" : "unavailable";
3365
+ }
3366
+ var ECOM_PAYMENT_UNDER_WAY = /* @__PURE__ */ new Set(["NOT_PAID", "PENDING", "PENDING_MERCHANT", "PARTIALLY_PAID"]);
3367
+ var ECOM_NO_ACCESS = /* @__PURE__ */ new Set(["FULLY_REFUNDED", "PARTIALLY_REFUNDED", "CANCELED", "DECLINED", "VOIDED"]);
3228
3368
 
3229
3369
  // ../../stdlib/flows/iap-checkout/src/iap-verticals/online-programs.ts
3230
3370
  var KIND = "onlineProgram";
3231
3371
  var BASE = "/online-programs/participants/v3/join-applications";
3232
- var onlineProgramOrders = {
3372
+ var ONLINE_PROGRAMS_APP = "2936472a-a1ed-4ae5-9f71-614313a9f4e7";
3373
+ var onlineProgramItemPayments = {
3233
3374
  kind: KIND,
3234
3375
  eligibility: (item) => singleUnitOf(KIND, item),
3376
+ itemPayment,
3377
+ readAccess,
3378
+ currentAccess,
3379
+ // wix-iap returns the member's pending Payment for the program again (rpc.impl.js, 1.0.14).
3380
+ reusesPayment: true
3381
+ };
3382
+ function itemPayment(item) {
3383
+ const programId = item.reference.id;
3384
+ return {
3385
+ catalogItem: { catalogItemId: programId, catalogAppId: ONLINE_PROGRAMS_APP },
3386
+ verticalRefOf: ({ joinApplicationId }) => joinApplicationId ? { joinApplicationId, programId } : null
3387
+ };
3388
+ }
3389
+ async function readAccess(verticalRef, bridge) {
3390
+ if (!isNonEmpty3(verticalRef.joinApplicationId)) return "unavailable";
3391
+ const answer = await bridge.call("GET", `${BASE}/${encodeURIComponent(verticalRef.joinApplicationId)}`);
3392
+ if (isRefusal(answer)) return accessRefused(answer);
3393
+ const application = bodyObject(answer, "joinApplication");
3394
+ return application ? accessOf(application) : "unavailable";
3395
+ }
3396
+ async function currentAccess(item, bridge) {
3397
+ const answer = await bridge.call("GET", `${BASE}/current/${encodeURIComponent(item.reference.id)}`);
3398
+ if (isRefusal(answer)) return accessRefused(answer);
3399
+ const application = bodyObject(answer, "joinApplication");
3400
+ if (!application) return "unavailable";
3401
+ const access = accessOf(application);
3402
+ return access !== "granted" && ENDED_STATUS.has(String(application.status)) ? "none" : access;
3403
+ }
3404
+ function accessOf(application) {
3405
+ const paid = application.paymentStatus === "PAYMENT_SUCCESSFUL" || application.paymentStatus === "NO_PAYMENT_REQUIRED";
3406
+ if (application.status === "APPROVED" && paid && isNonEmpty3(application.participantId)) return "granted";
3407
+ if (paid || PAYMENT_UNDER_WAY.has(String(application.paymentStatus))) return "pending";
3408
+ return NO_ACCESS_STATUS.has(String(application.status)) || NO_ACCESS_PAYMENT.has(String(application.paymentStatus)) ? "none" : "unavailable";
3409
+ }
3410
+ var PAYMENT_UNDER_WAY = /* @__PURE__ */ new Set(["PAYMENT_PENDING", "PAYMENT_IN_PROGRESS", "PENDING_OWNER_APPROVAL"]);
3411
+ var NO_ACCESS_STATUS = /* @__PURE__ */ new Set(["CANCELLED", "DECLINED", "SUSPENDED", "INVITED", "APPROVAL_PENDING"]);
3412
+ var ENDED_STATUS = /* @__PURE__ */ new Set(["CANCELLED", "DECLINED", "SUSPENDED"]);
3413
+ var NO_ACCESS_PAYMENT = /* @__PURE__ */ new Set(["PAYMENT_FAILED", "PAYMENT_CANCELED"]);
3414
+
3415
+ // ../../stdlib/flows/iap-checkout/src/iap-verticals/online-programs-orders.ts
3416
+ var KIND2 = "onlineProgram";
3417
+ var BASE2 = "/online-programs/participants/v3/join-applications";
3418
+ var onlineProgramClientOrders = {
3419
+ kind: KIND2,
3420
+ eligibility: (item) => singleUnitOf(KIND2, item),
3235
3421
  openOrder,
3236
3422
  reopenOrder,
3237
- readAccess,
3238
- currentAccess
3423
+ readAccess: readAccess2,
3424
+ currentAccess: currentAccess2
3239
3425
  };
3240
3426
  async function openOrder(item, bridge) {
3241
3427
  const found = await currentApplication(item.reference.id, bridge);
@@ -3250,29 +3436,29 @@ async function reopenOrder(order, bridge) {
3250
3436
  const attempt3 = await orderOf(read2.application, bridge, { mayPrepare: false });
3251
3437
  return attempt3.status === "open" && attempt3.cashierOrderId !== order.cashierOrderId ? ORDER_CLOSED : attempt3;
3252
3438
  }
3253
- async function readAccess(verticalRef, bridge) {
3439
+ async function readAccess2(verticalRef, bridge) {
3254
3440
  if (!isNonEmpty3(verticalRef.joinApplicationId)) return "unavailable";
3255
- const answer = await bridge.call("GET", `${BASE}/${encodeURIComponent(verticalRef.joinApplicationId)}`);
3441
+ const answer = await bridge.call("GET", `${BASE2}/${encodeURIComponent(verticalRef.joinApplicationId)}`);
3256
3442
  if (isRefusal(answer)) return accessRefused(answer);
3257
3443
  const application = bodyObject(answer, "joinApplication");
3258
- return application ? accessOf(application) : "unavailable";
3444
+ return application ? accessOf2(application) : "unavailable";
3259
3445
  }
3260
- async function currentAccess(item, bridge) {
3261
- const answer = await bridge.call("GET", `${BASE}/current/${encodeURIComponent(item.reference.id)}`);
3446
+ async function currentAccess2(item, bridge) {
3447
+ const answer = await bridge.call("GET", `${BASE2}/current/${encodeURIComponent(item.reference.id)}`);
3262
3448
  if (isRefusal(answer)) return accessRefused(answer);
3263
3449
  const application = bodyObject(answer, "joinApplication");
3264
3450
  if (!application) return "unavailable";
3265
- const access = accessOf(application);
3266
- return access !== "granted" && ENDED_STATUS.has(String(application.status)) ? "none" : access;
3451
+ const access = accessOf2(application);
3452
+ return access !== "granted" && ENDED_STATUS2.has(String(application.status)) ? "none" : access;
3267
3453
  }
3268
- function accessOf(application) {
3454
+ function accessOf2(application) {
3269
3455
  const paid = application.paymentStatus === "PAYMENT_SUCCESSFUL" || application.paymentStatus === "NO_PAYMENT_REQUIRED";
3270
3456
  if (application.status === "APPROVED" && paid && isNonEmpty3(application.participantId)) return "granted";
3271
- if (paid || PAYMENT_UNDER_WAY.has(String(application.paymentStatus))) return "pending";
3272
- return NO_ACCESS_STATUS.has(String(application.status)) || NO_ACCESS_PAYMENT.has(String(application.paymentStatus)) ? "none" : "unavailable";
3457
+ if (paid || PAYMENT_UNDER_WAY2.has(String(application.paymentStatus))) return "pending";
3458
+ return NO_ACCESS_STATUS2.has(String(application.status)) || NO_ACCESS_PAYMENT2.has(String(application.paymentStatus)) ? "none" : "unavailable";
3273
3459
  }
3274
3460
  async function orderOf(application, bridge, options) {
3275
- if (accessOf(application) === "granted") return GRANTED;
3461
+ if (accessOf2(application) === "granted") return GRANTED;
3276
3462
  if (application.status === "APPROVAL_PENDING" || application.status === "INVITED") return { status: "refused", reason: "approvalRequired" };
3277
3463
  if (application.status !== "APPROVED" && application.status !== "SUSPENDED") return ORDER_CLOSED;
3278
3464
  const payment = String(application.paymentStatus);
@@ -3290,7 +3476,7 @@ function inProgressOrder(application) {
3290
3476
  }
3291
3477
  async function preparedOrder(application, bridge) {
3292
3478
  const id = String(application.id ?? "");
3293
- const answer = await bridge.call("POST", `${BASE}/${encodeURIComponent(id)}/prepare-payment`, { paymentType: "SINGLE_PAYMENT" });
3479
+ const answer = await bridge.call("POST", `${BASE2}/${encodeURIComponent(id)}/prepare-payment`, { paymentType: "SINGLE_PAYMENT" });
3294
3480
  if (isHttp(answer, 428)) return reopenAfterRace(id, bridge);
3295
3481
  if (isRefusal(answer)) return attemptRefused(answer);
3296
3482
  const prepared = bodyObject(answer, "joinApplication");
@@ -3301,14 +3487,14 @@ async function reopenAfterRace(id, bridge) {
3301
3487
  return "attempt" in read2 ? read2.attempt : orderOf(read2.application, bridge, { mayPrepare: false });
3302
3488
  }
3303
3489
  async function currentApplication(programId, bridge) {
3304
- const answer = await bridge.call("GET", `${BASE}/current/${encodeURIComponent(programId)}`);
3490
+ const answer = await bridge.call("GET", `${BASE2}/current/${encodeURIComponent(programId)}`);
3305
3491
  if (isHttp(answer, 404)) return { application: null };
3306
3492
  if (isRefusal(answer)) return { attempt: attemptRefused(answer) };
3307
3493
  const application = bodyObject(answer, "joinApplication");
3308
3494
  return application ? { application } : { attempt: ORDER_REFUSED };
3309
3495
  }
3310
3496
  async function createdApplication(programId, bridge) {
3311
- const answer = await bridge.call("POST", BASE, { joinApplication: { programId } });
3497
+ const answer = await bridge.call("POST", BASE2, { joinApplication: { programId } });
3312
3498
  if (isHttp(answer, 409)) {
3313
3499
  const existing = await currentApplication(programId, bridge);
3314
3500
  if ("attempt" in existing) return existing;
@@ -3319,7 +3505,7 @@ async function createdApplication(programId, bridge) {
3319
3505
  }
3320
3506
  async function applicationById(id, bridge) {
3321
3507
  if (!isNonEmpty3(id)) return { attempt: ORDER_CLOSED };
3322
- const answer = await bridge.call("GET", `${BASE}/${encodeURIComponent(id)}`);
3508
+ const answer = await bridge.call("GET", `${BASE2}/${encodeURIComponent(id)}`);
3323
3509
  if (isHttp(answer, 404)) return { attempt: ORDER_CLOSED };
3324
3510
  if (isRefusal(answer)) return { attempt: attemptRefused(answer) };
3325
3511
  return applicationIn(answer);
@@ -3329,28 +3515,69 @@ function applicationIn(answer) {
3329
3515
  return application ? { application } : { attempt: ORDER_REFUSED };
3330
3516
  }
3331
3517
  var PREPARABLE = /* @__PURE__ */ new Set(["PAYMENT_PENDING", "PAYMENT_FAILED", "PAYMENT_CANCELED"]);
3332
- var PAYMENT_UNDER_WAY = /* @__PURE__ */ new Set(["PAYMENT_PENDING", "PAYMENT_IN_PROGRESS", "PENDING_OWNER_APPROVAL"]);
3333
- var NO_ACCESS_STATUS = /* @__PURE__ */ new Set(["CANCELLED", "DECLINED", "SUSPENDED", "INVITED", "APPROVAL_PENDING"]);
3334
- var ENDED_STATUS = /* @__PURE__ */ new Set(["CANCELLED", "DECLINED", "SUSPENDED"]);
3335
- var NO_ACCESS_PAYMENT = /* @__PURE__ */ new Set(["PAYMENT_FAILED", "PAYMENT_CANCELED"]);
3518
+ var PAYMENT_UNDER_WAY2 = /* @__PURE__ */ new Set(["PAYMENT_PENDING", "PAYMENT_IN_PROGRESS", "PENDING_OWNER_APPROVAL"]);
3519
+ var NO_ACCESS_STATUS2 = /* @__PURE__ */ new Set(["CANCELLED", "DECLINED", "SUSPENDED", "INVITED", "APPROVAL_PENDING"]);
3520
+ var ENDED_STATUS2 = /* @__PURE__ */ new Set(["CANCELLED", "DECLINED", "SUSPENDED"]);
3521
+ var NO_ACCESS_PAYMENT2 = /* @__PURE__ */ new Set(["PAYMENT_FAILED", "PAYMENT_CANCELED"]);
3336
3522
 
3337
3523
  // ../../stdlib/flows/iap-checkout/src/iap-verticals/pricing-plans.ts
3338
- var KIND2 = "pricingPlan";
3339
- var CHECKOUT = "/pricing-plans/v2/checkout/orders";
3524
+ var KIND3 = "pricingPlan";
3525
+ var PRICING_PLANS_APP = "1522827f-c56c-a5c9-2ac9-00f9e6ae12d3";
3340
3526
  var MEMBER_ORDERS = "/pricing-plans/v2/member/orders";
3341
- var pricingPlanOrders = {
3342
- kind: KIND2,
3343
- eligibility: (item) => singleUnitOf(KIND2, item),
3527
+ var pricingPlanItemPayments = {
3528
+ kind: KIND3,
3529
+ eligibility: (item) => singleUnitOf(KIND3, item),
3530
+ itemPayment: itemPayment2,
3531
+ readAccess: (verticalRef, bridge) => isNonEmpty3(verticalRef.planId) ? planAccess(verticalRef.planId, bridge) : Promise.resolve("unavailable"),
3532
+ currentAccess: (item, bridge) => planAccess(item.reference.id, bridge)
3533
+ };
3534
+ async function itemPayment2(item, bridge) {
3535
+ const planId = item.reference.id;
3536
+ const read2 = await bridge.call("GET", `/pricing-plans/v3/plans/${encodeURIComponent(planId)}`);
3537
+ if (isRefusal(read2)) return attemptRefused(read2);
3538
+ const variants = bodyObject(read2, "plan")?.pricingVariants;
3539
+ const only = Array.isArray(variants) && variants.length === 1 && isObject7(variants[0]) ? variants[0].id : void 0;
3540
+ if (!isNonEmpty3(only)) return { status: "refused", reason: "unsupportedItem" };
3541
+ return {
3542
+ catalogItem: { catalogItemId: planId, catalogAppId: PRICING_PLANS_APP, options: { type: "PLAN", planOptions: { pricingVariantId: only } } },
3543
+ verticalRefOf: ({ ecomOrderId }) => ecomOrderId ? { ecomOrderId, planId } : null
3544
+ };
3545
+ }
3546
+ async function planAccess(planId, bridge) {
3547
+ let pending = false;
3548
+ const pages = /* @__PURE__ */ new Set();
3549
+ for (let offset = 0; ; offset += 50) {
3550
+ const answer = await bridge.call("GET", `${MEMBER_ORDERS}?orderStatuses=ACTIVE&orderStatuses=PENDING&orderStatuses=DRAFT&limit=50&offset=${offset}`);
3551
+ if (isRefusal(answer)) return accessRefused(answer);
3552
+ const orders = answer.body?.orders;
3553
+ if (!Array.isArray(orders)) return "unavailable";
3554
+ const page = JSON.stringify(orders.map((order) => [order.id, order.planId, order.status]));
3555
+ if (orders.length === 50 && pages.has(page)) return "unavailable";
3556
+ pages.add(page);
3557
+ const selected = orders.filter((order) => order.planId === planId);
3558
+ if (selected.some((order) => order.status === "ACTIVE")) return "granted";
3559
+ pending || (pending = selected.some((order) => order.status === "PENDING" || order.status === "DRAFT"));
3560
+ if (orders.length < 50) return pending ? "pending" : "none";
3561
+ }
3562
+ }
3563
+
3564
+ // ../../stdlib/flows/iap-checkout/src/iap-verticals/pricing-plans-orders.ts
3565
+ var KIND4 = "pricingPlan";
3566
+ var CHECKOUT = "/pricing-plans/v2/checkout/orders";
3567
+ var MEMBER_ORDERS2 = "/pricing-plans/v2/member/orders";
3568
+ var pricingPlanClientOrders = {
3569
+ kind: KIND4,
3570
+ eligibility: (item) => singleUnitOf(KIND4, item),
3344
3571
  openOrder: openOrder2,
3345
3572
  reopenOrder: reopenOrder2,
3346
- readAccess: readAccess2,
3347
- currentAccess: currentAccess2
3573
+ readAccess: readAccess3,
3574
+ currentAccess: currentAccess3
3348
3575
  };
3349
- async function currentAccess2(item, bridge) {
3576
+ async function currentAccess3(item, bridge) {
3350
3577
  let pending = false;
3351
3578
  const pages = /* @__PURE__ */ new Set();
3352
3579
  for (let offset = 0; ; offset += 50) {
3353
- const answer = await bridge.call("GET", `${MEMBER_ORDERS}?orderStatuses=ACTIVE&orderStatuses=PENDING&orderStatuses=DRAFT&limit=50&offset=${offset}`);
3580
+ const answer = await bridge.call("GET", `${MEMBER_ORDERS2}?orderStatuses=ACTIVE&orderStatuses=PENDING&orderStatuses=DRAFT&limit=50&offset=${offset}`);
3354
3581
  if (isRefusal(answer)) return accessRefused(answer);
3355
3582
  const orders = answer.body?.orders;
3356
3583
  if (!Array.isArray(orders)) return "unavailable";
@@ -3378,14 +3605,14 @@ async function reopenOrder2(order, bridge) {
3378
3605
  const attempt3 = orderOf2(read2.order, order.verticalRef.planId ?? "");
3379
3606
  return attempt3.status === "open" && attempt3.cashierOrderId !== order.cashierOrderId ? ORDER_CLOSED : attempt3;
3380
3607
  }
3381
- async function readAccess2(verticalRef, bridge) {
3382
- if (!isNonEmpty3(verticalRef.orderId)) return "unavailable";
3383
- const answer = await bridge.call("GET", `${MEMBER_ORDERS}/${encodeURIComponent(verticalRef.orderId)}`);
3608
+ async function readAccess3(verticalRef, bridge) {
3609
+ if (!isNonEmpty3(verticalRef.orderId)) return isNonEmpty3(verticalRef.planId) ? planAccess(verticalRef.planId, bridge) : "unavailable";
3610
+ const answer = await bridge.call("GET", `${MEMBER_ORDERS2}/${encodeURIComponent(verticalRef.orderId)}`);
3384
3611
  if (isRefusal(answer)) return accessRefused(answer);
3385
3612
  const order = bodyObject(answer, "order");
3386
- return order ? accessOf2(order) : "unavailable";
3613
+ return order ? accessOf3(order) : "unavailable";
3387
3614
  }
3388
- function accessOf2(order) {
3615
+ function accessOf3(order) {
3389
3616
  if (order.status === "ACTIVE") return "granted";
3390
3617
  if (order.status === "PENDING") return "pending";
3391
3618
  if (order.status === "DRAFT") return "pending";
@@ -3394,7 +3621,7 @@ function accessOf2(order) {
3394
3621
  var NO_ACCESS = /* @__PURE__ */ new Set(["CANCELED", "ENDED", "PAUSED"]);
3395
3622
  function orderOf2(order, planId) {
3396
3623
  if (!order || !isNonEmpty3(order.id)) return ORDER_REFUSED;
3397
- if (accessOf2(order) === "granted") return GRANTED;
3624
+ if (accessOf3(order) === "granted") return GRANTED;
3398
3625
  if (order.status === "PENDING") return { status: "refused", reason: "paymentInProgress" };
3399
3626
  if (order.status !== "DRAFT") return ORDER_CLOSED;
3400
3627
  if (!isNonEmpty3(order.wixPayOrderId)) return ORDER_REFUSED;
@@ -3402,7 +3629,7 @@ function orderOf2(order, planId) {
3402
3629
  }
3403
3630
  async function memberOrder(orderId, bridge) {
3404
3631
  if (!isNonEmpty3(orderId)) return { attempt: ORDER_CLOSED };
3405
- const answer = await bridge.call("GET", `${MEMBER_ORDERS}/${encodeURIComponent(orderId)}`);
3632
+ const answer = await bridge.call("GET", `${MEMBER_ORDERS2}/${encodeURIComponent(orderId)}`);
3406
3633
  if (isRefusal(answer)) return { attempt: answer.status === "http" && answer.httpStatus === 404 ? ORDER_CLOSED : attemptRefused(answer) };
3407
3634
  return { order: bodyObject(answer, "order") };
3408
3635
  }
@@ -3411,84 +3638,44 @@ function isOneTimeUnlimited(order) {
3411
3638
  return pricing?.singlePaymentUnlimited === true;
3412
3639
  }
3413
3640
 
3414
- // ../../stdlib/flows/iap-checkout/src/iap-verticals/stores.ts
3415
- var KIND3 = "storesProduct";
3416
- var WIX_STORES_APP = "215238eb-22a5-4c36-9e7b-e7c08025e04e";
3417
- var storesProductOrders = {
3418
- kind: KIND3,
3419
- eligibility,
3420
- itemPayment,
3421
- readAccess: readAccess3
3422
- };
3423
- function eligibility(item) {
3424
- const single = singleUnitOf(KIND3, item);
3425
- if (!single.eligible) return single;
3426
- const catalog = item.catalogReference;
3427
- const variant = catalog?.options && Object.keys(catalog.options).length > 0;
3428
- return catalog && !variant && isNonEmpty3(catalog.appId) && catalog.appId.toLowerCase() === WIX_STORES_APP && catalog.catalogItemId === item.reference.id ? single : UNSUPPORTED;
3429
- }
3430
- function itemPayment(item) {
3431
- return { catalogItem: { catalogItemId: item.reference.id, catalogAppId: WIX_STORES_APP }, verticalRefOf: ({ ecomOrderId }) => ecomOrderId ? { orderId: ecomOrderId } : null };
3432
- }
3433
- function classifyCart(lines) {
3434
- if (lines.length === 0 || lines.some((line) => line.route === "resolving" || line.route === "unavailable")) return "blocked";
3435
- const apple = lines.filter((line) => line.route === "appleIap");
3436
- if (apple.length === 0) return "regular";
3437
- return lines.length === 1 && apple[0].quantity === 1 ? "appleIap" : "mixedRefused";
3438
- }
3439
- async function readAccess3(verticalRef, bridge) {
3440
- if (!isNonEmpty3(verticalRef.orderId)) return "unavailable";
3441
- const answer = await bridge.call("GET", `/ecom/v1/orders/${encodeURIComponent(verticalRef.orderId)}`);
3442
- if (isRefusal(answer)) return accessRefused(answer);
3443
- const status = String(bodyObject(answer, "order")?.paymentStatus);
3444
- if (status === "PAID") return "granted";
3445
- if (PAYMENT_UNDER_WAY2.has(status)) return "pending";
3446
- return NO_ACCESS2.has(status) ? "none" : "unavailable";
3447
- }
3448
- var PAYMENT_UNDER_WAY2 = /* @__PURE__ */ new Set(["NOT_PAID", "PENDING", "PENDING_MERCHANT", "PARTIALLY_PAID"]);
3449
- var NO_ACCESS2 = /* @__PURE__ */ new Set(["FULLY_REFUNDED", "PARTIALLY_REFUNDED", "CANCELED", "DECLINED", "VOIDED"]);
3450
-
3451
3641
  // ../../stdlib/flows/iap-checkout/src/iap-verticals/attendance.ts
3452
3642
  var BOOKING = "bookingsService";
3453
3643
  var TICKET = "eventsTicket";
3454
3644
  var NOT_ENABLED = { status: "refused", reason: "notEnabled" };
3645
+ var WIX_BOOKINGS_APP = "13d21c63-b5ec-5912-8397-c3a5ddb27a97";
3455
3646
  var CHANGED = { status: "refused", reason: "productChanged" };
3456
- var MINUTE_MS = 6e4;
3647
+ var WIX_EVENTS_APP = "140603ad-af8d-84a5-2c80-a0f60cb47351";
3457
3648
  var RELEASE_MARGIN_MS = 3e5;
3458
- var DEFAULT_RESERVATION_MINUTES = 60;
3459
3649
  var PAYMENT_TAKEN = ["PAID", "PARTIALLY_PAID", "EXEMPT", "REFUNDED"];
3460
3650
  var HAS_OFFSET = /(?:Z|[+-]\d{2}:?\d{2})$/i;
3461
3651
  var LATEST_ZONE_MS = 432e5;
3462
3652
  function attendanceOrdersWith(options) {
3463
- const now = options.now ?? Date.now;
3464
3653
  return {
3465
3654
  bookingOrders: {
3466
3655
  kind: BOOKING,
3467
3656
  repeatable: true,
3468
3657
  eligibility: (item) => eligible(item, BOOKING, options.bookingsEnabled),
3469
- openOrder: (item, bridge, beforeCreate, afterCreate) => options.bookingsEnabled ? openBooking(item, bridge, beforeCreate, afterCreate) : Promise.resolve(NOT_ENABLED),
3658
+ itemPayment: (item, bridge, beforeCreate, afterCreate) => options.bookingsEnabled ? bookingPayment(item, bridge, beforeCreate, afterCreate) : NOT_ENABLED,
3470
3659
  resolveOpening: resolveBookingOpening,
3471
- readAccess: bookingAccess,
3472
- reopenOrder: (order, bridge) => reopen(order, bridge, bookingAccess)
3660
+ readAccess: bookingAccess
3473
3661
  },
3474
3662
  eventTicketOrders: {
3475
3663
  kind: TICKET,
3476
3664
  repeatable: true,
3477
3665
  eligibility: (item) => eligible(item, TICKET, options.eventsEnabled),
3478
- openOrder: (item, bridge, beforeCreate, afterCreate) => options.eventsEnabled ? openTicket(item, bridge, now, beforeCreate, afterCreate) : Promise.resolve(NOT_ENABLED),
3479
- readAccess: ticketAccess,
3480
- reopenOrder: (order, bridge) => reopen(order, bridge, ticketAccess, now)
3666
+ itemPayment: ticketPayment,
3667
+ readAccess: ticketAccess
3481
3668
  }
3482
3669
  };
3483
3670
  }
3484
- var { bookingOrders, eventTicketOrders } = /* @__PURE__ */ attendanceOrdersWith({ bookingsEnabled: BOOKINGS_APPLE_SALES_ENABLED, eventsEnabled: EVENTS_APPLE_SALES_ENABLED });
3671
+ var { bookingOrders: bookingItemPayments, eventTicketOrders: eventTicketItemPayments } = /* @__PURE__ */ attendanceOrdersWith({ bookingsEnabled: BOOKINGS_APPLE_SALES_ENABLED, eventsEnabled: EVENTS_APPLE_SALES_ENABLED });
3485
3672
  function eligible(item, kind, enabled) {
3486
3673
  if (!enabled) return { eligible: false, reason: "notEnabled" };
3487
3674
  if (!singleUnitOf(kind, item).eligible || !isNonEmpty3(item.attemptId) || !item.attendance) return UNSUPPORTED;
3488
- const selection = kind === BOOKING ? item.attendance.booking : item.attendance.ticket;
3489
- return selection ? { eligible: true } : UNSUPPORTED;
3675
+ if (kind === TICKET) return isNonEmpty3(item.attendance.ticket?.eventId) ? { eligible: true } : UNSUPPORTED;
3676
+ return item.attendance.booking ? { eligible: true } : UNSUPPORTED;
3490
3677
  }
3491
- async function openBooking(item, bridge, beforeCreate, afterCreate) {
3678
+ async function bookingPayment(item, bridge, beforeCreate, afterCreate) {
3492
3679
  if (!eligible(item, BOOKING, true).eligible) return notCreated(ORDER_REFUSED);
3493
3680
  const selected = item.attendance.booking;
3494
3681
  if (selected.slot.serviceId !== item.reference.id || !isNonEmpty3(selected.slot.startDate) || !isNonEmpty3(selected.slot.endDate)) return notCreated(ORDER_REFUSED);
@@ -3508,7 +3695,11 @@ async function openBooking(item, bridge, beforeCreate, afterCreate) {
3508
3695
  const bookingId = bodyObject(created, "booking")?.id;
3509
3696
  if (!isNonEmpty3(bookingId)) return ORDER_REFUSED;
3510
3697
  afterCreate?.({ verticalRef: { bookingId } });
3511
- return bookingCheckout(item, bookingId, bridge);
3698
+ const serviceId = item.reference.id;
3699
+ return {
3700
+ catalogItem: { catalogItemId: serviceId, catalogAppId: WIX_BOOKINGS_APP, options: { bookingId } },
3701
+ verticalRefOf: ({ ecomOrderId }) => ecomOrderId ? { serviceId, bookingId, orderId: ecomOrderId } : null
3702
+ };
3512
3703
  }
3513
3704
  function slotGuard(slot) {
3514
3705
  const verticalRef = {};
@@ -3546,12 +3737,164 @@ function sameSlot(guarded, slot) {
3546
3737
  if (!guarded || !slot) return true;
3547
3738
  return guarded.sessionId === slot.sessionId && Date.parse(guarded.startDate ?? "") === Date.parse(String(slot.startDate));
3548
3739
  }
3740
+ async function bookingAccess(ref, bridge) {
3741
+ if (!ref.bookingId || !ref.orderId) return "unavailable";
3742
+ const order = await bridge.call("GET", `/ecom/v1/orders/${encodeURIComponent(ref.orderId)}`);
3743
+ if (isRefusal(order)) return accessRefused(order);
3744
+ const payment = bodyObject(order, "order")?.paymentStatus;
3745
+ if (payment === "FULLY_REFUNDED" || payment === "PARTIALLY_REFUNDED") return "none";
3746
+ const read2 = await bridge.call("POST", "/bookings/v2/bookings/query", { query: { filter: { id: { $eq: ref.bookingId } } } });
3747
+ if (isRefusal(read2)) return accessRefused(read2);
3748
+ const rows = isObject7(read2.body) ? read2.body.bookings : void 0;
3749
+ const booking = Array.isArray(rows) ? rows.find((b) => isObject7(b) && b.id === ref.bookingId) : void 0;
3750
+ if (!isObject7(booking)) return "unavailable";
3751
+ if (booking.status === "CANCELED" || booking.status === "CANCELLED" || booking.status === "DECLINED") return "none";
3752
+ return payment === "PAID" && booking.status === "CONFIRMED" && booking.paymentStatus === "PAID" ? "granted" : "pending";
3753
+ }
3754
+ async function ticketAccess(ref, bridge) {
3755
+ if (isNonEmpty3(ref.orderId)) return ecomOrderAccess(ref.orderId, bridge);
3756
+ if (!ref.eventId || !ref.orderNumber || !ref.ticketDefinitionId) return "unavailable";
3757
+ const read2 = await bridge.call("GET", `/events/v1/events/${encodeURIComponent(ref.eventId)}/orders/${encodeURIComponent(ref.orderNumber)}?fieldset=DETAILS&fieldset=TICKETS`);
3758
+ if (isRefusal(read2)) return accessRefused(read2);
3759
+ const order = bodyObject(read2, "order");
3760
+ if (order?.status === "CANCELED" || order?.status === "CANCELLED" || order?.status === "REFUNDED") return "none";
3761
+ const issued = Array.isArray(order?.tickets) && order.tickets.some((t) => isObject7(t) && isNonEmpty3(t.ticketNumber) && t.orderStatus === "PAID" && t.ticketDefinitionId === ref.ticketDefinitionId);
3762
+ return order?.status === "PAID" && issued ? "granted" : order ? "pending" : "unavailable";
3763
+ }
3764
+ function ticketPayment(item) {
3765
+ const eventId = item.attendance.ticket.eventId;
3766
+ const ticketDefinitionId = item.reference.id;
3767
+ return {
3768
+ catalogItem: { catalogItemId: ticketDefinitionId, catalogAppId: WIX_EVENTS_APP, options: { eventId } },
3769
+ // eCom checkout: the eCom order. Classic checkout (catalyst-server #24882): the Events order number.
3770
+ verticalRefOf: ({ ecomOrderId, eventsOrderNumber }) => {
3771
+ if (ecomOrderId) return { orderId: ecomOrderId, eventId, ticketDefinitionId };
3772
+ return eventsOrderNumber ? { orderNumber: eventsOrderNumber, eventId, ticketDefinitionId } : null;
3773
+ }
3774
+ };
3775
+ }
3776
+ function samePrice(value, item) {
3777
+ return isObject7(value) && value.currency === item.attendance?.currency && decimal(value.amount) !== null && decimal(value.amount) === decimal(item.attendance?.amount);
3778
+ }
3779
+ function decimal(value) {
3780
+ if (typeof value !== "string" || !/^\d+(?:\.\d+)?$/.test(value)) return null;
3781
+ return value.replace(/^0+(?=\d)/, "").replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
3782
+ }
3783
+ function matchesSlot(value, selected) {
3784
+ 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])));
3785
+ }
3786
+ function creationRefused(refusal) {
3787
+ const attempt3 = attemptRefused(refusal);
3788
+ return refusal.status === "http" && [400, 401, 403, 404, 405, 409, 410, 415, 422].includes(refusal.httpStatus) ? notCreated(attempt3) : attempt3;
3789
+ }
3790
+ function notCreated(attempt3) {
3791
+ return { ...attempt3, noOrderCreated: true };
3792
+ }
3793
+
3794
+ // ../../stdlib/flows/iap-checkout/src/iap-verticals/attendance-orders.ts
3795
+ var BOOKING2 = "bookingsService";
3796
+ var TICKET2 = "eventsTicket";
3797
+ var NOT_ENABLED2 = { status: "refused", reason: "notEnabled" };
3798
+ var CHANGED2 = { status: "refused", reason: "productChanged" };
3799
+ var MINUTE_MS = 6e4;
3800
+ var RELEASE_MARGIN_MS2 = 3e5;
3801
+ var DEFAULT_RESERVATION_MINUTES = 60;
3802
+ var PAYMENT_TAKEN2 = ["PAID", "PARTIALLY_PAID", "EXEMPT", "REFUNDED"];
3803
+ var HAS_OFFSET2 = /(?:Z|[+-]\d{2}:?\d{2})$/i;
3804
+ var LATEST_ZONE_MS2 = 432e5;
3805
+ function attendanceClientOrdersWith(options) {
3806
+ const now = options.now ?? Date.now;
3807
+ return {
3808
+ bookingOrders: {
3809
+ kind: BOOKING2,
3810
+ repeatable: true,
3811
+ eligibility: (item) => eligible2(item, BOOKING2, options.bookingsEnabled),
3812
+ openOrder: (item, bridge, beforeCreate, afterCreate) => options.bookingsEnabled ? openBooking(item, bridge, beforeCreate, afterCreate) : Promise.resolve(NOT_ENABLED2),
3813
+ resolveOpening: resolveBookingOpening2,
3814
+ readAccess: bookingAccess2,
3815
+ reopenOrder: (order, bridge) => reopen(order, bridge, bookingAccess2)
3816
+ },
3817
+ eventTicketOrders: {
3818
+ kind: TICKET2,
3819
+ repeatable: true,
3820
+ eligibility: (item) => eligible2(item, TICKET2, options.eventsEnabled),
3821
+ openOrder: (item, bridge, beforeCreate, afterCreate) => options.eventsEnabled ? openTicket(item, bridge, now, beforeCreate, afterCreate) : Promise.resolve(NOT_ENABLED2),
3822
+ readAccess: ticketAccess2,
3823
+ reopenOrder: (order, bridge) => reopen(order, bridge, ticketAccess2, now)
3824
+ }
3825
+ };
3826
+ }
3827
+ var { bookingOrders: bookingClientOrders, eventTicketOrders: eventTicketClientOrders } = /* @__PURE__ */ attendanceClientOrdersWith({ bookingsEnabled: BOOKINGS_APPLE_SALES_ENABLED, eventsEnabled: EVENTS_APPLE_SALES_ENABLED });
3828
+ function eligible2(item, kind, enabled) {
3829
+ if (!enabled) return { eligible: false, reason: "notEnabled" };
3830
+ if (!singleUnitOf(kind, item).eligible || !isNonEmpty3(item.attemptId) || !item.attendance) return UNSUPPORTED;
3831
+ const selection = kind === BOOKING2 ? item.attendance.booking : item.attendance.ticket;
3832
+ return selection ? { eligible: true } : UNSUPPORTED;
3833
+ }
3834
+ async function openBooking(item, bridge, beforeCreate, afterCreate) {
3835
+ if (!eligible2(item, BOOKING2, true).eligible) return notCreated2(ORDER_REFUSED);
3836
+ const selected = item.attendance.booking;
3837
+ if (selected.slot.serviceId !== item.reference.id || !isNonEmpty3(selected.slot.startDate) || !isNonEmpty3(selected.slot.endDate)) return notCreated2(ORDER_REFUSED);
3838
+ const read2 = await bridge.call("GET", `/bookings/v2/services/${encodeURIComponent(item.reference.id)}`);
3839
+ if (isRefusal(read2)) return notCreated2(attemptRefused(read2));
3840
+ const service = bodyObject(read2, "service");
3841
+ const metadata = bookingAttendanceOf(service);
3842
+ if (classifyForApple(metadata, item.attendance.currency) !== "appleIap" || !samePrice2({ amount: metadata.amount, currency: metadata.currency }, item)) return notCreated2(CHANGED2);
3843
+ if (isObject7(service?.onlineBooking) && service.onlineBooking.requireManualApproval === true) return notCreated2({ status: "refused", reason: "approvalRequired" });
3844
+ const availability = await bridge.call("POST", "/bookings/v1/availability/query", { query: { filter: { serviceId: [item.reference.id], startDate: selected.slot.startDate, endDate: selected.slot.endDate, bookable: true } } });
3845
+ if (isRefusal(availability)) return notCreated2(attemptRefused(availability));
3846
+ const entries = isObject7(availability.body) ? availability.body.availabilityEntries : void 0;
3847
+ if (!Array.isArray(entries) || !entries.some((entry) => isObject7(entry) && entry.bookable === true && matchesSlot2(entry.slot, selected.slot))) return notCreated2(CHANGED2);
3848
+ if (beforeCreate && !beforeCreate(slotGuard2(selected.slot))) return notCreated2({ status: "refused", reason: "storageUnavailable" });
3849
+ 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 } : {} } });
3850
+ if (isRefusal(created)) return creationRefused2(created);
3851
+ const bookingId = bodyObject(created, "booking")?.id;
3852
+ if (!isNonEmpty3(bookingId)) return ORDER_REFUSED;
3853
+ afterCreate?.({ verticalRef: { bookingId } });
3854
+ return bookingCheckout(item, bookingId, bridge);
3855
+ }
3856
+ function slotGuard2(slot) {
3857
+ const verticalRef = {};
3858
+ for (const key of ["sessionId", "startDate"]) if (isNonEmpty3(slot[key])) verticalRef[key] = slot[key];
3859
+ const ends = latestInstant2(String(slot.endDate));
3860
+ return Number.isFinite(ends) ? { verticalRef, releaseAt: ends + RELEASE_MARGIN_MS2 } : { verticalRef };
3861
+ }
3862
+ function latestInstant2(value) {
3863
+ if (HAS_OFFSET2.test(value)) return Date.parse(value);
3864
+ return Date.parse(`${value}Z`) + LATEST_ZONE_MS2;
3865
+ }
3866
+ async function resolveBookingOpening2(guard, item, bridge, options) {
3867
+ const scope = sameSlot2(guard.verticalRef, item?.attendance?.booking?.slot) ? "held" : "unrelated";
3868
+ const bookingId = guard.verticalRef?.bookingId;
3869
+ if (!bookingId || !options.settled) return scope;
3870
+ const released2 = await releaseBooking2(bookingId, bridge, options.claim);
3871
+ return released2 === "held" || released2 === "unavailable" && scope === "unrelated" ? scope : released2;
3872
+ }
3873
+ async function releaseBooking2(bookingId, bridge, claim) {
3874
+ const read2 = await bridge.call("POST", "/bookings/v2/bookings/query", { query: { filter: { id: { $eq: bookingId } } } });
3875
+ if (isRefusal(read2)) return read2.status === "http" && read2.httpStatus === 404 ? "released" : openingRefused2(read2);
3876
+ const rows = isObject7(read2.body) ? read2.body.bookings : void 0;
3877
+ const booking = Array.isArray(rows) ? rows.find((b) => isObject7(b) && b.id === bookingId) : void 0;
3878
+ if (!isObject7(booking)) return "held";
3879
+ if (["CANCELED", "CANCELLED", "DECLINED"].includes(String(booking.status)) || PAYMENT_TAKEN2.includes(String(booking.paymentStatus))) return "released";
3880
+ if (booking.status !== "CREATED" || !claim()) return "held";
3881
+ const cancelled = await bridge.call("POST", `/bookings/v2/bookings/${encodeURIComponent(bookingId)}/cancel`, { participantNotification: { notifyParticipants: false }, revision: booking.revision });
3882
+ return isRefusal(cancelled) ? openingRefused2(cancelled) : "released";
3883
+ }
3884
+ function openingRefused2(refusal) {
3885
+ if (refusal.status === "sessionChanged") return "sessionChanged";
3886
+ return refusal.status === "unavailable" ? "unavailable" : "held";
3887
+ }
3888
+ function sameSlot2(guarded, slot) {
3889
+ if (!guarded || !slot) return true;
3890
+ return guarded.sessionId === slot.sessionId && Date.parse(guarded.startDate ?? "") === Date.parse(String(slot.startDate));
3891
+ }
3549
3892
  async function bookingCheckout(item, bookingId, bridge) {
3550
3893
  const checkout = await bridge.call("POST", "/ecom/v1/checkouts", { lineItems: [{ quantity: 1, catalogReference: { appId: "13d21c63-b5ec-5912-8397-c3a5ddb27a97", catalogItemId: bookingId } }], channelType: "OTHER_PLATFORM" });
3551
3894
  if (isRefusal(checkout)) return attemptRefused(checkout);
3552
3895
  const entity = bodyObject(checkout, "checkout");
3553
3896
  const total = isObject7(entity?.priceSummary) ? entity.priceSummary.total : void 0;
3554
- if (!isObject7(total) || !samePrice({ amount: total.amount, currency: entity?.currency }, item)) return CHANGED;
3897
+ if (!isObject7(total) || !samePrice2({ amount: total.amount, currency: entity?.currency }, item)) return CHANGED2;
3555
3898
  if (!isNonEmpty3(entity?.id)) return ORDER_REFUSED;
3556
3899
  const placed = await bridge.call("POST", `/ecom/v1/checkouts/${encodeURIComponent(entity.id)}/create-order`, {});
3557
3900
  if (isRefusal(placed)) return attemptRefused(placed);
@@ -3559,7 +3902,7 @@ async function bookingCheckout(item, bookingId, bridge) {
3559
3902
  if (!isObject7(body) || !isNonEmpty3(body.orderId) || !isNonEmpty3(body.paymentGatewayOrderId)) return ORDER_REFUSED;
3560
3903
  return { status: "open", cashierOrderId: body.paymentGatewayOrderId, verticalRef: { serviceId: item.reference.id, bookingId, orderId: body.orderId } };
3561
3904
  }
3562
- async function bookingAccess(ref, bridge) {
3905
+ async function bookingAccess2(ref, bridge) {
3563
3906
  if (!ref.bookingId || !ref.orderId) return "unavailable";
3564
3907
  const order = await bridge.call("GET", `/ecom/v1/orders/${encodeURIComponent(ref.orderId)}`);
3565
3908
  if (isRefusal(order)) return accessRefused(order);
@@ -3574,19 +3917,19 @@ async function bookingAccess(ref, bridge) {
3574
3917
  return payment === "PAID" && booking.status === "CONFIRMED" && booking.paymentStatus === "PAID" ? "granted" : "pending";
3575
3918
  }
3576
3919
  async function openTicket(item, bridge, now, beforeCreate, afterCreate) {
3577
- if (!eligible(item, TICKET, true).eligible) return notCreated(ORDER_REFUSED);
3920
+ if (!eligible2(item, TICKET2, true).eligible) return notCreated2(ORDER_REFUSED);
3578
3921
  const selected = item.attendance.ticket;
3579
- if (!isNonEmpty3(selected.eventId)) return notCreated(ORDER_REFUSED);
3922
+ if (!isNonEmpty3(selected.eventId)) return notCreated2(ORDER_REFUSED);
3580
3923
  const read2 = await bridge.call("GET", `/events/v3/events/${encodeURIComponent(selected.eventId)}?fields=REGISTRATION&fields=DETAILS&fields=FORM`);
3581
- if (isRefusal(read2)) return notCreated(attemptRefused(read2));
3924
+ if (isRefusal(read2)) return notCreated2(attemptRefused(read2));
3582
3925
  const available = await bridge.call("POST", "/events/v1/checkout/available-tickets/query", { filter: { eventId: selected.eventId }, limit: 100, offset: 0 });
3583
- if (isRefusal(available)) return notCreated(attemptRefused(available));
3926
+ if (isRefusal(available)) return notCreated2(attemptRefused(available));
3584
3927
  const definitions = isObject7(available.body) ? available.body.definitions : void 0;
3585
3928
  const live = Array.isArray(definitions) ? definitions.find((t) => isObject7(t) && t.id === item.reference.id && t.saleStatus === "SALE_STARTED") : void 0;
3586
- if (!isObject7(live) || !samePrice(live.price, item)) return notCreated(CHANGED);
3929
+ if (!isObject7(live) || !samePrice2(live.price, item)) return notCreated2(CHANGED2);
3587
3930
  const event = bodyObject(read2, "event");
3588
- if (live.eventId !== selected.eventId || classifyForApple(availableTicketAttendanceOf(event, live), item.attendance.currency) !== "appleIap") return notCreated(ORDER_REFUSED);
3589
- if (beforeCreate && !beforeCreate({ releaseAt: now() + reservationMinutes(event) * MINUTE_MS + RELEASE_MARGIN_MS })) return notCreated({ status: "refused", reason: "storageUnavailable" });
3931
+ if (live.eventId !== selected.eventId || classifyForApple(availableTicketAttendanceOf(event, live), item.attendance.currency) !== "appleIap") return notCreated2(ORDER_REFUSED);
3932
+ if (beforeCreate && !beforeCreate({ releaseAt: now() + reservationMinutes(event) * MINUTE_MS + RELEASE_MARGIN_MS2 })) return notCreated2({ status: "refused", reason: "storageUnavailable" });
3590
3933
  return reserveTicket(item, bridge, now, afterCreate);
3591
3934
  }
3592
3935
  function reservationMinutes(event) {
@@ -3597,20 +3940,21 @@ function reservationMinutes(event) {
3597
3940
  async function reserveTicket(item, bridge, now, afterCreate) {
3598
3941
  const selected = item.attendance.ticket;
3599
3942
  const held = await bridge.call("POST", "/events/v1/checkout/reservations", { eventId: selected.eventId, ticketQuantities: [{ ticketDefinitionId: item.reference.id, quantity: 1 }], ignoreLimits: false, allowHiddenTickets: false });
3600
- if (isRefusal(held)) return creationRefused(held);
3943
+ if (isRefusal(held)) return creationRefused2(held);
3601
3944
  const reservation = held.body;
3602
3945
  if (!isObject7(reservation) || !isNonEmpty3(reservation.id) || !future(reservation.expires, now)) return ORDER_CLOSED;
3603
- afterCreate?.({ verticalRef: { reservationId: reservation.id }, releaseAt: Date.parse(reservation.expires) + RELEASE_MARGIN_MS });
3604
- if (!heldAsSelected(reservation, item)) return CHANGED;
3946
+ afterCreate?.({ verticalRef: { reservationId: reservation.id }, releaseAt: Date.parse(reservation.expires) + RELEASE_MARGIN_MS2 });
3947
+ if (!heldAsSelected(reservation, item)) return CHANGED2;
3605
3948
  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 } });
3606
3949
  if (isRefusal(placed)) return attemptRefused(placed);
3607
3950
  const order = bodyObject(placed, "order");
3608
- if (!samePrice(order?.totalPrice, item)) return CHANGED;
3951
+ if (!samePrice2(order?.totalPrice, item)) return CHANGED2;
3609
3952
  const expires = isObject7(placed.body) && placed.body.expires || reservation.expires;
3610
3953
  if (!future(expires, now) || !isNonEmpty3(order?.snapshotId) || !isNonEmpty3(order?.orderNumber)) return ORDER_CLOSED;
3611
3954
  return { status: "open", cashierOrderId: order.snapshotId, verticalRef: { eventId: selected.eventId, ticketDefinitionId: item.reference.id, reservationId: reservation.id, orderNumber: order.orderNumber, expires: String(expires) } };
3612
3955
  }
3613
- async function ticketAccess(ref, bridge) {
3956
+ async function ticketAccess2(ref, bridge) {
3957
+ if (isNonEmpty3(ref.orderId)) return ecomOrderAccess(ref.orderId, bridge);
3614
3958
  if (!ref.eventId || !ref.orderNumber || !ref.ticketDefinitionId) return "unavailable";
3615
3959
  const read2 = await bridge.call("GET", `/events/v1/events/${encodeURIComponent(ref.eventId)}/orders/${encodeURIComponent(ref.orderNumber)}?fieldset=DETAILS&fieldset=TICKETS`);
3616
3960
  if (isRefusal(read2)) return accessRefused(read2);
@@ -3619,55 +3963,90 @@ async function ticketAccess(ref, bridge) {
3619
3963
  const issued = Array.isArray(order?.tickets) && order.tickets.some((t) => isObject7(t) && isNonEmpty3(t.ticketNumber) && t.orderStatus === "PAID" && t.ticketDefinitionId === ref.ticketDefinitionId);
3620
3964
  return order?.status === "PAID" && issued ? "granted" : order ? "pending" : "unavailable";
3621
3965
  }
3622
- async function reopen(order, bridge, accessOf3, now) {
3623
- const access = await accessOf3(order.verticalRef, bridge);
3966
+ async function reopen(order, bridge, accessOf4, now) {
3967
+ const access = await accessOf4(order.verticalRef, bridge);
3624
3968
  if (access === "granted") return GRANTED;
3625
3969
  if (access === "unavailable" || access === "sessionChanged") return { status: access };
3626
3970
  if (access === "none" || now && !future(order.verticalRef.expires, now)) return ORDER_CLOSED;
3627
3971
  return { status: "open", ...order };
3628
3972
  }
3629
3973
  function heldAsSelected(reservation, item) {
3630
- if (isObject7(reservation.invoice)) return samePrice(reservation.invoice.grandTotal ?? reservation.invoice.total, item);
3974
+ if (isObject7(reservation.invoice)) return samePrice2(reservation.invoice.grandTotal ?? reservation.invoice.total, item);
3631
3975
  const lines = reservation.reservations;
3632
3976
  if (!Array.isArray(lines) || lines.length !== 1 || !isObject7(lines[0]) || lines[0].quantity !== 1) return false;
3633
3977
  const held = lines[0].ticket;
3634
- return isObject7(held) && held.id === item.reference.id && samePrice(held.price, item);
3978
+ return isObject7(held) && held.id === item.reference.id && samePrice2(held.price, item);
3635
3979
  }
3636
- function samePrice(value, item) {
3637
- return isObject7(value) && value.currency === item.attendance?.currency && decimal(value.amount) !== null && decimal(value.amount) === decimal(item.attendance?.amount);
3980
+ function samePrice2(value, item) {
3981
+ return isObject7(value) && value.currency === item.attendance?.currency && decimal2(value.amount) !== null && decimal2(value.amount) === decimal2(item.attendance?.amount);
3638
3982
  }
3639
- function decimal(value) {
3983
+ function decimal2(value) {
3640
3984
  if (typeof value !== "string" || !/^\d+(?:\.\d+)?$/.test(value)) return null;
3641
3985
  return value.replace(/^0+(?=\d)/, "").replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
3642
3986
  }
3643
3987
  function future(value, now) {
3644
3988
  return typeof value === "string" && Number.isFinite(Date.parse(value)) && Date.parse(value) > now();
3645
3989
  }
3646
- function matchesSlot(value, selected) {
3990
+ function matchesSlot2(value, selected) {
3647
3991
  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])));
3648
3992
  }
3649
- function creationRefused(refusal) {
3993
+ function creationRefused2(refusal) {
3650
3994
  const attempt3 = attemptRefused(refusal);
3651
- return refusal.status === "http" && [400, 401, 403, 404, 405, 409, 410, 415, 422].includes(refusal.httpStatus) ? notCreated(attempt3) : attempt3;
3995
+ return refusal.status === "http" && [400, 401, 403, 404, 405, 409, 410, 415, 422].includes(refusal.httpStatus) ? notCreated2(attempt3) : attempt3;
3652
3996
  }
3653
- function notCreated(attempt3) {
3997
+ function notCreated2(attempt3) {
3654
3998
  return { ...attempt3, noOrderCreated: true };
3655
3999
  }
3656
4000
 
4001
+ // ../../stdlib/flows/iap-checkout/src/iap-verticals/stores.ts
4002
+ var KIND5 = "storesProduct";
4003
+ var WIX_STORES_APP = "215238eb-22a5-4c36-9e7b-e7c08025e04e";
4004
+ var storesProductOrders = {
4005
+ kind: KIND5,
4006
+ eligibility,
4007
+ itemPayment: itemPayment3,
4008
+ readAccess: readAccess4
4009
+ };
4010
+ function eligibility(item) {
4011
+ const single = singleUnitOf(KIND5, item);
4012
+ if (!single.eligible) return single;
4013
+ const catalog = item.catalogReference;
4014
+ const variant = catalog?.options && Object.keys(catalog.options).length > 0;
4015
+ return catalog && !variant && isNonEmpty3(catalog.appId) && catalog.appId.toLowerCase() === WIX_STORES_APP && catalog.catalogItemId === item.reference.id ? single : UNSUPPORTED;
4016
+ }
4017
+ function itemPayment3(item) {
4018
+ return { catalogItem: { catalogItemId: item.reference.id, catalogAppId: WIX_STORES_APP }, verticalRefOf: ({ ecomOrderId }) => ecomOrderId ? { orderId: ecomOrderId } : null };
4019
+ }
4020
+ function classifyCart(lines) {
4021
+ if (lines.length === 0 || lines.some((line) => line.route === "resolving" || line.route === "unavailable")) return "blocked";
4022
+ const apple = lines.filter((line) => line.route === "appleIap");
4023
+ if (apple.length === 0) return "regular";
4024
+ return lines.length === 1 && apple[0].quantity === 1 ? "appleIap" : "mixedRefused";
4025
+ }
4026
+ function readAccess4(verticalRef, bridge) {
4027
+ return ecomOrderAccess(verticalRef.orderId, bridge);
4028
+ }
4029
+
3657
4030
  // ../../stdlib/flows/iap-checkout/src/iap-verticals/videos.ts
3658
- var KIND4 = "wixVideo";
3659
- var NOT_ENABLED2 = { status: "refused", reason: "notEnabled" };
4031
+ var KIND6 = "wixVideo";
4032
+ var NOT_ENABLED3 = { status: "refused", reason: "notEnabled" };
3660
4033
  var NO_ORDER_STEP = { status: "refused", reason: "notConfigured" };
3661
4034
  function videoOrdersWith(options) {
3662
4035
  return {
3663
- kind: KIND4,
3664
- eligibility: (item) => options.enabled ? singleUnitOf(KIND4, item) : { eligible: false, reason: "notEnabled" },
3665
- openOrder: async () => options.enabled ? NO_ORDER_STEP : NOT_ENABLED2,
4036
+ kind: KIND6,
4037
+ eligibility: (item) => options.enabled ? singleUnitOf(KIND6, item) : { eligible: false, reason: "notEnabled" },
4038
+ openOrder: async () => options.enabled ? NO_ORDER_STEP : NOT_ENABLED3,
3666
4039
  reopenOrder: async () => ORDER_CLOSED,
3667
4040
  readAccess: async () => "unavailable"
3668
4041
  };
3669
4042
  }
3670
4043
  var wixVideoOrders = /* @__PURE__ */ videoOrdersWith({ enabled: VIDEOS_APPLE_SALES_ENABLED });
4044
+
4045
+ // ../../stdlib/flows/iap-checkout/src/iap-verticals/index.ts
4046
+ var onlineProgramOrders = ONLINE_PROGRAM_ITEM_PAYMENT_ENABLED ? onlineProgramItemPayments : onlineProgramClientOrders;
4047
+ var pricingPlanOrders = PRICING_PLAN_ITEM_PAYMENT_ENABLED ? pricingPlanItemPayments : pricingPlanClientOrders;
4048
+ var bookingOrders = BOOKINGS_ITEM_PAYMENT_ENABLED ? bookingItemPayments : bookingClientOrders;
4049
+ var eventTicketOrders = EVENTS_ITEM_PAYMENT_ENABLED ? eventTicketItemPayments : eventTicketClientOrders;
3671
4050
  export {
3672
4051
  bookingOrders,
3673
4052
  classifyCart,