Ask A Question

Notifications

You’re not receiving notifications from this thread.

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

Jonas Johnson asked in Rails
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. 
Reply
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
Reply
Thanks, Chris I will give it a try.
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,563+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.