Sha256: 05365a10bd91631646d0e765d91d8d6ae584778c033be67e321119400244c697

Contents?: true

Size: 1.13 KB

Versions: 17

Compression:

Stored size: 1.13 KB

Contents

module Stripe
  module Plans
    class BillingTier
      include ActiveModel::Validations

      validates_presence_of :up_to
      validates_presence_of :flat_amount, if: ->(tier) { tier.unit_amount.nil? },
        message: 'one of `flat_amount` or `unit_amount` must be specified!'
      validates_presence_of :unit_amount, if: ->(tier) { tier.flat_amount.nil? },
        message: 'one of `flat_amount` or `unit_amount` must be specified!'
      validates_absence_of :flat_amount, if: ->(tier) { tier.unit_amount.present? },
        message: 'only one of `flat_amount` or `unit_amount` should be specified!'
      validates_absence_of :unit_amount, if: ->(tier) { tier.flat_amount.present? },
        message: 'only one of `flat_amount` or `unit_amount` should be specified!'

      attr_accessor :up_to, :flat_amount, :unit_amount

      def initialize(attrs)
        @up_to = attrs[:up_to]
        @flat_amount = attrs[:flat_amount]
        @unit_amount = attrs[:unit_amount]
      end

      def to_h
        {
          up_to: up_to,
          flat_amount: flat_amount,
          unit_amount: unit_amount
        }.compact
      end

    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
stripe-rails-2.6.0 lib/stripe/billing_tier.rb
stripe-rails-2.5.0 lib/stripe/billing_tier.rb
stripe-rails-2.4.0 lib/stripe/billing_tier.rb
stripe-rails-2.3.5 lib/stripe/billing_tier.rb
stripe-rails-2.3.4 lib/stripe/billing_tier.rb
stripe-rails-2.3.3 lib/stripe/billing_tier.rb
stripe-rails-2.3.2 lib/stripe/billing_tier.rb
stripe-rails-2.3.1 lib/stripe/billing_tier.rb
stripe-rails-2.3.0 lib/stripe/billing_tier.rb
stripe-rails-2.2.1 lib/stripe/billing_tier.rb
stripe-rails-2.2.0 lib/stripe/billing_tier.rb
stripe-rails-2.1.0 lib/stripe/billing_tier.rb
stripe-rails-2.0.0 lib/stripe/billing_tier.rb
stripe-rails-1.10.2 lib/stripe/billing_tier.rb
stripe-rails-2.0.0.pre lib/stripe/billing_tier.rb
stripe-rails-1.10.1 lib/stripe/billing_tier.rb
stripe-rails-1.10.0 lib/stripe/billing_tier.rb