Module: SpreeCmCommissioner::Checkout::CompleteDecorator

Defined in:
app/services/spree_cm_commissioner/checkout/complete_decorator.rb

Instance Method Summary collapse

Instance Method Details

#call(order:) ⇒ Object

Bypass the order state machine for transfer orders (skips guest finalization, unstocking, notifications). That also skips finalize!, which normally reconciles payment_state, so we reconcile it here to match the real order payment flow. It matters because with an auto-capture gateway the payment reaches :completed before completion, so Spree::Payment#update_order never sets payment_state (gated on order.completed?), leaving it nil. We call Spree's canonical update_payment_state, not the full updater.update, to leave transfer totals intact.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/spree_cm_commissioner/checkout/complete_decorator.rb', line 11

def call(order:)
  if order.ticket_transfer?
    order.updater.update_payment_total
    order.updater.update_payment_state

    order.update_columns( # rubocop:disable Rails/SkipsModelValidations
      state: 'complete',
      completed_at: order.completed_at || Time.current,
      payment_state: order.payment_state,
      payment_total: order.payment_total
    )
    success(order)
  else
    super
  end
end