K

Stripe Integration

Track affiliate sales from your Stripe payments. When customers purchase through affiliate links, commissions are automatically calculated and attributed.

Emil Klitmose

Written by Emil Klitmose

Updated recently

The Stripe integration allows you to track affiliate sales from your Stripe payments. When a customer makes a purchase through an affiliate link, Revshare receives webhook notifications from Stripe and automatically attributes the sale to the correct affiliate.

  • Automatic sale tracking via Stripe webhooks
  • Real-time commission calculation
  • Refund handling with automatic commission adjustments
  • Works with Stripe Checkout, Payment Intents, and Subscriptions

Overview

The Stripe integration connects your Revshare affiliate program with your Stripe account via webhooks. When payments are processed in Stripe, Revshare receives notifications and attributes sales to affiliates based on referral codes passed in the payment metadata.

This integration requires you to pass the affiliate referral code in your Stripe payment metadata. The tracking script on your website captures the referral code from affiliate links and stores it in a cookie, which you then pass to Stripe when creating payments.

How It Works

  1. Visitor clicks affiliate link — The tracking script captures the referral code and stores it in a cookie.
  2. Customer makes a purchase — Your checkout code reads the referral code from the cookie and passes it to Stripe as metadata.
  3. Stripe processes payment — Stripe sends a webhook notification to Revshare with the payment details and metadata.
  4. Commission is calculated — Revshare looks up the affiliate by referral code and calculates the commission based on your program settings.

Setup Steps

  1. Add tracking script — Add the Revshare tracking script to your website's <head> section. This captures affiliate referral codes from links.
  2. Configure webhook — In your Stripe dashboard, create a webhook endpoint pointing to your Revshare webhook URL. Subscribe to checkout.session.completed and charge.succeeded events.
  3. Pass metadata — Update your checkout code to pass the referral code in Stripe metadata (see below).
  4. Test the integration — Make a test purchase using an affiliate link and verify the sale appears in your Revshare dashboard.

Passing Metadata

When creating a Stripe Checkout session or payment, include the affiliate referral code in the metadata:

Stripe Checkout (JavaScript)

const session = await stripe.checkout.sessions.create({
  // ... your checkout config
  metadata: {
    ...window.revshare_metadata,  // Includes ref_code and program_id
  },
});

Payment Intent (JavaScript)

const paymentIntent = await stripe.paymentIntents.create({
  amount: 1000,
  currency: 'usd',
  metadata: {
    ref_code: getCookie('revshare_ref_YOUR_PROGRAM_ID'),
    program_id: 'YOUR_PROGRAM_ID',
  },
});

Tip: The tracking script automatically creates a window.revshare_metadata object containing the referral code and program ID. You can spread this directly into your Stripe metadata.

Need help? Check out our Payment Provider Guide for more detailed examples.