Class: StripeInvoice

Inherits:
StripeModelCallbacks::ApplicationRecord show all
Defined in:
lib/stripe_model_callbacks/models/stripe_invoice.rb

Instance Attribute Summary

Attributes inherited from StripeModelCallbacks::ApplicationRecord

#stripe_object

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from StripeModelCallbacks::ApplicationRecord

create_from_stripe!, create_on_stripe!, #destroy_on_stripe, #destroy_on_stripe!, #reload!, #reload_from_stripe!, #to_stripe, #update_on_stripe, #update_on_stripe!

Class Method Details

.stripe_classObject



14
15
16
# File 'lib/stripe_model_callbacks/models/stripe_invoice.rb', line 14

def self.stripe_class
  Stripe::Invoice
end

Instance Method Details

#assign_from_stripe(object) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/stripe_model_callbacks/models/stripe_invoice.rb', line 18

def assign_from_stripe(object)
  assign_attributes(
    stripe_charge_id: object.charge,
    stripe_customer_id: object.customer,
    stripe_subscription_id: object.subscription,
    due_date: object.due_date ? Time.zone.at(object.due_date) : nil,
    period_start: Time.zone.at(object.period_start),
    period_end: Time.zone.at(object.period_end)
  )

  assign_created(object)
  assign_amounts(object)

  StripeModelCallbacks::AttributesAssignerService.execute!(
    model: self, stripe_model: object,
    attributes: %w[
      attempted attempt_count billing closed currency description forgiven id livemode
      ending_balance forgiven next_payment_attempt number paid receipt_number
      starting_balance statement_descriptor tax_percent
    ]
  )

  assign_invoice_items(object)
end