Class: RecurringPayment

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

Instance Method Summary collapse

Instance Method Details

#schedule_payment(date) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/recurring_payment.rb', line 7

def schedule_payment(date)
  unless self..nil?
    if self..has_outstanding_balance?
      payment_amount = self..outstanding_balance
      if payment_amount < self.pay_up_to_amount

        money = Money.create(
          :amount => payment_amount.to_d,
          :description => "AutoPayment",
          :currency => Currency.usd
        )
        financial_txn = FinancialTxn.create(
          :apply_date => date,
          :money => money
        )
        financial_txn.description = "AutoPayment"
        financial_txn. = self..
        financial_txn.save

        PaymentApplication.create(
          :financial_txn => financial_txn,
          :payment_applied_to => self.,
          :money => money,
          :comment => "AutoPayment"
        )

        #make sure the payment is below the pay_up_to_amount
      else
        #notify payment greater than amount in autopay
      end
    end#make sure the account has an outstanding balance
  end#make sure it has a payment account
  
end