Sha256: a1f08282566442cdcee03d33781180f49852d967534637a881a771b08e1629c5

Contents?: true

Size: 846 Bytes

Versions: 14

Compression:

Stored size: 846 Bytes

Contents

module Spree
  class Subscription < ActiveRecord::Base
    include RoleSubscriber
    include RestrictiveDestroyer
    include ApiHandler

    acts_as_restrictive_destroyer column: :unsubscribed_at
    attr_accessor :card_token

    belongs_to :plan
    belongs_to :user
    has_many :events, class_name: 'Spree::SubscriptionEvent'

    validates :plan_id, :email, :user_id, presence: true
    validates :plan_id, uniqueness: { scope: [:user_id, :unsubscribed_at] }
    validates :user_id, uniqueness: { scope: :unsubscribed_at }

    delegate_belongs_to :plan, :api_plan_id
    before_validation :set_email, on: :create

    validate :verify_plan, on: :create

    private

    def set_email
      self.email = user.try(:email)
    end

    def verify_plan
      errors.add :plan_id, "is not active." unless plan.try(:visible?)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
spree_account_recurring-1.1.5 app/models/spree/subscription.rb
spree_account_recurring-1.0.7 app/models/spree/subscription.rb
spree_account_recurring-1.1.4 app/models/spree/subscription.rb
spree_account_recurring-1.0.6 app/models/spree/subscription.rb
spree_account_recurring-1.0.5 app/models/spree/subscription.rb
spree_account_recurring-1.1.3 app/models/spree/subscription.rb
spree_account_recurring-1.1.2 app/models/spree/subscription.rb
spree_account_recurring-1.0.4 app/models/spree/subscription.rb
spree_account_recurring-1.0.3 app/models/spree/subscription.rb
spree_account_recurring-1.0.2 app/models/spree/subscription.rb
spree_account_recurring-1.1.1 app/models/spree/subscription.rb
spree_account_recurring-1.1.0 app/models/spree/subscription.rb
spree_account_recurring-1.0.1 app/models/spree/subscription.rb
spree_account_recurring-1.0.0 app/models/spree/subscription.rb