1
0
Fork 0
forked from OpenNeo/impress
impress/app/models/donation.rb

27 lines
596 B
Ruby
Raw Normal View History

2014-09-09 19:06:38 -07:00
class Donation < ActiveRecord::Base
belongs_to :user
def self.create_from_charge(user, params)
amount = (BigDecimal.new(params[:amount]) * 100).floor
customer = Stripe::Customer.create(
card: params[:stripe_token]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => amount,
:description => 'Donation (thank you!)',
:currency => 'usd'
)
donation = Donation.new
donation.amount = amount
donation.charge_id = charge.id
donation.user_id = user.try(:id)
donation.save!
donation
end
end