Sha256: ce1534d7b227ca53fbe9f3ef139955a66f3e72afce2fbb43a7e332f39537f01a

Contents?: true

Size: 850 Bytes

Versions: 3

Compression:

Stored size: 850 Bytes

Contents

class StripeSku < StripeModelCallbacks::ApplicationRecord
  monetize :price_cents

  def self.stripe_class
    Stripe::Sku
  end

  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.metadata),
      price: Money.new(object.price, object.currency),
      stripe_product_id: object.product
    )

    StripeModelCallbacks::AttributesAssignerService.execute!(
      model: self, stripe_model: object,
      attributes: %w[currency]
    )
  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_sku.rb
stripe_model_callbacks-0.1.1 lib/stripe_model_callbacks/models/stripe_sku.rb
stripe_model_callbacks-0.1.0 lib/stripe_model_callbacks/models/stripe_sku.rb