Skip to main content

How would I setup a two-sided referral program in rails with stripe?

Rails • Asked by Jonas Johnson
I want to set up a two-sided referral program in rails that would similar to the setup used by Dropbox. How would I get this setup? The referral program would work with Stripe to reward the referring user and the invited user.  My main offer would be to have one month free for each referral. Referrals would be easily shared from the rails app. The referring person can access a referral status page to track progress. Chris has an awesome Stripe course and ideally, this would pick up where the other course left off to add the referral program. I have been searching for existing training or gems but I have been unable to find anything current or similar. If this was offered as a course, I would gladly pay for the course to get this setup. 

Rough outline of how I'd build this:

1. Create a unique referral token for each user
2. Add the link to the UI for the user (link to the homepage with the token) 
<%= link_to root_url(ref: current_user.referral_token), root_url(ref: current_user.referral_token) %>
3. Create a before action on ApplicationController to set the referrer
before_action :set_referrer 
def set_referrer
  # Just store this for later, we will check this out during checkout
  cookies[:ref] = {value: params[:ref], expiry: 30.days.from_now} if params[:ref] && !user_signed_in?
end
4. Then you can check for cookies[:ref] during checkout and apply the discount to the user accounts.

Probably the easiest solution for giving these coupons / discounts out is by simply updating each of the user accounts and applying a credit to each one. This way you don't have to deal with Stripe Coupons or roll your own subscription system.

Also, Stripe has a tutorial on using coupons that will be good to read through even though you may not use this: https://stripe.com/docs/recipes/coupons-for-charges

Thanks, Chris I will give it a try.

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.