Class: StripeCharge

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

Instance Attribute Summary

Attributes inherited from StripeModelCallbacks::ApplicationRecord

#stripe_object

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from StripeModelCallbacks::ApplicationRecord

check_object_is_stripe_class, #check_object_is_stripe_class, 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



13
14
15
# File 'lib/stripe_model_callbacks/models/stripe_charge.rb', line 13

def self.stripe_class
  Stripe::Charge
end

Instance Method Details

#assign_from_stripe(object) ⇒ Object



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

def assign_from_stripe(object)
  check_object_is_stripe_class(object)
  assign_attributes(
    created: Time.zone.at(object.created),
    stripe_customer_id: object.customer,
    livemode: object.livemode,
    stripe_invoice_id: object.invoice,
    metadata: JSON.generate(object.),
    stripe_order_id: object.order,
    stripe_source_id: object.source
  )

  assign_amounts_from_stripe(object)

  StripeModelCallbacks::AttributesAssignerService.execute!(
    model: self,
    stripe_model: object,
    attributes: %w[
      captured currency description dispute outcome refunded fraud_details failure_message failure_code on_behalf_of paid
      receipt_email receipt_number review shipping source_transfer statement_descriptor status transfer_group
    ]
  )
end