@curless/hotel-storefront 0.74.1 → 0.74.2

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.
@@ -629,7 +629,44 @@ export const cancelOutcome = (out) => {
629
629
  .toUpperCase();
630
630
  if (!s)
631
631
  return 'unknown';
632
- return CANCELLED_STATUSES.has(s) ? 'done' : 'refused';
632
+ // ⚠️ A PAID ORDER CANCELLED MAY BE ANSWERED BY ITS REFUND (0.74.2): "REFUNDED" from 9 is
633
+ // a cancellation done and its money on the way back - never "it stands as it was".
634
+ return CANCELLED_STATUSES.has(s) || REFUND_STATUSES.has(s) ? 'done' : 'refused';
635
+ };
636
+ /** 9's (and 12's) statuses that say a paid order's money is going back or is back. */
637
+ export const REFUND_STATUSES = new Set([
638
+ 'REFUNDED',
639
+ 'REFUNDING',
640
+ 'REFUND_REQUESTED',
641
+ 'REFUND_PENDING',
642
+ 'REFUND_PROCESSING',
643
+ 'REFUND_SUBMITTED',
644
+ ]);
645
+ /**
646
+ * Whether 9's answer for a PAID order says its money is going back (0.74.2, robin 11-17 through
647
+ * 总线程: one Cancel, which asks the refund too): `refunded` - its status says it is back;
648
+ * `requested` - a refund status, an amount going back above nothing, or its own words saying the
649
+ * refund was taken; undefined - none of these, so 9.1 is asked in the same cancel.
650
+ *
651
+ * ⚠️ WORDS THAT REFUSE A REFUND ARE NOT ONE: 「退款申请失败」 has 「退款申请」 in it.
652
+ */
653
+ export const cancelRefundSaid = (out) => {
654
+ const s = String(out?.status ?? '')
655
+ .trim()
656
+ .toUpperCase();
657
+ if (s === 'REFUNDED')
658
+ return 'refunded';
659
+ if (REFUND_STATUSES.has(s))
660
+ return 'requested';
661
+ const n = Number(out?.refundAmount);
662
+ if (Number.isFinite(n) && n > 0)
663
+ return 'requested';
664
+ const msg = String(out?.message ?? '');
665
+ if (/退款[^。.!!,,;;]{0,4}(失败|未|不|没有|无法|拒)|(无需|不予|不能|无法|未|没有?)(申请)?退款|\brefund(s|ed)?\b[^.,;]{0,20}\b(fail(ed)?|not|unable|denied|rejected|error)\b|\bno refund\b/i.test(msg))
666
+ return undefined;
667
+ if (/已(经)?(全额)?退款|退款(已|已经)?(受理|提交|申请成功|发起|处理中|成功)|已(申请|发起|提交)(了)?退款|\brefund(s|ed)?\b[^.]{0,30}\b(accepted|requested|submitted|initiated|processing|pending|issued|completed|on its way)\b|\b(was|been|is) refunded\b/i.test(msg))
668
+ return 'requested';
669
+ return undefined;
633
670
  };
634
671
  /**
635
672
  * The backend refusing because the guest's membership of that group is not linked - or its
@@ -685,6 +722,8 @@ export const createOtalessBookings = (deps) => {
685
722
  termsSent: 0,
686
723
  termsAgreed: 0,
687
724
  sessionRetried: 0,
725
+ /** Cancelled, and the refund the cancel asked (9.1) not taken - a person takes it up (0.74.2). */
726
+ refundNotSent: 0,
688
727
  };
689
728
  const keyOf = (who) => who.tripOwner ?? who.sessionId;
690
729
  const accountFor = (who, group) => {
@@ -901,6 +940,10 @@ export const createOtalessBookings = (deps) => {
901
940
  ...(r.refund.amount && !same(r.refund.amount, amount)
902
941
  ? { refundAmount: r.refund.amount }
903
942
  : {}),
943
+ // 0.74.2: the cancel's 9.1 not taken - said as held up, a person seeing to it.
944
+ ...(r.refund.status === 'not-sent' ? { refundStuck: true } : {}),
945
+ // Asked of the group, which reviews it before it goes back (9.1's own document).
946
+ ...(r.refund.status !== 'refunded' ? { groupReviews: true } : {}),
904
947
  };
905
948
  if (r.paid)
906
949
  return { method: 'card', amount, status: 'paid' };
@@ -2393,7 +2436,11 @@ export const createOtalessBookings = (deps) => {
2393
2436
  terms.push(termsBefore(ask, unsaid));
2394
2437
  }
2395
2438
  // Nothing booked, nothing waiting: the sign-in or link the backend asked for is the answer.
2396
- if (stayRefusals[0] && !booked.length && !terms.length)
2439
+ // ⚠️ UNLESS ANOTHER STAY FAILED BESIDE IT (0.74.2, 总线程's review of 0.74.1, P3): thrown,
2440
+ // the refusal took that stay's failure out of the answer - an order 8 made and we could not
2441
+ // cancel (「取消没成功、需要人工、不要付款」), still in the bookings and in the way of booking it
2442
+ // again. Then every failure is the answer, the refused stay's with its groups.
2443
+ if (stayRefusals[0] && !booked.length && !terms.length && failed.length <= stayRefusals.length)
2397
2444
  throw stayRefusals[0];
2398
2445
  return {
2399
2446
  booked,
@@ -2915,12 +2962,63 @@ export const createOtalessBookings = (deps) => {
2915
2962
  for (const [k, p] of pending)
2916
2963
  if (p.orderId === r.id)
2917
2964
  pending.delete(k);
2918
- const back = moneyOf(out?.refundAmount, out?.refundCurrency);
2919
- if (!unpaid && r.paid)
2920
- r.refund = { status: 'requested', ...(back ? { amount: back } : {}) };
2965
+ if (!unpaid && r.paid) {
2966
+ const said = cancelRefundSaid(out);
2967
+ const back = moneyOf(out?.refundAmount, out?.refundCurrency);
2968
+ if (said || !deps.refundsOn)
2969
+ // 9 said its money is going back (or is back) - never asked twice. Refunds off: what
2970
+ // 9 said, as it was before 0.74.2.
2971
+ r.refund = {
2972
+ status: said === 'refunded' ? 'refunded' : 'requested',
2973
+ ...(back && back.minor > 0 ? { amount: back } : {}),
2974
+ };
2975
+ else {
2976
+ // ⚠️ ONE CANCEL, AND THE MONEY ASKED BACK IN IT (0.74.2, robin 11-17 through 总线程:
2977
+ // 「申请退款和取消有什么区别,应该留一个取消就好了」): 9 did not say the refund was taken, so
2978
+ // 9.1 is asked now, all of it, as the refund tool did. ⚠️ CANCELLED STAYS CANCELLED:
2979
+ // a 9.1 that fails is said as that - a person takes it up - never "not cancelled".
2980
+ put(r);
2981
+ r.refund = await askRefund(r, acct, who, why);
2982
+ }
2983
+ }
2921
2984
  put(r);
2922
2985
  return toBooking(r);
2923
2986
  };
2987
+ /**
2988
+ * 9.1 for an order just cancelled (0.74.2): what the group did with it, or `not-sent` - its
2989
+ * refusal or silence logged in its own words for a person to take up. Nothing thrown.
2990
+ */
2991
+ const askRefund = async (r, acct, who, why) => {
2992
+ const g = r.group;
2993
+ try {
2994
+ const out = await withSession(acct, who, (cred) => client.refund({
2995
+ unifiedOrderId: r.id,
2996
+ ...(r.code ? { booking: r.code } : {}),
2997
+ providerCode: r.group,
2998
+ ...(why ? { reason: why } : {}),
2999
+ }, cred, deps.callerOf(who)));
3000
+ if (out?.success === false) {
3001
+ counts.refundNotSent += 1;
3002
+ log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${g} was cancelled, and its refund (9.1) was refused: ${forTheLog(String(out?.message ?? out?.status ?? 'no words'))} - nothing goes back until a person takes it up`);
3003
+ return { status: 'not-sent' };
3004
+ }
3005
+ const back = moneyOf(out?.refundAmount, out?.refundCurrency);
3006
+ return {
3007
+ status: String(out?.status ?? '').toUpperCase() === 'REFUNDED' ? 'refunded' : 'requested',
3008
+ ...(back && back.minor > 0 ? { amount: back } : {}),
3009
+ };
3010
+ }
3011
+ catch (err) {
3012
+ counts.refundNotSent += 1;
3013
+ const words = err instanceof OtalessError
3014
+ ? `${err.backendCode ?? err.status ?? ''} ${String(err.answer?.msg ?? err.message)}`
3015
+ : err instanceof Error
3016
+ ? err.message
3017
+ : String(err);
3018
+ log(`[otaless] NEEDS A PERSON: ${forTheLog(r.id)} at ${g} was cancelled, and its refund (9.1) ${unanswered(err) ? 'was not answered' : 'failed'}: ${forTheLog(words)} - nothing goes back until a person takes it up`);
3019
+ return { status: 'not-sent' };
3020
+ }
3021
+ };
2924
3022
  // ── refund: a preview, then the refund it previewed (9.1; 总线程's review of 0.63.0, B) ──
2925
3023
  /** Refund previews waiting to be sent, by their `preview`. */
2926
3024
  const refundPreviews = new Map();