Stripe Checkout Sessions
Step 1: Install Referral Rocket SDK
<!-- 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
const referralCode = window.Rocket.getReferralCode();
console.log('Referral code:', referralCode); // Will log the code or nullStep 4: Create Stripe Checkout Session with Referral Code
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;
}
};Last updated