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
|
2021-04-21 17:38:06 +02:00
|
|
|
has_one :payment_gateway_object, as: :item
|
2021-04-16 12:25:48 +02:00
|
|
|
|
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
|
2021-04-16 12:25:48 +02:00
|
|
|
return unless payment_gateway_object
|
2021-04-23 17:54:59 +02:00
|
|
|
|
|
|
|
stp_invoice = payment_gateway_object.gateway_object.retrieve
|
2021-06-02 20:07:53 +02:00
|
|
|
Stripe::PaymentIntent.retrieve(stp_invoice.payment_intent, api_key: Setting.get('stripe_secret_key')) # FIXME, maybe this is only used for stripe?
|
2021-01-27 17:24:10 +01:00
|
|
|
end
|
|
|
|
|
2020-12-21 17:37:58 +01:00
|
|
|
def self.columns_out_of_footprint
|
2021-04-16 12:25:48 +02:00
|
|
|
%w[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
|