Module: Spree::PaymentSessionTransitions
- Extended by:
- ActiveSupport::Concern
- Included in:
- PaymentSession, PaymentSetupSession
- Defined in:
- app/models/concerns/spree/payment_session_transitions.rb
Overview
Status transitions shared by PaymentSession and PaymentSetupSession — the replacement for their (identical) state machines.
Transitions are non-raising, matching the machines' non-bang events: the
webhook and synchronous completion paths race by design, and the loser
must land as a no-op false, never an exception. Each transition
publishes through the model's own publish_*_event method, exactly once —
only the writer whose conditional update moved the row publishes.
A transition writes status alone — unlike the machine's save, it never carries other dirty attributes along; a caller persists its own.
Instance Method Summary collapse
-
#can_cancel? ⇒ Boolean
A failed confirm can leave the provider intent payable.
-
#can_process? ⇒ Boolean
Guards preserved from the machine's transition graph.
- #cancel ⇒ Object
- #complete ⇒ Object
- #expire ⇒ Object
- #fail ⇒ Object
- #process ⇒ Object
Instance Method Details
#can_cancel? ⇒ Boolean
A failed confirm can leave the provider intent payable. Cancel is how placement retires it; the other transitions stay closed.
33 34 35 |
# File 'app/models/concerns/spree/payment_session_transitions.rb', line 33 def can_cancel? pending? || processing? || failed? end |
#can_process? ⇒ Boolean
Guards preserved from the machine's transition graph.
23 24 25 |
# File 'app/models/concerns/spree/payment_session_transitions.rb', line 23 def can_process? pending? end |
#cancel ⇒ Object
58 59 60 61 62 63 |
# File 'app/models/concerns/spree/payment_session_transitions.rb', line 58 def cancel return false unless transition_to('canceled', from: %w[pending processing failed]) publish_canceled_event true end |
#complete ⇒ Object
44 45 46 47 48 49 |
# File 'app/models/concerns/spree/payment_session_transitions.rb', line 44 def complete return false unless transition_to('completed', from: %w[pending processing]) publish_completed_event true end |
#expire ⇒ Object
65 66 67 68 69 70 |
# File 'app/models/concerns/spree/payment_session_transitions.rb', line 65 def expire return false unless transition_to('expired', from: %w[pending processing]) publish_expired_event true end |
#fail ⇒ Object
51 52 53 54 55 56 |
# File 'app/models/concerns/spree/payment_session_transitions.rb', line 51 def fail return false unless transition_to('failed', from: %w[pending processing]) publish_failed_event true end |
#process ⇒ Object
37 38 39 40 41 42 |
# File 'app/models/concerns/spree/payment_session_transitions.rb', line 37 def process return false unless transition_to('processing', from: %w[pending]) publish_processing_event true end |