this seems easier than expected

This commit is contained in:
Andrew Brown 2019-07-06 03:17:51 -05:00
parent ff8ef968b4
commit e9ad3eff91
2 changed files with 7 additions and 4 deletions

View File

@ -6,16 +6,13 @@ class PageUnlockPromoCode < ApplicationRecord
page_types.split('|') & Rails.application.config.content_types[:all].map(&:name)
end
def already_activated_users
promotions.select(:user_id)
end
def activate!(user)
return false unless uses_remaining > 0
# Make sure this user hasn't activated this promo code before
return false unless user.present?
# return if users.where(id: user.id).any?
return false if users.pluck(:id).include?(user.id)
# Activate!
# technically two requests at the same time could still double-activate at

View File

@ -25,6 +25,7 @@ class User < ApplicationRecord
end
has_many :promotions
has_many :image_uploads
has_one :referral_code, dependent: :destroy
@ -133,6 +134,7 @@ class User < ApplicationRecord
"https://www.gravatar.com/avatar/#{email_md5}?d=identicon&s=#{size}".html_safe
end
# TODO these (3) can probably all be scopes on the related object, no?
def active_subscriptions
subscriptions
.where('start_date < ?', Time.now)
@ -144,6 +146,10 @@ class User < ApplicationRecord
BillingPlan.where(id: billing_plan_ids).uniq
end
def active_promotions
promotions.active
end
def initialize_stripe_customer
if self.stripe_customer_id.nil?
customer_data = Stripe::Customer.create(email: self.email)