This article explains how to integrate Stripe with your Rapid Affiliates program using Stripe Connect, covering account connection, tracking script installation, and passing reference IDs during checkout sessions. It provides detailed, step‐by‐step instructions and code snippets to ensure a seamless integration that automates referral tracking and commission management, helping both your system and our Stripe partner verification process.
Written by Adrian
Apr 11, 2025
In this article, we explain how to integrate Stripe Connect during your program setup, ensuring that referrals, commissions, refunds, and disputes are managed automatically without any extra effort from you.
Begin the process by signing in to your Rapid Affiliates dashboard and starting your affiliate program setup. Once you’ve entered the required details such as program name, website / app URL, and your commission structure, select Stripe as your payment processor. A prominent button will appear prompting you to connect your Stripe account. By clicking it, you will be redirected to Stripe’s authorization page where you can securely authorize Rapid Affiliates the required permissions via Stripe Connect. After authorization, your account status will show as Connected, confirming a secure and seamless connection.
After your account is connected, the next step is to install our lightweight tracking script (just 1KB in size) on your website. This script is essential for monitoring referrals, capturing the reference ID, and ensuring that commissions are assigned automatically. To implement it, simply add the following code snippet into the <head>
section of your website’s root HTML file:
<script
src="https://rapidaff.io/scripts/ra.js"
async
data-rapidaff="<<YOUR_UNIQUE_ID>>">
</script>
If you are using a modern framework such as Next.js, you can integrate the script within your Root layout file. For example:
import Script from "next/script";
export default function RootLayout({ children }) {
return (
<html lang="en">
<Script
strategy="afterInteractive"
src="https://rapidaff.io/scripts/ra.js"
async={true}
data-rapidaff="<<YOUR_UNIQUE_ID>>"
/>
<body>{children}</body>
</html>
);
}
To accurately track referrals and assign commissions, it’s crucial to pass a reference ID during the checkout session creation. When a customer initiates a purchase, retrieve the reference ID from the global object using the code below:
const refId = window.rapidaff?.ref;
If the refId
exists, send it along with your request to create a Stripe checkout session. For example, you can forward it to your backend using a fetch request:
fetch("/api/create-checkout", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ refId })
});
On your backend, while creating the Stripe Checkout Session, include the received reference ID within the metadata. This metadata field (named rapidaff_ref
) enables Rapid Affiliates to automatically detect customer referrals, assign commissions accurately, and even manage refunds or disputes when needed. Below is an example implementation using Node.js:
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
app.post("/api/create-checkout", async (req, res) => {
const { refId } = req.body;
try {
const session = await stripe.checkout.sessions.create({
line_items: [
{
price: "<<PRODUCT_PRICE_ID>>",
quantity: 1,
},
],
mode: "subscription",
customer_email: "<<CUSTOMER_EMAIL>>",
success_url: "https://yourwebsite.com/success",
cancel_url: "https://yourwebsite.com/cancel",
metadata: {
rapidaff_ref: refId, // Pass the reference ID if available
},
});
res.json({ url: session.url });
} catch (error) {
res.status(500).json({ error: error.message });
}
});
By following these steps, your Rapid Affiliates program will seamlessly integrate with Stripe via Stripe Connect. All referral data and commission transactions are automatically managed, enabling your business to scale without extra overhead.