Stripe
Connect Stripe to Refport and sales are attributed to referral partners automatically — no webhook code required.
Refport's Stripe integration listens to your Stripe webhook events and attributes sales to referral partners automatically whenever a refp_id click ID is present. There's no need to write your own webhook handler or call track.sale() manually for Stripe payments.
How it works
- You connect your Stripe account in the Refport dashboard
- Refport receives Stripe webhook events (
checkout.session.completed,invoice.paid, etc.) - The webhook handler reads the click ID from session metadata or
client_reference_idand records the sale - The partner's commission is calculated and queued for payout
Connect your Stripe account
Go to Settings → Integrations → Stripe in the Refport dashboard and click Connect. This authorises Refport to receive your Stripe webhook events via Stripe Connect.
Refport automatically registers for the required events:
checkout.session.completedinvoice.paidcharge.refundedcustomer.subscription.created/deletedcustomer.created/updated
Passing the click ID to Stripe
There are three ways to pass referral attribution data to Stripe, depending on your setup.
Option 1 — Session metadata (recommended)
When creating a Checkout session in your code, add refportClickId and refportExternalCustomerId to the session metadata. This is the simplest approach and leaves client_reference_id free for your own use.
import Stripe from 'stripe';
import { getClickIdFromRequest } from 'refport';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
async function createCheckoutSession(req: Request, user: User, priceId: string) {
const clickId = getClickIdFromRequest(req);
const session = await stripe.checkout.sessions.create({
mode: 'subscription',
line_items: [{ price: priceId, quantity: 1 }],
success_url: 'https://yoursite.com/success',
cancel_url: 'https://yoursite.com/pricing',
metadata: {
refportExternalCustomerId: user.id,
refportClickId: clickId ?? undefined,
},
});
return session;
}Option 2 — client_reference_id
You can also set client_reference_id directly with the refp_id_ prefix. This is useful if you prefer not to use metadata or need backward compatibility.
const session = await stripe.checkout.sessions.create({
/* ...your params... */
client_reference_id: clickId
? `refp_id_${clickId}`
: undefined,
});Attribution fallback chain
Refport resolves the click ID in this order:
refportExternalCustomerIdin session metadata → find existing customerrefp_id_prefix inclient_reference_id→ extract click ID directlyrefportClickIdandrefportExternalCustomerIdin Stripe customer metadata → fallback from previous interactions- Customer email → match against known Refport customers
Recurring subscriptions
For subscription renewals, Refport automatically handles invoice.paid events. The click ID is carried forward from the original checkout session via the Stripe customer record — you don't need to pass it again on each renewal.
You can configure whether recurring renewals generate commissions in your program settings. Many programs only pay commission on the first payment.
Refunds
When Stripe fires a charge.refunded event, Refport automatically voids the corresponding sale commission. No additional configuration is needed.
Free trials
When a subscription is created with a trial period (customer.subscription.created with status: trialing), Refport tracks this as a lead event rather than a sale, attributing the trial start to the referring partner.
Testing the integration
Use Stripe's test mode to verify the integration end-to-end:
- Connect a Stripe test account in Refport's dashboard (separate from your live account)
- Use Stripe's test card
4242 4242 4242 4242to complete a checkout - Check Conversions in the Refport dashboard — the sale should appear within seconds
The Refport dashboard distinguishes between live and test events so test data doesn't pollute your production analytics.