Skip to content

Instantly share code, notes, and snippets.

@sprite2005
Created April 13, 2009 19:41
Show Gist options
  • Save sprite2005/94666 to your computer and use it in GitHub Desktop.
Save sprite2005/94666 to your computer and use it in GitHub Desktop.
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 / 60).to_i
# Amount vendor receives
vendor_amount = ((AppConfig.vendor_payout * transaction_object.billable_time * transaction_object.rate_cents)/60).to_i
# Vendor side refferaals
tier1_amount = (vendor_amount * AppConfig.tier1_payout).to_i
tier2_amount = (vendor_amount * AppConfig.tier2_payout).to_i
total_payout = (vendor_amount + tier1_amount * tier1_user_transactions.count + tier2_amount * tier2_user_transactions.count).to_i
system_amount = ((client_amount * -1) - total_payout).to_i
Transaction.transaction do
rt = receiver_user_transactions.first
rt.amount = Money.new(vendor_amount, transaction_object.currency)
rt.save!
st = sender_user_transactions.first
st.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
system.amount = Money.new(system_amount, transaction_object.currency)
system.save!
save!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment