Created
April 10, 2009 00:45
-
-
Save sprite2005/92851 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
| def begin_phone_transaction(vendor_user, client_user, call_log) | |
| vendor_tier1_user = vendor_user.parent | |
| vendor_tier2_user = vendor_user.parent.parent if vendor_tier1 | |
| client_tier1_user = client_user.parent | |
| client_tier2_user = client_user.parent.parent if client_tier1 | |
| t = new | |
| t.description = 'Phone Transaction' | |
| t.transaction_object = call_log | |
| t.transaction_type = 'phone' | |
| t.sender_user_transactions.build :user => client_user, :amount => Money.new(0, 'USD') | |
| t.receiver_user_transactions.build :user => vendor_user, :amount => Money.new(0, 'USD') | |
| t.system_user_transactions.build :user => SpecialUser.vipwithme_billing, :amount => Money.new(0, 'USD') | |
| # Build affiliate transactions | |
| t.tier1_user_transactions.build :user => vendor_tier1_user, :amount => Money.new(0, 'USD') if vendor_tier1_user | |
| t.tier1_user_transactions.build :user => client_tier1_user, :amount => Money.new(0, 'USD') if client_tier1_user | |
| t.tier2_user_transactions.build :user => vendor_tier2_user, :amount => Money.new(0, 'USD') if vendor_tier2_user | |
| t.tier2_user_transactions.build :user => client_tier2_user, :amount => Money.new(0, 'USD') if client_tier2_user | |
| t.save! | |
| t.transaction_progressing! | |
| t | |
| end | |
| end | |
| def update_phone_transaction | |
| # Update from the transaction object | |
| @vendor = receiver_user_transactions.first.user | |
| @client = sender_user_transactions.first.user | |
| # Amount client spends in cents | |
| client_amount = transaction_object.rate_cents * transaction_object.billable_time * -1 | |
| # Amount vendor receives | |
| vendor_amount = AppConfig.vendor_payout * transaction_object.billable_time * transaction_object.rate_cents | |
| # Vendor side refferaals | |
| tier1_amount = vendor_amount * AppConfig.tier1_payout | |
| tier2_amount = vendor_amount * AppConfig.tier2_payout | |
| total_payout = vendor_amount + tier1_amount * tier1_user_transactions.count + tier2_amount * tier2_user_transactions.count | |
| system_amount = client_amount - total_payout | |
| Transaction.transaction do | |
| rt = receiver_user_transactions.first.amount = Money.new(vendor_amount, transaction_object.currency) | |
| rt.save! | |
| st = sender_user_transactions.first.amount = Money.new(client_amount, transaction_object.currency) | |
| st.save! | |
| tier1_user_transactions.each do |ut| | |
| ut.amount = Money.new(tier1_amount, transaction_object.currency) | |
| ut.save! | |
| end | |
| tier2_user_transactions.each do |ut| | |
| ut.amount = Money.new(tier2_amount, transaction_object.currency) | |
| ut.save! | |
| end | |
| system = system_user_transactions.first.amount = Money.new(system_amount, transaction_object.currency) | |
| system.save! | |
| save! | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment