Sha256: 5c6b128293c2957919840e78c3a2ac3efeae5bad65bcc9e56b5f765c2aaee8ac
Contents?: true
Size: 910 Bytes
Versions: 3
Compression:
Stored size: 910 Bytes
Contents
module Spree class Subscription < Spree::Base include RoleSubscriber include RestrictiveDestroyer include ApiHandler acts_as_restrictive_destroyer column: :unsubscribed_at attr_accessor :card_token self.whitelisted_ransackable_attributes = %w[email subscribed_at] 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
3 entries across 3 versions & 1 rubygems