# Stripe API Integration
URL: /docs/affiliate-links/stripe-api
Description: Pass referral IDs through the Stripe API for affiliate tracking

# Overview

For custom checkout flows, you can pass the referral ID directly through the Stripe API.

<iframe
  width="100%"
  style={{ aspectRatio: '16/9' }}
  src="https://www.youtube.com/embed/RCOGOdtGXro"
  title="Stripe API integration for affiliate tracking"
  frameBorder="0"
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
  allowFullScreen
/>

## Implementation Steps

### 1. Add the PromoteKit Script

Add the PromoteKit script to your website. It should be on both your landing page (where referrals arrive) and your checkout page.

The script works across subdomains, so you can use it on both `yoursite.com` and `app.yoursite.com`.

### 2. Retrieve the Referral ID

After the script loads, you can access the referral ID:

**JavaScript/TypeScript:** Use `window.promotekit_referral`

**PHP:** Use `$_COOKIE['promotekit_referral']`

### 3. Pass to Stripe

Include the referral ID in the metadata when creating a checkout session or subscription:

```javascript
const session = await stripe.checkout.sessions.create({
  success_url: 'https://example.com/success',
  cancel_url: 'https://example.com/cancel',
  metadata: {
    promotekit_referral: req.body.referral,
  },
  line_items: [{ price: 'price_1OBQlV2eZvKYlo2CDL02DbMx', quantity: 1 }],
  mode: 'subscription',
});
```

## Manual Signup Tracking

For tracking users who sign up before they pay, use the `refer` function:

`window.promotekit.refer(email, stripe_customer_id)`

| Parameter            | Required | Description                       |
| -------------------- | -------- | --------------------------------- |
| `email`              | Yes      | Customer's email address          |
| `stripe_customer_id` | No       | Stripe customer ID (if available) |

This allows you to attribute the referral before payment occurs.