@curless/hotel-storefront 0.65.2 → 0.66.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account/fake-ota.d.ts +5 -0
- package/dist/account/fake-ota.d.ts.map +1 -1
- package/dist/account/fake-ota.js +6 -2
- package/dist/account/fake-ota.js.map +1 -1
- package/dist/account/index.d.ts +20 -0
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/index.js +155 -20
- package/dist/account/index.js.map +1 -1
- package/dist/account/pages.d.ts +40 -5
- package/dist/account/pages.d.ts.map +1 -1
- package/dist/account/pages.js +106 -20
- package/dist/account/pages.js.map +1 -1
- package/dist/account/requests.d.ts +2 -0
- package/dist/account/requests.d.ts.map +1 -1
- package/dist/account/requests.js.map +1 -1
- package/dist/account/store.d.ts +19 -1
- package/dist/account/store.d.ts.map +1 -1
- package/dist/account/store.js +20 -3
- package/dist/account/store.js.map +1 -1
- package/dist/card.generated.d.ts +1 -1
- package/dist/card.generated.js +2 -2
- package/dist/card.generated.js.map +1 -1
- package/dist/otaless/backend.d.ts +4 -2
- package/dist/otaless/backend.d.ts.map +1 -1
- package/dist/otaless/backend.js +17 -4
- package/dist/otaless/backend.js.map +1 -1
- package/dist/otaless/booking.d.ts +117 -28
- package/dist/otaless/booking.d.ts.map +1 -1
- package/dist/otaless/booking.js +621 -378
- package/dist/otaless/booking.js.map +1 -1
- package/dist/otaless/client.d.ts +37 -27
- package/dist/otaless/client.d.ts.map +1 -1
- package/dist/otaless/client.js +16 -6
- package/dist/otaless/client.js.map +1 -1
- package/dist/otaless/fake.d.ts +25 -13
- package/dist/otaless/fake.d.ts.map +1 -1
- package/dist/otaless/fake.js +47 -30
- package/dist/otaless/fake.js.map +1 -1
- package/dist/otaless/make.d.ts.map +1 -1
- package/dist/otaless/make.js +27 -15
- package/dist/otaless/make.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +22 -2
- package/dist/server.js.map +1 -1
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +4 -2
- package/dist/surface.js.map +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +71 -11
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +43 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/otaless/booking.js
CHANGED
|
@@ -6,19 +6,28 @@ import { movedSince } from '../huazhu/backend.js';
|
|
|
6
6
|
import { money, toMinor } from '../money.js';
|
|
7
7
|
import { CHANNEL_SESSION_EXPIRED, NOT_SIGNED_IN, OtalessBusy, OtalessError, REPEAT_SUBMIT, SESSION_ID, forTheLog, } from './client.js';
|
|
8
8
|
// Booking on the Otaless hotel backend: items 8-16 of its document of
|
|
9
|
-
// 2026-11-10
|
|
10
|
-
//
|
|
9
|
+
// 2026-11-10. Since 2026-11-11 the order is 8 `booking/create` - the backend's
|
|
10
|
+
// own answer to questions #56: 「booking/create 就行,checkout 所有的 api 不需要」
|
|
11
|
+
// (13 / 14 are not called any more) - as 总线程 settled it that day
|
|
12
|
+
// (docs/otaless-hotels.md §15, with 15.7 over the rest). Real money - written
|
|
13
|
+
// to production's standard. 8 holds no price and takes no "do not agree", so
|
|
14
|
+
// both are held here:
|
|
11
15
|
//
|
|
12
|
-
// -
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
16
|
+
// - TERMS FIRST, AGREED BY THE GUEST: every stay's cancellation terms - as the
|
|
17
|
+
// group sent them with the room, word for word - are shown before anything
|
|
18
|
+
// is ordered, and 8 is called only once the guest agreed on the card's own
|
|
19
|
+
// button or the one-time page (`acceptTerms`), never on the model's word.
|
|
20
|
+
// Terms the group answers the order with that are not the ones agreed hold
|
|
21
|
+
// the order's payment page back until the guest agrees to them too; not
|
|
22
|
+
// agreed, or not in `TERMS_MS`, the order is cancelled (9).
|
|
23
|
+
// - THE PRICE THE GUEST SAW, OR NOTHING: right before 8 the room is priced
|
|
24
|
+
// again (7) in the guest's own session - the one 8 then runs in (questions
|
|
25
|
+
// #62) - and held to the price the guest was shown; 8's own amount is then
|
|
26
|
+
// held to that quote, and an order at any other amount, for any other
|
|
27
|
+
// number of guests, or with a payment page not on the list is cancelled at
|
|
28
|
+
// once (9). One that cannot be cancelled is a person's, and said so.
|
|
29
|
+
// - A PAYMENT PAGE ON AN ADDRESS NOT LISTED IS NEVER HANDED ON - and a page
|
|
30
|
+
// listed with its order (`?order={order}`) only for that very order.
|
|
22
31
|
// - AN ORDER IS ACTED ON ONLY IF IT IS IN OUR OWN RECORD, as this guest's
|
|
23
32
|
// (their sign-in's member id): the id sent to the backend is the record's,
|
|
24
33
|
// never the model's.
|
|
@@ -26,19 +35,24 @@ import { CHANNEL_SESSION_EXPIRED, NOT_SIGNED_IN, OtalessBusy, OtalessError, REPE
|
|
|
26
35
|
// backend's own `/ota/sign-in`, its `accessToken` and `mcpSessionId` -
|
|
27
36
|
// `bookingAuth`), never kept here; a session this connector opens after a
|
|
28
37
|
// 4012 is kept by sign-in and group, in memory only. A 4012 is answered
|
|
29
|
-
// with one new handshake and one more try - never a loop.
|
|
38
|
+
// with one new handshake and one more try - never a loop. An order not
|
|
39
|
+
// answered for is never asked for again.
|
|
30
40
|
//
|
|
31
41
|
// ⚠️ NOTHING HERE IS REACHED UNLESS THE DEPLOYMENT TURNS BOOKING ON
|
|
32
42
|
// (`data.otaless.booking`, 酒店平台 0.63.0; robin 11-10 「我们要跑通测试流程的」):
|
|
33
43
|
// read-only - the default - the tools that would call it are not offered.
|
|
34
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* How long terms are kept for the guest to agree to (§12.1) - and how long an
|
|
46
|
+
* order whose terms changed holds its payment page back before it is
|
|
47
|
+
* cancelled (总线程 11-11, D).
|
|
48
|
+
*/
|
|
35
49
|
export const TERMS_MS = 10 * 60_000;
|
|
36
50
|
/** How long a group's `Mcp-Session-Id` is kept unused (§12.3). */
|
|
37
51
|
export const SESSION_IDLE_MS = 2 * 60 * 60_000;
|
|
38
52
|
/** A payment's status is asked for at most this often per order (§12.1, 15). */
|
|
39
53
|
export const STATUS_EVERY_MS = 10_000;
|
|
40
54
|
/**
|
|
41
|
-
* An order
|
|
55
|
+
* An order 8 did not answer for, not found in the group's list this long
|
|
42
56
|
* after it was asked for - and nothing there that could be it - no longer holds
|
|
43
57
|
* the stay back (总线程's re-review of 0.63.1, 1). Eight times the 15 minutes
|
|
44
58
|
* the document's checkout holds a room unpaid.
|
|
@@ -79,11 +93,14 @@ const PENDING_PER_ACCOUNT = 5;
|
|
|
79
93
|
const CHECKED_PER_LOOK = 5;
|
|
80
94
|
/**
|
|
81
95
|
* The payment pages a guest may be sent to, until a deployment says otherwise:
|
|
82
|
-
* the group checkout host of 13's
|
|
83
|
-
*
|
|
84
|
-
* re-review of 0.63.1, 720f5e4f): that is our own hosted
|
|
85
|
-
* any merchant and any amount
|
|
86
|
-
*
|
|
96
|
+
* the group checkout host of 13's example (`pay.discoverasr.com`). Exact host
|
|
97
|
+
* names: no wildcard, no other port. ⚠️ NOT `mcp.curless.ai` (总线程's
|
|
98
|
+
* re-review of 0.63.1, 720f5e4f; again 11-11, B): that is our own hosted
|
|
99
|
+
* checkout, which takes any merchant and any amount, and has no `/pay/cashier`
|
|
100
|
+
* 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`).
|
|
87
104
|
*/
|
|
88
105
|
export const DEFAULT_CHECKOUT_HOSTS = ['pay.discoverasr.com'];
|
|
89
106
|
/** How long a refund's preview can be sent back (总线程's review of 0.63.0, B). */
|
|
@@ -129,24 +146,57 @@ export const pathSegments = (path) => {
|
|
|
129
146
|
}
|
|
130
147
|
return out;
|
|
131
148
|
};
|
|
132
|
-
/**
|
|
149
|
+
/**
|
|
150
|
+
* One `checkoutHosts` entry: a host; a host and the path a page must be under
|
|
151
|
+
* (`host/a/b/`); or a host, the exact path and the one query parameter that
|
|
152
|
+
* must name the order (`host/a/b?order={order}` - `order` is the parameter's
|
|
153
|
+
* name, 总线程 11-11, B). A malformed path or query matches nothing.
|
|
154
|
+
*/
|
|
133
155
|
export const checkoutEntryOf = (entry) => {
|
|
134
156
|
const e = entry.trim();
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
|
|
157
|
+
const q = e.indexOf('?');
|
|
158
|
+
const left = q < 0 ? e : e.slice(0, q);
|
|
159
|
+
const slash = left.indexOf('/');
|
|
160
|
+
const host = (slash < 0 ? left : left.slice(0, slash)).toLowerCase();
|
|
161
|
+
const under = slash < 0 ? [] : (pathSegments(left.slice(slash)) ?? ['\u0000']);
|
|
162
|
+
if (q < 0)
|
|
163
|
+
return { host, under };
|
|
164
|
+
const m = /^([A-Za-z0-9_.~-]+)=\{order\}$/.exec(e.slice(q + 1));
|
|
165
|
+
return { host, under: under.length ? under : ['\u0000'], order: m?.[1] ?? '\u0000' };
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* What is wrong with a list of payment pages, or nothing: ⚠️ A HOST LISTED
|
|
169
|
+
* WITH ITS ORDER (`?order={order}`) IS LISTED NO WIDER (总线程 11-11, B) - no
|
|
170
|
+
* entry of it alone, or of a path a page is under, beside it: that would let
|
|
171
|
+
* any page there through. Entries naming the order are not wider than each other.
|
|
172
|
+
*/
|
|
173
|
+
export const checkoutHostsProblem = (hosts) => {
|
|
174
|
+
const entries = hosts.map((h) => ({ h, e: checkoutEntryOf(h) }));
|
|
175
|
+
for (const { h, e } of entries) {
|
|
176
|
+
if (e.order === undefined)
|
|
177
|
+
continue;
|
|
178
|
+
const wider = entries.find((x) => x.e.host === e.host && x.e.order === undefined);
|
|
179
|
+
if (wider)
|
|
180
|
+
return `"${wider.h}" lets any page on ${e.host} through beside "${h}", which takes only the order's own page`;
|
|
181
|
+
}
|
|
182
|
+
return undefined;
|
|
139
183
|
};
|
|
140
184
|
/**
|
|
141
185
|
* Where a payment page may send the guest: `https:`, an exact host on the
|
|
142
186
|
* list, no other port, no user in it - or nothing (总线程 11-10). An entry
|
|
143
|
-
* written with a path (`
|
|
144
|
-
*
|
|
187
|
+
* written with a path (`host/pay/`) also holds it to that path, by whole
|
|
188
|
+
* segments, compared after the path is put the way a server reads it
|
|
145
189
|
* (`pathSegments`: no `..`, `%2e` or `//` slips past); an entry of a host alone
|
|
146
190
|
* takes any path on it (总线程's review of 0.63.0, 8). The page handed on is
|
|
147
191
|
* the one checked: its path as compared.
|
|
192
|
+
*
|
|
193
|
+
* ⚠️ AN ENTRY NAMING THE ORDER (`host/pay/cashier?order={order}`, 总线程
|
|
194
|
+
* 11-11, B) TAKES ONE PAGE: that path exactly, and a query of that one
|
|
195
|
+
* parameter, once, naming `order` - this very order's `unifiedOrderId` - and
|
|
196
|
+
* no fragment. What is handed on is rebuilt from the entry and the order, never
|
|
197
|
+
* the backend's own string. No order to hold it to: nothing.
|
|
148
198
|
*/
|
|
149
|
-
export const payPageOf = (raw, hosts) => {
|
|
199
|
+
export const payPageOf = (raw, hosts, order) => {
|
|
150
200
|
if (!raw)
|
|
151
201
|
return undefined;
|
|
152
202
|
let u;
|
|
@@ -162,35 +212,46 @@ export const payPageOf = (raw, hosts) => {
|
|
|
162
212
|
const segs = pathSegments(u.pathname);
|
|
163
213
|
if (!segs)
|
|
164
214
|
return undefined;
|
|
165
|
-
const
|
|
215
|
+
for (const h of hosts) {
|
|
166
216
|
const e = checkoutEntryOf(h);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
217
|
+
if (e.host !== host || !e.under.every((seg, i) => segs[i] === seg))
|
|
218
|
+
continue;
|
|
219
|
+
if (e.order === undefined) {
|
|
220
|
+
u.pathname = `/${segs.join('/')}${segs.length && u.pathname.endsWith('/') ? '/' : ''}`;
|
|
221
|
+
return { url: u.toString(), host };
|
|
222
|
+
}
|
|
223
|
+
if (!order || segs.length !== e.under.length || u.hash)
|
|
224
|
+
continue;
|
|
225
|
+
const keys = [...u.searchParams.keys()];
|
|
226
|
+
if (keys.length !== 1 || keys[0] !== e.order || u.searchParams.get(e.order) !== order)
|
|
227
|
+
continue;
|
|
228
|
+
return {
|
|
229
|
+
url: `https://${host}/${e.under.join('/')}?${e.order}=${encodeURIComponent(order)}`,
|
|
230
|
+
host,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
return undefined;
|
|
173
234
|
};
|
|
174
|
-
/**
|
|
175
|
-
|
|
235
|
+
/**
|
|
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.
|
|
238
|
+
*/
|
|
239
|
+
const pageForLog = (raw) => {
|
|
176
240
|
try {
|
|
177
|
-
|
|
241
|
+
const u = new URL(String(raw));
|
|
242
|
+
return forTheLog(`${u.host}${u.pathname}`) || '?';
|
|
178
243
|
}
|
|
179
244
|
catch {
|
|
180
245
|
return 'not a URL';
|
|
181
246
|
}
|
|
182
247
|
};
|
|
183
|
-
/** The first of `keys` in `o` that is words - the terms' text and token under whatever name the group's tool gave them. */
|
|
184
|
-
const firstText = (o, keys) => {
|
|
185
|
-
for (const k of keys) {
|
|
186
|
-
const v = o?.[k];
|
|
187
|
-
if (typeof v === 'string' && v.trim())
|
|
188
|
-
return v;
|
|
189
|
-
}
|
|
190
|
-
return undefined;
|
|
191
|
-
};
|
|
192
248
|
/**
|
|
193
|
-
*
|
|
249
|
+
* Two terms the same but for spacing and punctuation (总线程 11-11, D): a
|
|
250
|
+
* group's answer formatted a little differently is not new terms to agree to.
|
|
251
|
+
*/
|
|
252
|
+
export const termsKey = (s) => s.normalize('NFKC').replace(/[\s\p{P}]/gu, '');
|
|
253
|
+
/**
|
|
254
|
+
* The statuses a cancellation (9 `booking/cancel`; 14 `checkout/cancel` before 11-11) is
|
|
194
255
|
* taken as DONE by - exactly these, case aside (总线程's review of 0.63.0, 4):
|
|
195
256
|
* the document's own words ("CANCELLED"; 14's "CANCELLED", "SUCCESS") and
|
|
196
257
|
* their spelling variants. ⚠️ NOT A PATTERN: /CANCEL|CLOSED|SUCCESS/ took
|
|
@@ -219,8 +280,6 @@ export const cancelOutcome = (out) => {
|
|
|
219
280
|
return 'unknown';
|
|
220
281
|
return CANCELLED_STATUSES.has(s) ? 'done' : 'refused';
|
|
221
282
|
};
|
|
222
|
-
const TERMS_TEXT_KEYS = ['terms', 'terms_text', 'termsText', 'terms_content', 'termsContent'];
|
|
223
|
-
const TERMS_TOKEN_KEYS = ['terms_token', 'termsToken'];
|
|
224
283
|
const isCode = (err, code) => err instanceof OtalessError && !(err instanceof OtalessBusy) && err.backendCode === code;
|
|
225
284
|
/**
|
|
226
285
|
* Sent, and no answer it could be read by: whether it was done is not known -
|
|
@@ -437,8 +496,9 @@ export const createOtalessBookings = (deps) => {
|
|
|
437
496
|
if (r.paid)
|
|
438
497
|
return { method: 'card', amount, status: 'paid' };
|
|
439
498
|
if (r.status === 'awaiting-payment') {
|
|
440
|
-
// ⚠️ NO LINK PAST ITS TIME: a page that cannot be paid any more is not handed on
|
|
441
|
-
|
|
499
|
+
// ⚠️ NO LINK PAST ITS TIME: a page that cannot be paid any more is not handed on -
|
|
500
|
+
// nor one held back for terms not agreed to yet (总线程 11-11, D).
|
|
501
|
+
const url = !r.held && now() < payableUntil(r) ? payLinks.get(r.id) : undefined;
|
|
442
502
|
return {
|
|
443
503
|
method: 'card',
|
|
444
504
|
amount,
|
|
@@ -492,8 +552,9 @@ export const createOtalessBookings = (deps) => {
|
|
|
492
552
|
},
|
|
493
553
|
...(r.cancelledAt ? { cancelledAt: r.cancelledAt } : {}),
|
|
494
554
|
};
|
|
495
|
-
// Beside the type, for the words (0.63.2): why it is not known
|
|
496
|
-
|
|
555
|
+
// Beside the type, for the words (0.63.2): why it is not known - and (11-11,
|
|
556
|
+
// 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 } : {});
|
|
497
558
|
};
|
|
498
559
|
const failedStay = (a, why, code) => ({
|
|
499
560
|
hotelId: a.hotel.id,
|
|
@@ -504,7 +565,8 @@ export const createOtalessBookings = (deps) => {
|
|
|
504
565
|
why,
|
|
505
566
|
...(code ? { code } : {}),
|
|
506
567
|
});
|
|
507
|
-
const
|
|
568
|
+
const limited = (a, name) => failedStay(a, `Not sent to ${name}: too many requests just now - ask again in a minute.`, 'limited');
|
|
569
|
+
const recordOf = (a, pairs, id, code, status) => ({
|
|
508
570
|
id,
|
|
509
571
|
code,
|
|
510
572
|
group: a.group,
|
|
@@ -517,10 +579,10 @@ export const createOtalessBookings = (deps) => {
|
|
|
517
579
|
roomName: a.roomName,
|
|
518
580
|
stay: a.stay,
|
|
519
581
|
rooms: a.rooms,
|
|
520
|
-
quoted:
|
|
521
|
-
quotedUsd:
|
|
582
|
+
quoted: pairs.orig,
|
|
583
|
+
...(pairs.usd ? { quotedUsd: pairs.usd } : {}),
|
|
522
584
|
status,
|
|
523
|
-
...(a.
|
|
585
|
+
...(a.agreed ? { terms: a.agreed } : {}),
|
|
524
586
|
guest: {
|
|
525
587
|
name: a.guest.name,
|
|
526
588
|
email: maskEmail(a.guest.email) ?? '',
|
|
@@ -532,26 +594,123 @@ export const createOtalessBookings = (deps) => {
|
|
|
532
594
|
orders.set(r.id, r);
|
|
533
595
|
save();
|
|
534
596
|
};
|
|
597
|
+
// ── terms (§15.2; 总线程 11-11, A and D) ──────────────────────────────────
|
|
598
|
+
const view = (p) => ({
|
|
599
|
+
ref: p.ref,
|
|
600
|
+
group: p.group,
|
|
601
|
+
groupName: p.groupName,
|
|
602
|
+
...(p.groupNames ? { groupNames: p.groupNames } : {}),
|
|
603
|
+
hotelId: p.hotelId,
|
|
604
|
+
hotelName: p.hotelName,
|
|
605
|
+
...(p.hotelNames ? { hotelNames: p.hotelNames } : {}),
|
|
606
|
+
roomName: p.roomName,
|
|
607
|
+
stay: p.stay,
|
|
608
|
+
rooms: p.rooms,
|
|
609
|
+
total: p.total,
|
|
610
|
+
text: p.text,
|
|
611
|
+
source: p.source,
|
|
612
|
+
more: true,
|
|
613
|
+
...(p.changed ? { changed: true } : {}),
|
|
614
|
+
...(p.bookingId ? { bookingId: p.bookingId } : {}),
|
|
615
|
+
...(p.confirmationCode ? { confirmationCode: p.confirmationCode } : {}),
|
|
616
|
+
until: p.until,
|
|
617
|
+
});
|
|
618
|
+
/** Keeps terms for the guest - a few per account, a bounded number in all. */
|
|
619
|
+
const remember = (p) => {
|
|
620
|
+
const mine = [...pending.values()].filter((x) => x.owner === p.owner);
|
|
621
|
+
for (const x of mine.slice(0, Math.max(0, mine.length - PENDING_PER_ACCOUNT + 1)))
|
|
622
|
+
pending.delete(x.ref);
|
|
623
|
+
pending.set(p.ref, p);
|
|
624
|
+
while (pending.size > PENDING_MAX) {
|
|
625
|
+
const first = pending.keys().next().value;
|
|
626
|
+
if (first === undefined)
|
|
627
|
+
break;
|
|
628
|
+
pending.delete(first);
|
|
629
|
+
}
|
|
630
|
+
counts.termsSent += 1;
|
|
631
|
+
return view(p);
|
|
632
|
+
};
|
|
633
|
+
const groupWords = (code) => {
|
|
634
|
+
const g = deps.groupOf(code);
|
|
635
|
+
return { groupName: g.name, ...(g.names ? { groupNames: g.names } : {}) };
|
|
636
|
+
};
|
|
637
|
+
/** The terms of one stay, for the guest to agree to before it is ordered. */
|
|
638
|
+
const termsBefore = (a) => remember({
|
|
639
|
+
ref: randomBytes(18).toString('base64url'),
|
|
640
|
+
group: a.group,
|
|
641
|
+
...groupWords(a.group),
|
|
642
|
+
hotelId: a.hotel.id,
|
|
643
|
+
hotelName: a.hotel.name,
|
|
644
|
+
...(a.hotel.names?.name ? { hotelNames: a.hotel.names.name } : {}),
|
|
645
|
+
roomName: a.roomName,
|
|
646
|
+
stay: a.stay,
|
|
647
|
+
rooms: a.rooms,
|
|
648
|
+
total: a.total,
|
|
649
|
+
text: a.agreed,
|
|
650
|
+
source: a.agreed ? 'room' : 'none',
|
|
651
|
+
more: true,
|
|
652
|
+
until: iso(now() + TERMS_MS),
|
|
653
|
+
owner: a.acct.owner,
|
|
654
|
+
key: a.acct.key,
|
|
655
|
+
ask: { roomId: a.roomId, guest: a.guest },
|
|
656
|
+
});
|
|
657
|
+
/**
|
|
658
|
+
* The terms an order is held back for (总线程 11-11, D): those kept - or,
|
|
659
|
+
* gone from memory (a restart), the order's own kept again until its time.
|
|
660
|
+
*/
|
|
661
|
+
const termsOfHeld = (r, acct) => {
|
|
662
|
+
if (!r.held || r.released || !r.terms || now() >= Date.parse(r.held.until))
|
|
663
|
+
return undefined;
|
|
664
|
+
for (const p of pending.values())
|
|
665
|
+
if (p.orderId === r.id && p.owner === acct.owner && now() <= Date.parse(p.until))
|
|
666
|
+
return view(p);
|
|
667
|
+
return remember({
|
|
668
|
+
ref: randomBytes(18).toString('base64url'),
|
|
669
|
+
group: r.group,
|
|
670
|
+
...groupWords(r.group),
|
|
671
|
+
hotelId: r.hotelId,
|
|
672
|
+
hotelName: r.hotelName,
|
|
673
|
+
...(r.hotelNames ? { hotelNames: r.hotelNames } : {}),
|
|
674
|
+
roomName: r.roomName,
|
|
675
|
+
stay: r.stay,
|
|
676
|
+
rooms: r.rooms,
|
|
677
|
+
total: r.quoted,
|
|
678
|
+
text: r.terms,
|
|
679
|
+
source: 'booking',
|
|
680
|
+
more: true,
|
|
681
|
+
changed: true,
|
|
682
|
+
bookingId: r.id,
|
|
683
|
+
confirmationCode: r.code || r.id,
|
|
684
|
+
until: r.held.until,
|
|
685
|
+
owner: r.owner,
|
|
686
|
+
key: acct.key,
|
|
687
|
+
orderId: r.id,
|
|
688
|
+
});
|
|
689
|
+
};
|
|
690
|
+
// ── an order cancelled at once (9; 总线程 11-11) ───────────────────────────
|
|
691
|
+
/** What the group's staff are told an order was cancelled for. */
|
|
692
|
+
const RELEASE_REASON = {
|
|
693
|
+
price: 'amount not as quoted',
|
|
694
|
+
amount: 'no amount given',
|
|
695
|
+
adults: 'guests not as asked',
|
|
696
|
+
address: 'payment page not accepted',
|
|
697
|
+
terms: 'terms not agreed by the guest',
|
|
698
|
+
};
|
|
535
699
|
/**
|
|
536
|
-
*
|
|
537
|
-
* payment
|
|
538
|
-
* PERSON:
|
|
700
|
+
* Cancels an order we will not hand on, at once - by 9, the only cancel there
|
|
701
|
+
* 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.
|
|
539
703
|
*/
|
|
540
|
-
const release = async (
|
|
704
|
+
const release = async (acct, who, r, why) => {
|
|
541
705
|
r.released = why;
|
|
706
|
+
r.held = undefined;
|
|
707
|
+
payLinks.delete(r.id);
|
|
708
|
+
for (const [ref, p] of pending)
|
|
709
|
+
if (p.orderId === r.id)
|
|
710
|
+
pending.delete(ref);
|
|
542
711
|
counts.released += 1;
|
|
543
712
|
try {
|
|
544
|
-
const done = await withSession(
|
|
545
|
-
? client.cancelBooking({
|
|
546
|
-
unifiedOrderId: r.id,
|
|
547
|
-
providerCode: a.group,
|
|
548
|
-
reason: 'price or payment page not as quoted',
|
|
549
|
-
}, cred, deps.callerOf(a.who))
|
|
550
|
-
: client.cancelCheckout({
|
|
551
|
-
unifiedOrderId: r.id,
|
|
552
|
-
providerCode: a.group,
|
|
553
|
-
reason: 'price or payment page not as quoted',
|
|
554
|
-
}, cred, deps.callerOf(a.who)));
|
|
713
|
+
const done = await withSession(acct, who, (cred) => client.cancelBooking({ unifiedOrderId: r.id, providerCode: r.group, reason: RELEASE_REASON[why] }, cred, deps.callerOf(who)));
|
|
555
714
|
// Not said to be done - refused, or not known: a person, as any failure here.
|
|
556
715
|
if (cancelOutcome(done) !== 'done')
|
|
557
716
|
throw new Error('not cancelled');
|
|
@@ -562,151 +721,243 @@ export const createOtalessBookings = (deps) => {
|
|
|
562
721
|
}
|
|
563
722
|
catch (err) {
|
|
564
723
|
r.releaseFailed = true;
|
|
724
|
+
r.needsPerson = 'release';
|
|
565
725
|
counts.releaseFailed += 1;
|
|
566
|
-
log(`[otaless] NEEDS A PERSON: order ${forTheLog(r.id)} at ${
|
|
726
|
+
log(`[otaless] NEEDS A PERSON: order ${forTheLog(r.id)} at ${r.group} (${why}) could not be cancelled: ${err instanceof Error ? err.name : 'error'}`);
|
|
567
727
|
put(r);
|
|
568
728
|
return false;
|
|
569
729
|
}
|
|
570
730
|
};
|
|
571
|
-
|
|
572
|
-
|
|
731
|
+
const releasedWhy = (g, why) => ({
|
|
732
|
+
price: `${g} asked for a different amount than the price the guest was shown`,
|
|
733
|
+
amount: `${g} did not say what it would charge`,
|
|
734
|
+
adults: `${g} took the order for another number of guests than the guest chose`,
|
|
735
|
+
address: `${g} sent a payment page on an address this connector does not send guests to`,
|
|
736
|
+
terms: `${g} asked for terms of its own to be agreed to when it was ordered, which cannot be shown here`,
|
|
737
|
+
})[why];
|
|
738
|
+
/** An order made that is not the one asked for: cancelled at once, and said as it came out. */
|
|
739
|
+
const letGo = async (a, r, why) => {
|
|
740
|
+
const g = deps.groupOf(a.group).name;
|
|
741
|
+
const gone = await release(a.acct, a.who, r, why);
|
|
742
|
+
if (gone)
|
|
743
|
+
return {
|
|
744
|
+
failed: failedStay(a, `${releasedWhy(g, why)}, so the order was cancelled at once and nothing was charged.${why === 'price' ? ' Price the trip again.' : ''}`,
|
|
745
|
+
// For the card to say in the guest's language (酒店平台 0.66.0, `NoRoomsCode`).
|
|
746
|
+
why === 'price' || why === 'amount' ? 'price-changed' : 'order-cancelled'),
|
|
747
|
+
};
|
|
748
|
+
// ⚠️ SAID AS IT IS: an order stands at the group that is not the one asked
|
|
749
|
+
// for - never "not booked". Listed, with no page to pay it on.
|
|
750
|
+
return {
|
|
751
|
+
failed: failedStay(a, `${releasedWhy(g, why)}, and cancelling the order it made did not go through just now - a person is looking at it. It is in the guest's bookings, with no payment page: it must not be paid.`, 'needs-person'),
|
|
752
|
+
};
|
|
753
|
+
};
|
|
754
|
+
// ── an order held for terms the group answered with (总线程 11-11, D) ──────
|
|
755
|
+
const later = deps.later ??
|
|
756
|
+
((ms, fn) => {
|
|
757
|
+
const t = setTimeout(fn, ms);
|
|
758
|
+
t.unref?.();
|
|
759
|
+
});
|
|
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) => {
|
|
762
|
+
const r = orders.get(id);
|
|
763
|
+
if (!r?.held || r.released || now() < Date.parse(r.held.until))
|
|
764
|
+
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');
|
|
772
|
+
};
|
|
773
|
+
/** This guest's held orders whose time ran out - the timer may not have run (a restart): cancelled now. */
|
|
774
|
+
const sweep = async (who) => {
|
|
775
|
+
for (const r of [...orders.values()]) {
|
|
776
|
+
if (!r.held || r.released || now() < Date.parse(r.held.until))
|
|
777
|
+
continue;
|
|
778
|
+
const acct = accountFor(who, r.group);
|
|
779
|
+
if (acct && acct.owner === r.owner)
|
|
780
|
+
await release(acct, who, r, 'terms');
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
/** What 8 answered, settled: an order to hand on, one held for new terms, or none. */
|
|
784
|
+
const settle = async (a, w, pairs) => {
|
|
573
785
|
const g = deps.groupOf(a.group);
|
|
574
786
|
const status = String(w?.status ?? '')
|
|
575
787
|
.trim()
|
|
576
788
|
.toUpperCase();
|
|
577
|
-
|
|
578
|
-
if (/TERMS/.test(status)) {
|
|
579
|
-
const words = firstText(w?.extraData, TERMS_TEXT_KEYS);
|
|
580
|
-
const token = firstText(w?.extraData, TERMS_TOKEN_KEYS);
|
|
581
|
-
// ⚠️ NEVER TERMS NOBODY SAW: none sent, or none to send the agreement back with - nothing.
|
|
582
|
-
if (!words || !token || token.length > 512 || words.length > TERMS_MAX)
|
|
583
|
-
return {
|
|
584
|
-
failed: failedStay(a, `${g.name} asks for the guest's agreement to terms it did not send in full, so nothing was booked or charged.`),
|
|
585
|
-
};
|
|
586
|
-
const mine = [...pending.values()].filter((p) => p.owner === a.acct.owner);
|
|
587
|
-
for (const p of mine.slice(0, Math.max(0, mine.length - PENDING_PER_ACCOUNT + 1)))
|
|
588
|
-
pending.delete(p.ref);
|
|
589
|
-
const ref = randomBytes(18).toString('base64url');
|
|
590
|
-
const terms = {
|
|
591
|
-
ref,
|
|
592
|
-
group: a.group,
|
|
593
|
-
groupName: g.name,
|
|
594
|
-
...(g.names ? { groupNames: g.names } : {}),
|
|
595
|
-
hotelId: a.hotel.id,
|
|
596
|
-
hotelName: a.hotel.name,
|
|
597
|
-
...(a.hotel.names?.name ? { hotelNames: a.hotel.names.name } : {}),
|
|
598
|
-
roomName: a.roomName,
|
|
599
|
-
stay: a.stay,
|
|
600
|
-
rooms: a.rooms,
|
|
601
|
-
total: a.pairs.orig,
|
|
602
|
-
text: words,
|
|
603
|
-
until: iso(now() + TERMS_MS),
|
|
604
|
-
};
|
|
605
|
-
pending.set(ref, {
|
|
606
|
-
...terms,
|
|
607
|
-
owner: a.acct.owner,
|
|
608
|
-
key: a.acct.key,
|
|
609
|
-
tokenOfTerms: token,
|
|
610
|
-
body: a.body,
|
|
611
|
-
pairs: a.pairs,
|
|
612
|
-
roomId: a.roomId,
|
|
613
|
-
...(a.terms ? { terms: a.terms } : {}),
|
|
614
|
-
at: now(),
|
|
615
|
-
});
|
|
616
|
-
while (pending.size > PENDING_MAX) {
|
|
617
|
-
const first = pending.keys().next().value;
|
|
618
|
-
if (first === undefined)
|
|
619
|
-
break;
|
|
620
|
-
pending.delete(first);
|
|
621
|
-
}
|
|
622
|
-
counts.termsSent += 1;
|
|
623
|
-
return { terms };
|
|
624
|
-
}
|
|
789
|
+
const id = text(w?.unifiedOrderId);
|
|
625
790
|
// ── refused ──
|
|
626
|
-
const err = text(w?.errorMessage);
|
|
791
|
+
const err = text(w?.errorMessage ?? undefined);
|
|
627
792
|
if (!w || w.success === false || status === 'FAILED' || err) {
|
|
628
793
|
if (err)
|
|
629
|
-
log(`[otaless]
|
|
794
|
+
log(`[otaless] booking at ${a.group} refused: "${forTheLog(err, [a.guest.name, a.guest.email, a.guest.phone])}"`);
|
|
630
795
|
return {
|
|
631
796
|
failed: failedStay(a, `${g.name} did not take the booking, so nothing was booked or charged.`),
|
|
632
797
|
};
|
|
633
798
|
}
|
|
634
|
-
const id = text(w.unifiedOrderId);
|
|
635
|
-
const code = text(w.originalOrderId) ?? '';
|
|
636
|
-
const page = text(w.checkoutUrl);
|
|
637
|
-
// ⚠️ "CONFIRMED" WITH A PAYMENT PAGE IS WAITING FOR ITS PAYMENT (questions #53,
|
|
638
|
-
// the document's own example): paid is what 15 says, never this status.
|
|
639
|
-
const confirmed = !page && (status === 'CONFIRMED' || status === 'PAID');
|
|
640
799
|
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
|
+
}
|
|
641
807
|
// Something may be held, under a number we were not told: kept to look for (12).
|
|
642
|
-
const r = recordOf(a, `pending:${randomBytes(8).toString('hex')}`, '', 'unconfirmed');
|
|
808
|
+
const r = recordOf(a, pairs, `pending:${randomBytes(8).toString('hex')}`, '', 'unconfirmed');
|
|
643
809
|
put(r);
|
|
644
|
-
log(`[otaless]
|
|
810
|
+
log(`[otaless] booking at ${a.group} answered with no order id (status ${forTheLog(status || '?')})`);
|
|
645
811
|
return { booked: toBooking(r) };
|
|
646
812
|
}
|
|
647
|
-
const
|
|
648
|
-
|
|
649
|
-
|
|
813
|
+
const code = text(w.originalOrderId) ?? '';
|
|
814
|
+
const page = text(w.checkoutUrl ?? undefined);
|
|
815
|
+
// ⚠️ "CONFIRMED" WITH A PAYMENT PAGE IS WAITING FOR ITS PAYMENT (questions
|
|
816
|
+
// #53, #61 (1) - 8's own example): paid is what 15 says, never this status.
|
|
817
|
+
const confirmed = !page && (status === 'CONFIRMED' || status === 'PAID');
|
|
818
|
+
const r = recordOf(a, pairs, id, code, confirmed ? 'confirmed' : 'awaiting-payment');
|
|
650
819
|
const charged = moneyOf(w.totalAmount, w.currency);
|
|
651
820
|
if (charged)
|
|
652
821
|
r.charged = charged;
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
failed: failedStay(a, `${g.name} confirmed it at a different amount than the price the guest was shown, and it could not be undone here just now - a person is looking at it; it is in the guest's bookings.`, 'price-changed'),
|
|
662
|
-
};
|
|
663
|
-
return {
|
|
664
|
-
failed: failedStay(a, charged
|
|
665
|
-
? `${g.name} asked for a different amount than the price the guest was shown, so it was not booked at it and nothing was charged - price the trip again.`
|
|
666
|
-
: `${g.name} did not say what it would charge, so it was not booked and nothing was charged.`, 'price-changed'),
|
|
667
|
-
};
|
|
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');
|
|
825
|
+
}
|
|
826
|
+
// ── the amount (总线程 11-10, 12.9 #2): either of this quote's two, to the cent ──
|
|
827
|
+
if (!charged || !(same(charged, pairs.orig) || same(charged, pairs.usd))) {
|
|
828
|
+
log(`[otaless] booking at ${a.group} asked ${charged ? `${charged.currency} ${charged.minor}` : 'no amount'}, quoted ${pairs.orig.currency} ${pairs.orig.minor}${pairs.usd ? ` / USD ${pairs.usd.minor}` : ''} - cancelled`);
|
|
829
|
+
return letGo(a, r, charged ? 'price' : 'amount');
|
|
668
830
|
}
|
|
669
|
-
// ── the
|
|
831
|
+
// ── the guests (总线程 11-11, C - questions #62): said, it is the number quoted ──
|
|
832
|
+
const adults = num(w.adultCount ?? w.adults);
|
|
833
|
+
if (adults !== undefined && adults !== a.stay.guests) {
|
|
834
|
+
log(`[otaless] booking at ${a.group} is for ${adults} adult(s), quoted for ${a.stay.guests} - cancelled`);
|
|
835
|
+
return letGo(a, r, 'adults');
|
|
836
|
+
}
|
|
837
|
+
// ── the payment page (总线程 11-10, rule 5; 11-11, B) ──
|
|
670
838
|
if (page) {
|
|
671
|
-
const ok = payPageOf(page, deps.checkoutHosts);
|
|
839
|
+
const ok = payPageOf(page, deps.checkoutHosts, id);
|
|
672
840
|
if (!ok) {
|
|
673
|
-
|
|
674
|
-
log(`[otaless]
|
|
675
|
-
return
|
|
676
|
-
failed: failedStay(a, `${g.name} sent a payment page on an address this connector does not send guests to, so it was not booked and nothing was charged.`),
|
|
677
|
-
};
|
|
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`);
|
|
843
|
+
return letGo(a, r, 'address');
|
|
678
844
|
}
|
|
679
845
|
r.payHost = ok.host;
|
|
680
846
|
payLinks.set(id, ok.url);
|
|
681
|
-
const hold = num(w.extraData?.hold_minutes);
|
|
682
|
-
if (hold !== undefined && hold > 0 && hold <= 24 * 60)
|
|
683
|
-
r.payBy = iso(now() + hold * 60_000);
|
|
684
847
|
}
|
|
685
848
|
else if (!confirmed) {
|
|
686
849
|
// Waiting, and no page to pay on: nothing to hand on - 15 says when it is paid.
|
|
687
|
-
log(`[otaless]
|
|
850
|
+
log(`[otaless] booking at ${a.group} is ${forTheLog(status || '?')} with no payment page`);
|
|
851
|
+
}
|
|
852
|
+
// ── the terms it came with (总线程 11-11, D) ──
|
|
853
|
+
const said = text(w.cancelPolicy ?? undefined);
|
|
854
|
+
if (said && said.length > TERMS_MAX) {
|
|
855
|
+
log(`[otaless] booking at ${a.group} came with terms too long to show - cancelled`);
|
|
856
|
+
return letGo(a, r, 'terms');
|
|
688
857
|
}
|
|
858
|
+
if (said && termsKey(said) !== termsKey(a.agreed)) {
|
|
859
|
+
// ⚠️ NOT THE TERMS AGREED TO: the order stands, its payment page is held
|
|
860
|
+
// back until the guest agrees to these too - not agreed, or not in time,
|
|
861
|
+
// it is cancelled.
|
|
862
|
+
r.terms = said;
|
|
863
|
+
r.held = { until: iso(now() + TERMS_MS) };
|
|
864
|
+
put(r);
|
|
865
|
+
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
|
+
});
|
|
869
|
+
const t = termsOfHeld(r, a.acct);
|
|
870
|
+
return t ? { terms: t } : { booked: toBooking(r) };
|
|
871
|
+
}
|
|
872
|
+
if (said)
|
|
873
|
+
r.terms = said;
|
|
689
874
|
put(r);
|
|
690
875
|
return { booked: toBooking(r) };
|
|
691
876
|
};
|
|
692
|
-
|
|
693
|
-
|
|
877
|
+
class Moved extends Error {
|
|
878
|
+
}
|
|
879
|
+
class NotPriced extends Error {
|
|
880
|
+
busy;
|
|
881
|
+
constructor(busy) {
|
|
882
|
+
super('not priced');
|
|
883
|
+
this.busy = busy;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Orders one stay whose terms the guest agreed to: priced again in their own
|
|
888
|
+
* session, held to the price they were shown - and only then 8, in that same
|
|
889
|
+
* session (总线程 11-11, C). A 4012 on either is one new handshake and one more
|
|
890
|
+
* try of both.
|
|
891
|
+
*/
|
|
892
|
+
const place = async (a) => {
|
|
694
893
|
const g = deps.groupOf(a.group);
|
|
894
|
+
let pairs;
|
|
895
|
+
/** What 8 itself threw, if it did: only that may have made an order. */
|
|
896
|
+
let fromBook;
|
|
695
897
|
let w;
|
|
696
898
|
try {
|
|
697
|
-
w = await withSession(a.acct, a.who, (cred) =>
|
|
899
|
+
w = await withSession(a.acct, a.who, async (cred) => {
|
|
900
|
+
fromBook = undefined;
|
|
901
|
+
let priced;
|
|
902
|
+
try {
|
|
903
|
+
priced = await deps.quoteIn(a.hotel, a.roomId, a.stay, a.rooms, cred, a.who);
|
|
904
|
+
}
|
|
905
|
+
catch (err) {
|
|
906
|
+
if (isCode(err, NOT_SIGNED_IN) || isCode(err, CHANNEL_SESSION_EXPIRED))
|
|
907
|
+
throw err;
|
|
908
|
+
throw new NotPriced(err instanceof OtalessBusy);
|
|
909
|
+
}
|
|
910
|
+
const orig = moneyOf(priced.data?.originalAmount, priced.data?.originalCurrency);
|
|
911
|
+
// ⚠️ THE PRICE THE GUEST SAW, TO THE CENT, OR 8 IS NOT CALLED.
|
|
912
|
+
if (!orig || !same(orig, a.total))
|
|
913
|
+
throw new Moved('moved');
|
|
914
|
+
const usd = text(priced.data?.settlementCurrency)?.toUpperCase() === 'USD'
|
|
915
|
+
? moneyOf(priced.data?.settlementAmount, 'USD')
|
|
916
|
+
: undefined;
|
|
917
|
+
pairs = { orig, ...(usd && usd.minor > 0 ? { usd } : {}) };
|
|
918
|
+
// ⚠️ THE SESSION THE QUOTE RAN IN - as it wrote it back, if it did.
|
|
919
|
+
const session = priced.session ?? cred.session;
|
|
920
|
+
const body = {
|
|
921
|
+
unifiedHotelId: a.hotel.id,
|
|
922
|
+
// ⚠️ AS /rooms SENT IT, prefix and all (questions #53) - never cut to its tail.
|
|
923
|
+
unifiedRoomId: a.roomId,
|
|
924
|
+
guestName: a.guest.name,
|
|
925
|
+
guestPhone: a.guest.phone ?? '',
|
|
926
|
+
...(a.guest.email ? { guestEmail: a.guest.email } : {}),
|
|
927
|
+
checkIn: a.stay.checkIn,
|
|
928
|
+
checkOut: a.stay.checkOut,
|
|
929
|
+
roomCount: a.rooms,
|
|
930
|
+
};
|
|
931
|
+
let booked;
|
|
932
|
+
try {
|
|
933
|
+
booked = await client.book(body, { token: cred.token, ...(session ? { session } : {}) }, deps.callerOf(a.who));
|
|
934
|
+
}
|
|
935
|
+
catch (err) {
|
|
936
|
+
fromBook = err;
|
|
937
|
+
throw err;
|
|
938
|
+
}
|
|
939
|
+
const back = booked.session ?? priced.session;
|
|
940
|
+
return { data: booked.data, ...(back ? { session: back } : {}) };
|
|
941
|
+
});
|
|
698
942
|
}
|
|
699
943
|
catch (err) {
|
|
700
|
-
if (err instanceof
|
|
944
|
+
if (err instanceof Moved)
|
|
945
|
+
return {
|
|
946
|
+
failed: failedStay(a, `${g.name}'s price moved since the guest saw it, so nothing was booked - price the trip again.`, 'price-changed'),
|
|
947
|
+
};
|
|
948
|
+
if (err instanceof NotPriced)
|
|
701
949
|
return {
|
|
702
|
-
failed:
|
|
950
|
+
failed: err.busy
|
|
951
|
+
? limited(a, g.name)
|
|
952
|
+
: failedStay(a, `${g.name} did not price it again just now, so nothing was booked.`, 'unreachable'),
|
|
703
953
|
};
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
954
|
+
if (err instanceof OtalessBusy)
|
|
955
|
+
return { failed: limited(a, g.name) };
|
|
956
|
+
// ⚠️ NOT SENT AGAIN (§12.1): 8 itself not answering - or refusing it as a
|
|
957
|
+
// repeat of one that went in a moment ago (10014) - may have made it.
|
|
958
|
+
// Kept to look for in the group's order list (12), said as not known.
|
|
959
|
+
if (err === fromBook && (unanswered(err) || isCode(err, REPEAT_SUBMIT))) {
|
|
960
|
+
const r = recordOf(a, pairs ?? { orig: a.total }, `pending:${randomBytes(8).toString('hex')}`, '', 'unconfirmed');
|
|
710
961
|
put(r);
|
|
711
962
|
return { booked: toBooking(r) };
|
|
712
963
|
}
|
|
@@ -716,10 +967,10 @@ export const createOtalessBookings = (deps) => {
|
|
|
716
967
|
};
|
|
717
968
|
throw err;
|
|
718
969
|
}
|
|
719
|
-
return settle(a, w);
|
|
970
|
+
return settle(a, w, pairs ?? { orig: a.total });
|
|
720
971
|
};
|
|
721
972
|
/**
|
|
722
|
-
* An order row that could be an order
|
|
973
|
+
* An order row that could be an order 8 did not answer for: of the group,
|
|
723
974
|
* for those nights, not one of ours, and holding something (not cancelled,
|
|
724
975
|
* failed, refunded or closed).
|
|
725
976
|
*/
|
|
@@ -737,6 +988,82 @@ export const createOtalessBookings = (deps) => {
|
|
|
737
988
|
.trim()
|
|
738
989
|
.toUpperCase());
|
|
739
990
|
};
|
|
991
|
+
const stayGuard = async (acct, who, label, roomRef, rooms, lockKey) => {
|
|
992
|
+
const group = acct.group;
|
|
993
|
+
const { hotel, stay } = label;
|
|
994
|
+
const name = deps.groupOf(group).name;
|
|
995
|
+
const sameStay = (o) => o.owner === acct.owner &&
|
|
996
|
+
o.hotelId === hotel.id &&
|
|
997
|
+
o.roomId === roomRef &&
|
|
998
|
+
o.stay.checkIn === stay.checkIn &&
|
|
999
|
+
o.stay.checkOut === stay.checkOut &&
|
|
1000
|
+
o.rooms === rooms;
|
|
1001
|
+
// 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);
|
|
1003
|
+
if (person)
|
|
1004
|
+
return {
|
|
1005
|
+
failed: failedStay(label, person.needsPerson === 'release'
|
|
1006
|
+
? `An earlier booking of this stay could not be cancelled at ${name} and needs a person to check it, so nothing new was booked.`
|
|
1007
|
+
: `An earlier booking of this stay needs a person to check its payment with ${name}, so nothing new was booked.`,
|
|
1008
|
+
// For the card to say in the guest's language (酒店平台 0.63.2, `NoRoomsCode`).
|
|
1009
|
+
'earlier-needs-person'),
|
|
1010
|
+
};
|
|
1011
|
+
const mine = [...orders.values()].filter((o) => sameStay(o) && !o.released);
|
|
1012
|
+
// Held for terms the group answered with: those terms, again - not a second order.
|
|
1013
|
+
const held = mine.find((o) => o.held);
|
|
1014
|
+
if (held) {
|
|
1015
|
+
const t = termsOfHeld(held, acct);
|
|
1016
|
+
if (t)
|
|
1017
|
+
return { terms: t };
|
|
1018
|
+
}
|
|
1019
|
+
// ⚠️ AN EARLIER ORDER OF THIS STAY THAT MAY HAVE BEEN MADE IS LOOKED FOR
|
|
1020
|
+
// FIRST, HOWEVER OLD (总线程's review of 0.63.0, 5): the group's order list
|
|
1021
|
+
// (12) is read; not found there - or not readable - nothing new is sent.
|
|
1022
|
+
const unknown = mine.filter((o) => o.status === 'unconfirmed' && !o.unverifiable);
|
|
1023
|
+
if (unknown.length) {
|
|
1024
|
+
const rows = await lookAtOrders(acct, who, group, unknown);
|
|
1025
|
+
const still = unknown.filter((o) => o.status === 'unconfirmed');
|
|
1026
|
+
// ⚠️ THE WAY OUT (总线程's re-review of 0.63.1, 1): long enough after it
|
|
1027
|
+
// was asked for - past any hold on an unpaid room - and with nothing in
|
|
1028
|
+
// the group's list that could be it, the stay is no longer held back.
|
|
1029
|
+
// The guest is told first, as it is; asked again, a new booking is made.
|
|
1030
|
+
// (Not by the payment status, 15: an order 8 never named has no id to
|
|
1031
|
+
// ask it by - its list, 12, is all there is.)
|
|
1032
|
+
if (rows &&
|
|
1033
|
+
still.length &&
|
|
1034
|
+
still.every((o) => now() - Date.parse(o.createdAt) >= UNCONFIRMED_GIVE_UP_MS) &&
|
|
1035
|
+
!rows.some((row) => couldBe(row, group, stay))) {
|
|
1036
|
+
for (const o of still) {
|
|
1037
|
+
o.unverifiable = true;
|
|
1038
|
+
put(o);
|
|
1039
|
+
}
|
|
1040
|
+
log(`[otaless] ${still.length} order(s) 8 did not answer for at ${group} could not be verified - the stay is no longer held back`);
|
|
1041
|
+
return {
|
|
1042
|
+
failed: failedStay(label, `The earlier booking of this stay could not be confirmed with ${name}: it may have been made, so the guest should check with ${name} before booking it again. Nothing new was booked this time - asked again, a new booking is made.`, 'earlier-unconfirmed'),
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
if (!rows || still.length)
|
|
1046
|
+
return {
|
|
1047
|
+
failed: failedStay(label, `An earlier booking of this stay is still being looked into with ${name} - whether it was made is not known yet, so nothing new was booked. Look at the bookings again in a few minutes.`),
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
// A second press, a lost answer, an order found in the list: the order
|
|
1051
|
+
// already made for this stay, while it may still be paid. ⚠️ WITH NO TIME
|
|
1052
|
+
// TO PAY BY, THE PAYMENT STATUS (15) IS ASKED FIRST (总线程's re-review of
|
|
1053
|
+
// 0.63.1, 2): closed, it lapses and its link is not handed on again; not
|
|
1054
|
+
// known, it is held to `ASSUMED_HOLD_MS`.
|
|
1055
|
+
for (const o of mine.filter((x) => x.status === 'awaiting-payment' && !x.held)) {
|
|
1056
|
+
if (!o.payBy)
|
|
1057
|
+
await lookAtPayment(acct, who, o, true);
|
|
1058
|
+
if (o.status === 'awaiting-payment' && !o.needsPerson && now() < payableUntil(o))
|
|
1059
|
+
return { reuse: o };
|
|
1060
|
+
}
|
|
1061
|
+
if (inFlight.has(lockKey))
|
|
1062
|
+
return {
|
|
1063
|
+
failed: failedStay(label, 'This stay is being booked already - look at the bookings in a moment rather than booking it again.'),
|
|
1064
|
+
};
|
|
1065
|
+
return undefined;
|
|
1066
|
+
};
|
|
740
1067
|
const requestBooking = async (trip, guest, who) => {
|
|
741
1068
|
// ⚠️ SIGNED IN AT EVERY GROUP OF THE TRIP, OR NOTHING IS SENT (robin 11-10:
|
|
742
1069
|
// one sign-in per group, the backend's own) - the whole trip is refused
|
|
@@ -751,13 +1078,14 @@ export const createOtalessBookings = (deps) => {
|
|
|
751
1078
|
const phone = guest.phone?.trim() ?? '';
|
|
752
1079
|
if (!name)
|
|
753
1080
|
throw refusal('guest', "Nothing was booked: the guest's name is needed.");
|
|
754
|
-
// The backend's `guestPhone` is required (
|
|
1081
|
+
// The backend's `guestPhone` is required (8).
|
|
755
1082
|
if (!phone)
|
|
756
1083
|
throw refusal('guest', "Nothing was booked: the guest's phone number is needed.");
|
|
757
1084
|
const long = guestTooLong({ name, email: guest.email ?? '', phone });
|
|
758
1085
|
if (long.length)
|
|
759
1086
|
throw refusal('guest', `Nothing was booked: ${long.join(', ')}.`);
|
|
760
1087
|
const g0 = { ...guest, name, phone, email: guest.email?.trim() ?? '' };
|
|
1088
|
+
await sweep(who);
|
|
761
1089
|
const failed = [];
|
|
762
1090
|
for (const l of trip.lines) {
|
|
763
1091
|
if (l.kind === 'extra') {
|
|
@@ -810,154 +1138,38 @@ export const createOtalessBookings = (deps) => {
|
|
|
810
1138
|
continue;
|
|
811
1139
|
}
|
|
812
1140
|
const lockKey = `${acct.owner}|${hotel.id}|${line.roomRef}|${stay.checkIn}|${stay.checkOut}|${rooms}`;
|
|
813
|
-
const
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
// ⚠️ AN EARLIER ORDER OF THIS STAY THAT MAY HAVE BEEN MADE IS LOOKED FOR
|
|
821
|
-
// FIRST, HOWEVER OLD (总线程's review of 0.63.0, 5): the group's order list
|
|
822
|
-
// (12) is read; not found there - or not readable - nothing new is sent.
|
|
823
|
-
const name = deps.groupOf(group).name;
|
|
824
|
-
// Said paid at another amount: a person's - nothing new beside it.
|
|
825
|
-
if ([...orders.values()].some((o) => sameStay(o) && o.needsPerson)) {
|
|
826
|
-
failed.push(failedStay(label, `An earlier booking of this stay needs a person to check its payment with ${name}, so nothing new was booked.`,
|
|
827
|
-
// For the card to say in the guest's language (酒店平台 0.63.2, `NoRoomsCode`).
|
|
828
|
-
'earlier-needs-person'));
|
|
829
|
-
continue;
|
|
830
|
-
}
|
|
831
|
-
const unknown = [...orders.values()].filter((o) => sameStay(o) && o.status === 'unconfirmed' && !o.unverifiable);
|
|
832
|
-
if (unknown.length) {
|
|
833
|
-
const rows = await lookAtOrders(acct, who, group, unknown);
|
|
834
|
-
const still = unknown.filter((o) => o.status === 'unconfirmed');
|
|
835
|
-
// ⚠️ THE WAY OUT (总线程's re-review of 0.63.1, 1): long enough after it
|
|
836
|
-
// was asked for - past any hold on an unpaid room - and with nothing in
|
|
837
|
-
// the group's list that could be it, the stay is no longer held back.
|
|
838
|
-
// The guest is told first, as it is; asked again, a new booking is made.
|
|
839
|
-
// (Not by the payment status, 15: an order 13 never named has no id to
|
|
840
|
-
// ask it by - its list, 12, is all there is.)
|
|
841
|
-
if (rows &&
|
|
842
|
-
still.length &&
|
|
843
|
-
still.every((o) => now() - Date.parse(o.createdAt) >= UNCONFIRMED_GIVE_UP_MS) &&
|
|
844
|
-
!rows.some((row) => couldBe(row, group, stay))) {
|
|
845
|
-
for (const o of still) {
|
|
846
|
-
o.unverifiable = true;
|
|
847
|
-
put(o);
|
|
848
|
-
}
|
|
849
|
-
log(`[otaless] ${still.length} order(s) 13 did not answer for at ${group} could not be verified - the stay is no longer held back`);
|
|
850
|
-
failed.push(failedStay(label, `The earlier booking of this stay could not be confirmed with ${name}: it may have been made, so the guest should check with ${name} before booking it again. Nothing new was booked this time - asked again, a new booking is made.`, 'earlier-unconfirmed'));
|
|
851
|
-
continue;
|
|
852
|
-
}
|
|
853
|
-
if (!rows || still.length) {
|
|
854
|
-
failed.push(failedStay(label, `An earlier booking of this stay is still being looked into with ${name} - whether it was made is not known yet, so nothing new was booked. Look at the bookings again in a few minutes.`));
|
|
855
|
-
continue;
|
|
1141
|
+
const guard = await stayGuard(acct, who, label, line.roomRef, rooms, lockKey);
|
|
1142
|
+
if (guard) {
|
|
1143
|
+
if ('failed' in guard)
|
|
1144
|
+
failed.push(guard.failed);
|
|
1145
|
+
else if ('reuse' in guard) {
|
|
1146
|
+
booked.push(toBooking(guard.reuse));
|
|
1147
|
+
reused.push(guard.reuse.id);
|
|
856
1148
|
}
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
// already made for this stay, while it may still be paid. ⚠️ WITH NO TIME
|
|
860
|
-
// TO PAY BY FROM 13, THE PAYMENT STATUS (15) IS ASKED FIRST (总线程's
|
|
861
|
-
// re-review of 0.63.1, 2): closed, it lapses and its link is not handed
|
|
862
|
-
// on again; not known, it is held to `ASSUMED_HOLD_MS`.
|
|
863
|
-
let before;
|
|
864
|
-
for (const o of [...orders.values()].filter((x) => sameStay(x) && x.status === 'awaiting-payment' && !x.needsPerson)) {
|
|
865
|
-
if (!o.payBy)
|
|
866
|
-
await lookAtPayment(acct, who, o, true);
|
|
867
|
-
if (o.status === 'awaiting-payment' && !o.needsPerson && now() < payableUntil(o)) {
|
|
868
|
-
before = o;
|
|
869
|
-
break;
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
if (before) {
|
|
873
|
-
booked.push(toBooking(before));
|
|
874
|
-
reused.push(before.id);
|
|
1149
|
+
else
|
|
1150
|
+
terms.push(guard.terms);
|
|
875
1151
|
continue;
|
|
876
1152
|
}
|
|
877
|
-
|
|
878
|
-
|
|
1153
|
+
const agreed = text(line.terms) ?? '';
|
|
1154
|
+
// ⚠️ WORD FOR WORD OR NOT AT ALL: terms too long to show are not cut.
|
|
1155
|
+
if (agreed.length > TERMS_MAX) {
|
|
1156
|
+
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.`));
|
|
879
1157
|
continue;
|
|
880
1158
|
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
continue;
|
|
896
|
-
}
|
|
897
|
-
const body = {
|
|
898
|
-
unifiedHotelId: hotel.id,
|
|
899
|
-
// ⚠️ AS /rooms SENT IT, prefix and all (questions #53: the dictionary says
|
|
900
|
-
// `{provider}:{roomId}`, the example has none) - never cut to its tail.
|
|
901
|
-
unifiedRoomId: line.roomRef,
|
|
902
|
-
providerCode: group,
|
|
903
|
-
guestName: g0.name,
|
|
904
|
-
guestPhone: phone,
|
|
905
|
-
...(g0.email ? { guestEmail: g0.email } : {}),
|
|
906
|
-
checkIn: stay.checkIn,
|
|
907
|
-
checkOut: stay.checkOut,
|
|
908
|
-
roomCount: rooms,
|
|
909
|
-
adults: Math.max(1, stay.guests),
|
|
910
|
-
// ⚠️ ALWAYS FALSE (总线程 11-10, rule 3): never the backend's automatic agreement.
|
|
911
|
-
termsAccepted: false,
|
|
912
|
-
expectedChargeUsd: usd.minor / 100,
|
|
913
|
-
};
|
|
914
|
-
const out = await ask({
|
|
915
|
-
acct,
|
|
916
|
-
who,
|
|
917
|
-
hotel,
|
|
918
|
-
group,
|
|
919
|
-
roomId: line.roomRef,
|
|
920
|
-
roomName: line.title,
|
|
921
|
-
stay,
|
|
922
|
-
rooms,
|
|
923
|
-
...(line.terms ? { terms: line.terms } : {}),
|
|
924
|
-
guest: g0,
|
|
925
|
-
pairs: { orig, usd },
|
|
926
|
-
body,
|
|
927
|
-
});
|
|
928
|
-
if (out.booked)
|
|
929
|
-
booked.push(out.booked);
|
|
930
|
-
if (out.failed)
|
|
931
|
-
failed.push(out.failed);
|
|
932
|
-
if (out.terms)
|
|
933
|
-
terms.push(out.terms);
|
|
934
|
-
}
|
|
935
|
-
catch (err) {
|
|
936
|
-
const name = deps.groupOf(group).name;
|
|
937
|
-
// Its price could not be read again just now: this stay, not the trip.
|
|
938
|
-
if (err instanceof OtalessBusy)
|
|
939
|
-
failed.push(failedStay(label, `Not sent to ${name}: too many requests just now - ask again in a minute.`, 'limited'));
|
|
940
|
-
else if (err instanceof OtalessError)
|
|
941
|
-
failed.push(failedStay(label, `${name} did not price it again just now, so nothing was booked.`, 'unreachable'));
|
|
942
|
-
// ⚠️ A STAY BOOKED IS NEVER DROPPED FROM THE ANSWER (the seam's rule): a
|
|
943
|
-
// refusal on a later stay - a session or a sign-in over - is said for that
|
|
944
|
-
// stay. With nothing booked yet, the whole ask is refused as it came.
|
|
945
|
-
else if (!booked.length && !terms.length)
|
|
946
|
-
throw err;
|
|
947
|
-
else
|
|
948
|
-
failed.push({
|
|
949
|
-
...failedStay(label, err instanceof Error && 'code' in err
|
|
950
|
-
? err.message
|
|
951
|
-
: `${name} did not take it, so nothing was booked.`),
|
|
952
|
-
// A later stay's sign-in over: the group to sign in at again, as the refusal names it.
|
|
953
|
-
...(Array.isArray(err.groups)
|
|
954
|
-
? { groups: [...err.groups] }
|
|
955
|
-
: {}),
|
|
956
|
-
});
|
|
957
|
-
}
|
|
958
|
-
finally {
|
|
959
|
-
inFlight.delete(lockKey);
|
|
960
|
-
}
|
|
1159
|
+
// ⚠️ NOTHING IS ORDERED YET (§15.1): the terms first, for the guest to agree to.
|
|
1160
|
+
terms.push(termsBefore({
|
|
1161
|
+
acct,
|
|
1162
|
+
who,
|
|
1163
|
+
hotel,
|
|
1164
|
+
group,
|
|
1165
|
+
roomId: line.roomRef,
|
|
1166
|
+
roomName: line.title,
|
|
1167
|
+
stay,
|
|
1168
|
+
rooms,
|
|
1169
|
+
agreed,
|
|
1170
|
+
guest: g0,
|
|
1171
|
+
total: line.total,
|
|
1172
|
+
}));
|
|
961
1173
|
}
|
|
962
1174
|
return {
|
|
963
1175
|
booked,
|
|
@@ -970,8 +1182,8 @@ export const createOtalessBookings = (deps) => {
|
|
|
970
1182
|
...(terms.length ? { terms } : {}),
|
|
971
1183
|
};
|
|
972
1184
|
};
|
|
973
|
-
// ── terms agreed to (§
|
|
974
|
-
/** Terms waiting for this guest - signed in now at their group, as the same owner. */
|
|
1185
|
+
// ── terms agreed to (§15.1, 15.2) ─────────────────────────────────────────
|
|
1186
|
+
/** Terms waiting for this guest - signed in now at their group, as the same owner, in time. */
|
|
975
1187
|
const pendingFor = (ref, who) => {
|
|
976
1188
|
const p = pending.get(ref);
|
|
977
1189
|
if (!p)
|
|
@@ -979,67 +1191,89 @@ export const createOtalessBookings = (deps) => {
|
|
|
979
1191
|
const acct = accountFor(who, p.group);
|
|
980
1192
|
if (!acct || p.owner !== acct.owner)
|
|
981
1193
|
return undefined;
|
|
982
|
-
if (now()
|
|
1194
|
+
if (now() > Date.parse(p.until)) {
|
|
983
1195
|
pending.delete(ref);
|
|
984
1196
|
return undefined;
|
|
985
1197
|
}
|
|
986
1198
|
return { p, acct };
|
|
987
1199
|
};
|
|
988
|
-
const
|
|
989
|
-
ref: p.ref,
|
|
990
|
-
group: p.group,
|
|
991
|
-
groupName: p.groupName,
|
|
992
|
-
...(p.groupNames ? { groupNames: p.groupNames } : {}),
|
|
993
|
-
hotelId: p.hotelId,
|
|
994
|
-
hotelName: p.hotelName,
|
|
995
|
-
...(p.hotelNames ? { hotelNames: p.hotelNames } : {}),
|
|
996
|
-
roomName: p.roomName,
|
|
997
|
-
stay: p.stay,
|
|
998
|
-
rooms: p.rooms,
|
|
999
|
-
total: p.total,
|
|
1000
|
-
text: p.text,
|
|
1001
|
-
until: p.until,
|
|
1002
|
-
});
|
|
1200
|
+
const termsGone = () => refusal('terms-gone', 'Those terms are no longer waiting to be agreed to (they are kept ten minutes, and agreed to once) - nothing more was done; ask to book again.');
|
|
1003
1201
|
const acceptTerms = async (ref, who) => {
|
|
1004
1202
|
const found = pendingFor(ref, who);
|
|
1005
1203
|
if (!found)
|
|
1006
|
-
throw
|
|
1204
|
+
throw termsGone();
|
|
1007
1205
|
const { p, acct } = found;
|
|
1008
|
-
// ⚠️ ONE USE: gone before
|
|
1206
|
+
// ⚠️ ONE USE: gone before anything is sent, whatever comes back.
|
|
1009
1207
|
pending.delete(ref);
|
|
1010
1208
|
counts.termsAgreed += 1;
|
|
1209
|
+
if (p.orderId) {
|
|
1210
|
+
// ── terms the group answered an order with: its payment page, now ──
|
|
1211
|
+
const r = orders.get(p.orderId);
|
|
1212
|
+
if (!r || r.owner !== acct.owner || r.released || !r.held)
|
|
1213
|
+
throw termsGone();
|
|
1214
|
+
r.held = undefined;
|
|
1215
|
+
put(r);
|
|
1216
|
+
log(`[otaless] the guest agreed to the terms ${r.group} answered ${forTheLog(r.id)} with - its payment page handed on`);
|
|
1217
|
+
return { booked: [toBooking(r)], failed: [] };
|
|
1218
|
+
}
|
|
1219
|
+
const ask = p.ask;
|
|
1220
|
+
if (!ask)
|
|
1221
|
+
throw termsGone();
|
|
1222
|
+
await sweep(who);
|
|
1011
1223
|
const hotel = deps.find(p.hotelId) ??
|
|
1012
1224
|
{
|
|
1013
1225
|
id: p.hotelId,
|
|
1014
1226
|
name: p.hotelName,
|
|
1015
1227
|
...(p.hotelNames ? { names: { name: p.hotelNames } } : {}),
|
|
1016
1228
|
};
|
|
1017
|
-
const
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1229
|
+
const label = { hotel, stay: p.stay, roomName: p.roomName };
|
|
1230
|
+
const lockKey = `${acct.owner}|${p.hotelId}|${ask.roomId}|${p.stay.checkIn}|${p.stay.checkOut}|${p.rooms}`;
|
|
1231
|
+
const guard = await stayGuard(acct, who, label, ask.roomId, p.rooms, lockKey);
|
|
1232
|
+
if (guard)
|
|
1233
|
+
return 'failed' in guard
|
|
1234
|
+
? { booked: [], failed: [guard.failed] }
|
|
1235
|
+
: 'reuse' in guard
|
|
1236
|
+
? { booked: [toBooking(guard.reuse)], failed: [], repeat: true }
|
|
1237
|
+
: { booked: [], failed: [], terms: [guard.terms] };
|
|
1238
|
+
inFlight.add(lockKey);
|
|
1239
|
+
try {
|
|
1240
|
+
const out = await place({
|
|
1241
|
+
acct,
|
|
1242
|
+
who,
|
|
1243
|
+
hotel,
|
|
1244
|
+
group: p.group,
|
|
1245
|
+
roomId: ask.roomId,
|
|
1246
|
+
roomName: p.roomName,
|
|
1247
|
+
stay: p.stay,
|
|
1248
|
+
rooms: p.rooms,
|
|
1249
|
+
agreed: p.text,
|
|
1250
|
+
guest: ask.guest,
|
|
1251
|
+
total: p.total,
|
|
1252
|
+
});
|
|
1253
|
+
return {
|
|
1254
|
+
booked: out.booked ? [out.booked] : [],
|
|
1255
|
+
failed: out.failed ? [out.failed] : [],
|
|
1256
|
+
...(out.terms ? { terms: [out.terms] } : {}),
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
finally {
|
|
1260
|
+
inFlight.delete(lockKey);
|
|
1261
|
+
}
|
|
1262
|
+
};
|
|
1263
|
+
const discardTerms = async (ref, who) => {
|
|
1264
|
+
const found = pendingFor(ref, who);
|
|
1265
|
+
if (!found)
|
|
1266
|
+
return {};
|
|
1267
|
+
const { p, acct } = found;
|
|
1268
|
+
pending.delete(ref);
|
|
1269
|
+
if (!p.orderId)
|
|
1270
|
+
return {};
|
|
1271
|
+
const r = orders.get(p.orderId);
|
|
1272
|
+
if (!r || r.owner !== acct.owner || r.released || !r.held)
|
|
1273
|
+
return {};
|
|
1274
|
+
// ⚠️ NOT AGREED: the order it held back is cancelled (总线程 11-11, D).
|
|
1275
|
+
await release(acct, who, r, 'terms');
|
|
1276
|
+
return { booking: toBooking(r) };
|
|
1043
1277
|
};
|
|
1044
1278
|
// ── the bookings, refreshed ───────────────────────────────────────────────
|
|
1045
1279
|
const statusOfRow = (s) => {
|
|
@@ -1119,7 +1353,7 @@ export const createOtalessBookings = (deps) => {
|
|
|
1119
1353
|
};
|
|
1120
1354
|
/**
|
|
1121
1355
|
* The group's order list (12): statuses, a lost payment link, and an order
|
|
1122
|
-
*
|
|
1356
|
+
* 8 did not answer for. The rows when the list was read - undefined when it
|
|
1123
1357
|
* could not be (and nothing changed).
|
|
1124
1358
|
*
|
|
1125
1359
|
* ⚠️ WHAT IS LET GO OR STILL BEING LOOKED FOR IS NOT TOUCHED (总线程's review
|
|
@@ -1171,7 +1405,8 @@ export const createOtalessBookings = (deps) => {
|
|
|
1171
1405
|
...(r.refund?.amount ? { amount: r.refund.amount } : {}),
|
|
1172
1406
|
};
|
|
1173
1407
|
if (r.status === 'awaiting-payment' && !payLinks.has(r.id)) {
|
|
1174
|
-
|
|
1408
|
+
// 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);
|
|
1175
1410
|
if (ok)
|
|
1176
1411
|
payLinks.set(r.id, ok.url);
|
|
1177
1412
|
}
|
|
@@ -1180,7 +1415,7 @@ export const createOtalessBookings = (deps) => {
|
|
|
1180
1415
|
}
|
|
1181
1416
|
if (known.has(id))
|
|
1182
1417
|
continue;
|
|
1183
|
-
// ── an order
|
|
1418
|
+
// ── an order 8 did not answer for (总线程's review of 0.63.0, 3) ──
|
|
1184
1419
|
// ⚠️ THE SAME HOTEL, THE SAME ROOM, THE SAME NIGHTS - BY ID: the group and
|
|
1185
1420
|
// the nights alone would claim another stay of the guest's. The document's
|
|
1186
1421
|
// order rows carry no hotel or room id; until the backend sends them
|
|
@@ -1209,11 +1444,11 @@ export const createOtalessBookings = (deps) => {
|
|
|
1209
1444
|
// ⚠️ AT ANOTHER AMOUNT, NOT CLAIMED: the record keeps its own id and stays
|
|
1210
1445
|
// unconfirmed - for a person.
|
|
1211
1446
|
if (!charged || !(same(charged, o.quoted) || same(charged, o.quotedUsd))) {
|
|
1212
|
-
log(`[otaless] NEEDS A PERSON: an order
|
|
1447
|
+
log(`[otaless] NEEDS A PERSON: an order 8 did not answer for was found at ${group} at another amount - not claimed`);
|
|
1213
1448
|
continue;
|
|
1214
1449
|
}
|
|
1215
1450
|
const s = statusOfRow(row.status);
|
|
1216
|
-
const ok = payPageOf(text(row.checkoutUrl ?? undefined), deps.checkoutHosts);
|
|
1451
|
+
const ok = payPageOf(text(row.checkoutUrl ?? undefined), deps.checkoutHosts, id);
|
|
1217
1452
|
orders.delete(o.id);
|
|
1218
1453
|
o.id = id;
|
|
1219
1454
|
o.code = text(row.originalOrderId) ?? '';
|
|
@@ -1267,9 +1502,11 @@ export const createOtalessBookings = (deps) => {
|
|
|
1267
1502
|
if (acct)
|
|
1268
1503
|
signed.set(g, acct);
|
|
1269
1504
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1505
|
+
await sweep(who);
|
|
1506
|
+
// Cancelled at once, and gone: not the guest's. ⚠️ ONE THAT COULD NOT BE
|
|
1507
|
+
// CANCELLED STAYS LISTED (11-11): it may stand at the group - a person's,
|
|
1508
|
+
// with no page to pay it on.
|
|
1509
|
+
const mine = [...orders.values()].filter((o) => signed.get(o.group)?.owner === o.owner && (!o.released || o.releaseFailed));
|
|
1273
1510
|
await refresh(who, mine, signed);
|
|
1274
1511
|
const list = mine
|
|
1275
1512
|
.sort((a, b) => b.createdAt.localeCompare(a.createdAt))
|
|
@@ -1318,7 +1555,7 @@ export const createOtalessBookings = (deps) => {
|
|
|
1318
1555
|
...base,
|
|
1319
1556
|
fee: money(0, amount.currency),
|
|
1320
1557
|
refund: money(0, amount.currency),
|
|
1321
|
-
rule: 'Not paid yet
|
|
1558
|
+
rule: 'Not paid yet - nothing has been charged for it.',
|
|
1322
1559
|
cancellable: true,
|
|
1323
1560
|
reason: 'unpaid',
|
|
1324
1561
|
};
|
|
@@ -1353,9 +1590,8 @@ export const createOtalessBookings = (deps) => {
|
|
|
1353
1590
|
throw refusal('unconfirmed', `${g} has not said yet whether it took this booking, so it cannot be cancelled yet - look at the bookings again in a few minutes.`);
|
|
1354
1591
|
const unpaid = r.status === 'awaiting-payment' && !r.paid;
|
|
1355
1592
|
const why = cleanReason(reason);
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
: client.cancelBooking({ unifiedOrderId: r.id, providerCode: r.group, ...(why ? { reason: why } : {}) }, cred, deps.callerOf(who)));
|
|
1593
|
+
// 9, paid or not: 14 is not called any more (questions #56).
|
|
1594
|
+
const out = await withSession(acct, who, (cred) => client.cancelBooking({ unifiedOrderId: r.id, providerCode: r.group, ...(why ? { reason: why } : {}) }, cred, deps.callerOf(who)));
|
|
1359
1595
|
const said = cancelOutcome(out);
|
|
1360
1596
|
// ⚠️ NOTHING SAID IS NOT DONE (总线程's review of 0.63.0, 4): our record
|
|
1361
1597
|
// stays as it was, and the guest is told it is not known yet.
|
|
@@ -1366,6 +1602,11 @@ export const createOtalessBookings = (deps) => {
|
|
|
1366
1602
|
r.status = 'cancelled';
|
|
1367
1603
|
r.cancelledAt = iso();
|
|
1368
1604
|
payLinks.delete(r.id);
|
|
1605
|
+
// Held for terms: those terms go with it.
|
|
1606
|
+
r.held = undefined;
|
|
1607
|
+
for (const [k, p] of pending)
|
|
1608
|
+
if (p.orderId === r.id)
|
|
1609
|
+
pending.delete(k);
|
|
1369
1610
|
const back = moneyOf(out?.refundAmount, out?.refundCurrency);
|
|
1370
1611
|
if (!unpaid && r.paid)
|
|
1371
1612
|
r.refund = { status: 'requested', ...(back ? { amount: back } : {}) };
|
|
@@ -1533,6 +1774,7 @@ export const createOtalessBookings = (deps) => {
|
|
|
1533
1774
|
return found ? view(found.p) : undefined;
|
|
1534
1775
|
},
|
|
1535
1776
|
acceptTerms,
|
|
1777
|
+
discardTerms,
|
|
1536
1778
|
previewRefund,
|
|
1537
1779
|
refund,
|
|
1538
1780
|
addons,
|
|
@@ -1542,6 +1784,7 @@ export const createOtalessBookings = (deps) => {
|
|
|
1542
1784
|
ordersAwaitingPayment: [...orders.values()].filter((o) => o.status === 'awaiting-payment')
|
|
1543
1785
|
.length,
|
|
1544
1786
|
ordersUnconfirmed: [...orders.values()].filter((o) => o.status === 'unconfirmed').length,
|
|
1787
|
+
ordersHeld: [...orders.values()].filter((o) => o.held && !o.released).length,
|
|
1545
1788
|
groupSessions: sessions.size,
|
|
1546
1789
|
termsWaiting: pending.size,
|
|
1547
1790
|
...counts,
|