Class: Order::CrHoldReleaseReconciler

Inherits:
Object
  • Object
show all
Defined in:
app/subscribers/order/cr_hold_release_reconciler.rb

Overview

Synchronous RES subscriber for Events::OrderCrHoldReleaseStarted — runs
INSIDE the release_order transition transaction (the event is published
from a before_transition, not deferred to commit), so an exception
mid-reconcile rolls the whole release back and the order stays untouched in
in_cr_hold.

Re-establishes coherent state before the CR-hold release routes on its
guards (SO728077 defect D / P1.4): recomputes discounts (safe post-P1.1/P1.3)
and tops up the shared-PI authorization (P1.6, capture-aware, idempotent).
When the order is STILL short after that honest recompute it emits the
attributed P1.8 shortfall report — but deliberately does NOT block routing:
pending_payment is where the machine parks genuinely underfunded orders
(with its own re-release hop). What this fixes is releases routing on
CORRUPTED totals, not the existence of underfunded orders.

See Also:

  • doc/tasks/202607082351_P14_ATOMIC_CR_HOLD_RELEASEdoc/tasks/202607082351_P14_ATOMIC_CR_HOLD_RELEASE.md

Instance Method Summary collapse

Instance Method Details

#call(event) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/subscribers/order/cr_hold_release_reconciler.rb', line 20

def call(event)
  # Sync + in-transaction: a vanished order is a bug, fail loud (find).
  order = Order.find(event.data[:order_id])
  order.reset_discount(reset_item_pricing: false)
  order.reload
  Order::AuthorizationSplitter.topup(order) if order.balance.positive?
  order.reload
  return unless order.balance.positive?

  # Genuinely short after an honest recompute — the guards will route to
  # pending_payment on accurate totals; tell ops WHY (the defect H lesson).
  ErrorReporting.warning('CR-hold release: order still short after reconciliation',
                         order_id: order.id,
                         custom_data: { report: order.funds_shortfall_report })
end