diff --git a/app/models/org_charge.rb b/app/models/org_charge.rb index 032a35a..88d000b 100644 --- a/app/models/org_charge.rb +++ b/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 diff --git a/db/migrate/20120513191039_add_amount_to_org_charge.rb b/db/migrate/20120513191039_add_amount_to_org_charge.rb new file mode 100644 index 0000000..f455fd6 --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index 7ae961f..eb78722 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 @@ -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" @@ -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| @@ -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" diff --git a/lib/tasks/gen_fees.rake b/lib/tasks/gen_fees.rake new file mode 100644 index 0000000..67135b2 --- /dev/null +++ b/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 diff --git a/lib/tasks/stripe_info.rake b/lib/tasks/stripe_info.rake deleted file mode 100644 index 8a7d832..0000000 --- a/lib/tasks/stripe_info.rake +++ /dev/null @@ -1,9 +0,0 @@ -task :stripe_info => :environment do - CampersCourses.all.each do |cc| - Stripe.api_key = Course.find(cc.course_id).organization.stripe_secret - cc.update_attributes( - org_id: Course.find(cc.course_id).organization.id, - charged_at: Time.at(Stripe::Charge.retrieve(cc.stripe_id).created.to_i) - ) - end -end