@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.
Files changed (67) 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 +33 -7
  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/_types/stdlib/flows/iap-checkout/src/order-refs.d.ts +8 -4
  19. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/audio-record.mjs +1 -1
  20. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/calendar.mjs +1 -1
  21. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/calls.mjs +1 -1
  22. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/contacts.mjs +1 -1
  23. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap-checkout.mjs +622 -197
  24. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap.mjs +52 -8
  25. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/location.mjs +1 -1
  26. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/motion.mjs +1 -1
  27. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/photos.mjs +1 -1
  28. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +500 -119
  29. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdk-types.mjs +1 -1
  30. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/tasks.mjs +1 -1
  31. package/dist/browser-plane/assets.json +5 -5
  32. package/dist/browser-plane/preview-deferred/{c04dd5fc5ad48e6b19678d4313159302e9a513ada94bfe515d8dfd5a54d46f5d.bin → fcafca348b6b973cfc2eadc938ddec3c515c641874cbca1667a43b22e1bf7a39.bin} +1 -1
  33. package/dist/browser-plane/sw.js +1 -1
  34. package/dist/cli.mjs +203 -56
  35. package/dist/preview-assets.generated.bin +0 -0
  36. package/guides/himi-json-output.md +26 -1
  37. package/guides/qa-builds.md +27 -4
  38. package/guides/sdk-reference.json +82 -12
  39. package/guides/skill.md +2 -2
  40. package/guides/web-page-sdk-reference.md +1 -1
  41. package/package.json +2 -2
  42. package/templates/beauty-salon/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  43. package/templates/beauty-salon/tier5-src/_shared/iap-worker.ts +2 -0
  44. package/templates/branded-lite/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  45. package/templates/branded-lite/tier5-src/_shared/iap-worker.ts +2 -0
  46. package/templates/community-club/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  47. package/templates/community-club/tier5-src/_shared/iap-worker.ts +2 -0
  48. package/templates/conference/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  49. package/templates/conference/tier5-src/_shared/iap-worker.ts +2 -0
  50. package/templates/events-meetups/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  51. package/templates/events-meetups/tier5-src/_shared/iap-worker.ts +2 -0
  52. package/templates/gym-fitness/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  53. package/templates/gym-fitness/tier5-src/_shared/iap-worker.ts +2 -0
  54. package/templates/nonprofit-cause/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  55. package/templates/nonprofit-cause/tier5-src/_shared/iap-worker.ts +2 -0
  56. package/templates/podcast-creator/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  57. package/templates/podcast-creator/tier5-src/_shared/iap-worker.ts +2 -0
  58. package/templates/portfolio-creative/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  59. package/templates/portfolio-creative/tier5-src/_shared/iap-worker.ts +2 -0
  60. package/templates/restaurant/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  61. package/templates/restaurant/tier5-src/_shared/iap-worker.ts +2 -0
  62. package/templates/retail-store/tier5-src/_shared/iap-worker.ts +2 -0
  63. package/templates/salon-spa/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  64. package/templates/salon-spa/tier5-src/_shared/iap-worker.ts +2 -0
  65. package/templates/wholesale-store/tier5-src/_shared/iap-worker.ts +2 -0
  66. package/templates/yoga-studio/tier5-src/_shared/iap-attendance-purchase.ts +6 -1
  67. 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", {
@@ -1780,7 +1818,8 @@ var NEEDS_SUPPORT_HOLD_MS = 6048e5;
1780
1818
  var ITEM_START_HOLD_MS = 36e5;
1781
1819
  function pruneExpiredHolds(partition, now) {
1782
1820
  const expired = partition.refs().filter((ref) => now - ref.updatedAt >= (HOLD_MS[ref.stage] ?? Infinity) || released(ref, now));
1783
- return expired.filter((ref) => partition.remove(ref.key)).map((ref) => ref.key);
1821
+ const removed = (ref) => ref.stage === "openingOrder" ? partition.removeGuard(ref) === "written" : partition.remove(ref.key);
1822
+ return expired.filter(removed).map((ref) => ref.key);
1784
1823
  }
1785
1824
  var OPENING_SETTLE_MS = 3e5;
1786
1825
  async function settleOpening(partition, adapter, guard, item, bridge, now) {
@@ -1788,23 +1827,36 @@ async function settleOpening(partition, adapter, guard, item, bridge, now) {
1788
1827
  if (!resolve) return "held";
1789
1828
  let current = guard;
1790
1829
  const claim = () => {
1791
- const next = { ...current, updatedAt: now };
1792
- if (!isStoredGuard(partition, current) || !partition.put(next)) return false;
1830
+ const next = { ...current, guardToken: newGuardToken(), updatedAt: now };
1831
+ if (partition.replaceGuard(current, next) !== "written") return false;
1793
1832
  current = next;
1794
1833
  return true;
1795
1834
  };
1796
1835
  const resolution = await resolve(guard, item, bridge, { settled: now - guard.updatedAt >= OPENING_SETTLE_MS, claim });
1797
- if (isStoredGuard(partition, current)) {
1798
- if (resolution !== "released") return resolution;
1799
- return partition.remove(guard.key) ? "released" : "storageUnavailable";
1836
+ if (resolution === "released") {
1837
+ const removed = partition.removeGuard(current);
1838
+ if (removed !== "replaced") return removed === "written" ? "released" : "storageUnavailable";
1839
+ } else if (isStoredGuard(partition, current)) {
1840
+ return resolution;
1800
1841
  }
1801
1842
  const stored = partition.refs().find((ref) => ref.key === guard.key);
1802
1843
  if (!stored) return "released";
1803
1844
  return stored.stage === "openingOrder" ? resolve(stored, item, bridge, { settled: false, claim: () => false }) : "held";
1804
1845
  }
1805
1846
  function isStoredGuard(partition, guard) {
1806
- const stored = partition.refs().find((ref) => ref.key === guard.key);
1807
- return stored?.stage === "openingOrder" && stored.updatedAt === guard.updatedAt;
1847
+ return holdsGuard(partition.refs(), guard);
1848
+ }
1849
+ function holdsGuard(refs, expected) {
1850
+ const stored = refs.find((ref) => ref.key === expected.key);
1851
+ if (stored?.stage !== "openingOrder") return false;
1852
+ return expected.guardToken === void 0 ? stored.guardToken === void 0 && stored.updatedAt === expected.updatedAt : stored.guardToken === expected.guardToken;
1853
+ }
1854
+ var guardTokens = 0;
1855
+ function newGuardToken() {
1856
+ const crypto = globalThis.crypto;
1857
+ if (typeof crypto?.randomUUID === "function") return crypto.randomUUID();
1858
+ const random = () => Math.random().toString(36).slice(2, 12);
1859
+ return `${Date.now().toString(36)}-${(guardTokens++).toString(36)}-${random()}${random()}`;
1808
1860
  }
1809
1861
  var MAX_ORDER_REFS = 16;
1810
1862
  function createWorkerOrderRefStore(storage) {
@@ -1816,19 +1868,34 @@ function createWorkerOrderRefStore(storage) {
1816
1868
  return {
1817
1869
  refs: () => readRefs(kv(), location) ?? [],
1818
1870
  put: (ref) => writeWith(location, key, (refs) => upsert(refs, ref)),
1819
- remove: (refKey) => writeWith(location, key, (refs) => refs.filter((stored) => stored.key !== refKey))
1871
+ remove: (refKey) => writeWith(location, key, (refs) => refs.filter((stored) => stored.key !== refKey)),
1872
+ replaceGuard: (expected, next) => guardedWrite(location, key, expected, (refs) => upsert(refs, next)),
1873
+ removeGuard: (expected) => guardedWrite(location, key, expected, (refs) => refs.filter((stored) => stored.key !== expected.key))
1820
1874
  };
1821
1875
  }
1876
+ function guardedWrite(location, key, expected, change) {
1877
+ let replaced = false;
1878
+ const written = writeWith(location, key, (refs) => {
1879
+ replaced = !holdsGuard(refs, expected);
1880
+ return replaced ? null : change(refs);
1881
+ });
1882
+ return written ? "written" : replaced ? "replaced" : "unavailable";
1883
+ }
1822
1884
  function writeWith(location, key, change) {
1823
1885
  const store = kv();
1824
1886
  if (!store) return false;
1825
- const current = readRefs(store, location);
1826
- const next = current && change(current);
1827
- if (!next) return false;
1828
- if (next.length > 0 && !updateIndex(store, key, true)) return false;
1829
- if (!writeVerified(store, location, serialize({ v: VERSION, refs: next }))) return false;
1830
- if (next.length === 0) updateIndex(store, key, false);
1831
- return true;
1887
+ for (let attempt3 = 0; attempt3 < WRITE_ATTEMPTS; attempt3++) {
1888
+ const raw = safely(() => store.getItem(location));
1889
+ const current = parseRefs(raw);
1890
+ const next = current && change(current);
1891
+ if (!next) return false;
1892
+ if (next.length > 0 && !updateIndex(store, key, true)) return false;
1893
+ if (safely(() => store.getItem(location)) !== raw) continue;
1894
+ if (!writeVerified(store, location, serialize({ v: VERSION, refs: next }))) return false;
1895
+ if (next.length === 0) updateIndex(store, key, false);
1896
+ return true;
1897
+ }
1898
+ return false;
1832
1899
  }
1833
1900
  function hasRefs(app) {
1834
1901
  if (!isUUID3(app.purchasesAppId) || !isUUID3(app.siteId)) return null;
@@ -1853,7 +1920,10 @@ function updateIndex(store, key, holdsRefs) {
1853
1920
  return next.length === members.length && next.every((m, i) => m === members[i]) || writeVerified(store, location, serialize({ v: VERSION, members: next }));
1854
1921
  }
1855
1922
  function readRefs(store, location) {
1856
- const parsed = readVersioned(store, location);
1923
+ return store ? parseRefs(safely(() => store.getItem(location))) : null;
1924
+ }
1925
+ function parseRefs(raw) {
1926
+ const parsed = parseVersioned(raw);
1857
1927
  if (parsed === "empty") return [];
1858
1928
  if (!parsed || !Array.isArray(parsed.refs) || !parsed.refs.every(isOrderRef)) return null;
1859
1929
  return parsed.refs;
@@ -1865,8 +1935,9 @@ function readIndex(store, location) {
1865
1935
  return parsed.members;
1866
1936
  }
1867
1937
  function readVersioned(store, location) {
1868
- if (!store) return null;
1869
- const raw = safely(() => store.getItem(location));
1938
+ return store ? parseVersioned(safely(() => store.getItem(location))) : null;
1939
+ }
1940
+ function parseVersioned(raw) {
1870
1941
  if (raw === void 0) return null;
1871
1942
  if (raw === null || raw === "") return "empty";
1872
1943
  const parsed = safely(() => JSON.parse(raw));
@@ -1883,7 +1954,7 @@ function isOrderRef(value) {
1883
1954
  if (!isObject6(value) || typeof value.key !== "string" || !STAGES.has(value.stage)) return false;
1884
1955
  if (typeof value.updatedAt !== "number") return false;
1885
1956
  if (value.releaseAt !== void 0 && typeof value.releaseAt !== "number") return false;
1886
- const optional = ["kind", "cashierOrderId", "wixTransactionId", "paymentId", "storeProductId", "appProductId", "appleTransactionId", "appAccountToken"];
1957
+ const optional = ["kind", "cashierOrderId", "wixTransactionId", "paymentId", "storeProductId", "appProductId", "appleTransactionId", "appAccountToken", "guardToken"];
1887
1958
  if (!optional.every((field) => value[field] === void 0 || typeof value[field] === "string")) return false;
1888
1959
  return value.verticalRef === void 0 || isStringMap(value.verticalRef);
1889
1960
  }
@@ -1939,6 +2010,7 @@ function isUUID3(value) {
1939
2010
  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);
1940
2011
  }
1941
2012
  var VERSION = 1;
2013
+ var WRITE_ATTEMPTS = 3;
1942
2014
  var PREFIX = "himi.iap.wix-checkout.v1";
1943
2015
  var STAGES = /* @__PURE__ */ new Set(["startingItem", "openingOrder", "ordered", "charged", "started", "submitted", "fulfilled", "held", "needsSupport"]);
1944
2016
  var HOLD_MS = { held: NEEDS_SUPPORT_HOLD_MS, needsSupport: NEEDS_SUPPORT_HOLD_MS, startingItem: ITEM_START_HOLD_MS };
@@ -2031,7 +2103,26 @@ function createWixOrderBackend(deps) {
2031
2103
  const blocked = saleBlocked(sale);
2032
2104
  if (blocked) return contextResult(catalogRef, blocked);
2033
2105
  const { adapter } = sale;
2034
- return paidByItem(adapter) ? startItemFor(sale, adapter.itemPayment(sale.item)) : startOrderFor({ ...sale, adapter });
2106
+ if (!paidByItem(adapter)) return startOrderFor({ ...sale, adapter });
2107
+ const country = await readStoreCountry();
2108
+ if (!sale.bridge.isCurrent()) return contextResult(catalogRef, STALE2);
2109
+ const { state, beforeCreate, afterCreate } = creationGuards(sale, void 0);
2110
+ const prepared = await adapter.itemPayment(sale.item, sale.bridge, beforeCreate, afterCreate);
2111
+ if (state.prevented) return contextResult(catalogRef, state.prevented);
2112
+ if (state.orphan) return contextResult(catalogRef, await releaseOrphan(sale, state.orphan));
2113
+ if (!sale.bridge.isCurrent()) return contextResult(catalogRef, STALE2);
2114
+ if ("status" in prepared) return contextResult(catalogRef, preparationStop(sale, prepared, state.guarded));
2115
+ if (state.guarded && !isStoredGuard(sale.partition, state.guarded)) return contextResult(catalogRef, retry("unavailable"));
2116
+ const stillBlocked = state.guarded === void 0 ? saleBlocked(sale) : null;
2117
+ if (stillBlocked) return contextResult(catalogRef, stillBlocked);
2118
+ return startItemFor(sale, prepared, country, state.guarded);
2119
+ }
2120
+ function preparationStop(sale, refusal, guarded) {
2121
+ if (refusal.noOrderCreated && guarded && sale.partition.removeGuard(guarded) === "unavailable") {
2122
+ return stopWith("rejected", "storageUnavailable");
2123
+ }
2124
+ if (refusal.status === "refused") return stopWith("rejected", refusal.reason);
2125
+ return refusal.status === "sessionChanged" ? STALE2 : retry("unavailable");
2035
2126
  }
2036
2127
  async function startOrderFor(sale) {
2037
2128
  const ordered = await orderFor(sale);
@@ -2090,59 +2181,60 @@ function createWixOrderBackend(deps) {
2090
2181
  unrelated: /* @__PURE__ */ new Set()
2091
2182
  };
2092
2183
  }
2093
- async function orderFor(sale) {
2094
- const existing = refAt(sale.partition, sale.catalogRef);
2095
- let prevented;
2096
- let guarded;
2184
+ function creationGuards(sale, existing) {
2185
+ const state = {};
2097
2186
  const beforeCreate = (guard = {}) => {
2098
2187
  if (!sale.adapter.repeatable || existing) return true;
2099
2188
  if (!sale.bridge.isCurrent()) {
2100
- prevented = STALE2;
2189
+ state.prevented = STALE2;
2101
2190
  return false;
2102
2191
  }
2103
2192
  const blocked = saleBlocked(sale);
2104
2193
  if (blocked) {
2105
- prevented = blocked;
2194
+ state.prevented = blocked;
2106
2195
  return false;
2107
2196
  }
2108
- const opening = persist(sale, { ...guard, key: sale.catalogRef, kind: sale.adapter.kind, stage: "openingOrder", updatedAt: now() });
2197
+ const opening = persist(sale, { ...guard, key: sale.catalogRef, kind: sale.adapter.kind, stage: "openingOrder", guardToken: newGuardToken(), updatedAt: now() });
2109
2198
  if (isStop(opening)) {
2110
- prevented = opening;
2199
+ state.prevented = opening;
2111
2200
  return false;
2112
2201
  }
2113
- guarded = opening.updatedAt;
2202
+ state.guarded = opening;
2114
2203
  return true;
2115
2204
  };
2116
2205
  const afterCreate = (guard) => {
2117
- const opening = refAt(sale.partition, sale.catalogRef);
2118
- if (opening?.stage !== "openingOrder" || opening.updatedAt !== guarded) return;
2119
- const recorded = persist(sale, { ...opening, ...guard, verticalRef: { ...opening.verticalRef, ...guard.verticalRef }, updatedAt: now() });
2120
- if (!isStop(recorded)) guarded = recorded.updatedAt;
2206
+ if (!state.guarded || !sale.bridge.isCurrent()) return true;
2207
+ const recorded = { ...state.guarded, ...guard, verticalRef: { ...state.guarded.verticalRef, ...guard.verticalRef }, updatedAt: now() };
2208
+ const written = sale.partition.replaceGuard(state.guarded, recorded);
2209
+ if (written === "written") state.guarded = recorded;
2210
+ if (written === "replaced") state.orphan = recorded;
2211
+ return written !== "replaced";
2121
2212
  };
2213
+ return { state, beforeCreate, afterCreate };
2214
+ }
2215
+ async function orderFor(sale) {
2216
+ const existing = refAt(sale.partition, sale.catalogRef);
2217
+ const { state, beforeCreate, afterCreate } = creationGuards(sale, existing);
2122
2218
  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);
2219
+ if (state.prevented) return state.prevented;
2220
+ if (state.orphan) return releaseOrphan(sale, state.orphan);
2221
+ const ref = recordOrder(sale, existing, attempt3, state.guarded);
2126
2222
  return isStop(ref) ? ref : { ref, placed: isPlaced(attempt3) };
2127
2223
  }
2128
- function stillGuarded(sale, guarded) {
2129
- const stored = refAt(sale.partition, sale.catalogRef);
2130
- return stored?.stage === "openingOrder" && stored.updatedAt === guarded;
2131
- }
2132
2224
  async function reopenOrOpen(sale, order) {
2133
2225
  const reopened = await sale.adapter.reopenOrder(order, sale.bridge);
2134
2226
  const closed = reopened.status === "refused" && reopened.reason === "orderClosed";
2135
2227
  return closed && !sale.adapter.repeatable ? sale.adapter.openOrder(sale.item, sale.bridge) : reopened;
2136
2228
  }
2137
2229
  function recordOrder(sale, existing, attempt3, guarded) {
2138
- if (attempt3.noOrderCreated && guarded !== void 0 && stillGuarded(sale, guarded) && !sale.partition.remove(sale.catalogRef)) {
2230
+ if (attempt3.noOrderCreated && guarded && sale.partition.removeGuard(guarded) === "unavailable") {
2139
2231
  return stopWith("rejected", "storageUnavailable");
2140
2232
  }
2141
2233
  if (attempt3.status === "granted") return alreadyOwned(sale);
2142
2234
  if (attempt3.status === "refused") return stopWith("rejected", attempt3.reason);
2143
2235
  if (attempt3.status !== "open") return attempt3.status === "sessionChanged" ? STALE2 : retry("unavailable");
2144
2236
  const kept = existing && existing.cashierOrderId === attempt3.cashierOrderId ? existing : { key: sale.catalogRef, updatedAt: 0 };
2145
- return persist(sale, {
2237
+ const ordered = {
2146
2238
  ...kept,
2147
2239
  key: sale.catalogRef,
2148
2240
  stage: "ordered",
@@ -2150,7 +2242,18 @@ function createWixOrderBackend(deps) {
2150
2242
  verticalRef: attempt3.verticalRef,
2151
2243
  cashierOrderId: attempt3.cashierOrderId,
2152
2244
  updatedAt: now()
2153
- });
2245
+ };
2246
+ return guarded ? persistGuarded(sale, guarded, ordered) : persist(sale, ordered);
2247
+ }
2248
+ async function releaseOrphan(sale, made) {
2249
+ const released2 = await sale.adapter.resolveOpening?.(made, sale.item, sale.bridge, { settled: true, claim: () => true });
2250
+ return released2 === "sessionChanged" || !sale.bridge.isCurrent() ? STALE2 : retry("unavailable");
2251
+ }
2252
+ function persistGuarded(sale, guarded, ref) {
2253
+ if (!sale.bridge.isCurrent()) return STALE2;
2254
+ const written = sale.partition.replaceGuard(guarded, ref);
2255
+ if (written === "replaced") return retry("unavailable");
2256
+ return written === "written" ? ref : stopWith("rejected", "storageUnavailable");
2154
2257
  }
2155
2258
  async function chargeFor(sale, ref, options) {
2156
2259
  const charge = await (options.placed ? chargePlacedOrder : ensureAppleIapCharge)(sale.bridge, deps.cashier, ref.cashierOrderId ?? "");
@@ -2206,24 +2309,39 @@ function createWixOrderBackend(deps) {
2206
2309
  if (isStop(recorded)) return contextResult(sale.catalogRef, recorded);
2207
2310
  return { status: "ok", context: { productId: started.storeProductId, appAccountToken: started.appAccountToken, scopeKey: sale.member.scopeKey } };
2208
2311
  }
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() });
2312
+ async function startItemFor(sale, itemPayment4, country, owned) {
2313
+ const made = refAt(sale.partition, sale.catalogRef);
2314
+ const guarded = made?.stage === "openingOrder" ? { verticalRef: made.verticalRef, releaseAt: made.releaseAt } : {};
2315
+ const next = {
2316
+ key: sale.catalogRef,
2317
+ stage: "startingItem",
2318
+ kind: sale.adapter.kind,
2319
+ storeProductId: sale.appleProduct.productId,
2320
+ ...guarded.verticalRef ? { verticalRef: guarded.verticalRef } : {},
2321
+ ...guarded.releaseAt !== void 0 ? { releaseAt: guarded.releaseAt } : {},
2322
+ updatedAt: now()
2323
+ };
2324
+ const attempt3 = owned ? persistGuarded(sale, owned, next) : persist(sale, next);
2211
2325
  if (isStop(attempt3)) return contextResult(sale.catalogRef, attempt3);
2212
- const started = await deps.wixIap.startItemPayment({ item: itemPayment2.catalogItem });
2326
+ const started = await deps.wixIap.startItemPayment({ item: itemPayment4.catalogItem, ...country ? { storeCountryCode: country } : {} });
2213
2327
  if (started.status === "outcomeUnknown") return contextResult(sale.catalogRef, sale.bridge.isCurrent() ? OUTCOME_UNKNOWN : STALE2);
2214
2328
  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);
2329
+ return startedItem(sale, itemPayment4, started);
2330
+ }
2331
+ function startedItem(sale, itemPayment4, started) {
2332
+ if (started.storeProductId !== sale.appleProduct.productId) return contextResult(sale.catalogRef, unsold(sale, stopWith("rejected", "productChanged")));
2333
+ const placed = itemPayment4.verticalRefOf(started);
2334
+ if (!placed) return contextResult(sale.catalogRef, unsold(sale, OUTCOME_UNKNOWN));
2335
+ const attempt3 = refAt(sale.partition, sale.catalogRef);
2336
+ const guarded = attempt3?.stage === "startingItem" ? attempt3 : void 0;
2337
+ const verticalRef = guarded?.verticalRef ? { ...guarded.verticalRef, ...placed } : placed;
2221
2338
  const { payment, storeProductId, appAccountToken } = started;
2222
2339
  const recorded = persist(sale, {
2223
2340
  key: sale.catalogRef,
2224
2341
  stage: "started",
2225
2342
  kind: sale.adapter.kind,
2226
2343
  verticalRef,
2344
+ ...guarded?.releaseAt !== void 0 ? { releaseAt: guarded.releaseAt } : {},
2227
2345
  wixTransactionId: payment.wixTransactionId,
2228
2346
  paymentId: payment.paymentId,
2229
2347
  storeProductId,
@@ -2234,11 +2352,31 @@ function createWixOrderBackend(deps) {
2234
2352
  if (isStop(recorded)) return contextResult(sale.catalogRef, recorded);
2235
2353
  return { status: "ok", context: { productId: storeProductId, appAccountToken, scopeKey: sale.member.scopeKey } };
2236
2354
  }
2355
+ function unsold(sale, stop) {
2356
+ handBackToGuard(sale.partition, sale.adapter, refAt(sale.partition, sale.catalogRef));
2357
+ return stop;
2358
+ }
2237
2359
  function itemRefusal(sale, failure3) {
2360
+ if (failure3.kind === "application" && failure3.code === "NOT_BOOKING_OWNER") return dropAttempt(sale, retry("bookingNotOwned"));
2238
2361
  if (failure3.kind === "application") return undoAttempt(sale, stopWith("rejected", ITEM_REFUSALS[failure3.code]));
2239
2362
  return undoAttempt(sale, failure3.kind === "unrecognized" ? NOT_CONFIGURED : failureStop(failure3));
2240
2363
  }
2241
2364
  function undoAttempt(sale, stop) {
2365
+ return handBackToGuard(sale.partition, sale.adapter, refAt(sale.partition, sale.catalogRef)) ? stop : dropAttempt(sale, stop);
2366
+ }
2367
+ function handBackToGuard(partition, adapter, attempt3) {
2368
+ if (!attempt3?.verticalRef || !adapter.resolveOpening) return false;
2369
+ return partition.put({
2370
+ key: attempt3.key,
2371
+ kind: adapter.kind,
2372
+ stage: "openingOrder",
2373
+ guardToken: newGuardToken(),
2374
+ verticalRef: attempt3.verticalRef,
2375
+ ...attempt3.releaseAt !== void 0 ? { releaseAt: attempt3.releaseAt } : {},
2376
+ updatedAt: now() - OPENING_SETTLE_MS
2377
+ });
2378
+ }
2379
+ function dropAttempt(sale, stop) {
2242
2380
  sale.partition.remove(sale.catalogRef);
2243
2381
  return stop;
2244
2382
  }
@@ -2247,9 +2385,8 @@ function createWixOrderBackend(deps) {
2247
2385
  }
2248
2386
  async function startRefusal(sale, ref, failure3) {
2249
2387
  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
- }
2388
+ if (failure3.code === "SUBSCRIPTION_NOT_IN_APP") return stopWith("rejected", "unsupportedItem");
2389
+ if (failure3.code === "ALREADY_SUBSCRIBED") return stopWith("rejected", "alreadySubscribed");
2253
2390
  if (failure3.code === "ALREADY_OWNED") return alreadyPaid(sale, ref);
2254
2391
  if (failure3.code === "NOT_PENDING" || failure3.code === "NOT_ORDER_BUYER") forget(sale, sale.catalogRef);
2255
2392
  return stopWith("rejected", failure3.code === "NOT_PENDING" ? "orderClosed" : "paymentRefused");
@@ -2346,12 +2483,37 @@ function createWixOrderBackend(deps) {
2346
2483
  if (proof.transaction.appAccountToken) return refByToken(refs, proof.transaction);
2347
2484
  return refs.filter((ref) => ref.stage === "started" && ref.storeProductId === productId).reduce((newest, ref) => !newest || ref.updatedAt >= newest.updatedAt ? ref : newest, void 0);
2348
2485
  }
2486
+ async function readStoreCountry() {
2487
+ try {
2488
+ return await deps.storeCountry?.() ?? null;
2489
+ } catch {
2490
+ return null;
2491
+ }
2492
+ }
2493
+ async function abandonPurchase(session, catalogRef) {
2494
+ const member = await memberOf(session);
2495
+ const partition = isStop(member) ? null : member.partition;
2496
+ if (!partition || !isCurrent(session)) return;
2497
+ const ref = refAt(partition, catalogRef);
2498
+ if (ref?.stage !== "started" || !ref.paymentId) return;
2499
+ const adapter = adapterFor(ref.kind);
2500
+ if (!adapter || !paidByItem(adapter)) return;
2501
+ if (!(deps.cancelPaymentEnabled ?? CANCEL_PAYMENT_ENABLED) || adapter.reusesPayment) {
2502
+ const current = refAt(partition, catalogRef);
2503
+ if (current?.stage === "started" && current.paymentId === ref.paymentId && current.updatedAt === ref.updatedAt) handBackToGuard(partition, adapter, ref);
2504
+ return;
2505
+ }
2506
+ const canceled = await deps.wixIap.cancelPayment({ paymentId: ref.paymentId });
2507
+ if (canceled.status !== "answered" || !isCurrent(session)) return;
2508
+ if (canceled.payment.status !== "canceled") return;
2509
+ if (refAt(partition, catalogRef)?.paymentId === ref.paymentId) partition.remove(catalogRef);
2510
+ }
2349
2511
  async function getMemberContext(session) {
2350
2512
  const member = await memberOf(session);
2351
2513
  if (isStop(member)) return { status: member.result };
2352
2514
  return { status: "ok", context: { scopeKey: member.scopeKey } };
2353
2515
  }
2354
- return { getPurchaseContext, getMemberContext, submitProof };
2516
+ return { getPurchaseContext, getMemberContext, submitProof, abandonPurchase };
2355
2517
  }
2356
2518
  function paidByItem(adapter) {
2357
2519
  return typeof adapter.itemPayment === "function";
@@ -2391,12 +2553,15 @@ var ITEM_REFUSALS = {
2391
2553
  UNSUPPORTED_ORDER: "orderRefused",
2392
2554
  CATALOG_NOT_SUPPORTED: "unsupportedItem",
2393
2555
  EVENT_CHECKOUT_NOT_ECOM: "unsupportedItem",
2556
+ SUBSCRIPTION_NOT_IN_APP: "unsupportedItem",
2557
+ // The site or the store cannot sell it, and a tap would be refused again: Buy stays disabled.
2394
2558
  VERTICAL_ACCESS_DENIED: "notConfigured",
2559
+ BILLING_COUNTRY_REQUIRED: "notConfigured",
2395
2560
  APP_NOT_CONFIGURED: "notConfigured",
2396
- ALREADY_SUBSCRIBED: "paymentRefused",
2397
- SUBSCRIPTION_NOT_IN_APP: "paymentRefused",
2398
- BILLING_COUNTRY_REQUIRED: "orderRefused",
2399
- NOT_BOOKING_OWNER: "orderRefused",
2561
+ ALREADY_SUBSCRIBED: "alreadySubscribed",
2562
+ MEMBER_DETAILS_REQUIRED: "memberDetailsRequired",
2563
+ // The booking is not this member's: itemRefusal drops the attempt and a new tap makes a new booking.
2564
+ NOT_BOOKING_OWNER: "bookingNotOwned",
2400
2565
  BOOKING_PAYMENT_PENDING: "paymentInProgress"
2401
2566
  };
2402
2567
  var KIND_STOPS = {
@@ -2483,7 +2648,8 @@ function enabledCheckout(deps) {
2483
2648
  bridge,
2484
2649
  itemFor: (key) => sales.get(key),
2485
2650
  productBusy,
2486
- report: onEvent
2651
+ report: onEvent,
2652
+ storeCountry: deps.storeCountry ?? storefrontCountryCode
2487
2653
  });
2488
2654
  const coordinator = createPurchaseCoordinator({
2489
2655
  store: deps.store ?? appleManagedStore,
@@ -2650,7 +2816,7 @@ function enabledCheckout(deps) {
2650
2816
  if (!isCurrent(session)) return;
2651
2817
  if (ref.stage === "needsSupport") setPayment(ref.key, "needsSupport");
2652
2818
  if (ref.stage === "fulfilled" && !options.dueOnly) {
2653
- const access = await accessOf3(session, ref);
2819
+ const access = await accessOf4(session, ref);
2654
2820
  if (!isCurrent(session)) return;
2655
2821
  if (access === "granted") setPayment(ref.key, "granted");
2656
2822
  else if (access === "none") payments.delete(ref.key);
@@ -2710,7 +2876,7 @@ function enabledCheckout(deps) {
2710
2876
  if (isFinalRefusal(payment.status)) return markNeedsSupport(partition, ref);
2711
2877
  if (payment.status !== "approved") return backOff(partition, ref, false);
2712
2878
  if (!ref.kind) return settleUnassociated(partition, ref);
2713
- const access = await accessOf3(session, ref);
2879
+ const access = await accessOf4(session, ref);
2714
2880
  if (!isCurrent(session)) return;
2715
2881
  if (access === "granted") return grant(partition, ref);
2716
2882
  backOff(partition, ref, access === "none");
@@ -2726,7 +2892,7 @@ function enabledCheckout(deps) {
2726
2892
  partition.remove(ref.key);
2727
2893
  setPayment(ref.key, "accessUnknown");
2728
2894
  }
2729
- async function accessOf3(session, ref) {
2895
+ async function accessOf4(session, ref) {
2730
2896
  const adapter = deps.adapters.find((candidate) => candidate.kind === ref.kind);
2731
2897
  if (!adapter || !ref.verticalRef) return "unavailable";
2732
2898
  return adapter.readAccess(ref.verticalRef, bindBridge(session, deps.session, bridge));
@@ -2866,8 +3032,12 @@ function outcomeAction(state, copy) {
2866
3032
  function refusalAction(failure3, copy) {
2867
3033
  if (failure3 === "sitePaymentUnavailable") return action(copy, "enabled", copy.sitePaymentUnavailable ?? copy.retry);
2868
3034
  const [mode, note] = REFUSALS[failure3 ?? "unavailable"] ?? ["enabled", "retry"];
2869
- return action(copy, mode, note ? copy[note] ?? "" : "");
3035
+ return action(copy, mode, note ? copy[note] ?? copy[OPTIONAL_COPY_FALLBACK[note] ?? "retry"] ?? "" : "");
2870
3036
  }
3037
+ var OPTIONAL_COPY_FALLBACK = {
3038
+ memberDetailsRequired: "retry",
3039
+ alreadySubscribed: "unavailable"
3040
+ };
2871
3041
  function action(copy, mode, note) {
2872
3042
  return { appleRoute: true, accessReady: false, buyLabel: copy.buy, buyDisabled: mode !== "enabled", buyBusy: mode === "busy", buyNote: note };
2873
3043
  }
@@ -2886,6 +3056,11 @@ var REFUSALS = {
2886
3056
  approvalRequired: ["disabled", "awaitingApproval"],
2887
3057
  signInRequired: ["disabled", "signInRequired"],
2888
3058
  notConfigured: ["disabled", "unavailable"],
3059
+ // The member can fix this: completing the profile and tapping again sells.
3060
+ memberDetailsRequired: ["enabled", "memberDetailsRequired"],
3061
+ alreadySubscribed: ["disabled", "alreadySubscribed"],
3062
+ // The booking was dropped: a tap (after fixing the details) books afresh.
3063
+ bookingNotOwned: ["enabled", "retry"],
2889
3064
  notEnabled: ["disabled", "unavailable"],
2890
3065
  storageUnavailable: ["disabled", "unavailable"],
2891
3066
  unsupportedItem: ["disabled", "unavailable"],
@@ -3225,17 +3400,74 @@ var UNSUPPORTED = { eligible: false, reason: "unsupportedItem" };
3225
3400
  var ORDER_REFUSED = { status: "refused", reason: "orderRefused" };
3226
3401
  var ORDER_CLOSED = { status: "refused", reason: "orderClosed" };
3227
3402
  var GRANTED = { status: "granted" };
3403
+ async function ecomOrderAccess(orderId, bridge) {
3404
+ if (!isNonEmpty3(orderId)) return "unavailable";
3405
+ const answer = await bridge.call("GET", `/ecom/v1/orders/${encodeURIComponent(orderId)}`);
3406
+ if (isRefusal(answer)) return accessRefused(answer);
3407
+ const status = String(bodyObject(answer, "order")?.paymentStatus);
3408
+ if (status === "PAID") return "granted";
3409
+ if (ECOM_PAYMENT_UNDER_WAY.has(status)) return "pending";
3410
+ return ECOM_NO_ACCESS.has(status) ? "none" : "unavailable";
3411
+ }
3412
+ var ECOM_PAYMENT_UNDER_WAY = /* @__PURE__ */ new Set(["NOT_PAID", "PENDING", "PENDING_MERCHANT", "PARTIALLY_PAID"]);
3413
+ var ECOM_NO_ACCESS = /* @__PURE__ */ new Set(["FULLY_REFUNDED", "PARTIALLY_REFUNDED", "CANCELED", "DECLINED", "VOIDED"]);
3228
3414
 
3229
3415
  // ../../stdlib/flows/iap-checkout/src/iap-verticals/online-programs.ts
3230
3416
  var KIND = "onlineProgram";
3231
3417
  var BASE = "/online-programs/participants/v3/join-applications";
3232
- var onlineProgramOrders = {
3418
+ var ONLINE_PROGRAMS_APP = "2936472a-a1ed-4ae5-9f71-614313a9f4e7";
3419
+ var onlineProgramItemPayments = {
3233
3420
  kind: KIND,
3234
3421
  eligibility: (item) => singleUnitOf(KIND, item),
3422
+ itemPayment,
3423
+ readAccess,
3424
+ currentAccess,
3425
+ // wix-iap returns the member's pending Payment for the program again (rpc.impl.js, 1.0.14).
3426
+ reusesPayment: true
3427
+ };
3428
+ function itemPayment(item) {
3429
+ const programId = item.reference.id;
3430
+ return {
3431
+ catalogItem: { catalogItemId: programId, catalogAppId: ONLINE_PROGRAMS_APP },
3432
+ verticalRefOf: ({ joinApplicationId }) => joinApplicationId ? { joinApplicationId, programId } : null
3433
+ };
3434
+ }
3435
+ async function readAccess(verticalRef, bridge) {
3436
+ if (!isNonEmpty3(verticalRef.joinApplicationId)) return "unavailable";
3437
+ const answer = await bridge.call("GET", `${BASE}/${encodeURIComponent(verticalRef.joinApplicationId)}`);
3438
+ if (isRefusal(answer)) return accessRefused(answer);
3439
+ const application = bodyObject(answer, "joinApplication");
3440
+ return application ? accessOf(application) : "unavailable";
3441
+ }
3442
+ async function currentAccess(item, bridge) {
3443
+ const answer = await bridge.call("GET", `${BASE}/current/${encodeURIComponent(item.reference.id)}`);
3444
+ if (isRefusal(answer)) return accessRefused(answer);
3445
+ const application = bodyObject(answer, "joinApplication");
3446
+ if (!application) return "unavailable";
3447
+ const access = accessOf(application);
3448
+ return access !== "granted" && ENDED_STATUS.has(String(application.status)) ? "none" : access;
3449
+ }
3450
+ function accessOf(application) {
3451
+ const paid = application.paymentStatus === "PAYMENT_SUCCESSFUL" || application.paymentStatus === "NO_PAYMENT_REQUIRED";
3452
+ if (application.status === "APPROVED" && paid && isNonEmpty3(application.participantId)) return "granted";
3453
+ if (paid || PAYMENT_UNDER_WAY.has(String(application.paymentStatus))) return "pending";
3454
+ return NO_ACCESS_STATUS.has(String(application.status)) || NO_ACCESS_PAYMENT.has(String(application.paymentStatus)) ? "none" : "unavailable";
3455
+ }
3456
+ var PAYMENT_UNDER_WAY = /* @__PURE__ */ new Set(["PAYMENT_PENDING", "PAYMENT_IN_PROGRESS", "PENDING_OWNER_APPROVAL"]);
3457
+ var NO_ACCESS_STATUS = /* @__PURE__ */ new Set(["CANCELLED", "DECLINED", "SUSPENDED", "INVITED", "APPROVAL_PENDING"]);
3458
+ var ENDED_STATUS = /* @__PURE__ */ new Set(["CANCELLED", "DECLINED", "SUSPENDED"]);
3459
+ var NO_ACCESS_PAYMENT = /* @__PURE__ */ new Set(["PAYMENT_FAILED", "PAYMENT_CANCELED"]);
3460
+
3461
+ // ../../stdlib/flows/iap-checkout/src/iap-verticals/online-programs-orders.ts
3462
+ var KIND2 = "onlineProgram";
3463
+ var BASE2 = "/online-programs/participants/v3/join-applications";
3464
+ var onlineProgramClientOrders = {
3465
+ kind: KIND2,
3466
+ eligibility: (item) => singleUnitOf(KIND2, item),
3235
3467
  openOrder,
3236
3468
  reopenOrder,
3237
- readAccess,
3238
- currentAccess
3469
+ readAccess: readAccess2,
3470
+ currentAccess: currentAccess2
3239
3471
  };
3240
3472
  async function openOrder(item, bridge) {
3241
3473
  const found = await currentApplication(item.reference.id, bridge);
@@ -3250,29 +3482,29 @@ async function reopenOrder(order, bridge) {
3250
3482
  const attempt3 = await orderOf(read2.application, bridge, { mayPrepare: false });
3251
3483
  return attempt3.status === "open" && attempt3.cashierOrderId !== order.cashierOrderId ? ORDER_CLOSED : attempt3;
3252
3484
  }
3253
- async function readAccess(verticalRef, bridge) {
3485
+ async function readAccess2(verticalRef, bridge) {
3254
3486
  if (!isNonEmpty3(verticalRef.joinApplicationId)) return "unavailable";
3255
- const answer = await bridge.call("GET", `${BASE}/${encodeURIComponent(verticalRef.joinApplicationId)}`);
3487
+ const answer = await bridge.call("GET", `${BASE2}/${encodeURIComponent(verticalRef.joinApplicationId)}`);
3256
3488
  if (isRefusal(answer)) return accessRefused(answer);
3257
3489
  const application = bodyObject(answer, "joinApplication");
3258
- return application ? accessOf(application) : "unavailable";
3490
+ return application ? accessOf2(application) : "unavailable";
3259
3491
  }
3260
- async function currentAccess(item, bridge) {
3261
- const answer = await bridge.call("GET", `${BASE}/current/${encodeURIComponent(item.reference.id)}`);
3492
+ async function currentAccess2(item, bridge) {
3493
+ const answer = await bridge.call("GET", `${BASE2}/current/${encodeURIComponent(item.reference.id)}`);
3262
3494
  if (isRefusal(answer)) return accessRefused(answer);
3263
3495
  const application = bodyObject(answer, "joinApplication");
3264
3496
  if (!application) return "unavailable";
3265
- const access = accessOf(application);
3266
- return access !== "granted" && ENDED_STATUS.has(String(application.status)) ? "none" : access;
3497
+ const access = accessOf2(application);
3498
+ return access !== "granted" && ENDED_STATUS2.has(String(application.status)) ? "none" : access;
3267
3499
  }
3268
- function accessOf(application) {
3500
+ function accessOf2(application) {
3269
3501
  const paid = application.paymentStatus === "PAYMENT_SUCCESSFUL" || application.paymentStatus === "NO_PAYMENT_REQUIRED";
3270
3502
  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";
3503
+ if (paid || PAYMENT_UNDER_WAY2.has(String(application.paymentStatus))) return "pending";
3504
+ return NO_ACCESS_STATUS2.has(String(application.status)) || NO_ACCESS_PAYMENT2.has(String(application.paymentStatus)) ? "none" : "unavailable";
3273
3505
  }
3274
3506
  async function orderOf(application, bridge, options) {
3275
- if (accessOf(application) === "granted") return GRANTED;
3507
+ if (accessOf2(application) === "granted") return GRANTED;
3276
3508
  if (application.status === "APPROVAL_PENDING" || application.status === "INVITED") return { status: "refused", reason: "approvalRequired" };
3277
3509
  if (application.status !== "APPROVED" && application.status !== "SUSPENDED") return ORDER_CLOSED;
3278
3510
  const payment = String(application.paymentStatus);
@@ -3290,7 +3522,7 @@ function inProgressOrder(application) {
3290
3522
  }
3291
3523
  async function preparedOrder(application, bridge) {
3292
3524
  const id = String(application.id ?? "");
3293
- const answer = await bridge.call("POST", `${BASE}/${encodeURIComponent(id)}/prepare-payment`, { paymentType: "SINGLE_PAYMENT" });
3525
+ const answer = await bridge.call("POST", `${BASE2}/${encodeURIComponent(id)}/prepare-payment`, { paymentType: "SINGLE_PAYMENT" });
3294
3526
  if (isHttp(answer, 428)) return reopenAfterRace(id, bridge);
3295
3527
  if (isRefusal(answer)) return attemptRefused(answer);
3296
3528
  const prepared = bodyObject(answer, "joinApplication");
@@ -3301,14 +3533,14 @@ async function reopenAfterRace(id, bridge) {
3301
3533
  return "attempt" in read2 ? read2.attempt : orderOf(read2.application, bridge, { mayPrepare: false });
3302
3534
  }
3303
3535
  async function currentApplication(programId, bridge) {
3304
- const answer = await bridge.call("GET", `${BASE}/current/${encodeURIComponent(programId)}`);
3536
+ const answer = await bridge.call("GET", `${BASE2}/current/${encodeURIComponent(programId)}`);
3305
3537
  if (isHttp(answer, 404)) return { application: null };
3306
3538
  if (isRefusal(answer)) return { attempt: attemptRefused(answer) };
3307
3539
  const application = bodyObject(answer, "joinApplication");
3308
3540
  return application ? { application } : { attempt: ORDER_REFUSED };
3309
3541
  }
3310
3542
  async function createdApplication(programId, bridge) {
3311
- const answer = await bridge.call("POST", BASE, { joinApplication: { programId } });
3543
+ const answer = await bridge.call("POST", BASE2, { joinApplication: { programId } });
3312
3544
  if (isHttp(answer, 409)) {
3313
3545
  const existing = await currentApplication(programId, bridge);
3314
3546
  if ("attempt" in existing) return existing;
@@ -3319,7 +3551,7 @@ async function createdApplication(programId, bridge) {
3319
3551
  }
3320
3552
  async function applicationById(id, bridge) {
3321
3553
  if (!isNonEmpty3(id)) return { attempt: ORDER_CLOSED };
3322
- const answer = await bridge.call("GET", `${BASE}/${encodeURIComponent(id)}`);
3554
+ const answer = await bridge.call("GET", `${BASE2}/${encodeURIComponent(id)}`);
3323
3555
  if (isHttp(answer, 404)) return { attempt: ORDER_CLOSED };
3324
3556
  if (isRefusal(answer)) return { attempt: attemptRefused(answer) };
3325
3557
  return applicationIn(answer);
@@ -3329,28 +3561,69 @@ function applicationIn(answer) {
3329
3561
  return application ? { application } : { attempt: ORDER_REFUSED };
3330
3562
  }
3331
3563
  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"]);
3564
+ var PAYMENT_UNDER_WAY2 = /* @__PURE__ */ new Set(["PAYMENT_PENDING", "PAYMENT_IN_PROGRESS", "PENDING_OWNER_APPROVAL"]);
3565
+ var NO_ACCESS_STATUS2 = /* @__PURE__ */ new Set(["CANCELLED", "DECLINED", "SUSPENDED", "INVITED", "APPROVAL_PENDING"]);
3566
+ var ENDED_STATUS2 = /* @__PURE__ */ new Set(["CANCELLED", "DECLINED", "SUSPENDED"]);
3567
+ var NO_ACCESS_PAYMENT2 = /* @__PURE__ */ new Set(["PAYMENT_FAILED", "PAYMENT_CANCELED"]);
3336
3568
 
3337
3569
  // ../../stdlib/flows/iap-checkout/src/iap-verticals/pricing-plans.ts
3338
- var KIND2 = "pricingPlan";
3339
- var CHECKOUT = "/pricing-plans/v2/checkout/orders";
3570
+ var KIND3 = "pricingPlan";
3571
+ var PRICING_PLANS_APP = "1522827f-c56c-a5c9-2ac9-00f9e6ae12d3";
3340
3572
  var MEMBER_ORDERS = "/pricing-plans/v2/member/orders";
3341
- var pricingPlanOrders = {
3342
- kind: KIND2,
3343
- eligibility: (item) => singleUnitOf(KIND2, item),
3573
+ var pricingPlanItemPayments = {
3574
+ kind: KIND3,
3575
+ eligibility: (item) => singleUnitOf(KIND3, item),
3576
+ itemPayment: itemPayment2,
3577
+ readAccess: (verticalRef, bridge) => isNonEmpty3(verticalRef.planId) ? planAccess(verticalRef.planId, bridge) : Promise.resolve("unavailable"),
3578
+ currentAccess: (item, bridge) => planAccess(item.reference.id, bridge)
3579
+ };
3580
+ async function itemPayment2(item, bridge) {
3581
+ const planId = item.reference.id;
3582
+ const read2 = await bridge.call("GET", `/pricing-plans/v3/plans/${encodeURIComponent(planId)}`);
3583
+ if (isRefusal(read2)) return attemptRefused(read2);
3584
+ const variants = bodyObject(read2, "plan")?.pricingVariants;
3585
+ const only = Array.isArray(variants) && variants.length === 1 && isObject7(variants[0]) ? variants[0].id : void 0;
3586
+ if (!isNonEmpty3(only)) return { status: "refused", reason: "unsupportedItem" };
3587
+ return {
3588
+ catalogItem: { catalogItemId: planId, catalogAppId: PRICING_PLANS_APP, options: { type: "PLAN", planOptions: { pricingVariantId: only } } },
3589
+ verticalRefOf: ({ ecomOrderId }) => ecomOrderId ? { ecomOrderId, planId } : null
3590
+ };
3591
+ }
3592
+ async function planAccess(planId, bridge) {
3593
+ let pending = false;
3594
+ const pages = /* @__PURE__ */ new Set();
3595
+ for (let offset = 0; ; offset += 50) {
3596
+ const answer = await bridge.call("GET", `${MEMBER_ORDERS}?orderStatuses=ACTIVE&orderStatuses=PENDING&orderStatuses=DRAFT&limit=50&offset=${offset}`);
3597
+ if (isRefusal(answer)) return accessRefused(answer);
3598
+ const orders = answer.body?.orders;
3599
+ if (!Array.isArray(orders)) return "unavailable";
3600
+ const page = JSON.stringify(orders.map((order) => [order.id, order.planId, order.status]));
3601
+ if (orders.length === 50 && pages.has(page)) return "unavailable";
3602
+ pages.add(page);
3603
+ const selected = orders.filter((order) => order.planId === planId);
3604
+ if (selected.some((order) => order.status === "ACTIVE")) return "granted";
3605
+ pending || (pending = selected.some((order) => order.status === "PENDING" || order.status === "DRAFT"));
3606
+ if (orders.length < 50) return pending ? "pending" : "none";
3607
+ }
3608
+ }
3609
+
3610
+ // ../../stdlib/flows/iap-checkout/src/iap-verticals/pricing-plans-orders.ts
3611
+ var KIND4 = "pricingPlan";
3612
+ var CHECKOUT = "/pricing-plans/v2/checkout/orders";
3613
+ var MEMBER_ORDERS2 = "/pricing-plans/v2/member/orders";
3614
+ var pricingPlanClientOrders = {
3615
+ kind: KIND4,
3616
+ eligibility: (item) => singleUnitOf(KIND4, item),
3344
3617
  openOrder: openOrder2,
3345
3618
  reopenOrder: reopenOrder2,
3346
- readAccess: readAccess2,
3347
- currentAccess: currentAccess2
3619
+ readAccess: readAccess3,
3620
+ currentAccess: currentAccess3
3348
3621
  };
3349
- async function currentAccess2(item, bridge) {
3622
+ async function currentAccess3(item, bridge) {
3350
3623
  let pending = false;
3351
3624
  const pages = /* @__PURE__ */ new Set();
3352
3625
  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}`);
3626
+ const answer = await bridge.call("GET", `${MEMBER_ORDERS2}?orderStatuses=ACTIVE&orderStatuses=PENDING&orderStatuses=DRAFT&limit=50&offset=${offset}`);
3354
3627
  if (isRefusal(answer)) return accessRefused(answer);
3355
3628
  const orders = answer.body?.orders;
3356
3629
  if (!Array.isArray(orders)) return "unavailable";
@@ -3378,14 +3651,14 @@ async function reopenOrder2(order, bridge) {
3378
3651
  const attempt3 = orderOf2(read2.order, order.verticalRef.planId ?? "");
3379
3652
  return attempt3.status === "open" && attempt3.cashierOrderId !== order.cashierOrderId ? ORDER_CLOSED : attempt3;
3380
3653
  }
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)}`);
3654
+ async function readAccess3(verticalRef, bridge) {
3655
+ if (!isNonEmpty3(verticalRef.orderId)) return isNonEmpty3(verticalRef.planId) ? planAccess(verticalRef.planId, bridge) : "unavailable";
3656
+ const answer = await bridge.call("GET", `${MEMBER_ORDERS2}/${encodeURIComponent(verticalRef.orderId)}`);
3384
3657
  if (isRefusal(answer)) return accessRefused(answer);
3385
3658
  const order = bodyObject(answer, "order");
3386
- return order ? accessOf2(order) : "unavailable";
3659
+ return order ? accessOf3(order) : "unavailable";
3387
3660
  }
3388
- function accessOf2(order) {
3661
+ function accessOf3(order) {
3389
3662
  if (order.status === "ACTIVE") return "granted";
3390
3663
  if (order.status === "PENDING") return "pending";
3391
3664
  if (order.status === "DRAFT") return "pending";
@@ -3394,7 +3667,7 @@ function accessOf2(order) {
3394
3667
  var NO_ACCESS = /* @__PURE__ */ new Set(["CANCELED", "ENDED", "PAUSED"]);
3395
3668
  function orderOf2(order, planId) {
3396
3669
  if (!order || !isNonEmpty3(order.id)) return ORDER_REFUSED;
3397
- if (accessOf2(order) === "granted") return GRANTED;
3670
+ if (accessOf3(order) === "granted") return GRANTED;
3398
3671
  if (order.status === "PENDING") return { status: "refused", reason: "paymentInProgress" };
3399
3672
  if (order.status !== "DRAFT") return ORDER_CLOSED;
3400
3673
  if (!isNonEmpty3(order.wixPayOrderId)) return ORDER_REFUSED;
@@ -3402,7 +3675,7 @@ function orderOf2(order, planId) {
3402
3675
  }
3403
3676
  async function memberOrder(orderId, bridge) {
3404
3677
  if (!isNonEmpty3(orderId)) return { attempt: ORDER_CLOSED };
3405
- const answer = await bridge.call("GET", `${MEMBER_ORDERS}/${encodeURIComponent(orderId)}`);
3678
+ const answer = await bridge.call("GET", `${MEMBER_ORDERS2}/${encodeURIComponent(orderId)}`);
3406
3679
  if (isRefusal(answer)) return { attempt: answer.status === "http" && answer.httpStatus === 404 ? ORDER_CLOSED : attemptRefused(answer) };
3407
3680
  return { order: bodyObject(answer, "order") };
3408
3681
  }
@@ -3411,84 +3684,44 @@ function isOneTimeUnlimited(order) {
3411
3684
  return pricing?.singlePaymentUnlimited === true;
3412
3685
  }
3413
3686
 
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
3687
  // ../../stdlib/flows/iap-checkout/src/iap-verticals/attendance.ts
3452
3688
  var BOOKING = "bookingsService";
3453
3689
  var TICKET = "eventsTicket";
3454
3690
  var NOT_ENABLED = { status: "refused", reason: "notEnabled" };
3691
+ var WIX_BOOKINGS_APP = "13d21c63-b5ec-5912-8397-c3a5ddb27a97";
3455
3692
  var CHANGED = { status: "refused", reason: "productChanged" };
3456
- var MINUTE_MS = 6e4;
3693
+ var WIX_EVENTS_APP = "140603ad-af8d-84a5-2c80-a0f60cb47351";
3457
3694
  var RELEASE_MARGIN_MS = 3e5;
3458
- var DEFAULT_RESERVATION_MINUTES = 60;
3459
3695
  var PAYMENT_TAKEN = ["PAID", "PARTIALLY_PAID", "EXEMPT", "REFUNDED"];
3460
3696
  var HAS_OFFSET = /(?:Z|[+-]\d{2}:?\d{2})$/i;
3461
3697
  var LATEST_ZONE_MS = 432e5;
3462
3698
  function attendanceOrdersWith(options) {
3463
- const now = options.now ?? Date.now;
3464
3699
  return {
3465
3700
  bookingOrders: {
3466
3701
  kind: BOOKING,
3467
3702
  repeatable: true,
3468
3703
  eligibility: (item) => eligible(item, BOOKING, options.bookingsEnabled),
3469
- openOrder: (item, bridge, beforeCreate, afterCreate) => options.bookingsEnabled ? openBooking(item, bridge, beforeCreate, afterCreate) : Promise.resolve(NOT_ENABLED),
3704
+ itemPayment: (item, bridge, beforeCreate, afterCreate) => options.bookingsEnabled ? bookingPayment(item, bridge, beforeCreate, afterCreate) : NOT_ENABLED,
3470
3705
  resolveOpening: resolveBookingOpening,
3471
- readAccess: bookingAccess,
3472
- reopenOrder: (order, bridge) => reopen(order, bridge, bookingAccess)
3706
+ readAccess: bookingAccess
3473
3707
  },
3474
3708
  eventTicketOrders: {
3475
3709
  kind: TICKET,
3476
3710
  repeatable: true,
3477
3711
  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)
3712
+ itemPayment: ticketPayment,
3713
+ readAccess: ticketAccess
3481
3714
  }
3482
3715
  };
3483
3716
  }
3484
- var { bookingOrders, eventTicketOrders } = /* @__PURE__ */ attendanceOrdersWith({ bookingsEnabled: BOOKINGS_APPLE_SALES_ENABLED, eventsEnabled: EVENTS_APPLE_SALES_ENABLED });
3717
+ var { bookingOrders: bookingItemPayments, eventTicketOrders: eventTicketItemPayments } = /* @__PURE__ */ attendanceOrdersWith({ bookingsEnabled: BOOKINGS_APPLE_SALES_ENABLED, eventsEnabled: EVENTS_APPLE_SALES_ENABLED });
3485
3718
  function eligible(item, kind, enabled) {
3486
3719
  if (!enabled) return { eligible: false, reason: "notEnabled" };
3487
3720
  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;
3721
+ if (kind === TICKET) return isNonEmpty3(item.attendance.ticket?.eventId) ? { eligible: true } : UNSUPPORTED;
3722
+ return item.attendance.booking ? { eligible: true } : UNSUPPORTED;
3490
3723
  }
3491
- async function openBooking(item, bridge, beforeCreate, afterCreate) {
3724
+ async function bookingPayment(item, bridge, beforeCreate, afterCreate) {
3492
3725
  if (!eligible(item, BOOKING, true).eligible) return notCreated(ORDER_REFUSED);
3493
3726
  const selected = item.attendance.booking;
3494
3727
  if (selected.slot.serviceId !== item.reference.id || !isNonEmpty3(selected.slot.startDate) || !isNonEmpty3(selected.slot.endDate)) return notCreated(ORDER_REFUSED);
@@ -3507,8 +3740,12 @@ async function openBooking(item, bridge, beforeCreate, afterCreate) {
3507
3740
  if (isRefusal(created)) return creationRefused(created);
3508
3741
  const bookingId = bodyObject(created, "booking")?.id;
3509
3742
  if (!isNonEmpty3(bookingId)) return ORDER_REFUSED;
3510
- afterCreate?.({ verticalRef: { bookingId } });
3511
- return bookingCheckout(item, bookingId, bridge);
3743
+ if (afterCreate?.({ verticalRef: { bookingId } }) === false) return { status: "unavailable" };
3744
+ const serviceId = item.reference.id;
3745
+ return {
3746
+ catalogItem: { catalogItemId: serviceId, catalogAppId: WIX_BOOKINGS_APP, options: { bookingId } },
3747
+ verticalRefOf: ({ ecomOrderId }) => ecomOrderId ? { serviceId, bookingId, orderId: ecomOrderId } : null
3748
+ };
3512
3749
  }
3513
3750
  function slotGuard(slot) {
3514
3751
  const verticalRef = {};
@@ -3546,12 +3783,164 @@ function sameSlot(guarded, slot) {
3546
3783
  if (!guarded || !slot) return true;
3547
3784
  return guarded.sessionId === slot.sessionId && Date.parse(guarded.startDate ?? "") === Date.parse(String(slot.startDate));
3548
3785
  }
3786
+ async function bookingAccess(ref, bridge) {
3787
+ if (!ref.bookingId || !ref.orderId) return "unavailable";
3788
+ const order = await bridge.call("GET", `/ecom/v1/orders/${encodeURIComponent(ref.orderId)}`);
3789
+ if (isRefusal(order)) return accessRefused(order);
3790
+ const payment = bodyObject(order, "order")?.paymentStatus;
3791
+ if (payment === "FULLY_REFUNDED" || payment === "PARTIALLY_REFUNDED") return "none";
3792
+ const read2 = await bridge.call("POST", "/bookings/v2/bookings/query", { query: { filter: { id: { $eq: ref.bookingId } } } });
3793
+ if (isRefusal(read2)) return accessRefused(read2);
3794
+ const rows = isObject7(read2.body) ? read2.body.bookings : void 0;
3795
+ const booking = Array.isArray(rows) ? rows.find((b) => isObject7(b) && b.id === ref.bookingId) : void 0;
3796
+ if (!isObject7(booking)) return "unavailable";
3797
+ if (booking.status === "CANCELED" || booking.status === "CANCELLED" || booking.status === "DECLINED") return "none";
3798
+ return payment === "PAID" && booking.status === "CONFIRMED" && booking.paymentStatus === "PAID" ? "granted" : "pending";
3799
+ }
3800
+ async function ticketAccess(ref, bridge) {
3801
+ if (isNonEmpty3(ref.orderId)) return ecomOrderAccess(ref.orderId, bridge);
3802
+ if (!ref.eventId || !ref.orderNumber || !ref.ticketDefinitionId) return "unavailable";
3803
+ const read2 = await bridge.call("GET", `/events/v1/events/${encodeURIComponent(ref.eventId)}/orders/${encodeURIComponent(ref.orderNumber)}?fieldset=DETAILS&fieldset=TICKETS`);
3804
+ if (isRefusal(read2)) return accessRefused(read2);
3805
+ const order = bodyObject(read2, "order");
3806
+ if (order?.status === "CANCELED" || order?.status === "CANCELLED" || order?.status === "REFUNDED") return "none";
3807
+ const issued = Array.isArray(order?.tickets) && order.tickets.some((t) => isObject7(t) && isNonEmpty3(t.ticketNumber) && t.orderStatus === "PAID" && t.ticketDefinitionId === ref.ticketDefinitionId);
3808
+ return order?.status === "PAID" && issued ? "granted" : order ? "pending" : "unavailable";
3809
+ }
3810
+ function ticketPayment(item) {
3811
+ const eventId = item.attendance.ticket.eventId;
3812
+ const ticketDefinitionId = item.reference.id;
3813
+ return {
3814
+ catalogItem: { catalogItemId: ticketDefinitionId, catalogAppId: WIX_EVENTS_APP, options: { eventId } },
3815
+ // eCom checkout: the eCom order. Classic checkout (catalyst-server #24882): the Events order number.
3816
+ verticalRefOf: ({ ecomOrderId, eventsOrderNumber }) => {
3817
+ if (ecomOrderId) return { orderId: ecomOrderId, eventId, ticketDefinitionId };
3818
+ return eventsOrderNumber ? { orderNumber: eventsOrderNumber, eventId, ticketDefinitionId } : null;
3819
+ }
3820
+ };
3821
+ }
3822
+ function samePrice(value, item) {
3823
+ return isObject7(value) && value.currency === item.attendance?.currency && decimal(value.amount) !== null && decimal(value.amount) === decimal(item.attendance?.amount);
3824
+ }
3825
+ function decimal(value) {
3826
+ if (typeof value !== "string" || !/^\d+(?:\.\d+)?$/.test(value)) return null;
3827
+ return value.replace(/^0+(?=\d)/, "").replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
3828
+ }
3829
+ function matchesSlot(value, selected) {
3830
+ 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])));
3831
+ }
3832
+ function creationRefused(refusal) {
3833
+ const attempt3 = attemptRefused(refusal);
3834
+ return refusal.status === "http" && [400, 401, 403, 404, 405, 409, 410, 415, 422].includes(refusal.httpStatus) ? notCreated(attempt3) : attempt3;
3835
+ }
3836
+ function notCreated(attempt3) {
3837
+ return { ...attempt3, noOrderCreated: true };
3838
+ }
3839
+
3840
+ // ../../stdlib/flows/iap-checkout/src/iap-verticals/attendance-orders.ts
3841
+ var BOOKING2 = "bookingsService";
3842
+ var TICKET2 = "eventsTicket";
3843
+ var NOT_ENABLED2 = { status: "refused", reason: "notEnabled" };
3844
+ var CHANGED2 = { status: "refused", reason: "productChanged" };
3845
+ var MINUTE_MS = 6e4;
3846
+ var RELEASE_MARGIN_MS2 = 3e5;
3847
+ var DEFAULT_RESERVATION_MINUTES = 60;
3848
+ var PAYMENT_TAKEN2 = ["PAID", "PARTIALLY_PAID", "EXEMPT", "REFUNDED"];
3849
+ var HAS_OFFSET2 = /(?:Z|[+-]\d{2}:?\d{2})$/i;
3850
+ var LATEST_ZONE_MS2 = 432e5;
3851
+ function attendanceClientOrdersWith(options) {
3852
+ const now = options.now ?? Date.now;
3853
+ return {
3854
+ bookingOrders: {
3855
+ kind: BOOKING2,
3856
+ repeatable: true,
3857
+ eligibility: (item) => eligible2(item, BOOKING2, options.bookingsEnabled),
3858
+ openOrder: (item, bridge, beforeCreate, afterCreate) => options.bookingsEnabled ? openBooking(item, bridge, beforeCreate, afterCreate) : Promise.resolve(NOT_ENABLED2),
3859
+ resolveOpening: resolveBookingOpening2,
3860
+ readAccess: bookingAccess2,
3861
+ reopenOrder: (order, bridge) => reopen(order, bridge, bookingAccess2)
3862
+ },
3863
+ eventTicketOrders: {
3864
+ kind: TICKET2,
3865
+ repeatable: true,
3866
+ eligibility: (item) => eligible2(item, TICKET2, options.eventsEnabled),
3867
+ openOrder: (item, bridge, beforeCreate, afterCreate) => options.eventsEnabled ? openTicket(item, bridge, now, beforeCreate, afterCreate) : Promise.resolve(NOT_ENABLED2),
3868
+ readAccess: ticketAccess2,
3869
+ reopenOrder: (order, bridge) => reopen(order, bridge, ticketAccess2, now)
3870
+ }
3871
+ };
3872
+ }
3873
+ var { bookingOrders: bookingClientOrders, eventTicketOrders: eventTicketClientOrders } = /* @__PURE__ */ attendanceClientOrdersWith({ bookingsEnabled: BOOKINGS_APPLE_SALES_ENABLED, eventsEnabled: EVENTS_APPLE_SALES_ENABLED });
3874
+ function eligible2(item, kind, enabled) {
3875
+ if (!enabled) return { eligible: false, reason: "notEnabled" };
3876
+ if (!singleUnitOf(kind, item).eligible || !isNonEmpty3(item.attemptId) || !item.attendance) return UNSUPPORTED;
3877
+ const selection = kind === BOOKING2 ? item.attendance.booking : item.attendance.ticket;
3878
+ return selection ? { eligible: true } : UNSUPPORTED;
3879
+ }
3880
+ async function openBooking(item, bridge, beforeCreate, afterCreate) {
3881
+ if (!eligible2(item, BOOKING2, true).eligible) return notCreated2(ORDER_REFUSED);
3882
+ const selected = item.attendance.booking;
3883
+ if (selected.slot.serviceId !== item.reference.id || !isNonEmpty3(selected.slot.startDate) || !isNonEmpty3(selected.slot.endDate)) return notCreated2(ORDER_REFUSED);
3884
+ const read2 = await bridge.call("GET", `/bookings/v2/services/${encodeURIComponent(item.reference.id)}`);
3885
+ if (isRefusal(read2)) return notCreated2(attemptRefused(read2));
3886
+ const service = bodyObject(read2, "service");
3887
+ const metadata = bookingAttendanceOf(service);
3888
+ if (classifyForApple(metadata, item.attendance.currency) !== "appleIap" || !samePrice2({ amount: metadata.amount, currency: metadata.currency }, item)) return notCreated2(CHANGED2);
3889
+ if (isObject7(service?.onlineBooking) && service.onlineBooking.requireManualApproval === true) return notCreated2({ status: "refused", reason: "approvalRequired" });
3890
+ 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 } } });
3891
+ if (isRefusal(availability)) return notCreated2(attemptRefused(availability));
3892
+ const entries = isObject7(availability.body) ? availability.body.availabilityEntries : void 0;
3893
+ if (!Array.isArray(entries) || !entries.some((entry) => isObject7(entry) && entry.bookable === true && matchesSlot2(entry.slot, selected.slot))) return notCreated2(CHANGED2);
3894
+ if (beforeCreate && !beforeCreate(slotGuard2(selected.slot))) return notCreated2({ status: "refused", reason: "storageUnavailable" });
3895
+ 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 } : {} } });
3896
+ if (isRefusal(created)) return creationRefused2(created);
3897
+ const bookingId = bodyObject(created, "booking")?.id;
3898
+ if (!isNonEmpty3(bookingId)) return ORDER_REFUSED;
3899
+ if (afterCreate?.({ verticalRef: { bookingId } }) === false) return { status: "unavailable" };
3900
+ return bookingCheckout(item, bookingId, bridge);
3901
+ }
3902
+ function slotGuard2(slot) {
3903
+ const verticalRef = {};
3904
+ for (const key of ["sessionId", "startDate"]) if (isNonEmpty3(slot[key])) verticalRef[key] = slot[key];
3905
+ const ends = latestInstant2(String(slot.endDate));
3906
+ return Number.isFinite(ends) ? { verticalRef, releaseAt: ends + RELEASE_MARGIN_MS2 } : { verticalRef };
3907
+ }
3908
+ function latestInstant2(value) {
3909
+ if (HAS_OFFSET2.test(value)) return Date.parse(value);
3910
+ return Date.parse(`${value}Z`) + LATEST_ZONE_MS2;
3911
+ }
3912
+ async function resolveBookingOpening2(guard, item, bridge, options) {
3913
+ const scope = sameSlot2(guard.verticalRef, item?.attendance?.booking?.slot) ? "held" : "unrelated";
3914
+ const bookingId = guard.verticalRef?.bookingId;
3915
+ if (!bookingId || !options.settled) return scope;
3916
+ const released2 = await releaseBooking2(bookingId, bridge, options.claim);
3917
+ return released2 === "held" || released2 === "unavailable" && scope === "unrelated" ? scope : released2;
3918
+ }
3919
+ async function releaseBooking2(bookingId, bridge, claim) {
3920
+ const read2 = await bridge.call("POST", "/bookings/v2/bookings/query", { query: { filter: { id: { $eq: bookingId } } } });
3921
+ if (isRefusal(read2)) return read2.status === "http" && read2.httpStatus === 404 ? "released" : openingRefused2(read2);
3922
+ const rows = isObject7(read2.body) ? read2.body.bookings : void 0;
3923
+ const booking = Array.isArray(rows) ? rows.find((b) => isObject7(b) && b.id === bookingId) : void 0;
3924
+ if (!isObject7(booking)) return "held";
3925
+ if (["CANCELED", "CANCELLED", "DECLINED"].includes(String(booking.status)) || PAYMENT_TAKEN2.includes(String(booking.paymentStatus))) return "released";
3926
+ if (booking.status !== "CREATED" || !claim()) return "held";
3927
+ const cancelled = await bridge.call("POST", `/bookings/v2/bookings/${encodeURIComponent(bookingId)}/cancel`, { participantNotification: { notifyParticipants: false }, revision: booking.revision });
3928
+ return isRefusal(cancelled) ? openingRefused2(cancelled) : "released";
3929
+ }
3930
+ function openingRefused2(refusal) {
3931
+ if (refusal.status === "sessionChanged") return "sessionChanged";
3932
+ return refusal.status === "unavailable" ? "unavailable" : "held";
3933
+ }
3934
+ function sameSlot2(guarded, slot) {
3935
+ if (!guarded || !slot) return true;
3936
+ return guarded.sessionId === slot.sessionId && Date.parse(guarded.startDate ?? "") === Date.parse(String(slot.startDate));
3937
+ }
3549
3938
  async function bookingCheckout(item, bookingId, bridge) {
3550
3939
  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
3940
  if (isRefusal(checkout)) return attemptRefused(checkout);
3552
3941
  const entity = bodyObject(checkout, "checkout");
3553
3942
  const total = isObject7(entity?.priceSummary) ? entity.priceSummary.total : void 0;
3554
- if (!isObject7(total) || !samePrice({ amount: total.amount, currency: entity?.currency }, item)) return CHANGED;
3943
+ if (!isObject7(total) || !samePrice2({ amount: total.amount, currency: entity?.currency }, item)) return CHANGED2;
3555
3944
  if (!isNonEmpty3(entity?.id)) return ORDER_REFUSED;
3556
3945
  const placed = await bridge.call("POST", `/ecom/v1/checkouts/${encodeURIComponent(entity.id)}/create-order`, {});
3557
3946
  if (isRefusal(placed)) return attemptRefused(placed);
@@ -3559,7 +3948,7 @@ async function bookingCheckout(item, bookingId, bridge) {
3559
3948
  if (!isObject7(body) || !isNonEmpty3(body.orderId) || !isNonEmpty3(body.paymentGatewayOrderId)) return ORDER_REFUSED;
3560
3949
  return { status: "open", cashierOrderId: body.paymentGatewayOrderId, verticalRef: { serviceId: item.reference.id, bookingId, orderId: body.orderId } };
3561
3950
  }
3562
- async function bookingAccess(ref, bridge) {
3951
+ async function bookingAccess2(ref, bridge) {
3563
3952
  if (!ref.bookingId || !ref.orderId) return "unavailable";
3564
3953
  const order = await bridge.call("GET", `/ecom/v1/orders/${encodeURIComponent(ref.orderId)}`);
3565
3954
  if (isRefusal(order)) return accessRefused(order);
@@ -3574,19 +3963,19 @@ async function bookingAccess(ref, bridge) {
3574
3963
  return payment === "PAID" && booking.status === "CONFIRMED" && booking.paymentStatus === "PAID" ? "granted" : "pending";
3575
3964
  }
3576
3965
  async function openTicket(item, bridge, now, beforeCreate, afterCreate) {
3577
- if (!eligible(item, TICKET, true).eligible) return notCreated(ORDER_REFUSED);
3966
+ if (!eligible2(item, TICKET2, true).eligible) return notCreated2(ORDER_REFUSED);
3578
3967
  const selected = item.attendance.ticket;
3579
- if (!isNonEmpty3(selected.eventId)) return notCreated(ORDER_REFUSED);
3968
+ if (!isNonEmpty3(selected.eventId)) return notCreated2(ORDER_REFUSED);
3580
3969
  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));
3970
+ if (isRefusal(read2)) return notCreated2(attemptRefused(read2));
3582
3971
  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));
3972
+ if (isRefusal(available)) return notCreated2(attemptRefused(available));
3584
3973
  const definitions = isObject7(available.body) ? available.body.definitions : void 0;
3585
3974
  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);
3975
+ if (!isObject7(live) || !samePrice2(live.price, item)) return notCreated2(CHANGED2);
3587
3976
  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" });
3977
+ if (live.eventId !== selected.eventId || classifyForApple(availableTicketAttendanceOf(event, live), item.attendance.currency) !== "appleIap") return notCreated2(ORDER_REFUSED);
3978
+ if (beforeCreate && !beforeCreate({ releaseAt: now() + reservationMinutes(event) * MINUTE_MS + RELEASE_MARGIN_MS2 })) return notCreated2({ status: "refused", reason: "storageUnavailable" });
3590
3979
  return reserveTicket(item, bridge, now, afterCreate);
3591
3980
  }
3592
3981
  function reservationMinutes(event) {
@@ -3597,20 +3986,21 @@ function reservationMinutes(event) {
3597
3986
  async function reserveTicket(item, bridge, now, afterCreate) {
3598
3987
  const selected = item.attendance.ticket;
3599
3988
  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);
3989
+ if (isRefusal(held)) return creationRefused2(held);
3601
3990
  const reservation = held.body;
3602
3991
  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;
3992
+ if (afterCreate?.({ verticalRef: { reservationId: reservation.id }, releaseAt: Date.parse(reservation.expires) + RELEASE_MARGIN_MS2 }) === false) return { status: "unavailable" };
3993
+ if (!heldAsSelected(reservation, item)) return CHANGED2;
3605
3994
  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
3995
  if (isRefusal(placed)) return attemptRefused(placed);
3607
3996
  const order = bodyObject(placed, "order");
3608
- if (!samePrice(order?.totalPrice, item)) return CHANGED;
3997
+ if (!samePrice2(order?.totalPrice, item)) return CHANGED2;
3609
3998
  const expires = isObject7(placed.body) && placed.body.expires || reservation.expires;
3610
3999
  if (!future(expires, now) || !isNonEmpty3(order?.snapshotId) || !isNonEmpty3(order?.orderNumber)) return ORDER_CLOSED;
3611
4000
  return { status: "open", cashierOrderId: order.snapshotId, verticalRef: { eventId: selected.eventId, ticketDefinitionId: item.reference.id, reservationId: reservation.id, orderNumber: order.orderNumber, expires: String(expires) } };
3612
4001
  }
3613
- async function ticketAccess(ref, bridge) {
4002
+ async function ticketAccess2(ref, bridge) {
4003
+ if (isNonEmpty3(ref.orderId)) return ecomOrderAccess(ref.orderId, bridge);
3614
4004
  if (!ref.eventId || !ref.orderNumber || !ref.ticketDefinitionId) return "unavailable";
3615
4005
  const read2 = await bridge.call("GET", `/events/v1/events/${encodeURIComponent(ref.eventId)}/orders/${encodeURIComponent(ref.orderNumber)}?fieldset=DETAILS&fieldset=TICKETS`);
3616
4006
  if (isRefusal(read2)) return accessRefused(read2);
@@ -3619,55 +4009,90 @@ async function ticketAccess(ref, bridge) {
3619
4009
  const issued = Array.isArray(order?.tickets) && order.tickets.some((t) => isObject7(t) && isNonEmpty3(t.ticketNumber) && t.orderStatus === "PAID" && t.ticketDefinitionId === ref.ticketDefinitionId);
3620
4010
  return order?.status === "PAID" && issued ? "granted" : order ? "pending" : "unavailable";
3621
4011
  }
3622
- async function reopen(order, bridge, accessOf3, now) {
3623
- const access = await accessOf3(order.verticalRef, bridge);
4012
+ async function reopen(order, bridge, accessOf4, now) {
4013
+ const access = await accessOf4(order.verticalRef, bridge);
3624
4014
  if (access === "granted") return GRANTED;
3625
4015
  if (access === "unavailable" || access === "sessionChanged") return { status: access };
3626
4016
  if (access === "none" || now && !future(order.verticalRef.expires, now)) return ORDER_CLOSED;
3627
4017
  return { status: "open", ...order };
3628
4018
  }
3629
4019
  function heldAsSelected(reservation, item) {
3630
- if (isObject7(reservation.invoice)) return samePrice(reservation.invoice.grandTotal ?? reservation.invoice.total, item);
4020
+ if (isObject7(reservation.invoice)) return samePrice2(reservation.invoice.grandTotal ?? reservation.invoice.total, item);
3631
4021
  const lines = reservation.reservations;
3632
4022
  if (!Array.isArray(lines) || lines.length !== 1 || !isObject7(lines[0]) || lines[0].quantity !== 1) return false;
3633
4023
  const held = lines[0].ticket;
3634
- return isObject7(held) && held.id === item.reference.id && samePrice(held.price, item);
4024
+ return isObject7(held) && held.id === item.reference.id && samePrice2(held.price, item);
3635
4025
  }
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);
4026
+ function samePrice2(value, item) {
4027
+ return isObject7(value) && value.currency === item.attendance?.currency && decimal2(value.amount) !== null && decimal2(value.amount) === decimal2(item.attendance?.amount);
3638
4028
  }
3639
- function decimal(value) {
4029
+ function decimal2(value) {
3640
4030
  if (typeof value !== "string" || !/^\d+(?:\.\d+)?$/.test(value)) return null;
3641
4031
  return value.replace(/^0+(?=\d)/, "").replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
3642
4032
  }
3643
4033
  function future(value, now) {
3644
4034
  return typeof value === "string" && Number.isFinite(Date.parse(value)) && Date.parse(value) > now();
3645
4035
  }
3646
- function matchesSlot(value, selected) {
4036
+ function matchesSlot2(value, selected) {
3647
4037
  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
4038
  }
3649
- function creationRefused(refusal) {
4039
+ function creationRefused2(refusal) {
3650
4040
  const attempt3 = attemptRefused(refusal);
3651
- return refusal.status === "http" && [400, 401, 403, 404, 405, 409, 410, 415, 422].includes(refusal.httpStatus) ? notCreated(attempt3) : attempt3;
4041
+ return refusal.status === "http" && [400, 401, 403, 404, 405, 409, 410, 415, 422].includes(refusal.httpStatus) ? notCreated2(attempt3) : attempt3;
3652
4042
  }
3653
- function notCreated(attempt3) {
4043
+ function notCreated2(attempt3) {
3654
4044
  return { ...attempt3, noOrderCreated: true };
3655
4045
  }
3656
4046
 
4047
+ // ../../stdlib/flows/iap-checkout/src/iap-verticals/stores.ts
4048
+ var KIND5 = "storesProduct";
4049
+ var WIX_STORES_APP = "215238eb-22a5-4c36-9e7b-e7c08025e04e";
4050
+ var storesProductOrders = {
4051
+ kind: KIND5,
4052
+ eligibility,
4053
+ itemPayment: itemPayment3,
4054
+ readAccess: readAccess4
4055
+ };
4056
+ function eligibility(item) {
4057
+ const single = singleUnitOf(KIND5, item);
4058
+ if (!single.eligible) return single;
4059
+ const catalog = item.catalogReference;
4060
+ const variant = catalog?.options && Object.keys(catalog.options).length > 0;
4061
+ return catalog && !variant && isNonEmpty3(catalog.appId) && catalog.appId.toLowerCase() === WIX_STORES_APP && catalog.catalogItemId === item.reference.id ? single : UNSUPPORTED;
4062
+ }
4063
+ function itemPayment3(item) {
4064
+ return { catalogItem: { catalogItemId: item.reference.id, catalogAppId: WIX_STORES_APP }, verticalRefOf: ({ ecomOrderId }) => ecomOrderId ? { orderId: ecomOrderId } : null };
4065
+ }
4066
+ function classifyCart(lines) {
4067
+ if (lines.length === 0 || lines.some((line) => line.route === "resolving" || line.route === "unavailable")) return "blocked";
4068
+ const apple = lines.filter((line) => line.route === "appleIap");
4069
+ if (apple.length === 0) return "regular";
4070
+ return lines.length === 1 && apple[0].quantity === 1 ? "appleIap" : "mixedRefused";
4071
+ }
4072
+ function readAccess4(verticalRef, bridge) {
4073
+ return ecomOrderAccess(verticalRef.orderId, bridge);
4074
+ }
4075
+
3657
4076
  // ../../stdlib/flows/iap-checkout/src/iap-verticals/videos.ts
3658
- var KIND4 = "wixVideo";
3659
- var NOT_ENABLED2 = { status: "refused", reason: "notEnabled" };
4077
+ var KIND6 = "wixVideo";
4078
+ var NOT_ENABLED3 = { status: "refused", reason: "notEnabled" };
3660
4079
  var NO_ORDER_STEP = { status: "refused", reason: "notConfigured" };
3661
4080
  function videoOrdersWith(options) {
3662
4081
  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,
4082
+ kind: KIND6,
4083
+ eligibility: (item) => options.enabled ? singleUnitOf(KIND6, item) : { eligible: false, reason: "notEnabled" },
4084
+ openOrder: async () => options.enabled ? NO_ORDER_STEP : NOT_ENABLED3,
3666
4085
  reopenOrder: async () => ORDER_CLOSED,
3667
4086
  readAccess: async () => "unavailable"
3668
4087
  };
3669
4088
  }
3670
4089
  var wixVideoOrders = /* @__PURE__ */ videoOrdersWith({ enabled: VIDEOS_APPLE_SALES_ENABLED });
4090
+
4091
+ // ../../stdlib/flows/iap-checkout/src/iap-verticals/index.ts
4092
+ var onlineProgramOrders = ONLINE_PROGRAM_ITEM_PAYMENT_ENABLED ? onlineProgramItemPayments : onlineProgramClientOrders;
4093
+ var pricingPlanOrders = PRICING_PLAN_ITEM_PAYMENT_ENABLED ? pricingPlanItemPayments : pricingPlanClientOrders;
4094
+ var bookingOrders = BOOKINGS_ITEM_PAYMENT_ENABLED ? bookingItemPayments : bookingClientOrders;
4095
+ var eventTicketOrders = EVENTS_ITEM_PAYMENT_ENABLED ? eventTicketItemPayments : eventTicketClientOrders;
3671
4096
  export {
3672
4097
  bookingOrders,
3673
4098
  classifyCart,