This article explains how to set up the Stripe Buy Button with Rapid Affiliates, emphasizing the importance of capturing and passing the affiliate reference ID in the Stripe checkout session metadata. Detailed instructions and code examples ensure that referrals and commissions are accurately tracked through the integration process.
Written by Adrian
Apr 11, 2025
Integrating the Stripe Buy Button with Rapid Affiliates enables you to streamline purchases while ensuring that every transaction captures essential affiliate referral data. In this guide, we focus on the crucial step of passing your unique reference ID through metadata during the Stripe checkout session creation.
Start by embedding the Stripe Buy Button on your website where customers make purchases. Whether you are using a custom component or a pre-built solution, ensure that the button is connected to your backend endpoint that initiates the creation of a Stripe checkout session. This integration not only simplifies the purchase process but also sets the stage for effective affiliate tracking.
A key part of this integration is capturing the affiliate reference ID. When the tracking script is correctly installed on your site, the reference ID can be retrieved from the global object. For example:
const refId = window.rapidaff?.ref;
This value is essential because it links each transaction back to the right affiliate, ensuring that referrals and commissions are accounted for accurately.
When your backend creates a Stripe checkout session, it is important to include the captured reference ID in the session’s metadata. By assigning this value to a key (commonly named rapidaff_ref
), Rapid Affiliates can easily detect, track, and manage affiliate referrals. Below is an example of how you might implement this in a Node.js environment:
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
app.post('/api/create-checkout', async (req, res) => {
const { refId } = req.body; // Retrieve the reference ID from the client request
try {
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [{
price: 'YOUR_PRODUCT_PRICE_ID',
quantity: 1,
}],
mode: 'payment',
success_url: 'https://yourwebsite.com/success',
cancel_url: 'https://yourwebsite.com/cancel',
metadata: {
rapidaff_ref: refId // Pass the reference ID for affiliate tracking
},
});
res.json({ url: session.url });
} catch (error) {
res.status(500).json({ error: error.message });
}
});
In this example, the checkout session is created with the necessary parameters, and the reference ID is securely attached within the metadata. This practice ensures that every completed transaction is automatically linked to the correct affiliate referral.
window.rapidaff?.ref
reliably returns the affiliate reference ID.By carefully capturing and passing the affiliate reference ID during the checkout session creation, you enable your Rapid Affiliates program to automatically track referrals, assign commissions accurately, and handle related scenarios such as refunds or disputes. This integration not only simplifies your payment processing but also empowers your affiliate program to scale efficiently with minimal manual intervention.