Skip to main content
Refer a friend: you get 1,000 credits when they first pay for Pro or Team; they get 20% off for 3 months.
Turn customers into a sales channel. A referral program gives a reward to a customer who brings a new one (the referrer), and optionally one to the new customer (the referee). Ledger makes each referrer’s code, checks every redemption, waits for the trigger you choose, checks the cards in Stripe, and pays out both sides. Each reward is a reward from your catalog: a coupon that takes money off, or a grant of credits or units.

The catalog

Add referralPrograms to your catalog beside the rewards they name, or write one with POST /v1/referral-programs:
ledger.catalog.json
A catalog without referralPrograms leaves your programs as they are; one with it states all of them, and a program left out is archived. A change to a program applies to referrals from then on; referrals already rewarded keep what they got.

Give each referrer a code

Get a customer’s referral code returns the referrer’s code in a program: made on the first call, the same one on every call after. Show it on their account page or in a share link.
Codes are 8 characters from A-Z and 2-9, without the look-alikes 0, O, 1, I and L, and unique among all your codes, promotion codes included.

Redeem a referral code

The new customer types the code where they’d type a promotion code, and your app sends it to POST /v1/customers/redemptions, the same route as any promotion code:
The reply has the referral: rewarded at once for a signup program, pending until the trigger for first_payment. When the program gives the new customer a reward at redeem, the reply also carries their redemption.

What each side gets, and when

A coupon goes on the bill like any discount, and a grant joins the customer’s balance and sends credits.granted.

The trigger

With first_payment, a referral pays out once it has turned into revenue: the new customer’s first invoice with money paid for a covered plan. Ledger records the trigger in the same transaction as the payment, from every path that pays for a plan: a first invoice, a lifetime plan, a converted trial, a renewal or an upgrade. A free plan, a trial’s $0 invoice or a 100%-off first month waits for the first invoice with money on it. The referral worker then pays it out within seconds:
  1. It reads the cards saved on both customers in Stripe. If the new customer has a card the referrer has saved (the same card fingerprint), the referral is refused with same_payment_method.
  2. If the referrer already has maxRewardsPerReferrer rewards, it’s refused with referrer_limit_reached.
  3. Otherwise it’s rewarded: both rewards are given and a referral.rewarded webhook is sent.
The new customer keeps their own reward when a referral is refused. If Stripe is unavailable, the worker retries, from 30 seconds apart up to once an hour, until it gets an answer.

Fraud checks

Ledger refuses a referral code for:
  • the referrer themselves, or a customer on the same Stripe customer (422 self_referral);
  • a customer already referred in this program (409 already_referred);
  • a customer who has paid for a plan or credit pack (409 referee_not_new), so referral rewards go to genuinely new customers;
  • with signup, a referrer who already has maxRewardsPerReferrer rewards (409 referrer_limit_reached).
At the trigger, the card check stops a customer referring themselves with a second account.

See a customer’s referrals

List a customer’s referrals returns their codes, the customers they referred (asReferrer, newest first), and who referred them (asReferee), each with its status and refusedReason.

Routes

Webhooks

Rules

  • A program’s rewards are active rewards of the environment (unknown_reward).
  • Archive a program before archiving a reward it gives (409 reward_in_use). Archiving a program stops new codes and redemptions; referrals already made keep their rewards.
  • Each customer is referred once per program, and only before they’ve paid for a plan or credit pack.
  • A refund of the new customer’s payment leaves the referrer’s reward in place.