Class: StripeSku

Inherits:
StripeModelCallbacks::ApplicationRecord show all
Defined in:
lib/stripe_model_callbacks/models/stripe_sku.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



4
5
6
# File 'lib/stripe_model_callbacks/models/stripe_sku.rb', line 4

def self.stripe_class
  Stripe::Sku
end

Instance Method Details

#assign_from_stripe(object) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/stripe_model_callbacks/models/stripe_sku.rb', line 8

def assign_from_stripe(object)
  assign_attributes(
    active: object.active == true,
    created: Time.zone.at(object.created),
    updated: Time.zone.at(object.updated),
    stripe_attributes: JSON.generate(object.attributes),
    inventory_quantity: object.inventory.quantity,
    inventory_type: object.inventory.type,
    inventory_value: object.inventory.value,
    livemode: object.livemode,
    metadata: JSON.generate(object.),
    price: Money.new(object.price, object.currency),
    stripe_product_id: object.product
  )

  StripeModelCallbacks::AttributesAssignerService.execute!(
    model: self, stripe_model: object,
    attributes: %w[currency]
  )
end