Add payment structure

This commit is contained in:
2015-04-29 10:21:12 +02:00
parent 9d5e3f684c
commit e4e7198af5
8 changed files with 59 additions and 5 deletions
+16
View File
@@ -0,0 +1,16 @@
class ListPayment
include SimplyStored::Couch
include ActiveModel::SerializerSupport
property :amount
property :source # bitcoin, apple_pay, etc...
belongs_to :list
belongs_to :user
after_save :close_list_when_is_paid
validates :list_id, presence: true
def close_list_when_is_paid
amount_paid = list.list_payments.inject(0.0){|sum, payment| sum + payment.amount}
list.close! if amount_paid >= list.price
end
end