Created
May 20, 2010 23:56
-
-
Save sprite2005/408296 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aasm_column :state | |
aasm_initial_state :initial | |
aasm_state :account_topped_up | |
aasm_state :back_in_conference | |
aasm_state :call_warned | |
aasm_state :contacting_client | |
aasm_state :contacting_vendor | |
aasm_state :client_left_chat | |
aasm_state :client_hungup_early | |
aasm_state :client_reject | |
aasm_state :declined_adding_credit | |
aasm_state :out_of_credit | |
aasm_state :vendor_left_chat | |
aasm_state :vendor_no_answer | |
aasm_state :vendor_reject | |
aasm_state :vendor_left_during_topup | |
aasm_state :in_conference | |
aasm_event :contact_client do | |
transitions :to => :contacting_client, | |
:from => :initial | |
end | |
aasm_event :recorded_listing_answered do | |
transitions :to => :recorded_listing_client_answered, | |
:from => [:initial, :contacting_client] | |
end | |
aasm_event :recorded_listing_listen do | |
transitions :to => :recorded_listing_client_listening, | |
:from => [:recorded_listing_client_answered], | |
:on_transition => lambda { |session| | |
listing = Listing.find_by_id session.listing_id | |
client = User.find_by_id session.client_id | |
vendor = User.find_by_id session.listing.user_id | |
call_log = session.call_log | |
call_log.billable_time = 0 | |
call_log.last_billed_time = Time.now | |
call_log.listing = listing | |
call_log.listing_name = listing.name | |
call_log.rate_cents = listing.rate_cents | |
call_log.client = client | |
call_log.vendor = vendor | |
call_log.live = false | |
# This code should be fine once Jason moves it | |
call_log.vendor_connection_charge_cents = 0 | |
call_log.vendor_number = vendor.active_phone_number.number | |
call_log.client_connection_charge_cents = client.active_phone_number.info.rate_in_cents | |
call_log.client_number = client.active_phone_number.number | |
# End | |
call_log.save | |
t = Transaction.begin_phone_transaction(vendor, client, call_log) | |
session.transaction_id = t.id | |
session.save } | |
end | |
aasm_event :recorded_listing_hangup do | |
transitions :to => :recorded_listing_client_hungup, | |
:from => [:recorded_listing_client_answered, :recorded_listing_client_listening], | |
:on_transition => lambda { |session| | |
t = Transaction.find_by_id session.transaction_id | |
if t | |
if t.progressing? | |
t.transaction_complete! | |
end | |
end } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment