2020-10-27 16:02:41 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Represents a due date and the associated amount for a PaymentSchedule
|
2020-12-22 09:53:41 +01:00
|
|
|
class PaymentScheduleItem < Footprintable
|
2020-10-27 16:02:41 +01:00
|
|
|
belongs_to :payment_schedule
|
2020-11-12 16:44:55 +01:00
|
|
|
belongs_to :invoice
|
2020-12-16 18:33:43 +01:00
|
|
|
after_create :chain_record
|
|
|
|
|
2021-01-25 13:05:27 +01:00
|
|
|
def first?
|
|
|
|
payment_schedule.ordered_items.first == self
|
|
|
|
end
|
|
|
|
|
2021-01-27 17:24:10 +01:00
|
|
|
def payment_intent
|
|
|
|
return unless stp_invoice_id
|
|
|
|
|
|
|
|
key = Setting.get('stripe_secret_key')
|
|
|
|
stp_invoice = Stripe::Invoice.retrieve(stp_invoice_id, api_key: key)
|
|
|
|
Stripe::PaymentIntent.retrieve(stp_invoice.payment_intent, api_key: key)
|
|
|
|
end
|
|
|
|
|
2020-12-21 17:37:58 +01:00
|
|
|
def self.columns_out_of_footprint
|
2021-02-08 15:28:47 +01:00
|
|
|
%w[invoice_id stp_invoice_id state payment_method client_secret]
|
2020-12-21 17:37:58 +01:00
|
|
|
end
|
2020-10-27 16:02:41 +01:00
|
|
|
end
|