@curless/hotel-storefront 0.66.0 → 0.67.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/account/fake-ota.d.ts.map +1 -1
  2. package/dist/account/fake-ota.js +2 -0
  3. package/dist/account/fake-ota.js.map +1 -1
  4. package/dist/account/index.d.ts +20 -0
  5. package/dist/account/index.d.ts.map +1 -1
  6. package/dist/account/index.js +85 -24
  7. package/dist/account/index.js.map +1 -1
  8. package/dist/account/ota-member.d.ts +2 -0
  9. package/dist/account/ota-member.d.ts.map +1 -1
  10. package/dist/account/ota-member.js +2 -0
  11. package/dist/account/ota-member.js.map +1 -1
  12. package/dist/account/pages.d.ts +16 -1
  13. package/dist/account/pages.d.ts.map +1 -1
  14. package/dist/account/pages.js +88 -10
  15. package/dist/account/pages.js.map +1 -1
  16. package/dist/account/requests.d.ts +1 -1
  17. package/dist/account/requests.d.ts.map +1 -1
  18. package/dist/account/store.d.ts +38 -1
  19. package/dist/account/store.d.ts.map +1 -1
  20. package/dist/account/store.js +32 -1
  21. package/dist/account/store.js.map +1 -1
  22. package/dist/card.generated.d.ts +1 -1
  23. package/dist/card.generated.js +2 -2
  24. package/dist/card.generated.js.map +1 -1
  25. package/dist/config.d.ts +20 -0
  26. package/dist/config.d.ts.map +1 -1
  27. package/dist/config.js.map +1 -1
  28. package/dist/otaless/backend.d.ts +6 -0
  29. package/dist/otaless/backend.d.ts.map +1 -1
  30. package/dist/otaless/backend.js +70 -5
  31. package/dist/otaless/backend.js.map +1 -1
  32. package/dist/otaless/booking.d.ts +119 -5
  33. package/dist/otaless/booking.d.ts.map +1 -1
  34. package/dist/otaless/booking.js +477 -59
  35. package/dist/otaless/booking.js.map +1 -1
  36. package/dist/otaless/client.d.ts +83 -7
  37. package/dist/otaless/client.d.ts.map +1 -1
  38. package/dist/otaless/client.js +117 -13
  39. package/dist/otaless/client.js.map +1 -1
  40. package/dist/otaless/fake.d.ts +45 -2
  41. package/dist/otaless/fake.d.ts.map +1 -1
  42. package/dist/otaless/fake.js +94 -10
  43. package/dist/otaless/fake.js.map +1 -1
  44. package/dist/otaless/make.d.ts +8 -0
  45. package/dist/otaless/make.d.ts.map +1 -1
  46. package/dist/otaless/make.js +55 -4
  47. package/dist/otaless/make.js.map +1 -1
  48. package/dist/otaless/places.d.ts +14 -0
  49. package/dist/otaless/places.d.ts.map +1 -1
  50. package/dist/otaless/places.js +108 -1
  51. package/dist/otaless/places.js.map +1 -1
  52. package/dist/pictures.d.ts +19 -0
  53. package/dist/pictures.d.ts.map +1 -0
  54. package/dist/pictures.js +74 -0
  55. package/dist/pictures.js.map +1 -0
  56. package/dist/server.d.ts +17 -2
  57. package/dist/server.d.ts.map +1 -1
  58. package/dist/server.js +415 -40
  59. package/dist/server.js.map +1 -1
  60. package/dist/sessions.d.ts +23 -0
  61. package/dist/sessions.d.ts.map +1 -1
  62. package/dist/sessions.js +39 -1
  63. package/dist/sessions.js.map +1 -1
  64. package/dist/supplier.js +4 -0
  65. package/dist/supplier.js.map +1 -1
  66. package/dist/surface.d.ts +24 -1
  67. package/dist/surface.d.ts.map +1 -1
  68. package/dist/surface.js +31 -4
  69. package/dist/surface.js.map +1 -1
  70. package/dist/tools.d.ts +30 -0
  71. package/dist/tools.d.ts.map +1 -1
  72. package/dist/tools.js +221 -27
  73. package/dist/tools.js.map +1 -1
  74. package/dist/trip-ids.d.ts +38 -1
  75. package/dist/trip-ids.d.ts.map +1 -1
  76. package/dist/trip-ids.js +98 -3
  77. package/dist/trip-ids.js.map +1 -1
  78. package/dist/types.d.ts +69 -1
  79. package/dist/types.d.ts.map +1 -1
  80. package/package.json +1 -1
@@ -58,6 +58,13 @@ export const STATUS_EVERY_MS = 10_000;
58
58
  * the document's checkout holds a room unpaid.
59
59
  */
60
60
  export const UNCONFIRMED_GIVE_UP_MS = 2 * 60 * 60_000;
61
+ /**
62
+ * An order a person was to see to (`needsPerson`), still not settled this long
63
+ * after: no longer holds the stay back - the guest is told first, as it is
64
+ * (总线程's review of 0.66.0, 6). The same two hours as an order 8 did not
65
+ * answer for: any hold on an unpaid room is long gone by then.
66
+ */
67
+ export const NEEDS_PERSON_GIVE_UP_MS = 2 * 60 * 60_000;
61
68
  /**
62
69
  * An order waiting for its payment with no time to pay by from 13: taken as
63
70
  * payable this long after it was made, or after the payment status (15) last
@@ -98,9 +105,10 @@ const CHECKED_PER_LOOK = 5;
98
105
  * re-review of 0.63.1, 720f5e4f; again 11-11, B): that is our own hosted
99
106
  * checkout, which takes any merchant and any amount, and has no `/pay/cashier`
100
107
  * behind it today - though 8's example names it. A page there is not handed
101
- * on: the order is cancelled and its host and path logged, to ask the backend
102
- * about. Should it ever be listed, it is as `mcp.curless.ai/pay/cashier?order={order}`
103
- * - that page for that order alone (`payPageOf`).
108
+ * on: the order is cancelled and its host logged, to ask the backend about.
109
+ * Should it ever be listed, it is as `mcp.curless.ai/pay/cashier?order={order}`
110
+ * - that page for that order alone (`payPageOf`). A page on a host listed
111
+ * alone must still name the order (总线程's review of 0.66.0, 2).
104
112
  */
105
113
  export const DEFAULT_CHECKOUT_HOSTS = ['pay.discoverasr.com'];
106
114
  /** How long a refund's preview can be sent back (总线程's review of 0.63.0, B). */
@@ -190,6 +198,12 @@ export const checkoutHostsProblem = (hosts) => {
190
198
  * takes any path on it (总线程's review of 0.63.0, 8). The page handed on is
191
199
  * the one checked: its path as compared.
192
200
  *
201
+ * ⚠️ AND ONLY A PAGE NAMING THIS ORDER (总线程's review of 0.66.0, 2): through an
202
+ * entry without `{order}`, the order's `unifiedOrderId` or `originalOrderId` must
203
+ * be in the page - a whole path segment, or a whole query value. Neither there,
204
+ * or no order to hold it to: nothing. (`pay.discoverasr.com` until its pages'
205
+ * real form is known - then an exact entry naming `{order}`.)
206
+ *
193
207
  * ⚠️ AN ENTRY NAMING THE ORDER (`host/pay/cashier?order={order}`, 总线程
194
208
  * 11-11, B) TAKES ONE PAGE: that path exactly, and a query of that one
195
209
  * parameter, once, naming `order` - this very order's `unifiedOrderId` - and
@@ -217,39 +231,186 @@ export const payPageOf = (raw, hosts, order) => {
217
231
  if (e.host !== host || !e.under.every((seg, i) => segs[i] === seg))
218
232
  continue;
219
233
  if (e.order === undefined) {
234
+ if (!namesOrder(u, segs, order))
235
+ continue;
220
236
  u.pathname = `/${segs.join('/')}${segs.length && u.pathname.endsWith('/') ? '/' : ''}`;
221
237
  return { url: u.toString(), host };
222
238
  }
223
- if (!order || segs.length !== e.under.length || u.hash)
239
+ if (!order?.id || segs.length !== e.under.length || u.hash)
224
240
  continue;
225
241
  const keys = [...u.searchParams.keys()];
226
- if (keys.length !== 1 || keys[0] !== e.order || u.searchParams.get(e.order) !== order)
242
+ if (keys.length !== 1 || keys[0] !== e.order || u.searchParams.get(e.order) !== order.id)
227
243
  continue;
228
244
  return {
229
- url: `https://${host}/${e.under.join('/')}?${e.order}=${encodeURIComponent(order)}`,
245
+ url: `https://${host}/${e.under.join('/')}?${e.order}=${encodeURIComponent(order.id)}`,
230
246
  host,
231
247
  };
232
248
  }
233
249
  return undefined;
234
250
  };
235
251
  /**
236
- * The host and path of a page not handed on, for the log - never its query or
237
- * fragment (they may carry a payment token): what 总线程 asks the backend about.
252
+ * Whether a page names the order: its `unifiedOrderId` or `originalOrderId` as
253
+ * a whole path segment (as written, or decoded) or a whole query value - never
254
+ * a part of one, never in the fragment (总线程's review of 0.66.0, 2).
255
+ */
256
+ const namesOrder = (u, segs, order) => {
257
+ const ids = [order?.id, order?.code].filter((x) => !!x);
258
+ if (!ids.length)
259
+ return false;
260
+ const decoded = (seg) => {
261
+ try {
262
+ return decodeURIComponent(seg);
263
+ }
264
+ catch {
265
+ return seg;
266
+ }
267
+ };
268
+ return (segs.some((seg) => ids.includes(seg) || ids.includes(decoded(seg))) ||
269
+ [...u.searchParams.values()].some((v) => ids.includes(v)));
270
+ };
271
+ /** Whether a page is on a host the list names - whatever its path. */
272
+ const onListedHost = (raw, hosts) => {
273
+ try {
274
+ const host = new URL(String(raw)).hostname.toLowerCase();
275
+ return hosts.some((h) => checkoutEntryOf(h).host === host);
276
+ }
277
+ catch {
278
+ return false;
279
+ }
280
+ };
281
+ /**
282
+ * The host of a page not handed on, for the log - never its path, query or
283
+ * fragment: some payment pages carry their token in the path (总线程's review
284
+ * of 0.66.0, 4).
238
285
  */
239
- const pageForLog = (raw) => {
286
+ const hostForLog = (raw) => {
240
287
  try {
241
- const u = new URL(String(raw));
242
- return forTheLog(`${u.host}${u.pathname}`) || '?';
288
+ return forTheLog(new URL(String(raw)).host) || '?';
243
289
  }
244
290
  catch {
245
291
  return 'not a URL';
246
292
  }
247
293
  };
294
+ /** A path segment written on the log as it is: a plain lower-case word - anything else is its length. */
295
+ const PATH_WORD = /^[a-z_-]{1,20}$/;
296
+ /** A query parameter's name written as it is: a plain word, either case. */
297
+ const KEY_WORD = /^[A-Za-z_-]{1,20}$/;
298
+ /** At most this many path segments, and as many parameters, on one shape. */
299
+ const SHAPE_PARTS = 12;
300
+ /**
301
+ * The form of a payment page not handed on, for the log - NO VALUE OF IT
302
+ * (总线程 11-11 late): each path segment a plain word as it is, or its length;
303
+ * each parameter's name (a plain word, or its length) and its value's length;
304
+ * and where this order's `unifiedOrderId` / `originalOrderId` is in it - or
305
+ * that it is not. From the first real page, the exact `{order}` entry can be
306
+ * written; no payment token reaches the log.
307
+ */
308
+ export const pageShape = (raw, order) => {
309
+ let u;
310
+ try {
311
+ u = new URL(String(raw));
312
+ }
313
+ catch {
314
+ return 'not a URL';
315
+ }
316
+ const segs = pathSegments(u.pathname) ?? u.pathname.split('/').filter(Boolean);
317
+ const pairs = [...u.searchParams.entries()];
318
+ const size = (x) => `<${x.length} chars>`;
319
+ const key = (k) => (KEY_WORD.test(k) ? k : size(k));
320
+ const more = (n) => (n > SHAPE_PARTS ? ` (+${n - SHAPE_PARTS} more)` : '');
321
+ const decoded = (x) => {
322
+ try {
323
+ return decodeURIComponent(x);
324
+ }
325
+ catch {
326
+ return x;
327
+ }
328
+ };
329
+ const path = `/${segs
330
+ .slice(0, SHAPE_PARTS)
331
+ .map((x) => (PATH_WORD.test(x) ? x : size(x)))
332
+ .join('/')}${more(segs.length)}`;
333
+ const query = pairs.length
334
+ ? ` ? ${pairs
335
+ .slice(0, SHAPE_PARTS)
336
+ .map(([k, v]) => `${key(k)}=${size(v)}`)
337
+ .join(' & ')}${more(pairs.length)}`
338
+ : '';
339
+ const hash = u.hash.length > 1 ? ` # ${size(u.hash.slice(1))}` : '';
340
+ const where = [];
341
+ for (const [what, id] of [
342
+ ['unifiedOrderId', order?.id],
343
+ ['originalOrderId', order?.code],
344
+ ]) {
345
+ if (!id)
346
+ continue;
347
+ segs.forEach((x, i) => {
348
+ const d = decoded(x);
349
+ if (x === id || d === id)
350
+ where.push(`${what} is path segment ${i + 1}`);
351
+ else if (x.includes(id) || d.includes(id))
352
+ where.push(`${what} is inside path segment ${i + 1}`);
353
+ });
354
+ for (const [k, v] of pairs) {
355
+ if (v === id)
356
+ where.push(`${what} is the value of ${key(k)}`);
357
+ else if (v.includes(id))
358
+ where.push(`${what} is inside the value of ${key(k)}`);
359
+ if (k.includes(id))
360
+ where.push(`${what} is inside a parameter's name`);
361
+ }
362
+ if (decoded(u.hash.slice(1)).includes(id))
363
+ where.push(`${what} is in the fragment`);
364
+ }
365
+ return `${path}${query}${hash} - ${where.length ? where.join(', ') : 'this order is not in it'}`;
366
+ };
248
367
  /**
249
368
  * Two terms the same but for spacing and punctuation (总线程 11-11, D): a
250
369
  * group's answer formatted a little differently is not new terms to agree to.
251
370
  */
252
371
  export const termsKey = (s) => s.normalize('NFKC').replace(/[\s\p{P}]/gu, '');
372
+ /** Which step a refusal of 8 - or its status - asks for, or none. */
373
+ export const stepAsked = (said) => {
374
+ const s = String(said ?? '');
375
+ if (/\bterms[ _-]?required\b/i.test(s))
376
+ return 'terms';
377
+ if (/\bconfirm(?:ation)?[ _-]?required\b/i.test(s))
378
+ return 'confirm';
379
+ return undefined;
380
+ };
381
+ /**
382
+ * What to agree to or confirm, and the token to do it with, as 8 would send
383
+ * them back with `terms_required` / `confirm_required` - both, or nothing.
384
+ * ⚠️ THE NAMES ARE THE ONES ASKED FOR IN QUESTIONS #66 AND #68
385
+ * (`termsText` / `termsToken`, `confirmText` / `confirmToken`, or written with
386
+ * `_`), not yet in 8's document: until the backend answers, an answer naming
387
+ * them otherwise is a refusal, as it is today. An amount or nights beside them
388
+ * are read by 8's own names (`totalAmount`, `currency`, `checkIn`, `checkOut`).
389
+ */
390
+ export const groupStepOf = (step, data) => {
391
+ if (!data || typeof data !== 'object')
392
+ return undefined;
393
+ const d = data;
394
+ const said = step === 'terms' ? (d.termsText ?? d.terms_text) : (d.confirmText ?? d.confirm_text);
395
+ const token = step === 'terms' ? (d.termsToken ?? d.terms_token) : (d.confirmToken ?? d.confirm_token);
396
+ if (typeof said !== 'string' || typeof token !== 'string')
397
+ return undefined;
398
+ const t = said.trim();
399
+ const k = token.trim();
400
+ if (!t || t.length > TERMS_MAX || !/^[\x21-\x7e]{1,512}$/.test(k))
401
+ return undefined;
402
+ const amount = moneyOf(d.totalAmount, d.currency);
403
+ const named = (d.totalAmount ?? d.currency) !== undefined && (d.totalAmount ?? d.currency) !== null;
404
+ const checkIn = text(d.checkIn);
405
+ const checkOut = text(d.checkOut);
406
+ return {
407
+ text: t,
408
+ token: k,
409
+ ...(amount ? { amount } : named ? { amountUnread: true } : {}),
410
+ ...(checkIn ? { checkIn } : {}),
411
+ ...(checkOut ? { checkOut } : {}),
412
+ };
413
+ };
253
414
  /**
254
415
  * The statuses a cancellation (9 `booking/cancel`; 14 `checkout/cancel` before 11-11) is
255
416
  * taken as DONE by - exactly these, case aside (总线程's review of 0.63.0, 4):
@@ -525,7 +686,8 @@ export const createOtalessBookings = (deps) => {
525
686
  quantity: r.rooms,
526
687
  unit: money(Math.round(r.quoted.minor / Math.max(1, n * r.rooms)), r.quoted.currency),
527
688
  total: r.quoted,
528
- terms: r.terms ?? '',
689
+ // Not agreed to: on the card's terms and the one-time page only (总线程's review of 0.67.0, 1).
690
+ terms: r.termsNew ? '' : (r.terms ?? ''),
529
691
  day: r.stay.checkIn,
530
692
  };
531
693
  const payment = paymentOf(r);
@@ -554,7 +716,18 @@ export const createOtalessBookings = (deps) => {
554
716
  };
555
717
  // Beside the type, for the words (0.63.2): why it is not known - and (11-11,
556
718
  // D) an order whose payment page waits for terms the group answered it with.
557
- return Object.assign(booking, r.unverifiable ? { unverifiable: true } : {}, r.needsPerson ? { needsPerson: r.needsPerson } : {}, r.held ? { termsChanged: true, termsUntil: r.held.until } : {});
719
+ return Object.assign(booking, r.unverifiable ? { unverifiable: true } : {}, r.needsPerson ? { needsPerson: r.needsPerson } : {}, r.held?.step === 'confirm'
720
+ ? { confirmAsked: true, termsUntil: r.held.until }
721
+ : r.held
722
+ ? { termsChanged: true, termsUntil: r.held.until }
723
+ : {},
724
+ // With a person past its time and the guest told so: no longer holds the stay
725
+ // back (总线程's review of 0.66.0, 6) - the words must not say it does.
726
+ r.needsPerson && r.rebookable ? { rebookable: true } : {},
727
+ // Beside the type, for the words (酒店平台 0.67.1, robin 11-12): a step the
728
+ // group asked for with nothing to show - it may need the group to confirm
729
+ // it separately; and an order made with no terms to agree to.
730
+ r.stepUnsent ? { confirmUnseen: true } : {}, r.noTerms ? { noTermsGiven: true } : {});
558
731
  };
559
732
  const failedStay = (a, why, code) => ({
560
733
  hotelId: a.hotel.id,
@@ -567,6 +740,7 @@ export const createOtalessBookings = (deps) => {
567
740
  });
568
741
  const limited = (a, name) => failedStay(a, `Not sent to ${name}: too many requests just now - ask again in a minute.`, 'limited');
569
742
  const recordOf = (a, pairs, id, code, status) => ({
743
+ ...(a.noTerms ? { noTerms: true } : {}),
570
744
  id,
571
745
  code,
572
746
  group: a.group,
@@ -611,6 +785,7 @@ export const createOtalessBookings = (deps) => {
611
785
  source: p.source,
612
786
  more: true,
613
787
  ...(p.changed ? { changed: true } : {}),
788
+ ...(p.askedByGroup ? { askedByGroup: p.askedByGroup } : {}),
614
789
  ...(p.bookingId ? { bookingId: p.bookingId } : {}),
615
790
  ...(p.confirmationCode ? { confirmationCode: p.confirmationCode } : {}),
616
791
  until: p.until,
@@ -654,13 +829,91 @@ export const createOtalessBookings = (deps) => {
654
829
  key: a.acct.key,
655
830
  ask: { roomId: a.roomId, guest: a.guest },
656
831
  });
832
+ /** Where what a group asks to agree to or confirm is not what the guest was shown - or nothing. */
833
+ const stepOff = (asked, a, pairs) => asked.amountUnread ||
834
+ (asked.amount && !(same(asked.amount, pairs.orig) || same(asked.amount, pairs.usd)))
835
+ ? 'another amount'
836
+ : (asked.checkIn !== undefined && asked.checkIn !== a.stay.checkIn) ||
837
+ (asked.checkOut !== undefined && asked.checkOut !== a.stay.checkOut)
838
+ ? 'other nights'
839
+ : undefined;
840
+ /**
841
+ * 8 asked for a second step (`terms_required`, questions #66;
842
+ * `confirm_required`, #68). ⚠️ NEVER AGREED OR CONFIRMED FOR THE GUEST (#52):
843
+ * with what to agree to or confirm and a token - and, where it names an
844
+ * amount or nights, the price and nights the guest was shown - it is the
845
+ * guest's to read and do themselves, nothing ordered; done, 8 is priced again
846
+ * and sent once more with the token. Without both - or asked again after the
847
+ * guest did it - nothing is booked, and the log says which it was.
848
+ */
849
+ const groupAsked = (a, step, data, pairs) => {
850
+ const g = deps.groupOf(a.group);
851
+ const what = `${step}_required`;
852
+ const code = (step === 'terms' ? 'group-terms' : 'group-confirm');
853
+ const asked = groupStepOf(step, data);
854
+ if (asked && !a.groupStep) {
855
+ const off = stepOff(asked, a, pairs);
856
+ const amountOff = off === 'another amount';
857
+ if (off) {
858
+ log(`[otaless] booking at ${a.group} answered ${what} for ${amountOff ? 'another amount' : 'other nights'} than the guest was shown - not shown, not booked`);
859
+ return {
860
+ failed: failedStay(a, `${g.name} asked for ${step === 'terms' ? 'its terms to be agreed to' : 'the booking to be confirmed'} at ${amountOff ? 'another amount' : 'other nights'} than the guest was shown, so nothing was booked or charged.`, code),
861
+ };
862
+ }
863
+ log(`[otaless] booking at ${a.group} answered ${what} with what to ${step === 'terms' ? 'agree to' : 'confirm'} - shown to the guest, nothing ordered`);
864
+ return {
865
+ terms: remember({
866
+ ref: randomBytes(18).toString('base64url'),
867
+ group: a.group,
868
+ ...groupWords(a.group),
869
+ hotelId: a.hotel.id,
870
+ hotelName: a.hotel.name,
871
+ ...(a.hotel.names?.name ? { hotelNames: a.hotel.names.name } : {}),
872
+ roomName: a.roomName,
873
+ stay: a.stay,
874
+ rooms: a.rooms,
875
+ total: a.total,
876
+ text: asked.text,
877
+ source: 'booking',
878
+ more: true,
879
+ askedByGroup: step,
880
+ until: iso(now() + TERMS_MS),
881
+ owner: a.acct.owner,
882
+ key: a.acct.key,
883
+ ask: {
884
+ roomId: a.roomId,
885
+ guest: a.guest,
886
+ roomTerms: a.agreed,
887
+ token: asked.token,
888
+ step,
889
+ },
890
+ }),
891
+ };
892
+ }
893
+ log(a.groupStep
894
+ ? `[otaless] booking at ${a.group} answered ${what} again, after the guest ${step === 'terms' ? 'agreed to its terms' : 'confirmed it'} - not booked`
895
+ : `[otaless] booking at ${a.group} answered ${what} with no ${step === 'terms' ? 'terms' : 'details'} and token to show the guest - not booked (questions #${step === 'terms' ? 66 : 68})`);
896
+ const again = step === 'terms'
897
+ ? `${g.name} asked for its terms to be agreed to again after the guest agreed to them, so nothing was booked or charged.`
898
+ : `${g.name} asked for the booking to be confirmed again after the guest confirmed it, so nothing was booked or charged.`;
899
+ const none = step === 'terms'
900
+ ? `${g.name} asked for terms of its own to be agreed to, which it did not send to be shown here, so nothing was booked or charged.`
901
+ : `${g.name} asked for the booking to be confirmed in a second step, and did not send what to confirm to be shown here, so nothing was booked or charged.`;
902
+ // New codes for the card (酒店平台's next version): until then, these words.
903
+ return { failed: failedStay(a, a.groupStep ? again : none, code) };
904
+ };
657
905
  /**
658
906
  * The terms an order is held back for (总线程 11-11, D): those kept - or,
659
907
  * gone from memory (a restart), the order's own kept again until its time.
660
908
  */
661
909
  const termsOfHeld = (r, acct) => {
662
- if (!r.held || r.released || !r.terms || now() >= Date.parse(r.held.until))
910
+ const confirming = r.held?.step === 'confirm';
911
+ const shown = confirming ? r.confirmText : r.terms;
912
+ if (!r.held || r.released || !shown || now() >= Date.parse(r.held.until))
663
913
  return undefined;
914
+ // Seen in this conversation: its time running out is cancelled with this sign-in.
915
+ if (acct.owner === r.owner)
916
+ heldBy.set(r.id, acct.key);
664
917
  for (const p of pending.values())
665
918
  if (p.orderId === r.id && p.owner === acct.owner && now() <= Date.parse(p.until))
666
919
  return view(p);
@@ -675,10 +928,10 @@ export const createOtalessBookings = (deps) => {
675
928
  stay: r.stay,
676
929
  rooms: r.rooms,
677
930
  total: r.quoted,
678
- text: r.terms,
931
+ text: shown,
679
932
  source: 'booking',
680
933
  more: true,
681
- changed: true,
934
+ ...(confirming ? { askedByGroup: 'confirm' } : { changed: true }),
682
935
  bookingId: r.id,
683
936
  confirmationCode: r.code || r.id,
684
937
  until: r.held.until,
@@ -695,21 +948,32 @@ export const createOtalessBookings = (deps) => {
695
948
  adults: 'guests not as asked',
696
949
  address: 'payment page not accepted',
697
950
  terms: 'terms not agreed by the guest',
951
+ confirm: 'not confirmed by the guest',
952
+ 'confirm-unsent': 'its confirmation cannot be sent back yet',
698
953
  };
954
+ /** Thrown where there is no sign-in at the order's group to cancel it with. */
955
+ class NotSignedIn extends Error {
956
+ name = 'not signed in there';
957
+ }
699
958
  /**
700
959
  * Cancels an order we will not hand on, at once - by 9, the only cancel there
701
960
  * is now. Its payment page goes first, whatever comes back. ⚠️ ONE THAT DOES
702
- * NOT CANCEL NEEDS A PERSON: logged as such, kept, listed - never paid.
961
+ * NOT CANCEL NEEDS A PERSON: logged as such, kept, listed - never paid. So
962
+ * does one with no sign-in to cancel it with (`acct` none - 总线程's review of
963
+ * 0.66.0, 1).
703
964
  */
704
965
  const release = async (acct, who, r, why) => {
705
966
  r.released = why;
706
967
  r.held = undefined;
968
+ heldBy.delete(r.id);
707
969
  payLinks.delete(r.id);
708
970
  for (const [ref, p] of pending)
709
971
  if (p.orderId === r.id)
710
972
  pending.delete(ref);
711
973
  counts.released += 1;
712
974
  try {
975
+ if (!acct)
976
+ throw new NotSignedIn();
713
977
  const done = await withSession(acct, who, (cred) => client.cancelBooking({ unifiedOrderId: r.id, providerCode: r.group, reason: RELEASE_REASON[why] }, cred, deps.callerOf(who)));
714
978
  // Not said to be done - refused, or not known: a person, as any failure here.
715
979
  if (cancelOutcome(done) !== 'done')
@@ -722,6 +986,7 @@ export const createOtalessBookings = (deps) => {
722
986
  catch (err) {
723
987
  r.releaseFailed = true;
724
988
  r.needsPerson = 'release';
989
+ r.needsPersonAt = iso();
725
990
  counts.releaseFailed += 1;
726
991
  log(`[otaless] NEEDS A PERSON: order ${forTheLog(r.id)} at ${r.group} (${why}) could not be cancelled: ${err instanceof Error ? err.name : 'error'}`);
727
992
  put(r);
@@ -734,6 +999,8 @@ export const createOtalessBookings = (deps) => {
734
999
  adults: `${g} took the order for another number of guests than the guest chose`,
735
1000
  address: `${g} sent a payment page on an address this connector does not send guests to`,
736
1001
  terms: `${g} asked for terms of its own to be agreed to when it was ordered, which cannot be shown here`,
1002
+ confirm: `${g} made the order asking for it to be confirmed, with nothing here the guest could confirm as they were shown it`,
1003
+ 'confirm-unsent': `${g} asked for the order to be confirmed first, and that confirmation cannot be sent back from here yet`,
737
1004
  })[why];
738
1005
  /** An order made that is not the one asked for: cancelled at once, and said as it came out. */
739
1006
  const letGo = async (a, r, why) => {
@@ -743,7 +1010,11 @@ export const createOtalessBookings = (deps) => {
743
1010
  return {
744
1011
  failed: failedStay(a, `${releasedWhy(g, why)}, so the order was cancelled at once and nothing was charged.${why === 'price' ? ' Price the trip again.' : ''}`,
745
1012
  // For the card to say in the guest's language (酒店平台 0.66.0, `NoRoomsCode`).
746
- why === 'price' || why === 'amount' ? 'price-changed' : 'order-cancelled'),
1013
+ why === 'price' || why === 'amount'
1014
+ ? 'price-changed'
1015
+ : why === 'confirm-unsent'
1016
+ ? 'group-confirm'
1017
+ : 'order-cancelled'),
747
1018
  };
748
1019
  // ⚠️ SAID AS IT IS: an order stands at the group that is not the one asked
749
1020
  // for - never "not booked". Listed, with no page to pay it on.
@@ -757,29 +1028,55 @@ export const createOtalessBookings = (deps) => {
757
1028
  const t = setTimeout(fn, ms);
758
1029
  t.unref?.();
759
1030
  });
760
- /** A held order's time ran out: cancelled - if the guest is signed in at its group to do it with. */
761
- const lapse = async (id, key) => {
1031
+ /**
1032
+ * The conversation each held order was last seen in, by order id - in memory
1033
+ * only: whose sign-in its time running out is cancelled with.
1034
+ */
1035
+ const heldBy = new Map();
1036
+ /** What a held order is cancelled for when it is not agreed to or confirmed. */
1037
+ const heldFor = (r) => r.held?.step === 'confirm' ? 'confirm' : 'terms';
1038
+ /** A held order whose time ran out - or is past it already (not a number): due. */
1039
+ const heldOver = (r) => !(now() < Date.parse(r.held?.until ?? ''));
1040
+ /**
1041
+ * A held order's time ran out: cancelled with the guest's sign-in at its
1042
+ * group. ⚠️ NOT LEFT STANDING (总线程's review of 0.66.0, 1): not signed in
1043
+ * there now - or not known in whose conversation, after a restart - it
1044
+ * needs a person, said as such on the log, as any order that did not cancel.
1045
+ */
1046
+ const lapse = async (id) => {
762
1047
  const r = orders.get(id);
763
- if (!r?.held || r.released || now() < Date.parse(r.held.until))
1048
+ if (!r?.held || r.released || !heldOver(r))
764
1049
  return;
765
- const who = { sessionId: key };
766
- const acct = accountFor(who, r.group);
767
- if (!acct || acct.owner !== r.owner) {
768
- log(`[otaless] order ${forTheLog(id)} at ${r.group}: its terms were not agreed in time, and the guest is not signed in there to cancel it with - cancelled when they next look`);
769
- return;
770
- }
771
- await release(acct, who, r, 'terms');
1050
+ const key = heldBy.get(id);
1051
+ const who = { sessionId: key ?? '' };
1052
+ const acct = key ? accountFor(who, r.group) : undefined;
1053
+ await release(acct && acct.owner === r.owner ? acct : undefined, who, r, heldFor(r));
1054
+ };
1055
+ /** A held order's time, kept: `lapse` just after it - for whichever conversation saw it last. */
1056
+ const holdFor = (r, key) => {
1057
+ if (key)
1058
+ heldBy.set(r.id, key);
1059
+ const left = Date.parse(r.held?.until ?? '') - now();
1060
+ later(Number.isFinite(left) && left > 0 ? left + 1_000 : 0, () => {
1061
+ lapse(r.id).catch(() => undefined);
1062
+ });
772
1063
  };
773
- /** This guest's held orders whose time ran out - the timer may not have run (a restart): cancelled now. */
1064
+ /** This guest's held orders whose time ran out - before their timer: cancelled now. */
774
1065
  const sweep = async (who) => {
775
1066
  for (const r of [...orders.values()]) {
776
- if (!r.held || r.released || now() < Date.parse(r.held.until))
1067
+ if (!r.held || r.released || !heldOver(r))
777
1068
  continue;
778
1069
  const acct = accountFor(who, r.group);
779
1070
  if (acct && acct.owner === r.owner)
780
- await release(acct, who, r, 'terms');
1071
+ await release(acct, who, r, heldFor(r));
781
1072
  }
782
1073
  };
1074
+ // ⚠️ HELD ORDERS KEPT ACROSS A RESTART (总线程's review of 0.66.0, 1): their
1075
+ // timers went with the process. Each gets its own again - one whose time ran
1076
+ // out while it was down, at once - so none is left standing at its group.
1077
+ for (const r of [...orders.values()])
1078
+ if (r.held && !r.released)
1079
+ holdFor(r);
783
1080
  /** What 8 answered, settled: an order to hand on, one held for new terms, or none. */
784
1081
  const settle = async (a, w, pairs) => {
785
1082
  const g = deps.groupOf(a.group);
@@ -797,13 +1094,10 @@ export const createOtalessBookings = (deps) => {
797
1094
  };
798
1095
  }
799
1096
  if (!id) {
800
- // Terms of its own to agree to, and no order: 8 has nothing to send them back with.
801
- if (/TERMS/.test(status)) {
802
- log(`[otaless] booking at ${a.group} asked for terms (${forTheLog(status)}) - not booked`);
803
- return {
804
- failed: failedStay(a, `${g.name} asked for terms of its own to be agreed to, which cannot be shown here, so nothing was booked or charged.`),
805
- };
806
- }
1097
+ // Terms of its own to agree to, and no order (questions #66).
1098
+ const step = /TERMS/.test(status) ? 'terms' : stepAsked(status);
1099
+ if (step)
1100
+ return groupAsked(a, step, w, pairs);
807
1101
  // Something may be held, under a number we were not told: kept to look for (12).
808
1102
  const r = recordOf(a, pairs, `pending:${randomBytes(8).toString('hex')}`, '', 'unconfirmed');
809
1103
  put(r);
@@ -819,9 +1113,11 @@ export const createOtalessBookings = (deps) => {
819
1113
  const charged = moneyOf(w.totalAmount, w.currency);
820
1114
  if (charged)
821
1115
  r.charged = charged;
822
- if (/TERMS/.test(status)) {
823
- log(`[otaless] booking at ${a.group} made ${forTheLog(id)} asking for terms - cancelled`);
824
- return letGo(a, r, 'terms');
1116
+ // A step the group asks for, the order made (questions #66, #68).
1117
+ const step = /TERMS/.test(status) ? 'terms' : stepAsked(status);
1118
+ if (step && !deps.proceedWithoutGroupConfirm) {
1119
+ log(`[otaless] booking at ${a.group} made ${forTheLog(id)} asking for ${step === 'terms' ? 'terms' : 'it to be confirmed'} - cancelled (questions #${step === 'terms' ? 66 : 68}; proceedWithoutGroupConfirm off)`);
1120
+ return letGo(a, r, step === 'terms' ? 'terms' : 'confirm-unsent');
825
1121
  }
826
1122
  // ── the amount (总线程 11-10, 12.9 #2): either of this quote's two, to the cent ──
827
1123
  if (!charged || !(same(charged, pairs.orig) || same(charged, pairs.usd))) {
@@ -836,10 +1132,15 @@ export const createOtalessBookings = (deps) => {
836
1132
  }
837
1133
  // ── the payment page (总线程 11-10, rule 5; 11-11, B) ──
838
1134
  if (page) {
839
- const ok = payPageOf(page, deps.checkoutHosts, id);
1135
+ const ok = payPageOf(page, deps.checkoutHosts, { id, code });
840
1136
  if (!ok) {
841
- // ⚠️ ITS HOST AND PATH ON THE LOG (总线程 11-11, B) - never its query.
842
- log(`[otaless] booking at ${a.group} sent a payment page on ${pageForLog(page)}, not on the list or not this order's - cancelled`);
1137
+ // ⚠️ ITS HOST ALONE ON THE LOG (总线程's review of 0.66.0, 4) - never its
1138
+ // path or query: either may carry a payment token.
1139
+ log(`[otaless] booking at ${a.group} sent a payment page on ${hostForLog(page)}, not on the list or not this order's - cancelled`);
1140
+ // On a host listed: its shape, no value (总线程 11-11 late) - to write
1141
+ // the exact `{order}` entry from the first real one.
1142
+ if (onListedHost(page, deps.checkoutHosts))
1143
+ log(`[otaless] that page's shape: ${pageShape(page, { id, code })}`);
843
1144
  return letGo(a, r, 'address');
844
1145
  }
845
1146
  r.payHost = ok.host;
@@ -855,17 +1156,55 @@ export const createOtalessBookings = (deps) => {
855
1156
  log(`[otaless] booking at ${a.group} came with terms too long to show - cancelled`);
856
1157
  return letGo(a, r, 'terms');
857
1158
  }
858
- if (said && termsKey(said) !== termsKey(a.agreed)) {
1159
+ // ── a step the group asks for, the order made (proceedWithoutGroupConfirm) ──
1160
+ // Checked as any order above. ⚠️ WHAT IT SENT TO AGREE TO OR CONFIRM IS THE
1161
+ // GUEST'S (总线程's review of 0.67.0, 2): its page held back until they do -
1162
+ // not, or not in time, cancelled (9). Nothing sent: handed on (robin 11-12),
1163
+ // and the booking says the step could not be sent back.
1164
+ if (step) {
1165
+ const asked = groupStepOf(step, w);
1166
+ const q = step === 'terms' ? 66 : 68;
1167
+ if (asked) {
1168
+ const off = stepOff(asked, a, pairs);
1169
+ const other = !!said &&
1170
+ termsKey(said) !== termsKey(a.agreed) &&
1171
+ (step === 'confirm' || termsKey(said) !== termsKey(asked.text));
1172
+ if (off || other) {
1173
+ log(`[otaless] booking ${forTheLog(id)} at ${a.group} answered ${step}_required ${off ? `for ${off} than the guest was shown` : 'and came with other terms too'} - cancelled (questions #${q})`);
1174
+ return letGo(a, r, other ? 'terms' : step === 'confirm' ? 'confirm' : 'terms');
1175
+ }
1176
+ if (step === 'confirm') {
1177
+ if (said)
1178
+ r.terms = said;
1179
+ r.confirmText = asked.text;
1180
+ r.held = { until: iso(now() + TERMS_MS), step: 'confirm' };
1181
+ }
1182
+ else {
1183
+ r.terms = asked.text;
1184
+ r.termsNew = true;
1185
+ r.held = { until: iso(now() + TERMS_MS) };
1186
+ }
1187
+ put(r);
1188
+ log(`[otaless] booking ${forTheLog(id)} at ${a.group} answered ${step}_required with what to ${step === 'terms' ? 'agree to' : 'confirm'} - its payment page held back for the guest (questions #${q})`);
1189
+ holdFor(r, a.acct.key);
1190
+ const t = termsOfHeld(r, a.acct);
1191
+ return t ? { terms: t } : { booked: toBooking(r) };
1192
+ }
1193
+ r.stepUnsent = step;
1194
+ log(`[otaless] booking ${forTheLog(id)} at ${a.group} answered ${step}_required with nothing to ${step === 'terms' ? 'agree to' : 'confirm'} and no token - handed on with its order, the checks passed (proceedWithoutGroupConfirm; questions #${q})`);
1195
+ }
1196
+ if (said &&
1197
+ termsKey(said) !== termsKey(a.agreed) &&
1198
+ !(a.groupStep?.step === 'terms' && termsKey(said) === termsKey(a.groupStep.text))) {
859
1199
  // ⚠️ NOT THE TERMS AGREED TO: the order stands, its payment page is held
860
1200
  // back until the guest agrees to these too - not agreed, or not in time,
861
1201
  // it is cancelled.
862
1202
  r.terms = said;
1203
+ r.termsNew = true;
863
1204
  r.held = { until: iso(now() + TERMS_MS) };
864
1205
  put(r);
865
1206
  log(`[otaless] booking ${forTheLog(id)} at ${a.group} came with other terms than the guest agreed to - its payment page held back`);
866
- later(TERMS_MS + 1_000, () => {
867
- lapse(id, a.acct.key).catch(() => undefined);
868
- });
1207
+ holdFor(r, a.acct.key);
869
1208
  const t = termsOfHeld(r, a.acct);
870
1209
  return t ? { terms: t } : { booked: toBooking(r) };
871
1210
  }
@@ -927,6 +1266,13 @@ export const createOtalessBookings = (deps) => {
927
1266
  checkIn: a.stay.checkIn,
928
1267
  checkOut: a.stay.checkOut,
929
1268
  roomCount: a.rooms,
1269
+ // Only after the guest agreed to the terms 8 asked for (questions #66).
1270
+ ...(a.groupStep?.step === 'terms'
1271
+ ? { termsToken: a.groupStep.token, termsAccepted: true }
1272
+ : {}),
1273
+ ...(a.groupStep?.step === 'confirm'
1274
+ ? { confirmToken: a.groupStep.token, confirmed: true }
1275
+ : {}),
930
1276
  };
931
1277
  let booked;
932
1278
  try {
@@ -961,6 +1307,10 @@ export const createOtalessBookings = (deps) => {
961
1307
  put(r);
962
1308
  return { booked: toBooking(r) };
963
1309
  }
1310
+ // ⚠️ 8 REFUSED FOR TERMS (robin 11-11 18:30, Ascott: code 500 "terms_required").
1311
+ const step = err === fromBook && err instanceof OtalessError ? stepAsked(err.answer?.msg) : undefined;
1312
+ if (step)
1313
+ return groupAsked(a, step, err instanceof OtalessError ? err.answer?.data : undefined, pairs ?? { orig: a.total });
964
1314
  if (err instanceof OtalessError)
965
1315
  return {
966
1316
  failed: failedStay(a, `${g.name} did not take the booking, so nothing was booked or charged.`),
@@ -999,7 +1349,25 @@ export const createOtalessBookings = (deps) => {
999
1349
  o.stay.checkOut === stay.checkOut &&
1000
1350
  o.rooms === rooms;
1001
1351
  // A person's: said paid at another amount, or cancelled at once and not undone.
1002
- const person = [...orders.values()].find((o) => sameStay(o) && o.needsPerson);
1352
+ const people = [...orders.values()].filter((o) => sameStay(o) && o.needsPerson && !o.rebookable);
1353
+ // ⚠️ THE WAY OUT (总线程's review of 0.66.0, 6), as for an order that could
1354
+ // not be verified: with a person this long and still not settled, the stay
1355
+ // is no longer held back. The guest is told first, as it is - it may stand
1356
+ // at the group, check there; asked again, a new booking is made.
1357
+ if (people.length &&
1358
+ people.every((o) => now() - Date.parse(o.needsPersonAt ?? o.createdAt) >= NEEDS_PERSON_GIVE_UP_MS)) {
1359
+ for (const o of people) {
1360
+ o.rebookable = true;
1361
+ put(o);
1362
+ }
1363
+ log(`[otaless] ${people.length} order(s) at ${group} still with a person after ${NEEDS_PERSON_GIVE_UP_MS / 3_600_000}h - the stay is no longer held back`);
1364
+ return {
1365
+ failed: failedStay(label, `An earlier booking of this stay is still with a person to sort out with ${name}, and it may stand there: the guest should check with ${name} before booking it again. Nothing new was booked this time - asked again, a new booking is made.`,
1366
+ // New for the card (酒店平台's next version): until then, these words.
1367
+ 'earlier-needs-person-overdue'),
1368
+ };
1369
+ }
1370
+ const person = people[0];
1003
1371
  if (person)
1004
1372
  return {
1005
1373
  failed: failedStay(label, person.needsPerson === 'release'
@@ -1156,8 +1524,7 @@ export const createOtalessBookings = (deps) => {
1156
1524
  failed.push(failedStay(label, `${deps.groupOf(group).name}'s terms for this room are too long to show in full here, so nothing was booked.`));
1157
1525
  continue;
1158
1526
  }
1159
- // ⚠️ NOTHING IS ORDERED YET (§15.1): the terms first, for the guest to agree to.
1160
- terms.push(termsBefore({
1527
+ const ask = {
1161
1528
  acct,
1162
1529
  who,
1163
1530
  hotel,
@@ -1169,7 +1536,27 @@ export const createOtalessBookings = (deps) => {
1169
1536
  agreed,
1170
1537
  guest: g0,
1171
1538
  total: line.total,
1172
- }));
1539
+ };
1540
+ // No terms for this room to agree to, and the deployment lets that go on
1541
+ // (robin 11-12 「条款没有也让走下一步」): ordered now - said on the booking.
1542
+ if (!agreed && deps.proceedWithoutGroupConfirm) {
1543
+ inFlight.add(lockKey);
1544
+ try {
1545
+ const out = await place({ ...ask, noTerms: true });
1546
+ if (out.booked)
1547
+ booked.push(out.booked);
1548
+ if (out.failed)
1549
+ failed.push(out.failed);
1550
+ if (out.terms)
1551
+ terms.push(out.terms);
1552
+ }
1553
+ finally {
1554
+ inFlight.delete(lockKey);
1555
+ }
1556
+ continue;
1557
+ }
1558
+ // ⚠️ NOTHING IS ORDERED YET (§15.1): the terms first, for the guest to agree to.
1559
+ terms.push(termsBefore(ask));
1173
1560
  }
1174
1561
  return {
1175
1562
  booked,
@@ -1211,9 +1598,13 @@ export const createOtalessBookings = (deps) => {
1211
1598
  const r = orders.get(p.orderId);
1212
1599
  if (!r || r.owner !== acct.owner || r.released || !r.held)
1213
1600
  throw termsGone();
1601
+ const confirming = r.held.step === 'confirm';
1214
1602
  r.held = undefined;
1603
+ r.termsNew = undefined;
1215
1604
  put(r);
1216
- log(`[otaless] the guest agreed to the terms ${r.group} answered ${forTheLog(r.id)} with - its payment page handed on`);
1605
+ log(confirming
1606
+ ? `[otaless] the guest confirmed what ${r.group} asked to confirm for ${forTheLog(r.id)} - its payment page handed on (its token is not sent back: 8 has no way to for an order made - questions #68)`
1607
+ : `[otaless] the guest agreed to the terms ${r.group} answered ${forTheLog(r.id)} with - its payment page handed on`);
1217
1608
  return { booked: [toBooking(r)], failed: [] };
1218
1609
  }
1219
1610
  const ask = p.ask;
@@ -1246,7 +1637,11 @@ export const createOtalessBookings = (deps) => {
1246
1637
  roomName: p.roomName,
1247
1638
  stay: p.stay,
1248
1639
  rooms: p.rooms,
1249
- agreed: p.text,
1640
+ // A step 8 asked for (questions #66, #68): the room's terms were agreed first; this now.
1641
+ agreed: ask.token ? (ask.roomTerms ?? '') : p.text,
1642
+ ...(ask.token
1643
+ ? { groupStep: { step: ask.step ?? 'terms', text: p.text, token: ask.token } }
1644
+ : {}),
1250
1645
  guest: ask.guest,
1251
1646
  total: p.total,
1252
1647
  });
@@ -1271,8 +1666,8 @@ export const createOtalessBookings = (deps) => {
1271
1666
  const r = orders.get(p.orderId);
1272
1667
  if (!r || r.owner !== acct.owner || r.released || !r.held)
1273
1668
  return {};
1274
- // ⚠️ NOT AGREED: the order it held back is cancelled (总线程 11-11, D).
1275
- await release(acct, who, r, 'terms');
1669
+ // ⚠️ NOT AGREED - OR NOT CONFIRMED: the order it held back is cancelled (总线程 11-11, D).
1670
+ await release(acct, who, r, heldFor(r));
1276
1671
  return { booking: toBooking(r) };
1277
1672
  };
1278
1673
  // ── the bookings, refreshed ───────────────────────────────────────────────
@@ -1317,6 +1712,7 @@ export const createOtalessBookings = (deps) => {
1317
1712
  if (paid) {
1318
1713
  if (amount && !asked(amount, r)) {
1319
1714
  r.needsPerson = 'paid-amount';
1715
+ r.needsPersonAt = iso();
1320
1716
  payLinks.delete(r.id);
1321
1717
  put(r);
1322
1718
  log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${r.group} paid ${amount.currency} ${amount.minor}, not what was asked - not taken as paid`);
@@ -1384,6 +1780,7 @@ export const createOtalessBookings = (deps) => {
1384
1780
  const amount = moneyOf(row.totalAmount, row.currency);
1385
1781
  if (!amount || !asked(amount, r)) {
1386
1782
  r.needsPerson = 'paid-amount';
1783
+ r.needsPersonAt = iso();
1387
1784
  payLinks.delete(r.id);
1388
1785
  put(r);
1389
1786
  log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${group} is listed PAID at ${amount ? `${amount.currency} ${amount.minor}` : 'no amount'}, not what was asked - not taken as paid`);
@@ -1406,7 +1803,10 @@ export const createOtalessBookings = (deps) => {
1406
1803
  };
1407
1804
  if (r.status === 'awaiting-payment' && !payLinks.has(r.id)) {
1408
1805
  // Held to this order's own page where the list says so (11-11, B).
1409
- const ok = payPageOf(text(row.checkoutUrl ?? undefined), deps.checkoutHosts, r.id);
1806
+ const ok = payPageOf(text(row.checkoutUrl ?? undefined), deps.checkoutHosts, {
1807
+ id: r.id,
1808
+ code: r.code,
1809
+ });
1410
1810
  if (ok)
1411
1811
  payLinks.set(r.id, ok.url);
1412
1812
  }
@@ -1448,7 +1848,10 @@ export const createOtalessBookings = (deps) => {
1448
1848
  continue;
1449
1849
  }
1450
1850
  const s = statusOfRow(row.status);
1451
- const ok = payPageOf(text(row.checkoutUrl ?? undefined), deps.checkoutHosts, id);
1851
+ const ok = payPageOf(text(row.checkoutUrl ?? undefined), deps.checkoutHosts, {
1852
+ id,
1853
+ code: text(row.originalOrderId),
1854
+ });
1452
1855
  orders.delete(o.id);
1453
1856
  o.id = id;
1454
1857
  o.code = text(row.originalOrderId) ?? '';
@@ -1559,6 +1962,19 @@ export const createOtalessBookings = (deps) => {
1559
1962
  cancellable: true,
1560
1963
  reason: 'unpaid',
1561
1964
  };
1965
+ // ⚠️ TERMS THE GUEST HAS NOT AGREED TO ARE NOT SAID HERE (总线程's review of
1966
+ // 0.67.0, 1): only that they are not the ones shown before - their words are
1967
+ // on the card and the one-time page.
1968
+ if (r.termsNew)
1969
+ return {
1970
+ ...base,
1971
+ fee: amount,
1972
+ refund: money(0, amount.currency),
1973
+ rule: `The cancellation terms ${g} answered this booking with are not the ones the guest saw before, and the guest has not agreed to them - they are on the card or the one-time page, not here. ${g} says what it keeps when it cancels.`,
1974
+ cancellable: true,
1975
+ feeIsCap: true,
1976
+ feeUnknown: true,
1977
+ };
1562
1978
  // ⚠️ THE GROUP'S OWN TERMS, AS THEY CAME; ONLY WITHOUT THEM THE CAP
1563
1979
  // (总线程 11-10). There is no dry run: what is kept is the group's to say
1564
1980
  // when it cancels - the fee here is the most it could be.
@@ -1648,7 +2064,7 @@ export const createOtalessBookings = (deps) => {
1648
2064
  amount,
1649
2065
  fromPayment: !!r.paidAmount,
1650
2066
  groupDecides: true,
1651
- terms: r.terms ?? '',
2067
+ terms: r.termsNew ? '' : (r.terms ?? ''),
1652
2068
  until: iso(now() + REFUND_PREVIEW_MS),
1653
2069
  };
1654
2070
  };
@@ -1785,6 +2201,8 @@ export const createOtalessBookings = (deps) => {
1785
2201
  .length,
1786
2202
  ordersUnconfirmed: [...orders.values()].filter((o) => o.status === 'unconfirmed').length,
1787
2203
  ordersHeld: [...orders.values()].filter((o) => o.held && !o.released).length,
2204
+ // ⚠️ CHECK AFTER A DEPLOY: 1 on the dev backend's alone (总线程 11-12).
2205
+ proceedWithoutGroupConfirm: deps.proceedWithoutGroupConfirm ? 1 : 0,
1788
2206
  groupSessions: sessions.size,
1789
2207
  termsWaiting: pending.size,
1790
2208
  ...counts,