Class: Billingly::Payment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/billingly/payment.rb

Class Method Summary collapse

Class Method Details

.credit_for(customer, amount) ⇒ Object

Process a new payment done by a customer. Payments can be credited at any point and they are bound to increase a customer’s balance. Payments are not mapped 1 to 1 with invoices, instead, invoices are deemed as paid whenever the customer’s balance is enough to cover them.



13
14
15
16
17
# File 'app/models/billingly/payment.rb', line 13

def self.credit_for(customer, amount) 
  create!(amount: amount, customer: customer).tap do |payment|
    customer.add_to_journal(amount, :cash, :paid, payment: payment)
  end
end