Sha256: 11b18600a157fc25b58182b0d2106d45c14179cd57af3a2b7e49a24e1e404bfd

Contents?: true

Size: 963 Bytes

Versions: 3

Compression:

Stored size: 963 Bytes

Contents

class StripePlan < StripeModelCallbacks::ApplicationRecord
  belongs_to :stripe_product, optional: true, primary_key: "stripe_id"

  has_many :stripe_invoice_items, primary_key: "stripe_id"
  has_many :stripe_subscriptions, primary_key: "stripe_id"
  has_many :stripe_subscription_items, primary_key: "stripe_id"

  scope :not_deleted, -> { where(deleted_at: nil) }

  monetize :amount_cents

  def self.stripe_class
    Stripe::Plan
  end

  def assign_from_stripe(object)
    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[
        created currency id interval interval_count livemode metadata nickname statement_descriptor
        trial_period_days
      ]
    )
  end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stripe_model_callbacks-0.1.2 lib/stripe_model_callbacks/models/stripe_plan.rb
stripe_model_callbacks-0.1.1 lib/stripe_model_callbacks/models/stripe_plan.rb
stripe_model_callbacks-0.1.0 lib/stripe_model_callbacks/models/stripe_plan.rb