# 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.promotekit.com/affiliate-links-setup/stripe-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
