Skip to content

Instantly share code, notes, and snippets.

@edave
Created February 5, 2011 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edave/812076 to your computer and use it in GitHub Desktop.
Save edave/812076 to your computer and use it in GitHub Desktop.
include AASM
aasm_column :current_state
aasm_state :active
aasm_state :free_trial
aasm_state :disabled #this is for accounts that have exceed free trial and have not paid
aasm_state :payment_failed
#aasm_state :free_acct
aasm_event :payment_succeeded do
transitions :to => :active, :from => [:free_trial, :disabled, :payment_failed] # when a payment succeeds, the account is active
end
aasm_event :disable do
transitions :to => :disabled, :from => [:free_trial, :active, :payment_failed] # when an account is overdue, or at the end of a free trial, it should be disabled
end
aasm_event :payment_failure do
transitions :to => :payment_failed, :from [:active, :disabled] # when an account tries to make a payment and it fails, send it into payment failure
transitions :to => :free_trial, :from [:free_trial] # when an account tries to make a payment during the free period, and it fails, just put them back into the free period
# should add a conditional check to make sure that this rule doesn't work if they've exceeded their free trial period
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment