> For the complete documentation index, see [llms.txt](https://docs.promotekit.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.promotekit.com/affiliate-links-setup/stripe-api.md).

# Stripe API

Go to Step 4 (PromoteKit Integration) in your PromoteKit setup tab to follow along with these instructions. We also have a video walkthrough for NextJS:

{% embed url="<https://www.youtube.com/watch?v=RCOGOdtGXro>" %}

## Add the PromoteKit Script to your Site

The PromoteKit script will go on both your site's landing page (where you'll be sending referrals), and the page on your site / app where your customers checkout. It's ok if your marketing site and app site are on different subdomains - the cookie tracking works across all subdomains of a domain. A common setup would be embedding the script on your marketing site at yourdomain.com, and app domain at app.yourdomain.com.

Copy this script and paste it within your site's \<head> or \<body> tags.

## Send the Referral ID to Stripe

Once the script is embedded, the referral ID will be retrievable with JavaScript/TypeScript using `window.promotekit_referral`, or with PHP using `$_COOKIE['promotekit_referral']`

You will need to pass this ID in the metadata field when [creating a Stripe checkout session](https://docs.stripe.com/api/checkout/sessions/create) or when [creating a Stripe subscription](https://docs.stripe.com/api/subscriptions/create). In the body of either of these API calls, include `promotekit_referral` within the metadata.

{% code title="JavaScript Checkout Session Creation Example" %}

```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',
});
```

{% endcode %}

## Optional Step: Manually Tracking Signups

If you want to attach referrals to affiliates manually when they signup to your service and before they have paid, you can use this function:

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

Email is a required parameter, and stripe customer id is an optional parameter.
