Integrations

Track referred sales through Stripe

Connect your Stripe account and put one script tag on your site. Referred sales are then attributed on their own. A restricted key is a Stripe credential whose permissions you choose when you create it, and AffiliateRail uses one that reads charges and invoices and writes nothing. Test mode works the same as live. Test sales are marked, and a marked sale never pays anyone.

Published 3 September 2026. Every claim on this page was read off the documentation linked below on 3 September 2026. Written by Jimi Barkway, who built AffiliateRail. Jimi has run affiliate programs from both sides of the link. Corrections go to support@affiliaterail.com.

01 Attribution

How does a referred sale reach AffiliateRail?

Attribution is the job of deciding which partner gets credited for a sale. A visitor lands on a partner link. The script records the click and keeps the referral in a first-party cookie, which is one set by your own domain rather than a third party, so browsers treat it far better. The default window is 60 days, and the first touch wins.

If you sell through Stripe Checkout, a Payment Link, a Pricing Table or a Buy Button, there is nothing to build. The script stamps the checkout for you. When Stripe reports the payment, the sale lands and your rule prices the commission.

<script async
  src="https://app.affiliaterail.com/rail/v1/rail.js"
  data-rail="prg_xxxx"></script>
The whole install: one tag in the head of every page. Nothing else to add.

02 Server-side

What if I build checkout on my server?

Three lines of code. Read the rail_referral cookie, take its click id, and pass it to Stripe as metadata.rail_referral. Put it on the customer, the subscription or the checkout session, whichever you create.

The docs have the lines in Node, Next.js and Python. Binding is idempotent on the Stripe customer id. The first event that carries a click id wins, and a later one changes nothing.

Four ways a sale is attributed

  • Checkout, Payment Links, Pricing Tables, Buy Buttons

    Nothing to build. The script stamps the checkout.

  • Server-side metadata

    Three lines: read the cookie, take the click id, pass it to Stripe.

  • Coupons

    A promotion code is the discount code your customer types at checkout. Assign a Stripe one to a partner and sales using it are credited with no click at all.

  • Leads and the API

    Approved leads and API-created customers bind explicitly.

03 Read only

What does AffiliateRail read, and what can it write?

It reads charges, payment intents and invoices. It writes nothing. Stripe's consent screen asks for read and write access, because Stripe closed its read-only scope to new platforms. The key we point at your account is a restricted one that cannot write.

Refunds flow back and correct the commission on their own. Payouts never run through Stripe. They go from your own PayPal or Wise account.

The AffiliateRail home screen: revenue from affiliates, commissions, customers and clicks, with top partners and recent activity
The home screen: revenue from affiliates, commissions and clicks, all read from Stripe.

In their words

What Stripe's own page says

A unique string to reference the Checkout Session. This can be a customer ID, a cart ID, or similar, and can be used to reconcile the Session with your internal systems.

Stripe API reference, the Checkout Session object, client_reference_id, checked 3 September 2026

That is the field the tracking script stamps on Stripe Checkout, Payment Links, Pricing Tables and Buy Buttons, so the referral rides Stripe's own object back to the ledger and nothing on your side has to carry it.

Step by step

From an empty account to an attributed test sale

About 10 minutes, on test data, before any real money is involved.

  1. Connect Stripe in test mode

    From Getting started, choose Connect Stripe and pick your test-mode account. The event shapes are the same as live. Test sales are marked and never paid, so use your real programme.

  2. Put the tag on your site

    One script tag in the head of every page. Settings, Integrations shows it ready to copy with your program id. Or have your assistant add it and check it.

  3. Add yourself as a partner

    Getting started gives you a working link. Open your site through it and the verifier turns green when the click lands.

  4. Make a test sale

    Pay with Stripe's test card. The sale appears under Insights, Attribution health, and a commission under Commissions.

14 days free, no card. The steps above are the whole setup.

Said plainly

What the Stripe integration does, and does not do

Both lists are read off the same docs pages as everything else here.

It does

  • Attributes the Checkout family with nothing built

    Checkout, Payment Links, Pricing Tables and Buy Buttons. The script stamps client_reference_id, even on elements added after load.

  • Reads refunds and corrects the commission

    An unpaid commission is voided. A clawback is money taken back after you have already paid it, so a paid one becomes a deduction against the next balance.

  • Works with coupons

    Assign a partner a Stripe promotion code. Sales using it attribute even without a click.

  • Runs the same in test mode

    Connect a test account and prove the whole loop before any real money. Test sales are marked. They never pay a partner.

It does not

  • Write to your Stripe account

    The restricted key cannot. Payouts never touch Stripe either.

  • Fingerprint browsers

    A first-party cookie and localStorage. Nothing is read from the device beyond that.

  • Track inside an iframe

    The script refuses, which stops manufactured clicks.

Questions

Common questions

Do I need Stripe Checkout?

No. Checkout, Payment Links, Pricing Tables and Buy Buttons need nothing built. For Stripe Elements or any server-driven flow, pass the click id as metadata.rail_referral. Three lines of code.

Why does Stripe ask for read and write access?

Stripe closed its read-only scope to new platforms. The key AffiliateRail points at your account is a restricted one that can read charges, payment intents and invoices and write nothing.

What happens to a commission when a sale is refunded?

An unpaid commission is voided. An already-paid one gets a negative clawback booked against the partner's next balance.

Can I test it without real money?

Yes. Connect a test-mode account, click your own link and pay with Stripe's test card. The sale shows as attributed under Insights, Attribution health. It is marked as a test. It adds nothing to a partner's balance and never enters a payout, so you can do this on your real programme.

Sources

Where these facts come from

Every claim on this page was read off the product's own documentation on the date shown. The docs change with the product, and then this page is behind until we fix it. Email support@affiliaterail.com and we will correct it and move the date.

Start

Fourteen days to see a referred sale land, with nothing on the line

No card. Cancel in one click. Full refund within 30 days of your first payment.