Now with MCP · your agent can query commission, affiliates, and payouts. Read-only. Connect a client
← Blog

How to Add an Affiliate Program to Stripe (2026)

Stripe has no built-in affiliate program. Set one up in 15 minutes, script, webhook, and recurring commission that survives renewals.

SSled13 min read
·Share on X

Stripe processes most of the indie SaaS revenue on the internet in 2026. It's powerful, it's reliable, and it's the default payment infrastructure for almost every B2B subscription product you've ever heard of.

But it has a notable gap that surprises every first-time founder: Stripe has no built-in affiliate program. No referral tracking, no commission ledger, no affiliate dashboard. The pricing page sells "Billing," "Tax," "Connect," "Atlas," "Radar," "Sigma" (every adjacent feature you can think of) but referral attribution is conspicuously absent.

The reason Stripe doesn't build it is the same reason they don't build a CRM: they want their platform to be unopinionated infrastructure, with third-party tools layering on top. Which is fine, except that the affiliate-tool market is split between expensive enterprise tools (Rewardful, Tolt, FirstPromoter at $49–$249/mo) and a long tail of janky abandoned WordPress plugins. There's surprisingly little in the middle.

This guide walks through the modern way to set up Stripe affiliate tracking in 2026: a 15-minute integration that handles attribution, recurring commission on subscription renewals, refund clawback, and a self-serve affiliate dashboard. Same shape as a Polar or Paddle setup, but tuned for Stripe's specific webhook quirks.

You, realizing on month two that "invoice.payment_succeeded" doesn't carry your checkout metadata

What you'll have when you're done

  • A public signup page where creators join your affiliate program (no approval queue required)
  • A unique referral link per affiliate (e.g. yourapp.com/?ref=alex2026)
  • Automatic attribution when a referred visitor completes Stripe Checkout
  • Recurring commission that follows subscription renewals, the single hardest part to get right
  • Refund handling that claws back commission when a customer disputes or refunds
  • A dashboard showing clicks, MRR by affiliate, pending payouts
  • An affiliate-facing dashboard where each creator sees their own numbers

Total setup time: 10–15 minutes assuming you're comfortable in your Stripe dashboard and your checkout code.

TL;DR

The three snippets that do 95% of the work:

<!-- 1. Drop on your marketing site -->
<script async src="https://usesled.com/{your-slug}/t.js"></script>
2. In Stripe Dashboard → Developers → Webhooks → Add endpoint:
   URL:    https://usesled.com/{your-slug}/api/webhook/stripe
   Events: checkout.session.completed
           invoice.payment_succeeded
           charge.refunded
// 3. In your Stripe checkout-session creation
await stripe.checkout.sessions.create({
  line_items: [{ price: priceId, quantity: 1 }],
  mode: "subscription",
  success_url: "https://yourapp.com/thanks",
  metadata: {
    referral: cookies().get("ta_ref")?.value ?? "",
  },
});

That's it. The rest of this post explains why each piece exists, the Stripe-specific gotchas, and the subscription-renewal pitfall that bites every DIY affiliate integration in month two.

How Stripe affiliate tracking actually works

Five moments in the flow:

  1. Visitor arrives via affiliate link. Someone on Twitter shared yourapp.com/?ref=alex2026. The visitor clicked.
  2. Tracking script reads the parameter and drops a cookie. A ~1KB JS script (t.js) reads ?ref=alex2026 and writes a ta_ref cookie for 90 days.
  3. Visitor browses, eventually starts checkout. Could be 30 seconds, could be 8 weeks. While the cookie is alive, attribution holds.
  4. Your checkout code passes the cookie to Stripe. When you create the Stripe Checkout Session, you attach metadata: { referral: cookieValue }. The Stripe Session carries this metadata through to the resulting subscription and every future renewal-related event.
  5. Stripe fires webhooks. Your affiliate tool receives checkout.session.completed, looks up metadata.referral, matches it to an affiliate, and records the conversion + commission. For renewals, it fires invoice.payment_succeeded.

The key insight: attribution is server-side, via Stripe metadata, not client-side. You don't need any JavaScript on your /thanks page. The webhook does the work after the order completes.

Step 1: Drop the tracking script

Pick an affiliate tool. We'll use Sled in the examples because it's Stripe-aware out of the box (handles whsec_ signature verification, subscription renewal events, charge refunds), but the shape is identical for any Stripe-compatible tool.

After signup, you get a slug (say acme) and a tracking script URL:

<script async src="https://usesled.com/acme/t.js"></script>

Drop it in the <head> of your marketing site. On Next.js App Router:

// app/layout.tsx
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <head>
        <script async src="https://usesled.com/acme/t.js"></script>
      </head>
      <body>{children}</body>
    </html>
  );
}

What the script does:

  • Reads ?ref=CODE from the URL
  • Writes CODE into a first-party ta_ref cookie (90-day default)
  • POSTs a click event to your affiliate tool (deduped by IP for 24 hours so refreshes don't inflate counts)

Under 1KB minified, no external dependencies, no third-party calls. Safe to drop on every page including landing pages with strict performance budgets.

Step 2: Add the Stripe webhook

In your Stripe Dashboard → Developers → Webhooks → Add endpoint:

Field Value
Endpoint URL https://usesled.com/acme/api/webhook/stripe
Events to send checkout.session.completed, invoice.payment_succeeded, charge.refunded
API version Default (your account's current version)

Stripe will generate a signing secret that starts with whsec_. Copy it.

In Sled (or whichever tool), paste the secret at Settings → Stripe webhook secret. This is how the tool verifies that incoming events actually came from Stripe and weren't spoofed by an attacker hitting your webhook URL with fake commission events.

Gotcha: Stripe webhooks include a Stripe-Signature header in the format t=<timestamp>,v1=<sig> and the signature is HMAC-SHA256 of <timestamp>.<raw-body>. The t timestamp must be within 5 minutes of now to prevent replay attacks. If you're rolling your own verifier, get all three checks right, timestamp tolerance, payload concatenation order, and timing-safe string comparison. Off-the-shelf tools handle this.

Wherever you create Stripe Checkout Sessions, attach the ta_ref cookie as metadata:

import Stripe from "stripe";
import { cookies } from "next/headers";

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

export async function createCheckout(priceId: string) {
  const referral = (await cookies()).get("ta_ref")?.value ?? "";

  return await stripe.checkout.sessions.create({
    line_items: [{ price: priceId, quantity: 1 }],
    mode: "subscription",
    success_url: "https://yourapp.com/thanks?session_id={CHECKOUT_SESSION_ID}",
    cancel_url: "https://yourapp.com/pricing",
    metadata: {
      referral,
    },
    subscription_data: {
      metadata: {
        referral, // ALSO attach to the subscription itself, see why below
      },
    },
  });
}

Notice we attach the referral in two places: on the Checkout Session itself, and inside subscription_data.metadata. This is critical for the subscription renewal flow, see next section.

If you're using Stripe Payment Links (no code, just a hosted URL), you can append metadata via URL parameters when generating the link in the dashboard. Less flexible but works for simple setups.

That's the integration. When a referred customer pays, the conversion appears in your affiliate dashboard within seconds.

The hard part: recurring commission on Stripe subscription renewals

This is the part most DIY Stripe affiliate code gets wrong, and it's the reason indie SaaS founders post angry tweets six months in.

When a customer first subscribes, you get a checkout.session.completed webhook with metadata.referral populated. Easy.

When Stripe bills them in month 2, you get invoice.payment_succeeded. The invoice object has subscription (the subscription ID), customer, amount_paid, but the original Checkout Session's metadata is not on the invoice. If your code only looks at invoice.metadata.referral, every renewal looks like an organic sale, and the affiliate's recurring commission silently goes to zero starting month 2.

Affiliates think they're earning $8.70/month for the life of a $29 subscription. Actually, they earn $8.70 once.

Why we attach metadata to subscription_data (Step 3)

Notice in the snippet above, we did this:

subscription_data: {
  metadata: { referral },
},

This copies the referral onto the subscription object itself, not just the checkout session. The subscription is the durable entity that persists across renewals.

Then, on every invoice.payment_succeeded, your affiliate tool can do:

const invoice = event.data.object;
const subscription = await stripe.subscriptions.retrieve(invoice.subscription);
const referral = subscription.metadata?.referral;

The referral survives. Recurring commission works.

The cleaner approach: subscription-ID inheritance

Even better than retrieving the subscription on every renewal (which adds API latency and rate-limit pressure on busy programs), record the mapping subscription_id → affiliate_code on the first conversion, then look it up locally on every renewal.

In pseudocode:

// On checkout.session.completed:
const session = event.data.object;
const refCode = session.metadata?.referral;
const subId = session.subscription; // null for one-off purchases

if (refCode) {
  const affiliateId = await findAffiliateByCode(refCode);
  if (affiliateId) {
    await recordCommission({ orderId: session.id, affiliateId, amount: session.amount_total });
    if (subId) {
      // Remember it for renewals
      await rememberSubscriptionAffiliate(subId, affiliateId);
    }
  }
}

// On invoice.payment_succeeded:
const invoice = event.data.object;
// Skip the very first invoice, it's already paid via checkout.session.completed
if (invoice.billing_reason !== "subscription_cycle") return;

const affiliateId = await getSubscriptionAffiliate(invoice.subscription);
if (affiliateId) {
  await recordCommission({
    orderId: invoice.id,
    affiliateId,
    amount: invoice.amount_paid,
    isRecurring: true,
  });
}

The billing_reason !== "subscription_cycle" check is essential. Stripe fires invoice.payment_succeeded on the first invoice too (because checkout creates an invoice as part of subscription setup), but you already counted that one via checkout.session.completed. Without this guard, every first month is double-paid.

Sled handles this whole flow out of the box, including the edge cases for plan upgrades, proration, and trial-to-paid conversions. Worth checking if you'd rather not maintain this yourself.

Step 4: Handle refunds and chargebacks

When a customer refunds or charges back, you want to claw back the commission you owed the affiliate. Otherwise the math goes: affiliate drives a $100 sale, you pay them $30 commission, customer refunds the full $100, you lose $130 on the deal.

Stripe fires charge.refunded when this happens. The relevant fields:

const charge = event.data.object;
const refundedOrderId = charge.payment_intent; // matches the original payment_intent
await markCommissionRefunded(refundedOrderId);

If you're using a managed tool, this is automatic. If you're rolling your own, the trick is that the refund event references the payment_intent, not the checkout.session.id. You need to record both IDs on the original conversion so refunds can be matched back.

For chargebacks (disputes), listen to charge.dispute.created as well. Chargebacks are rare but devastating, they include a $15 Stripe fee on top of the lost revenue. Most affiliate tools treat disputed charges identically to refunds: claw back the commission.

The technical setup is done. Now the strategic choices.

Commission rate. For indie SaaS in 2026, the modern baseline is 25–30% recurring for the life of the subscription. Lower than 20% is uncompetitive, affiliates have hundreds of programs to choose from. Higher than 40% is fine for VIP creators driving real volume, but unsustainable as a default.

Cookie window. 90 days is the modern standard. Long enough to handle B2B buying cycles (which routinely take 30–60 days from first touch to decision). Anything shorter and creators legitimately complain. Anything longer (180+ days) muddies attribution between competing affiliates.

Recurring vs one-time. For SaaS, always recurring. One-time commission is fine for digital downloads or courses, but for subscriptions it under-motivates the long-tail content (blog posts, YouTube videos) that keeps driving signups for years.

Set these in your affiliate tool's settings, not in code. You'll change them as you learn what works.

Step 6: Launch the affiliate signup page

Share your affiliate signup URL. For Sled, it's https://usesled.com/{your-slug}/join. Anyone visits, signs up with name + email + payout method, gets their unique referral link instantly.

Promote it from:

  • Your site footer ("Become an affiliate")
  • Your customer onboarding email (sign-up day +7: "By the way, we have a 30% recurring affiliate program, link here")
  • Your existing happy customers via DM (highest conversion rate of any channel)
  • The "Affiliate" sections of niche directories in your space

Skip the approval queue. The friction of "apply and wait for approval" is the single biggest reason indie affiliate programs never bootstrap their first 10 affiliates. Approve everyone by default; remove the bad actors after.

What this costs in 2026

Tool Stripe support Price Setup time
Sled Native (handles whsec_, renewals, refunds, disputes) 10-day free trial, then $19/mo Pro ~15 minutes
Rewardful Native (their original integration) $49–$149/mo ~30 minutes
Tolt Native Stripe, plus documented Paddle Basic $69 / Growth $99 / Pro $199 (tolt.io, 2026-11-03) ~20 minutes
FirstPromoter Native $49–$149/mo ~30 minutes
DIY (write it yourself) Full control Free + your time 3–5 days + ongoing maintenance

For most indie SaaS on Stripe, the choice is between Sled (cheap, simple) and Rewardful/Tolt (more features, more money). Pick based on whether you need the enterprise-tier features (multi-tier referrals, complex coupon-based attribution) or whether you'd rather pay $19/mo and ship.

The DIY path is real (Stripe's webhook spec is the best in the industry, the SDK is excellent) but you'll spend 3–5 days getting the renewal inheritance, refund handling, dashboard, and bulk-email recruitment flow right. And then you maintain it forever, including every time Stripe updates an event payload.

Common Stripe affiliate gotchas

A few things that bite people for the first time:

"First-month conversions are being double-counted"

You're listening to both checkout.session.completed AND invoice.payment_succeeded without the billing_reason !== "subscription_cycle" guard. The first invoice fires both events. Add the guard.

"Renewals aren't crediting the affiliate"

You're reading invoice.metadata.referral (always empty on renewals) instead of the underlying subscription's metadata. Either retrieve the subscription on each renewal, or (better) record subscription_id → affiliate_code on first conversion and look it up locally.

"Webhook signature verification fails"

Three usual causes: (1) you're verifying against the parsed JSON body instead of the raw request body, Stripe's signature is computed against the raw bytes, parsing changes them. (2) Your server's clock is off by more than 5 minutes, fix NTP. (3) You're using the wrong signing secret (test vs live, or you have two webhook endpoints with different secrets).

"Conversions show up in the dashboard but the affiliate doesn't get credited"

Check metadata.referral on the actual Checkout Session in your Stripe dashboard. If it's empty, your checkout code isn't reading the ta_ref cookie correctly. The most common cause: server-side rendering reads the cookie at a moment when it hasn't been set yet because the tracking script hasn't run on a fresh visitor. Use a small client-side hand-off: read the cookie on the pricing page, POST it to your checkout endpoint, then create the session with that value.

"Refunds aren't clawing back commission"

charge.refunded references payment_intent, not checkout.session.id. If your tool stores conversions keyed by session ID and doesn't also record the payment_intent, refund matching fails silently. Most managed tools store both.

"Stripe is sending duplicate webhook events"

Stripe retries failed deliveries. Your handler must be idempotent, deduplicate by event.id. Sled does this automatically; if you're DIY, store a (tenant_id, stripe_event_id) unique index and ignore duplicates.

Frequently asked questions

Does Stripe have a built-in affiliate program?

No. Stripe provides excellent billing infrastructure but does not include affiliate tracking, commission calculation, or affiliate-facing dashboards. You need a separate tool that listens to Stripe's webhooks.

Can I use Rewardful with Stripe?

Yes, Rewardful is Stripe-native and well-built. It's a fine choice if you can justify the $49+/mo price. For smaller programs, lighter tools like Sled cost less for substantially the same functionality on Stripe.

How do I handle subscription renewals on Stripe correctly?

Renewal events (invoice.payment_succeeded) don't carry your original Checkout Session metadata. You need to either retrieve the subscription on every renewal and read its metadata, or record the subscription_id → affiliate_code mapping on first conversion and look it up locally. See the code sample above.

Payment Links support metadata via URL parameters. You can generate per-affiliate links with the referral code baked in. Less flexible than the Checkout Session API path but viable for simple setups.

Does Sled support Stripe Billing's invoicing for B2B?

Yes, Sled listens to invoice.payment_succeeded regardless of whether the invoice came from a subscription or a manually-created Stripe Invoice. Custom B2B invoicing flows attribute correctly as long as the parent subscription (or invoice) carries metadata.referral.

25–30% recurring is the modern indie SaaS baseline. Higher for VIP affiliates (40%+), lower (15–20%) only if your gross margins are very thin (high-cost infrastructure-heavy products).

Do I need a custom checkout, or does Stripe-hosted Checkout work?

Stripe-hosted Checkout works perfectly. The only requirement is that you create the Checkout Session server-side (which you should be doing anyway) and pass metadata.referral when you create it. The visitor never sees or interacts with the metadata.

Yes. See our Rewardful migration guide, it covers preserving every existing ?via=code link as a 308 redirect to ?ref=code so no affiliate has to update their backlinks.

What if I'm on Polar.sh, not Stripe?

Polar's webhook format is different (and its signature scheme isn't whsec_). Read the Polar.sh affiliate program guide instead.


Want to set up a Stripe affiliate program in the next 15 minutes? Sled is Stripe-native, handles subscription renewals correctly (no double-counting, no missed renewals), and comes with a 10-day free trial. Read the docs →

Try Sled

Recurring commission on every renewal.

Polar-native affiliate tracking, with Stripe and Paddle handled the same way. 10-day trial, no card required, cancel anytime. Then $19/mo or $99/yr.

Keep reading

All posts →