Search code examples
database-designreferralsstripe-payments

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


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.


Solution

  • 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
      });