Add payment structure
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user