Skip to content

Commit

Permalink
gen_fees rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Bolton committed May 13, 2012
1 parent 1f7bfef commit 5f87594
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
1 change: 1 addition & 0 deletions app/models/org_charge.rb
@@ -1,3 +1,4 @@
class OrgCharge < ActiveRecord::Base
belongs_to :organization
validates_uniqueness_of :stripe_id, scope: :organization_id
end
6 changes: 6 additions & 0 deletions db/migrate/20120513191039_add_amount_to_org_charge.rb
@@ -0,0 +1,6 @@
class AddAmountToOrgCharge < ActiveRecord::Migration
def change
add_column :org_charges, :amount, :integer

end
end
25 changes: 23 additions & 2 deletions db/schema.rb
Expand Up @@ -11,12 +11,27 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120513110608) do
ActiveRecord::Schema.define(:version => 20120513191039) do

create_table "campers", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "user_id"
t.text "health_info"
t.date "birthday"
t.string "first_name"
t.string "last_name"
t.string "street"
t.string "city"
t.string "state"
t.string "zip"
end

create_table "campers_courses", :force => true do |t|
t.integer "user_id"
t.integer "course_id"
t.string "stripe_id"
t.datetime "created_at"
t.datetime "charged_at"
t.integer "org_id"
end
Expand Down Expand Up @@ -58,8 +73,8 @@
t.integer "price"
t.text "reg_description"
t.string "reg_link"
t.boolean "show_map", :default => true
t.integer "max_campers"
t.boolean "show_map", :default => true
t.date "deadline"
t.boolean "deadline_set", :default => false
t.string "suite"
Expand Down Expand Up @@ -92,6 +107,7 @@
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "organization_id"
t.integer "amount"
end

create_table "organizations", :force => true do |t|
Expand Down Expand Up @@ -127,6 +143,11 @@
t.integer "organization_id"
end

create_table "organizations_users", :force => true do |t|
t.integer "organization_id"
t.integer "user_id"
end

create_table "users", :force => true do |t|
t.string "email", :null => false
t.string "crypted_password"
Expand Down
12 changes: 12 additions & 0 deletions lib/tasks/gen_fees.rake
@@ -0,0 +1,12 @@
task :gen_fees => :environment do
Organization.all.each do |organization|
Stripe.api_key = organization.stripe_secret
transactions = CampersCourses.where(org_id: organization.id).map{|c| c.stripe_id}.uniq
if transactions.present?
transactions.each{ |id|
amount = Stripe::Charge.retrieve(id).amount * 0.021
organization.org_charges.create(stripe_id: id, amount: amount)
}
end
end
end
9 changes: 0 additions & 9 deletions lib/tasks/stripe_info.rake

This file was deleted.

0 comments on commit 5f87594

Please sign in to comment.