A very simple referral program built on top on Stripe - how to segregate payments?

800 Views Asked by At

I have a page where there's a button which creates a Stripe session and a user gets redirected to Stripe and makes a payment there, for some digital product.

Some of my users my would also be members of my referral program. Such a user would then have a special URL with his unique "referral_id". And on the payment page I'd check whether or not URL contains "referral_id". The rest of the process, from the point of view of a user who makes a payment, would remain the same - redirect to Stripe and payment.

I plan that I'd save "referral_id" in metadata and send it along with other params, to create a Stripe session.

My goal: to be able to easily identify what payments have come under whose referral id, based on "referral_id" in metadata. And which with no referral at all. And also, to segregate the payments for each referral, to sum them up.... preferably via my Stripe dashboard.

For instance.

"Referral A has made $X this month"

"Referral B has made $Y this month"

"There've been $Z in payments with no referral, this month"

Q: how can I do this with "referral_id" in metadata? Would it be possible at all?


There won't be plenty of referral users... Let's say, there'll be 10 for a while.

I probably don't need Stripe Connect because I want everything to be as simple as possible for now.

2

There are 2 best solutions below

1
Jakub Ner On BEST ANSWER

The charges API allows specifying a description.

The description can be anything you want. It's your own tidbit of info you can have added to each transaction.

When you export transactions on the Stripe site to a CSV, the description can be exported too. I assume it can be extracted with their APIs as well.

Would that help / suffice?

const stripe = require('stripe')
await stripe(stripe_secret_key).charges.create({
    amount: ..,
    currency: ..,
    source: ..,
    application_fee: ..,
    description: "this here can be whatever"
  }, {
    stripe_account: accountId
  });
2
Paul Asjes On

There isn't really a way to do this on the Stripe dashboard, but you can certainly build something like this yourself.

You'd start by retrieving all the Checkout Sessions, then loop over the list and add up the totals based on the reference_id in metadata (or lack thereof).

Rather than redoing the above logic every time you want to check the totals (which will get progressively slower as the number of completed Checkout Sessions increases) you could instead rely on webhooks to increment your totals as they come in via the checkout.session.completed event.