Referral Rocket
HomeDashboard
  • What is Referral Rocket?
  • Referral Program Examples
  • Getting Started
    • Campaigns
      • Campaign Types
      • Campaigns Details
        • Milestone Details
        • Reward Details
        • Referrer Widget
        • Invitee Widget
      • Installing/Tracking your Referral Campaign
        • Option 1: Hosted Solution (No/Low Code)
        • Option 2: Custom Solution
          • Simple Referral Program Redirect: Quick Setup Guide
          • Redirect user to hosted campaign
          • Embed Referral Rocket Widget
          • Integrate the referral program inside your webapp for logged in user
        • Referral Tracking
          • Track referral on Sign Up page
          • Track referral on Payments
      • Reward Management
      • Campaign Participants
      • Campaign Dashboards
  • Developer Tooks
    • Javascript SDK
    • REST API
      • API Endpoint
    • Webhooks
      • Setup
      • Testing
      • Events
  • Integrations
    • Stripe
      • How to setup Stripe?
        • Stripe Settings
      • Referral Tracking with Stripe
        • Promo Code Referral Tracking with Stripe
        • Setup Stripe Pricing Table
        • Setup Stripe Payment Links
        • Setup Stripe Payment Button
        • Stripe Checkout Sessions
    • Cashfree
    • Razorpay
    • MemberSpace
    • Outseta
    • Shopify
      • How to setup Shopify?
      • Add Referral Widget on Shopify Stor
      • Popup Script to Display Discount Codes
    • ScoreApp
  • Rewards
    • Tremendous
      • How to integrate Tremendous?
        • Tremendous Settings
      • How to issue rewards with Tremendous?
    • PayPal Mass Payments
    • Wise Batch Payments
    • Stripe
    • Shopify
    • RazorPayX
    • Paypal
  • Affiliate Hub
    • Affiliate Program Hub
  • Product Updates
    • December 2024
  • Trust Center
  • Contact Us
  • FAQ
    • Where to find Campaign ID?
    • Understanding the Test Plan: Perfect for Testing, Limited for Production
Powered by GitBook
On this page
  • Step 1: Install Referral Rocket SDK
  • Step 2: Retrieve Referral Code
  • Step 4: Create Stripe Checkout Session with Referral Code
  1. Integrations
  2. Stripe
  3. Referral Tracking with Stripe

Stripe Checkout Sessions

This guide shows you how to integrate referral codes from Referral Rocket into your Stripe checkout sessions, allowing you to track referrals and attribute conversions properly.

Step 1: Install Referral Rocket SDK

First, install the Referral Rocket library by adding the script to the <head> section of your website. Replace YOUR-CAMPAIGN-ID with your actual campaign ID.

<!-- Add this script in the HEAD tag -->
<script   type="text/javascript"   campaign-id="YOUR-CAMPAIGN-ID"   defer   src="https://app.referralrocket.io/widget/widgetIndex.js"></script>

Step 2: Retrieve Referral Code

Use the getReferralCode() function to retrieve the referral code stored in cookies. This function returns the referral code if available, or null if no referral code is found.

const referralCode = window.Rocket.getReferralCode();
console.log('Referral code:', referralCode); // Will log the code or null

Step 4: Create Stripe Checkout Session with Referral Code

When creating your Stripe checkout session, include the referral code in the client_reference_id field. This allows you to track which purchases came from referrals.

const createCheckoutSession = async () => {
  try {
    // Get the referral code from Referral Rocket
    const referralCode = window.Rocket.getReferralCode();
    
    // Create the Stripe checkout session
    const stripeSession = await stripe.checkout.sessions.create({
      success_url: "https://your-website.com/success",
      cancel_url: "https://your-website.com/cancel",
      client_reference_id: referralCode, // Pass the referral code here
      mode: "subscription", // or "payment" for one-time purchases
      line_items: [
        {
          price: "price_1JZ2e2LzKb4YjC8Cw", // Your Stripe price ID
          quantity: 1,
        }
      ]
    });
    
    console.log('Checkout session created:', stripeSession.id);
    return stripeSession;
    
  } catch (error) {
    console.error('Error creating checkout session:', error);
    throw error;
  }
};
PreviousSetup Stripe Payment ButtonNextCashfree

Last updated 4 days ago