Class: StripePlan

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



12
13
14
# File 'lib/stripe_model_callbacks/models/stripe_plan.rb', line 12

def self.stripe_class
  Stripe::Plan
end

Instance Method Details

#assign_from_stripe(object) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/stripe_model_callbacks/models/stripe_plan.rb', line 16

def assign_from_stripe(object)
  check_object_is_stripe_class(object)
  self.active = object.active == true if object.respond_to?(:active)
  assign_attributes(amount: Money.new(object.amount, object.currency))
  self.stripe_product_id = object.product if object.respond_to?(:product)

  StripeModelCallbacks::AttributesAssignerService.execute!(
    model: self, stripe_model: object,
    attributes: %w[
      aggregate_usage amount_decimal billing_scheme
      created currency id interval interval_count livemode metadata nickname statement_descriptor
      trial_period_days usage_type
    ]
  )
end

#nameObject



32
33
34
# File 'lib/stripe_model_callbacks/models/stripe_plan.rb', line 32

def name
  nickname.presence || stripe_product&.name
end