Module: Carter::StateMachine::Cart::ClassMethods

Defined in:
lib/carter/state_machine.rb

Instance Method Summary collapse

Instance Method Details

#init_statesObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/carter/state_machine.rb', line 11

def init_states
  state_machine :state, :initial => :active do
    state :active, :processing, :failure, :success, :expired
    
    event :checkout do 
      transition [:active, :failure] => :processing
    end
  
    event :succeeded do
      transition :processing => :success
    end
  
    event :failed do
      transition :processing => :failure
    end
  
    event :expire do
      transition :active => :expired
    end
    
    after_transition :on => :succeeded, :do => :on_success # gateway says yes - to what is needed to add the products to the buyer.
    
    # +checkout hook+ - probably goes off to payment gateway.
    # expects another transition to be made in here to continue the cart lifecycle
    # possible actions are `cart.failed`, `cart.succeeded` for now that should do it.
    after_transition :on => :checkout, :do => :on_checkout 
    after_transition :on => :failed, :do => :on_failed
  end
end