Class: StripeProduct

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



5
6
7
# File 'lib/stripe_model_callbacks/models/stripe_product.rb', line 5

def self.stripe_class
  Stripe::Subscription
end

Instance Method Details

#assign_from_stripe(object) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/stripe_model_callbacks/models/stripe_product.rb', line 9

def assign_from_stripe(object)
  check_object_is_stripe_class(object, [Stripe::Product, Stripe::Subscription])
  assign_attributes(
    active: object.active == true,
    product_type: object.type,
    stripe_attributes: JSON.generate(object.attributes),
    updated: Time.zone.at(object.updated)
  )

  if object.respond_to?(:package_dimensions)
    assign_attributes(
      package_dimensions_height: object.package_dimensions&.height,
      package_dimensions_length: object.package_dimensions&.length,
      package_dimensions_weight: object.package_dimensions&.weight,
      package_dimensions_width: object.package_dimensions&.width
    )
  end

  assign_attributes(shippable: object.shippable == true) if object.respond_to?(:shippable)

  StripeModelCallbacks::AttributesAssignerService.execute!(
    model: self, stripe_model: object,
    attributes: %w[
      caption created description id livemode
      name metadata statement_descriptor unit_label
    ]
  )
end