@curless/hotel-storefront 0.84.1 → 0.84.3

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 (95) hide show
  1. package/dist/account/addon-pages.d.ts.map +1 -1
  2. package/dist/account/addon-pages.js +23 -7
  3. package/dist/account/addon-pages.js.map +1 -1
  4. package/dist/account/cancel-pages.d.ts +118 -0
  5. package/dist/account/cancel-pages.d.ts.map +1 -0
  6. package/dist/account/cancel-pages.js +313 -0
  7. package/dist/account/cancel-pages.js.map +1 -0
  8. package/dist/account/index.d.ts +40 -1
  9. package/dist/account/index.d.ts.map +1 -1
  10. package/dist/account/index.js +376 -33
  11. package/dist/account/index.js.map +1 -1
  12. package/dist/account/pages.d.ts +31 -3
  13. package/dist/account/pages.d.ts.map +1 -1
  14. package/dist/account/pages.js +98 -19
  15. package/dist/account/pages.js.map +1 -1
  16. package/dist/account/requests.d.ts +11 -1
  17. package/dist/account/requests.d.ts.map +1 -1
  18. package/dist/account/requests.js +2 -1
  19. package/dist/account/requests.js.map +1 -1
  20. package/dist/card.generated.d.ts +1 -1
  21. package/dist/card.generated.js +2 -2
  22. package/dist/card.generated.js.map +1 -1
  23. package/dist/config.d.ts +12 -5
  24. package/dist/config.d.ts.map +1 -1
  25. package/dist/config.js.map +1 -1
  26. package/dist/otaless/addons-answers.d.ts +2 -0
  27. package/dist/otaless/addons-answers.d.ts.map +1 -1
  28. package/dist/otaless/addons-answers.js +46 -12
  29. package/dist/otaless/addons-answers.js.map +1 -1
  30. package/dist/otaless/addons.d.ts +34 -5
  31. package/dist/otaless/addons.d.ts.map +1 -1
  32. package/dist/otaless/addons.js +150 -47
  33. package/dist/otaless/addons.js.map +1 -1
  34. package/dist/otaless/backend.d.ts.map +1 -1
  35. package/dist/otaless/backend.js +55 -1
  36. package/dist/otaless/backend.js.map +1 -1
  37. package/dist/otaless/booking.d.ts +39 -4
  38. package/dist/otaless/booking.d.ts.map +1 -1
  39. package/dist/otaless/booking.js +406 -61
  40. package/dist/otaless/booking.js.map +1 -1
  41. package/dist/otaless/client.d.ts.map +1 -1
  42. package/dist/otaless/client.js +3 -1
  43. package/dist/otaless/client.js.map +1 -1
  44. package/dist/otaless/fake.d.ts +14 -0
  45. package/dist/otaless/fake.d.ts.map +1 -1
  46. package/dist/otaless/fake.js +18 -8
  47. package/dist/otaless/fake.js.map +1 -1
  48. package/dist/otaless/make.d.ts.map +1 -1
  49. package/dist/otaless/make.js +12 -3
  50. package/dist/otaless/make.js.map +1 -1
  51. package/dist/otaless/shop-answers.d.ts +57 -1
  52. package/dist/otaless/shop-answers.d.ts.map +1 -1
  53. package/dist/otaless/shop-answers.js +115 -12
  54. package/dist/otaless/shop-answers.js.map +1 -1
  55. package/dist/otaless/shop-client.d.ts +7 -0
  56. package/dist/otaless/shop-client.d.ts.map +1 -1
  57. package/dist/otaless/shop-client.js +5 -0
  58. package/dist/otaless/shop-client.js.map +1 -1
  59. package/dist/otaless/shop-fake.d.ts +8 -0
  60. package/dist/otaless/shop-fake.d.ts.map +1 -1
  61. package/dist/otaless/shop-fake.js +5 -3
  62. package/dist/otaless/shop-fake.js.map +1 -1
  63. package/dist/otaless/shop-ids.d.ts +26 -0
  64. package/dist/otaless/shop-ids.d.ts.map +1 -0
  65. package/dist/otaless/shop-ids.js +49 -0
  66. package/dist/otaless/shop-ids.js.map +1 -0
  67. package/dist/otaless/shop-record.d.ts.map +1 -1
  68. package/dist/otaless/shop-record.js +27 -9
  69. package/dist/otaless/shop-record.js.map +1 -1
  70. package/dist/otaless/shop-service.d.ts +85 -21
  71. package/dist/otaless/shop-service.d.ts.map +1 -1
  72. package/dist/otaless/shop-service.js +159 -21
  73. package/dist/otaless/shop-service.js.map +1 -1
  74. package/dist/otaless/shop.d.ts +33 -7
  75. package/dist/otaless/shop.d.ts.map +1 -1
  76. package/dist/otaless/shop.js +76 -27
  77. package/dist/otaless/shop.js.map +1 -1
  78. package/dist/otaless/wallet.d.ts.map +1 -1
  79. package/dist/otaless/wallet.js +27 -6
  80. package/dist/otaless/wallet.js.map +1 -1
  81. package/dist/server.d.ts +1 -1
  82. package/dist/server.d.ts.map +1 -1
  83. package/dist/server.js +77 -6
  84. package/dist/server.js.map +1 -1
  85. package/dist/tools.d.ts +33 -19
  86. package/dist/tools.d.ts.map +1 -1
  87. package/dist/tools.js +368 -27
  88. package/dist/tools.js.map +1 -1
  89. package/dist/trip-ids.d.ts +30 -1
  90. package/dist/trip-ids.d.ts.map +1 -1
  91. package/dist/trip-ids.js +57 -2
  92. package/dist/trip-ids.js.map +1 -1
  93. package/dist/types.d.ts +20 -0
  94. package/dist/types.d.ts.map +1 -1
  95. package/package.json +1 -1
@@ -633,9 +633,9 @@ export const CANCELLED_STATUSES = new Set([
633
633
  ]);
634
634
  /**
635
635
  * What a cancellation's answer says: `done` - `success` not false and a status
636
- * in `CANCELLED_STATUSES`; `refused` - `success` false, or another status;
637
- * `unknown` - no status said (an empty answer): nothing is changed on our side,
638
- * and the guest is told so.
636
+ * in `CANCELLED_STATUSES`; `refused` - `success` false, a status that stands or one of
637
+ * failing; `unknown` - no status said (an empty answer), or one not known here (0.84.2):
638
+ * nothing is changed on our side, and the guest is told so.
639
639
  */
640
640
  export const cancelOutcome = (out) => {
641
641
  if (out?.success === false)
@@ -647,7 +647,15 @@ export const cancelOutcome = (out) => {
647
647
  return 'unknown';
648
648
  // ⚠️ A PAID ORDER CANCELLED MAY BE ANSWERED BY ITS REFUND (0.74.2): "REFUNDED" from 9 is
649
649
  // a cancellation done and its money on the way back - never "it stands as it was".
650
- return CANCELLED_STATUSES.has(s) || REFUND_STATUSES.has(s) ? 'done' : 'refused';
650
+ if (CANCELLED_STATUSES.has(s) || REFUND_STATUSES.has(s))
651
+ return 'done';
652
+ // ⚠️ "NOT CANCELLED" ONLY WHERE IT SAYS SO (0.84.2, the 11-25 code audit's P2-2): a status that
653
+ // stands (`LIVE_ROW_STATUSES`) or a word of failing. Any other - PROCESSING, CANCEL_PENDING - is
654
+ // not known: never "it stands as it was".
655
+ if (LIVE_ROW_STATUSES.has(s) ||
656
+ /FAIL|REJECT|DENIED|DECLINED|REFUSED|ERROR|INVALID|NOT_ALLOWED|CANCELL?ABLE/.test(s))
657
+ return 'refused';
658
+ return 'unknown';
651
659
  };
652
660
  /** 9's (and 12's) statuses that say a paid order's money is going back or is back. */
653
661
  export const REFUND_STATUSES = new Set([
@@ -704,10 +712,29 @@ export const refundOutcome = (out) => {
704
712
  return 'not-sent';
705
713
  if (s === 'REFUNDED')
706
714
  return 'refunded';
707
- if (!s && out?.success !== true)
708
- return 'unsure';
709
- return 'sent';
715
+ // ⚠️ AN ALLOW-LIST (0.84.2, the 11-25 code audit's P1-3): a refund is taken only where its
716
+ // status says so - `REFUND_STATUSES` or a word of taking (`REFUND_TAKEN`); `success: true`
717
+ // with no status at all is its taking too. Any other status - NOT_ALLOWED, NON_REFUNDABLE,
718
+ // UNPAID, EXPIRED - is not known, never "submitted" (a person checks; nothing sent again).
719
+ if (REFUND_STATUSES.has(s) || REFUND_TAKEN.has(s))
720
+ return 'sent';
721
+ if (!s && out?.success === true)
722
+ return 'sent';
723
+ return 'unsure';
710
724
  };
725
+ /** 9.1's words of a refund taken, beside `REFUND_STATUSES` (0.84.2). */
726
+ const REFUND_TAKEN = new Set([
727
+ 'SUCCESS',
728
+ 'SUCCEEDED',
729
+ 'ACCEPTED',
730
+ 'SUBMITTED',
731
+ 'REQUESTED',
732
+ 'PROCESSING',
733
+ // Not PENDING (总线程's review of 0.84.2): an unpaid order's own status too (Atour's 8) - not known.
734
+ 'REFUND_SUCCESS',
735
+ 'REFUND_SUCCEEDED',
736
+ 'REFUND_ACCEPTED',
737
+ ]);
711
738
  /**
712
739
  * 9 refusing a PAID order with `paid_use_refund` (0.80.1, 11-20 - robin's video: AT-F2519E, paid
713
740
  * and confirmed, answered HTTP 500 "paid_use_refund", nothing changed at the backend): it cancels a
@@ -767,6 +794,20 @@ const unanswered = (err) => err instanceof OtalessError &&
767
794
  !(err instanceof OtalessBusy) &&
768
795
  err.backendCode === undefined &&
769
796
  !(err.status !== undefined && err.status >= 400 && err.status < 500);
797
+ /**
798
+ * A server error from the backend (0.84.2, the 11-25 code audit's P1-1): `code` 500-599 in its
799
+ * answer, or HTTP 500-599 with one of its answers. ⚠️ NOT A REFUSAL: it may come after the group
800
+ * did what was asked (8 has answered 500 with its order made - questions #96). Never a limit of
801
+ * ours, never the sign-in (401) or a group's session (4012).
802
+ */
803
+ const serverFault = (err) => err instanceof OtalessError &&
804
+ !(err instanceof OtalessBusy) &&
805
+ ((typeof err.backendCode === 'number' && err.backendCode >= 500 && err.backendCode < 600) ||
806
+ (err.backendCode === undefined &&
807
+ typeof err.status === 'number' &&
808
+ err.status >= 500 &&
809
+ err.status < 600));
810
+ const errMsg = (err) => err instanceof OtalessError ? err.answer?.msg : undefined;
770
811
  export const createOtalessBookings = (deps) => {
771
812
  const { client, now, log } = deps;
772
813
  const iso = (t = now()) => new Date(t).toISOString();
@@ -810,6 +851,8 @@ export const createOtalessBookings = (deps) => {
810
851
  cancelByRefundRefused: 0,
811
852
  /** …or not answered: whether it was taken is not known - a person checks (0.80.1). */
812
853
  cancelByRefundUnsure: 0,
854
+ /** 8 answered PAID / CONFIRMED (no page) for an order not as chosen - kept, a person's (0.84.2). */
855
+ settledAt8Off: 0,
813
856
  };
814
857
  const keyOf = (who) => who.tripOwner ?? who.sessionId;
815
858
  const accountFor = (who, group) => {
@@ -1068,14 +1111,17 @@ export const createOtalessBookings = (deps) => {
1068
1111
  /** One of the amounts the order asked: 13's, the quote's, or the quote's USD. */
1069
1112
  const asked = (m, r) => same(m, r.charged) || same(m, r.quoted) || same(m, r.quotedUsd);
1070
1113
  /** What was paid - as the group reported it, else what the order asked (总线程's re-review of 0.63.1, 3). */
1071
- const paidOf = (r) => r.paidAmount ?? r.charged ?? r.quoted;
1114
+ // A charge of nothing (8's 0) is no amount (0.84.2, 总线程's review, 3): the quote stands in for it.
1115
+ const paidOf = (r) => r.paidAmount ?? (r.charged && r.charged.minor > 0 ? r.charged : r.quoted);
1072
1116
  /**
1073
1117
  * Shown as a person's (`unconfirmed`, nothing of its money said, no link): an order with a
1074
1118
  * person that was not paid - one we could not cancel at once (`release`). ⚠️ NOT ONE THAT WAS
1075
1119
  * PAID (0.75.1, the review's P1-b): paid at another amount (`paid-amount`), it is paid - said
1076
1120
  * so at what was paid, and cancelled with its refund; the difference is the person's.
1077
1121
  */
1078
- const withPerson = (r) => !!r.needsPerson && !r.paid;
1122
+ // ⚠️ NOT ONE CONFIRMED WITH ITS PAYMENT NOT KNOWN (0.84.2): it is confirmed - said so, with what
1123
+ // differs (`differs`) - and its payment is still looked at.
1124
+ const withPerson = (r) => !!r.needsPerson && !r.paid && r.needsPerson !== 'differs';
1079
1125
  /**
1080
1126
  * Until when an order waiting for its payment may still be paid: 13's time,
1081
1127
  * else `ASSUMED_HOLD_MS` after it was made or last said waiting (总线程's
@@ -1103,8 +1149,22 @@ export const createOtalessBookings = (deps) => {
1103
1149
  // Asked of the group, which reviews it before it goes back (9.1's own document).
1104
1150
  ...(r.refund.status !== 'refunded' ? { groupReviews: true } : {}),
1105
1151
  };
1152
+ // ⚠️ WHAT IS PAID OR ASKED, AND THE PRICE SHOWN WHERE THEY DIFFER (0.84.2, P0-2 / P1-4 of the
1153
+ // 11-25 code audit): the group's USD figure, or 8's own amount (`skipPriceChecks`), is said
1154
+ // beside the price the guest agreed to - never one number standing for the other.
1155
+ const differs = !same(amount, r.quoted);
1156
+ // ⚠️ PAID AT ANOTHER AMOUNT (`paid-amount`) READS AS ANY PAID ORDER (0.75.1): the price
1157
+ // shown is said beside it, and nothing of a person checking it.
1158
+ const quotedAs = differs ? { quotedAs: r.quoted } : {};
1106
1159
  if (r.paid)
1107
- return { method: 'card', amount, status: 'paid' };
1160
+ return {
1161
+ method: 'card',
1162
+ amount,
1163
+ status: 'paid',
1164
+ ...(r.paidWhenBooked ? { chargedWhenBooked: true } : {}),
1165
+ ...(r.amountUnsaid ? { amountUnsaid: true } : {}),
1166
+ ...quotedAs,
1167
+ };
1108
1168
  if (r.status === 'awaiting-payment') {
1109
1169
  // ⚠️ NO LINK PAST ITS TIME: a page that cannot be paid any more is not handed on -
1110
1170
  // nor one held back for terms not agreed to yet (总线程 11-11, D).
@@ -1115,10 +1175,14 @@ export const createOtalessBookings = (deps) => {
1115
1175
  status: 'awaiting',
1116
1176
  ...(url ? { url } : {}),
1117
1177
  ...(r.payBy ? { payBy: r.payBy } : {}),
1178
+ ...quotedAs,
1118
1179
  };
1119
1180
  }
1120
- if (r.status === 'expired' || (r.status === 'cancelled' && r.payHost))
1181
+ if (r.status === 'expired')
1121
1182
  return { method: 'card', amount, status: 'lapsed' };
1183
+ // ⚠️ CANCELLED BEFORE IT WAS PAID IS NOT "NOT PAID IN TIME" (0.84.2, the UI review's P2-2).
1184
+ if (r.status === 'cancelled' && r.payHost && !r.paymentUnknown)
1185
+ return { method: 'card', amount, status: 'lapsed', cancelledUnpaid: true };
1122
1186
  return undefined;
1123
1187
  };
1124
1188
  /**
@@ -1175,6 +1239,10 @@ export const createOtalessBookings = (deps) => {
1175
1239
  // Beside the type, for the words (0.63.2): why it is not known - and (11-11,
1176
1240
  // D) an order whose payment page waits for terms the group answered it with.
1177
1241
  return Object.assign(booking, r.unverifiable ? { unverifiable: true } : {},
1242
+ // 0.84.2 (P0-1): confirmed with no payment page - whether it was paid is not known.
1243
+ r.paymentUnknown && !r.paid ? { paymentUnknown: true } : {},
1244
+ // 0.84.2 (总线程's re-review): what is not as the guest chose - said, a person checking it.
1245
+ r.differs?.length && !ENDED.has(r.status) ? { differs: [...r.differs] } : {},
1178
1246
  // With status `unconfirmed` only, as the type has it: a paid one is said as paid (0.75.1).
1179
1247
  withPerson(r) && r.needsPerson ? { needsPerson: r.needsPerson } : {}, r.held?.step === 'confirm'
1180
1248
  ? { confirmAsked: true, termsUntil: r.held.until }
@@ -1256,6 +1324,7 @@ export const createOtalessBookings = (deps) => {
1256
1324
  ...(p.bookingId ? { bookingId: p.bookingId } : {}),
1257
1325
  ...(p.confirmationCode ? { confirmationCode: p.confirmationCode } : {}),
1258
1326
  until: p.until,
1327
+ ...(p.payAs ? { payAs: p.payAs } : {}),
1259
1328
  });
1260
1329
  /** Keeps terms for the guest - a few per account, a bounded number in all. */
1261
1330
  const remember = (p) => {
@@ -1281,6 +1350,27 @@ export const createOtalessBookings = (deps) => {
1281
1350
  * group's `/site` did not say whether it asks for terms of its own - agreed, 8 is sent with
1282
1351
  * `termsRequired: true` (0.72.1).
1283
1352
  */
1353
+ /**
1354
+ * The quote's own USD figure, where the price shown is in another currency (P1-4): the one the
1355
+ * guest was shown under this sign-in, its price that very price - else none.
1356
+ */
1357
+ const withPayAs = (a) => {
1358
+ const m = payAsOf(a);
1359
+ return m ? { payAs: m } : {};
1360
+ };
1361
+ const payAsOf = (a) => {
1362
+ const w = deps.recentQuote?.(a.hotel, a.roomId, a.stay, a.rooms, a.acct.token);
1363
+ if (!w)
1364
+ return undefined;
1365
+ const p = priceTaken(w);
1366
+ const orig = moneyOf(p.amount, p.currency);
1367
+ if (!orig || !same(orig, a.total))
1368
+ return undefined;
1369
+ const usd = text(w.settlementCurrency)?.toUpperCase() === 'USD'
1370
+ ? moneyOf(w.settlementAmount, 'USD')
1371
+ : undefined;
1372
+ return usd && usd.minor > 0 && usd.currency !== a.total.currency ? usd : undefined;
1373
+ };
1284
1374
  const termsBefore = (a, askGroup = false) => remember({
1285
1375
  ref: randomBytes(18).toString('base64url'),
1286
1376
  group: a.group,
@@ -1292,6 +1382,7 @@ export const createOtalessBookings = (deps) => {
1292
1382
  stay: a.stay,
1293
1383
  rooms: a.rooms,
1294
1384
  total: a.total,
1385
+ ...withPayAs(a),
1295
1386
  text: a.agreed,
1296
1387
  source: a.agreed ? 'room' : 'none',
1297
1388
  more: true,
@@ -1413,6 +1504,7 @@ export const createOtalessBookings = (deps) => {
1413
1504
  stay: a.stay,
1414
1505
  rooms: a.rooms,
1415
1506
  total: a.total,
1507
+ ...withPayAs(a),
1416
1508
  text: shown,
1417
1509
  source: 'booking',
1418
1510
  more: true,
@@ -1458,6 +1550,10 @@ export const createOtalessBookings = (deps) => {
1458
1550
  stay: r.stay,
1459
1551
  rooms: r.rooms,
1460
1552
  total: priceOf(r),
1553
+ // The order made: what its page asks, where it is in another currency (P1-4).
1554
+ ...(r.charged && r.charged.minor > 0 && r.charged.currency !== priceOf(r).currency
1555
+ ? { payAs: r.charged }
1556
+ : {}),
1461
1557
  text: shown,
1462
1558
  source: 'booking',
1463
1559
  more: true,
@@ -1676,6 +1772,37 @@ export const createOtalessBookings = (deps) => {
1676
1772
  .slice(0, 10)
1677
1773
  .map((id) => forTheLog(id))
1678
1774
  .join(', ')}${older.length > 10 ? ', …' : ''}) - each was logged when it happened, as one for a person; once a person has taken one up, write refund.handledAt on it in otaless-orders.json (service stopped)`);
1775
+ // ⚠️ KEPT FROM BEFORE 0.84.2, CONFIRMED BY 8 WITH NO PAYMENT PAGE AND TAKEN AS NOT PAID (总线程's
1776
+ // review of 0.84.2, 5 - JI-A60303, paid from the JI wallet): `confirmed` with no page ever and not
1777
+ // seen paid is only ever such an order - its payment is not known: looked at again by 15 and 12,
1778
+ // and cancelled with its refund once seen paid. Said once, here.
1779
+ for (const r of [...orders.values()]) {
1780
+ if (r.status !== 'confirmed' || r.paid || r.paymentUnknown || r.payHost)
1781
+ continue;
1782
+ if (r.id.startsWith('pending:') || r.released)
1783
+ continue;
1784
+ r.paymentUnknown = true;
1785
+ save();
1786
+ log(`[otaless] ${forTheLog(r.id)} at ${r.group} was confirmed by 8 with no payment page before 0.84.2 and kept as not paid - whether it was paid (a wallet at the group, questions #102) is looked at again`);
1787
+ }
1788
+ // ⚠️ CANCELLED, ITS PAYMENT NEVER KNOWN (0.84.2, 总线程's review): said again when the service starts,
1789
+ // as a refund not known is - for `REFUND_SAID_DAYS`, then counted in one line.
1790
+ const olderUnknown = [];
1791
+ for (const r of [...orders.values()]) {
1792
+ if (!r.paymentUnknown || r.paid || !ENDED.has(r.status))
1793
+ continue;
1794
+ const at = Date.parse(r.cancelledAt ?? r.createdAt);
1795
+ if (Number.isFinite(at) && at < saidSince) {
1796
+ olderUnknown.push(r.id);
1797
+ continue;
1798
+ }
1799
+ log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${r.group} is cancelled; it was confirmed with no payment page and whether it was paid is still not known - if it was, its refund is to be asked of the group`);
1800
+ }
1801
+ if (olderUnknown.length)
1802
+ log(`[otaless] ${olderUnknown.length} cancelled more than ${REFUND_SAID_DAYS} days ago with their payment never known (${olderUnknown
1803
+ .slice(0, 10)
1804
+ .map((id) => forTheLog(id))
1805
+ .join(', ')}${olderUnknown.length > 10 ? ', …' : ''}) - each was logged when it happened, as one for a person`);
1679
1806
  // ⚠️ A PAID ORDER CANCELLED THROUGH ITS REFUND, NOT KNOWN (0.80.1): `asking` kept is a 9.1 a
1680
1807
  // restart cut short - nobody knows whether it was sent: `unsure`, as one not answered. Each is
1681
1808
  // said line by line for `REFUND_SAID_DAYS`, then counted in one line, as the refunds above.
@@ -1860,6 +1987,98 @@ export const createOtalessBookings = (deps) => {
1860
1987
  return termsFrom8(a, w);
1861
1988
  return settleOrder(a, w, pairs);
1862
1989
  };
1990
+ /**
1991
+ * ⚠️ 8 ANSWERED `PAID` - OR `CONFIRMED` WITH NO PAYMENT PAGE (0.84.2, the 11-25 code audit's P0-1;
1992
+ * 总线程's review of 0.84.2, 2 and 3): the backend may have taken the money when it made the order -
1993
+ * from a wallet at the group (questions #102). `paid`: paid, at what 8 said (`paidAmount`) - its
1994
+ * page, if it sent one, never handed on (it would be paid twice); no amount said, said so
1995
+ * (`amountUnsaid`), never ¥0 and never the quote as what was charged. `unknown`: whether it was
1996
+ * paid is not known (`paymentUnknown`) - asked of 15 at once, then 15 and 12. ⚠️ NEITHER IS
1997
+ * CANCELLED AT ONCE: 9 cancels no paid order (`paid_use_refund`), and "cancelled at once, nothing
1998
+ * charged" could be untrue. What is not as the guest chose - the amount, the guests, the terms -
1999
+ * is a person's (NEEDS A PERSON on the log; a paid one `needsPerson: 'paid-amount'`, the stay held
2000
+ * back), and the booking says what is known of the money.
2001
+ */
2002
+ const settledAt8 = async (a, r, w, pairs, charged, kind) => {
2003
+ if (kind === 'paid') {
2004
+ r.paid = true;
2005
+ r.paidWhenBooked = true;
2006
+ if (charged)
2007
+ r.paidAmount = charged;
2008
+ else
2009
+ r.amountUnsaid = true;
2010
+ }
2011
+ else
2012
+ r.paymentUnknown = true;
2013
+ const off = [];
2014
+ // ⚠️ WHAT IS NOT AS THE GUEST CHOSE, FOR THE GUEST (总线程's re-review of 0.84.2): said on the
2015
+ // booking - never a plain "confirmed" over two guests booked as one, or other terms.
2016
+ const differs = new Set();
2017
+ const matches = !!charged && (same(charged, pairs.orig) || same(charged, pairs.usd));
2018
+ // Dev testing only (`skipPriceChecks`): 8's own amount is the booking's, as for any order.
2019
+ if (charged && !matches && deps.skipPriceChecks?.has(a.group) === true)
2020
+ r.atGroupAmount = true;
2021
+ else if (!matches) {
2022
+ differs.add(charged ? 'amount' : 'amount-unsaid');
2023
+ off.push(charged
2024
+ ? `${kind === 'paid' ? 'charged' : 'asked'} ${amountForLog(charged)}, quoted ${amountForLog(pairs.orig)}${pairs.usd ? ` / ${amountForLog(pairs.usd)}` : ''}`
2025
+ : 'no amount said');
2026
+ }
2027
+ const adults = num(w.adultCount ?? w.adults);
2028
+ if (adults !== undefined && adults !== a.stay.guests) {
2029
+ differs.add('guests');
2030
+ off.push(`for ${adults} adult(s), quoted for ${a.stay.guests}`);
2031
+ }
2032
+ const said = text(w.cancelPolicy ?? undefined);
2033
+ // The terms the guest agreed to stay the booking's; others the group sent are the person's.
2034
+ if (said && said.length <= TERMS_MAX && !asksTermsOnly(a) && agreedTo(said, a))
2035
+ r.terms = said;
2036
+ else if (said) {
2037
+ differs.add('terms');
2038
+ off.push('with other terms than the guest agreed to');
2039
+ }
2040
+ if (asksTermsOnly(a)) {
2041
+ differs.add('terms');
2042
+ off.push('when only its terms were asked for, none agreed yet');
2043
+ }
2044
+ const step = /TERMS/.test(String(w.status ?? '').toUpperCase())
2045
+ ? 'terms'
2046
+ : stepAsked(String(w.status ?? ''));
2047
+ if (step) {
2048
+ differs.add('step');
2049
+ off.push(`asking for a step (${step})`);
2050
+ }
2051
+ const page = text(w.checkoutUrl ?? undefined);
2052
+ if (kind === 'paid' && page)
2053
+ off.push('with a payment page too, not handed on');
2054
+ if (off.length) {
2055
+ // Both kinds a person's (总线程's re-review): `paid-amount` - paid, the difference to settle;
2056
+ // `differs` - its payment not known, the order not as chosen (its payment still looked at).
2057
+ r.needsPerson = kind === 'paid' ? 'paid-amount' : 'differs';
2058
+ r.needsPersonAt = iso();
2059
+ if (differs.size)
2060
+ r.differs = [...differs];
2061
+ counts.settledAt8Off += 1;
2062
+ log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${a.group} was ${kind === 'paid' ? 'paid when 8 made it (PAID' : 'confirmed by 8 with no payment page, whether paid not known (CONFIRMED'}${kind === 'paid' && !page ? ', no payment page' : ''} - questions #102) ${off.join('; ')} - kept${kind === 'paid' ? ' as paid' : ''}, nothing cancelled; settle it with ${a.group}`);
2063
+ }
2064
+ else
2065
+ log(`[otaless] booking ${forTheLog(r.id)} at ${a.group}: 8 answered ${kind === 'paid' ? `PAID - paid when it was booked${charged ? `, ${amountForLog(charged)}` : ''}` : 'CONFIRMED with no payment page'} (questions #102)`);
2066
+ put(r);
2067
+ if (kind === 'unknown')
2068
+ await settleUnknownPayment(a.acct, a.who, r);
2069
+ return { booked: toBooking(r) };
2070
+ };
2071
+ /**
2072
+ * ⚠️ CONFIRMED WITH NO PAYMENT PAGE (0.84.2, P0-1): whether it was paid, asked of the payment
2073
+ * status (15) at once - paid there, it is paid; anything else, it stays not known (never
2074
+ * "nothing has been charged"), looked at again by 15 and the order list (12).
2075
+ */
2076
+ const settleUnknownPayment = async (acct, who, r) => {
2077
+ if (!r.paymentUnknown || r.paid)
2078
+ return;
2079
+ const got = await lookAtPayment(acct, who, r, true);
2080
+ log(`[otaless] booking ${forTheLog(r.id)} at ${r.group}: 8 answered CONFIRMED with no payment page - ${got === 'paid' ? 'the payment status says paid' : 'whether it was paid is not known yet; looked at again'}`);
2081
+ };
1863
2082
  /** What 8 answered with - an order, a refusal or nothing - settled (`settle`). */
1864
2083
  const settleOrder = async (a, w, pairs) => {
1865
2084
  const g = deps.groupOf(a.group);
@@ -1909,8 +2128,10 @@ export const createOtalessBookings = (deps) => {
1909
2128
  const page = text(w.checkoutUrl ?? undefined);
1910
2129
  // ⚠️ "CONFIRMED" WITH A PAYMENT PAGE IS WAITING FOR ITS PAYMENT (questions
1911
2130
  // #53, #61 (1) - 8's own example): paid is what 15 says, never this status.
1912
- const confirmed = !page && (status === 'CONFIRMED' || status === 'PAID');
1913
- const r = recordOf(a, pairs, id, code, confirmed ? 'confirmed' : 'awaiting-payment');
2131
+ // ⚠️ PAID IS PAID, WITH A PAGE OR WITHOUT (0.84.2, 总线程's review): its page is never handed on.
2132
+ const paidAt = status === 'PAID';
2133
+ const confirmed = !page && status === 'CONFIRMED';
2134
+ const r = recordOf(a, pairs, id, code, paidAt || confirmed ? 'confirmed' : 'awaiting-payment');
1914
2135
  // ⚠️ NOTHING TO PAY IS NO AMOUNT (0.71.2, 总线程's review P2-2): the dev backend answers
1915
2136
  // 0 often enough (questions #46), and with the group's price not checked an order of
1916
2137
  // US$0 went out with its payment page. Zero or less is no amount - cancelled as one.
@@ -1918,6 +2139,16 @@ export const createOtalessBookings = (deps) => {
1918
2139
  const charged = asked8 && asked8.minor > 0 ? asked8 : undefined;
1919
2140
  if (asked8)
1920
2141
  r.charged = asked8;
2142
+ // ⚠️ PAID AT 8, NO PAGE: THE MONEY HAS MOVED (0.84.2, the 11-25 code audit's P0-1). JI's wallet
2143
+ // (questions #102) - 「Paid from your Ji wallet — $68.00」 - was kept as not paid and said
2144
+ // "Nothing has been charged … held until undefined UTC", and could never be refunded. Paid
2145
+ // is paid: settled on its own (`paidAt8`), never cancelled at once by 9.
2146
+ if (paidAt)
2147
+ return settledAt8(a, r, w, pairs, charged, 'paid');
2148
+ // ⚠️ CONFIRMED, NO PAGE: WHETHER IT WAS PAID IS NOT KNOWN (0.84.2, P0-1) - never cancelled at
2149
+ // once for an amount, the guests or terms (总线程's review, 2): it may have been charged.
2150
+ if (confirmed)
2151
+ return settledAt8(a, r, w, pairs, charged, 'unknown');
1921
2152
  // A step the group asks for, the order made (questions #66, #68).
1922
2153
  const step = /TERMS/.test(status) ? 'terms' : stepAsked(status);
1923
2154
  if (step && !deps.proceedWithoutGroupConfirm) {
@@ -2066,6 +2297,7 @@ export const createOtalessBookings = (deps) => {
2066
2297
  if (said)
2067
2298
  r.terms = said;
2068
2299
  put(r);
2300
+ await settleUnknownPayment(a.acct, a.who, r);
2069
2301
  return { booked: toBooking(r) };
2070
2302
  };
2071
2303
  /**
@@ -2357,9 +2589,23 @@ export const createOtalessBookings = (deps) => {
2357
2589
  // ⚠️ NOT SENT AGAIN (§12.1): 8 itself not answering - or refusing it as a
2358
2590
  // repeat of one that went in a moment ago (10014) - may have made it.
2359
2591
  // Kept to look for in the group's order list (12), said as not known.
2360
- if (err === fromBook && (unanswered(err) || isCode(err, REPEAT_SUBMIT))) {
2592
+ // ⚠️ …AND A SERVER ERROR IS NOT A NO (0.84.2, the 11-25 code audit's P1-1): code 500-599
2593
+ // that is not a step, not an order named and not "not linked" (all read below) may come
2594
+ // after the group made the order (questions #96) - "not known", as the add-on's 500 is;
2595
+ // never "nothing was booked or charged", and the stay is held back, not booked twice.
2596
+ const fault = err === fromBook && serverFault(err) && !stepAsked(errMsg(err)) && !unlinkedSaid(err);
2597
+ const named = fault && err instanceof OtalessError
2598
+ ? refusalOf(a, err.answer?.data, err.answer?.msg)
2599
+ : undefined;
2600
+ if (err === fromBook &&
2601
+ (unanswered(err) || isCode(err, REPEAT_SUBMIT) || (fault && !named))) {
2361
2602
  const r = recordOf(a, pairs ?? { orig: a.total }, `pending:${randomBytes(8).toString('hex')}`, '', 'unconfirmed');
2603
+ // ⚠️ ONLY ITS TERMS WERE ASKED (0.84.2, P2-3): nothing agreed - never handed on if found.
2604
+ if (asksTermsOnly(a))
2605
+ r.termsUnagreed = true;
2362
2606
  put(r);
2607
+ if (fault)
2608
+ log(`[otaless] booking at ${a.group}: 8 answered a server error (code ${err.backendCode ?? err.status}) - whether it was made is not known (核对中), never sent again; looked for in its order list (12) (questions #96)`);
2363
2609
  // ⚠️ 8's STEP 3 (0.74.0): its token stays - in memory alone, with the order not known -
2364
2610
  // and is never sent again; the order is looked for in the group's order list (12)
2365
2611
  // as any other (questions #88: whether the backend can look one up by its token).
@@ -2414,7 +2660,9 @@ export const createOtalessBookings = (deps) => {
2414
2660
  .trim()
2415
2661
  .toUpperCase());
2416
2662
  };
2417
- const stayGuard = async (acct, who, label, roomRef, rooms, lockKey) => {
2663
+ const stayGuard = async (acct, who, label, roomRef, rooms, lockKey,
2664
+ /** The caller holds `lockKey` already (0.84.2, P2-1): its own booking is not "being booked". */
2665
+ holding = false) => {
2418
2666
  const group = acct.group;
2419
2667
  const { hotel, stay } = label;
2420
2668
  const name = deps.groupOf(group).name;
@@ -2453,7 +2701,9 @@ export const createOtalessBookings = (deps) => {
2453
2701
  return {
2454
2702
  failed: failedStay(label, person.needsPerson === 'release'
2455
2703
  ? `An earlier booking of this stay could not be cancelled at ${name} and needs a person to check it, so nothing new was booked.`
2456
- : `An earlier booking of this stay needs a person to check its payment with ${name}, so nothing new was booked.`,
2704
+ : person.needsPerson === 'differs'
2705
+ ? `An earlier booking of this stay was confirmed by ${name} not quite as chosen, and a person is checking it with ${name}, so nothing new was booked.`
2706
+ : `An earlier booking of this stay needs a person to check its payment with ${name}, so nothing new was booked.`,
2457
2707
  // For the card to say in the guest's language (酒店平台 0.63.2, `NoRoomsCode`).
2458
2708
  'earlier-needs-person'),
2459
2709
  };
@@ -2511,12 +2761,11 @@ export const createOtalessBookings = (deps) => {
2511
2761
  // terms are shown - nothing will be sent to 8 for it.
2512
2762
  if (currencyHeld(group, hotel.id, roomRef, stay))
2513
2763
  return { failed: currencyRefused({ ...label, group }) };
2514
- if (inFlight.has(lockKey))
2515
- return {
2516
- failed: failedStay(label, 'This stay is being booked already - look at the bookings in a moment rather than booking it again.'),
2517
- };
2764
+ if (!holding && inFlight.has(lockKey))
2765
+ return { failed: beingBooked(label) };
2518
2766
  return undefined;
2519
2767
  };
2768
+ const beingBooked = (label) => failedStay(label, 'This stay is being booked already - look at the bookings in a moment rather than booking it again.');
2520
2769
  /**
2521
2770
  * The trip priced once per currency ITS QUOTES ARE IN (总线程 11-12, after 酒店平台 0.69.3's
2522
2771
  * `pricedByQuoteCurrency`): one quote of the whole trip, as before - and when the backend
@@ -2709,6 +2958,12 @@ export const createOtalessBookings = (deps) => {
2709
2958
  // and any other orders it, as the document has it.
2710
2959
  const needsTerms = await groupTermsOf(group);
2711
2960
  if (needsTerms) {
2961
+ // ⚠️ BOOKED ALREADY MEANWHILE (0.84.2, 总线程's review): the guard above awaited - another
2962
+ // request for this stay may hold the lock now.
2963
+ if (inFlight.has(lockKey)) {
2964
+ failed.push(beingBooked(label));
2965
+ continue;
2966
+ }
2712
2967
  inFlight.add(lockKey);
2713
2968
  try {
2714
2969
  const out = await placeStay(label, {
@@ -2733,6 +2988,12 @@ export const createOtalessBookings = (deps) => {
2733
2988
  // No terms for this room to agree to, and the deployment lets that go on
2734
2989
  // (robin 11-12 「条款没有也让走下一步」): ordered now - said on the booking.
2735
2990
  if (!agreed && deps.proceedWithoutGroupConfirm) {
2991
+ // ⚠️ BOOKED ALREADY MEANWHILE (0.84.2, 总线程's review): the guard above awaited - another
2992
+ // request for this stay may hold the lock now.
2993
+ if (inFlight.has(lockKey)) {
2994
+ failed.push(beingBooked(label));
2995
+ continue;
2996
+ }
2736
2997
  inFlight.add(lockKey);
2737
2998
  try {
2738
2999
  const out = await placeStay(label, {
@@ -2823,15 +3084,20 @@ export const createOtalessBookings = (deps) => {
2823
3084
  };
2824
3085
  const label = { hotel, stay: p.stay, roomName: p.roomName };
2825
3086
  const lockKey = `${acct.owner}|${p.hotelId}|${ask.roomId}|${p.stay.checkIn}|${p.stay.checkOut}|${p.rooms}`;
2826
- const guard = await stayGuard(acct, who, label, ask.roomId, p.rooms, lockKey);
2827
- if (guard)
2828
- return 'failed' in guard
2829
- ? { booked: [], failed: [guard.failed] }
2830
- : 'reuse' in guard
2831
- ? { booked: [toBooking(guard.reuse)], failed: [], repeat: true }
2832
- : { booked: [], failed: [], terms: [guard.terms] };
3087
+ // ⚠️ THE LOCK BEFORE THE GUARD (0.84.2, the 11-25 code audit's P2-1): two cards agreed at once
3088
+ // both passed the guard - it reads the group's list and payment status (awaits) - before either
3089
+ // took the lock, and the same stay could be ordered twice. Taken first, held through.
3090
+ if (inFlight.has(lockKey))
3091
+ return { booked: [], failed: [beingBooked(label)] };
2833
3092
  inFlight.add(lockKey);
2834
3093
  try {
3094
+ const guard = await stayGuard(acct, who, label, ask.roomId, p.rooms, lockKey, true);
3095
+ if (guard)
3096
+ return 'failed' in guard
3097
+ ? { booked: [], failed: [guard.failed] }
3098
+ : 'reuse' in guard
3099
+ ? { booked: [toBooking(guard.reuse)], failed: [], repeat: true }
3100
+ : { booked: [], failed: [], terms: [guard.terms] };
2835
3101
  const out = await place({
2836
3102
  acct,
2837
3103
  who,
@@ -2910,7 +3176,12 @@ export const createOtalessBookings = (deps) => {
2910
3176
  * difference is a person's (`needsPerson`, NEEDS A PERSON on the log).
2911
3177
  */
2912
3178
  const lookAtPayment = async (acct, who, r, force = false) => {
2913
- if (r.status !== 'awaiting-payment' || r.id.startsWith('pending:') || r.needsPerson)
3179
+ // ⚠️ …AND ONE CONFIRMED WITH NO PAGE, WHOSE PAYMENT IS NOT KNOWN (0.84.2, P0-1): only "paid"
3180
+ // moves it - it is never closed or expired on 15's word, the group having confirmed it.
3181
+ const unknownPaid = !!r.paymentUnknown && !r.paid && !ENDED.has(r.status);
3182
+ if ((r.status !== 'awaiting-payment' && !unknownPaid) ||
3183
+ r.id.startsWith('pending:') ||
3184
+ (r.needsPerson && r.needsPerson !== 'differs'))
2914
3185
  return 'unknown';
2915
3186
  const last = checkedAt.get(r.id) ?? 0;
2916
3187
  if (!force && now() - last < STATUS_EVERY_MS)
@@ -2932,6 +3203,7 @@ export const createOtalessBookings = (deps) => {
2932
3203
  }
2933
3204
  r.paid = true;
2934
3205
  r.status = 'confirmed';
3206
+ r.paymentUnknown = undefined;
2935
3207
  // ⚠️ WHAT WAS PAID, AS SAID: what the booking says and a refund previews.
2936
3208
  if (amount)
2937
3209
  r.paidAmount = amount;
@@ -2941,6 +3213,13 @@ export const createOtalessBookings = (deps) => {
2941
3213
  log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${r.group} paid ${amount.currency} ${amount.minor}, not what was asked (${r.quoted.currency} ${r.quoted.minor}) - taken as paid at what was paid; the difference is to be settled with ${r.group}`);
2942
3214
  return 'paid';
2943
3215
  }
3216
+ if (unknownPaid) {
3217
+ if (s?.pollAgain === true || said === 'PENDING' || said === 'PENDING_PAYMENT') {
3218
+ r.pendingSeenAt = iso();
3219
+ put(r);
3220
+ }
3221
+ return 'unknown';
3222
+ }
2944
3223
  if (s?.pollAgain !== true &&
2945
3224
  (CLOSED_PAYMENT_STATUSES.has(said) || (!!r.payBy && now() > Date.parse(r.payBy)))) {
2946
3225
  r.status = 'expired';
@@ -3013,8 +3292,10 @@ export const createOtalessBookings = (deps) => {
3013
3292
  r.status !== 'cancelled' &&
3014
3293
  !(r.status === 'awaiting-payment' && s.status === 'confirmed' && !s.paid))
3015
3294
  r.status = s.status;
3016
- if (s.paid)
3295
+ if (s.paid) {
3017
3296
  r.paid = true;
3297
+ r.paymentUnknown = undefined;
3298
+ }
3018
3299
  if (s.refunded)
3019
3300
  r.refund = {
3020
3301
  status: 'refunded',
@@ -3160,6 +3441,27 @@ export const createOtalessBookings = (deps) => {
3160
3441
  log(`[otaless] ${claimedAs} - not booked`);
3161
3442
  continue;
3162
3443
  }
3444
+ // ⚠️ FOUND, AND ONLY ITS TERMS WERE ASKED WHEN IT WAS SENT (0.84.2, the audit's P2-3): the
3445
+ // guest agreed to nothing and pressed nothing - its page is never handed on. Unpaid, it is
3446
+ // cancelled at once; paid at the group, it is paid, and a person's.
3447
+ if (o.termsUnagreed) {
3448
+ o.termsUnagreed = undefined;
3449
+ known.add(id);
3450
+ if (s.paid) {
3451
+ o.status = 'confirmed';
3452
+ o.paid = true;
3453
+ o.paidAmount = charged;
3454
+ o.needsPerson = 'paid-amount';
3455
+ o.needsPersonAt = iso();
3456
+ put(o);
3457
+ log(`[otaless] NEEDS A PERSON: ${claimedAs}, paid - it was sent when only its terms were asked for, none agreed; kept as paid, nothing cancelled`);
3458
+ continue;
3459
+ }
3460
+ o.status = 'awaiting-payment';
3461
+ log(`[otaless] ${claimedAs} - sent when only its terms were asked for, none agreed: cancelled`);
3462
+ await release(acct, who, o, 'terms');
3463
+ continue;
3464
+ }
3163
3465
  // ⚠️ PAID IS ONLY "PAID": "CONFIRMED" unpaid is still waiting for its payment.
3164
3466
  if (s.paid) {
3165
3467
  o.status = 'confirmed';
@@ -3169,6 +3471,13 @@ export const createOtalessBookings = (deps) => {
3169
3471
  else if (s.status === 'cancelled' || s.status === 'failed') {
3170
3472
  o.status = s.status;
3171
3473
  }
3474
+ else if (!ok && st === 'CONFIRMED') {
3475
+ // ⚠️ CONFIRMED WITH NO PAYMENT PAGE, FOUND IN THE LIST (0.84.2, 总线程's review, 4): as 8's own
3476
+ // answer would have been - whether it was paid is not known, never "not paid, nothing charged".
3477
+ o.status = 'confirmed';
3478
+ o.paymentUnknown = true;
3479
+ log(`[otaless] ${claimedAs}, no payment page - whether it was paid is not known; looked at again`);
3480
+ }
3172
3481
  else {
3173
3482
  o.status = 'awaiting-payment';
3174
3483
  if (ok) {
@@ -3200,7 +3509,9 @@ export const createOtalessBookings = (deps) => {
3200
3509
  .filter((r) => r.status === 'unconfirmed' ||
3201
3510
  (r.status === 'awaiting-payment' && !payLinks.has(r.id)) ||
3202
3511
  // 0.80.1: a cancel through its refund not known - the list may say what became of it.
3203
- r.refundCancel?.state === 'unsure')
3512
+ r.refundCancel?.state === 'unsure' ||
3513
+ // 0.84.2 (P0-1): confirmed with no payment page - the list may say it is paid.
3514
+ (!!r.paymentUnknown && !r.paid))
3204
3515
  .map((r) => r.group));
3205
3516
  for (const g of groups) {
3206
3517
  const acct = signed.get(g);
@@ -3208,7 +3519,7 @@ export const createOtalessBookings = (deps) => {
3208
3519
  await lookAtOrders(acct, who, g, mine.filter((r) => r.group === g));
3209
3520
  }
3210
3521
  for (const r of newest
3211
- .filter((o) => o.status === 'awaiting-payment')
3522
+ .filter((o) => o.status === 'awaiting-payment' || (!!o.paymentUnknown && !o.paid))
3212
3523
  .slice(0, CHECKED_PER_LOOK)) {
3213
3524
  const acct = signed.get(r.group);
3214
3525
  if (acct)
@@ -3250,8 +3561,9 @@ export const createOtalessBookings = (deps) => {
3250
3561
  if (!own)
3251
3562
  return null;
3252
3563
  const { r, acct } = own;
3253
- // Paid a moment ago: said as paid, as its cancel will take it (0.75.1, C6).
3254
- if (r.status === 'awaiting-payment' && !r.paid)
3564
+ // Paid a moment ago: said as paid, as its cancel will take it (0.75.1, C6) - and one whose
3565
+ // payment is not known (0.84.2, P0-1).
3566
+ if ((r.status === 'awaiting-payment' || r.paymentUnknown) && !r.paid)
3255
3567
  await lookAtPayment(acct, who, r, true);
3256
3568
  await refresh(who, [r], new Map([[r.group, acct]]));
3257
3569
  const amount = paidOf(r);
@@ -3355,7 +3667,7 @@ export const createOtalessBookings = (deps) => {
3355
3667
  // ⚠️ PAID A MOMENT AGO IS PAID (0.75.1, the review's C6): the payment status (15) is asked
3356
3668
  // now, not at most every `STATUS_EVERY_MS` - paid within those seconds, it was cancelled as
3357
3669
  // unpaid: 9 alone, nothing asked back.
3358
- if (r.status === 'awaiting-payment' && !r.paid)
3670
+ if ((r.status === 'awaiting-payment' || r.paymentUnknown) && !r.paid)
3359
3671
  await lookAtPayment(acct, who, r, true);
3360
3672
  if (r.status === 'cancelled' || r.status === 'expired' || r.status === 'failed')
3361
3673
  return toBooking(r);
@@ -3366,7 +3678,6 @@ export const createOtalessBookings = (deps) => {
3366
3678
  // "done" would ask 9.1 a second time, not 9.1. A person is checking with the group.
3367
3679
  if (r.refundCancel)
3368
3680
  throw refusal('cancel-unknown', `${g} has not said yet whether it took the refund request that cancels this paid booking, so it is not known yet whether it is cancelled - a person here is checking with ${g}, and nothing more is sent for it until then.`);
3369
- const unpaid = r.status === 'awaiting-payment' && !r.paid;
3370
3681
  const why = cleanReason(reason);
3371
3682
  // 9, paid or not: 14 is not called any more (questions #56).
3372
3683
  let out;
@@ -3394,19 +3705,40 @@ export const createOtalessBookings = (deps) => {
3394
3705
  for (const [k, p] of pending)
3395
3706
  if (p.orderId === r.id)
3396
3707
  pending.delete(k);
3397
- if (!unpaid && r.paid) {
3398
- const said = cancelRefundSaid(out);
3708
+ // ⚠️ 9'S OWN WORD OF A REFUND IS READ FOR EVERY ORDER (0.84.2, the audit's P2-5): one paid at
3709
+ // the group that 15 had not said yet - REFUNDED from 9 - was told "not paid: nothing booked or
3710
+ // charged". A refund said is a payment made: taken as paid, and as refunding. ⚠️ BY ITS STATUS
3711
+ // OR WORDS ONLY: the document has 9 answer `refundAmount` for any order (questions #51) - an
3712
+ // amount alone on an order not seen paid says nothing.
3713
+ const refundSaid = cancelRefundSaid(out);
3714
+ if (!r.paid && refundSaid && refundSaid.by !== 'amount') {
3715
+ r.paid = true;
3716
+ r.paymentUnknown = undefined;
3717
+ log(`[otaless] CHECK: ${forTheLog(r.id)} at ${r.group} was not seen paid here, and 9 cancelled it saying its refund (${refundSaid.by}) - taken as paid, its refund as 9 said`);
3718
+ }
3719
+ if (r.paymentUnknown && !r.paid)
3720
+ // ⚠️ CONFIRMED WITH NO PAGE, CANCELLED, ITS PAYMENT STILL NOT KNOWN (0.84.2, P0-1): said so -
3721
+ // never "nothing was charged"; the list (12) may still say it was paid, and refunded.
3722
+ log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${r.group} was cancelled; it was confirmed with no payment page and whether it was paid is not known - if it was, its refund is to be asked of the group`);
3723
+ if (r.paid) {
3724
+ const said = refundSaid;
3399
3725
  const back = moneyOf(out?.refundAmount, out?.refundCurrency);
3400
- if (said || !deps.refundsOn) {
3401
- // 9 said its money is going back (or is back) - never asked twice. Refunds off: what
3402
- // 9 said, as it was before 0.74.2.
3726
+ if (!said && !deps.refundsOn) {
3727
+ // ⚠️ REFUNDS OFF, AND 9 SAID NOTHING OF ITS MONEY (0.84.2, P2-5): never "submitted" - no
3728
+ // refund was asked from here. A person takes it up with the group.
3729
+ r.refund = { status: 'not-sent' };
3730
+ counts.refundNotSent += 1;
3731
+ log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${r.group} is paid and was cancelled; 9 said nothing of its refund and refunds are off here - nothing was asked back`);
3732
+ }
3733
+ else if (said) {
3734
+ // 9 said its money is going back (or is back) - never asked twice.
3403
3735
  r.refund = {
3404
- status: said?.state === 'refunded' ? 'refunded' : 'requested',
3736
+ status: said.state === 'refunded' ? 'refunded' : 'requested',
3405
3737
  ...(back && back.minor > 0 ? { amount: back } : {}),
3406
3738
  };
3407
3739
  // ⚠️ AN AMOUNT ALONE (0.74.3, P2-3): taken as asked, and said so to whoever reads the
3408
3740
  // log - if 9 does not refund by itself (questions #51), nothing else would show it.
3409
- if (said?.by === 'amount') {
3741
+ if (said.by === 'amount') {
3410
3742
  counts.refundAssumed += 1;
3411
3743
  log(`[otaless] CHECK: ${forTheLog(r.id)} at ${r.group} cancelled with refundAmount ${back ? `${back.currency} ${back.minor}` : String(out?.refundAmount)} and no refund status or words - taken as its refund asked, 9.1 not sent (questions #51)`);
3412
3744
  }
@@ -3440,7 +3772,7 @@ export const createOtalessBookings = (deps) => {
3440
3772
  counts.refundNotSent += 1;
3441
3773
  else
3442
3774
  counts.refundUnsure += 1;
3443
- log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${r.group} was cancelled, and its refund (9.1) ${got.how}: ${forTheLog(got.words)} - ${got.state === 'unsure' ? 'whether it was sent is not known; check with the group' : 'nothing goes back until a person takes it up'}`);
3775
+ log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${r.group} was cancelled, and its refund (9.1) ${got.how}: ${forTheLog(got.words, [r.guest.name])} - ${got.state === 'unsure' ? 'whether it was sent is not known; check with the group' : 'nothing goes back until a person takes it up'}`);
3444
3776
  return { status: got.state };
3445
3777
  };
3446
3778
  /**
@@ -3476,9 +3808,14 @@ export const createOtalessBookings = (deps) => {
3476
3808
  ? err.message
3477
3809
  : String(err);
3478
3810
  // ⚠️ NOT ANSWERED IS NOT REFUSED (0.74.3, P3): a 9.1 that timed out may have been taken.
3479
- return unanswered(err)
3480
- ? { state: 'unsure', how: 'was not answered', words }
3481
- : { state: 'not-sent', how: 'failed', words, err };
3811
+ // ⚠️ NOR A SERVER ERROR, NOR A REPEAT REFUSED (0.84.2, the 11-25 code audit's P1-1): code
3812
+ // 500-599 may come after the refund was taken, and 10014 says one went in a moment ago -
3813
+ // "not known", never "nothing refunded, it stands": a second Cancel would ask 9.1 twice.
3814
+ if (unanswered(err))
3815
+ return { state: 'unsure', how: 'was not answered', words };
3816
+ if (serverFault(err) || isCode(err, REPEAT_SUBMIT))
3817
+ return { state: 'unsure', how: 'was answered with a server error', words };
3818
+ return { state: 'not-sent', how: 'failed', words, err };
3482
3819
  }
3483
3820
  };
3484
3821
  /**
@@ -3534,13 +3871,13 @@ export const createOtalessBookings = (deps) => {
3534
3871
  if (got.err instanceof OtalessBusy || (got.err instanceof Error && typeof code === 'string'))
3535
3872
  throw got.err;
3536
3873
  counts.cancelByRefundRefused += 1;
3537
- log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${r.group} is paid and the guest asked to cancel it; 9 answered paid_use_refund, and the refund (9.1) that cancels it ${got.how}: ${forTheLog(got.words)} - not cancelled, nothing refunded`);
3874
+ log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${r.group} is paid and the guest asked to cancel it; 9 answered paid_use_refund, and the refund (9.1) that cancels it ${got.how}: ${forTheLog(got.words, [r.guest.name])} - not cancelled, nothing refunded`);
3538
3875
  throw refusal('not-cancelled', `${g} did not cancel it - it stands as it was, and nothing was refunded: ${g} cancels a paid booking only through a refund of it, and it did not take the refund request.`);
3539
3876
  }
3540
3877
  r.refundCancel = { state: 'unsure', at: r.refundCancel?.at ?? iso() };
3541
3878
  put(r);
3542
3879
  counts.cancelByRefundUnsure += 1;
3543
- log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${r.group} is paid; 9 answered paid_use_refund, and the refund (9.1) that cancels it ${got.how}: ${forTheLog(got.words)} - whether it was taken, and the booking cancelled with it, is not known; nothing more is sent for it - check with the group, then (service stopped) delete refundCancel on it in otaless-orders.json and write what the group said`);
3880
+ log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${r.group} is paid; 9 answered paid_use_refund, and the refund (9.1) that cancels it ${got.how}: ${forTheLog(got.words, [r.guest.name])} - whether it was taken, and the booking cancelled with it, is not known; nothing more is sent for it - check with the group, then (service stopped) delete refundCancel on it in otaless-orders.json and write what the group said`);
3544
3881
  throw refusal('cancel-unknown', `${g} did not say in time whether it took the refund request that cancels this paid booking, so it is not known yet whether it is cancelled or whether its refund was submitted - nothing is changed here, a person here is checking with ${g}, and nothing more is sent for it until then.`);
3545
3882
  };
3546
3883
  // ── refund: a preview, then the refund it previewed (9.1; 总线程's review of 0.63.0, B) ──
@@ -3607,22 +3944,27 @@ export const createOtalessBookings = (deps) => {
3607
3944
  !same(shown.amount, paidOf(r)))
3608
3945
  throw refusal('refund-preview', 'Nothing was asked: a refund is asked only after the guest was shown what it asks for (the refund preview of this booking) - show it to them again first.');
3609
3946
  const why = cleanReason(reason);
3610
- // ⚠️ ALL OF IT, NEVER A PART (`amountUsd` is never sent), and no
3947
+ // ⚠️ THE SAME 9.1 AS A CANCEL'S (0.84.2, the 11-25 code audit's P2-6 - no tool offers this one,
3948
+ // and the server refuses it, but it is kept as safe as the cancel's): "asking" is written before
3949
+ // it is sent, its answer read by the allow-list (`refundOutcome`), and one not answered - or a
3950
+ // server error - is not known: never sent again, a person checks. ALL OF IT, NEVER A PART, and no
3611
3951
  // `sessionToken` (questions #53): the backend takes the guest from the sign-in.
3612
- const out = await withSession(acct, who, (cred) => client.refund({
3613
- unifiedOrderId: r.id,
3614
- ...(r.code ? { booking: r.code } : {}),
3615
- providerCode: r.group,
3616
- ...(why ? { reason: why } : {}),
3617
- }, cred, deps.callerOf(who)));
3618
- if (out?.success === false)
3952
+ r.refund = { status: 'not-sent', asking: true };
3953
+ put(r);
3954
+ const got = await sendRefund(r, acct, who, why);
3955
+ if (got.state === 'requested' || got.state === 'refunded') {
3956
+ r.refund = { status: got.state, ...(got.amount ? { amount: got.amount } : {}) };
3957
+ put(r);
3958
+ return toBooking(r);
3959
+ }
3960
+ if (got.state === 'not-sent') {
3961
+ r.refund = undefined;
3962
+ put(r);
3619
3963
  throw refusal('not-refunded', `${g} did not take the refund request.`);
3620
- const back = moneyOf(out?.refundAmount, out?.refundCurrency);
3621
- r.refund = {
3622
- status: String(out?.status ?? '').toUpperCase() === 'REFUNDED' ? 'refunded' : 'requested',
3623
- ...(back ? { amount: back } : {}),
3624
- };
3964
+ }
3965
+ r.refund = { status: 'unsure' };
3625
3966
  put(r);
3967
+ log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${r.group}: its refund (9.1) ${got.how}: ${forTheLog(got.words, [r.guest.name])} - whether it was taken is not known; check with the group`);
3626
3968
  return toBooking(r);
3627
3969
  };
3628
3970
  const KINDS = { transfer: 'transfer', dining: 'dining' };
@@ -3877,6 +4219,9 @@ export const createOtalessBookings = (deps) => {
3877
4219
  proceedWithoutGroupConfirm: deps.proceedWithoutGroupConfirm ? 1 : 0,
3878
4220
  groupSessions: sessions.size,
3879
4221
  termsWaiting: pending.size,
4222
+ // 0.84.2: whether paid is not known (confirmed by 8 with no page) - open, and cancelled so.
4223
+ ordersPaymentUnknown: [...orders.values()].filter((o) => o.paymentUnknown && !o.paid).length,
4224
+ ordersCancelledPaymentUnknown: [...orders.values()].filter((o) => o.paymentUnknown && !o.paid && ENDED.has(o.status)).length,
3880
4225
  ...counts,
3881
4226
  }),
3882
4227
  };