Created
March 8, 2018 23:02
-
-
Save lettergram/6655c32f0f13a7adab0cdb8eea40f269 to your computer and use it in GitHub Desktop.
Referrals for rails user controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add referrals only to new users | |
referred_by = params[:referred_by] | |
if referred_by.present? | |
if User.exists?(referred_by) | |
referrer = User.find(referred_by) | |
subscription = PaymentSystem.get_subscription(referrer.subscription_id) | |
if subscription.trial_end > Time.now.to_i | |
subscription.trial_end = (Time.at(subscription.trial_end) + 90.days).to_i | |
else | |
subscription.trial_end = (Time.now + 90.days).to_i | |
end | |
subscription.save | |
@user.referred_by = referred_by.to_i | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment