> ## Documentation Index
> Fetch the complete documentation index at: https://docs.partnero.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Stripe integration

> Track purchases made through Stripe and attribute them to the partner who referred the customer

The Stripe integration has two parts, and both are required:

1. **Authorize Stripe** so Partnero receives the payments your customers make.
2. **Add referral tracking to your site** so Partnero knows which partner referred each customer — from your
   sign-up flow, or from Stripe Payment Links.

Authorization on its own gives Partnero payments it cannot attribute to anyone. Step 2 is what creates the
referred customer the payments attach to.

> [!NOTE]
>
> Your program's own integration guide, with your program ID already filled in, lives in the app under
> **Integration** → **Guides**. It is the source of truth for the snippets below.

## Step 1: Authorize Stripe

Authorizing lets Partnero see the payments your customers make, including renewals. You only need one of
these.

> [accordion] Option A: Install the Partnero app for Stripe
>
> Partnero is a verified Stripe partner.
>
> 1. Log in to Stripe and open the [Partnero app on the Stripe marketplace](https://marketplace.stripe.com/apps/partnero).
> 2. Click **Install from partner** and confirm.
> 3. Back in the Stripe dashboard, click **Connect Program**.
> 4. Choose the Partnero program to connect.

> [accordion] Option B: Authorize from Partnero
>
> 1. Go to **Integration** and scroll to **Apps & Integrations**.
> 2. Click **Authorize** next to Stripe.
> 3. Choose how to authorize:
>    * **OAuth** — redirects to Stripe to grant Partnero access.
>    * **API key** — paste the key from **Developers → API keys** in Stripe.
> 4. Click **Authorize**.
>
> Refer-a-friend programs get an extra option here to sync existing customers.

You do not configure Stripe webhooks yourself. Partnero subscribes to the events it needs when you authorize.

## Step 2: Add referral tracking to your site

This is what tells Partnero which partner referred a customer. Without it, Stripe sends Partnero payments it
cannot attribute to anyone.

Pick the method that matches how your business takes payment.

### Install the tracking script

Both methods start here. This snippet identifies visitors arriving through a partner's referral link and stores
the partner key in a first-party cookie.

**Copy your own snippet from the app** — don't retype the one below. It is generated per program and already
contains your program ID:

1. Open the program and go to **Integration**.
2. Copy the **PartneroJS** snippet shown there. It also appears inside every guide on the **Guides** tab.

Paste it before the closing `</head>` tag on every page a referred visitor might land on — ideally site-wide.

For reference, the snippet looks like this, where `YOUR_PROGRAM_ID` is filled in for you:

```html theme={"system"}
<!-- PartneroJS -->
<script>
(function(p,t,n,e,r,o){p['__partnerObject']=r;function f(){var c={a:arguments,q:[]};var r=this.push(c);return "number"!=typeof r?r:f.bind(c.q);}
f.q=f.q||[];p[r]=p[r]||f.bind(f.q);p[r].q=p[r].q||f.q;o=t.createElement(n);var _=t.getElementsByTagName(n)[0];o.async=1;
o.src=e+'?v'+(~~(new Date().getTime()/1e6));_.parentNode.insertBefore(o,_);})(window,document,'script','https://app.partnero.com/js/universal.js','po');
po('program', 'YOUR_PROGRAM_ID', 'load');
</script>
<!-- End PartneroJS -->
```

### Then choose a method

> [tab] Stripe Payment Links
>
> Use this if customers pay through Stripe Payment Links, a [Pricing table](https://docs.stripe.com/payments/checkout/pricing-table),
> or a [Buy button](https://docs.stripe.com/payment-links/buy-button). One script covers all three.
>
> Add it to every page containing payment links, at the bottom of the page directly above the closing
> `</body>` tag.
>
> ```html theme={"system"}
> <script>
> po('integration', 'stripe', null);
> </script>
> ```
>
> If your payment links use a custom domain rather than `buy.stripe.com`, name it:
>
> ```html theme={"system"}
> <script>
> po('integration', 'stripe', {"stripe_payment_links_domain": "checkout.example.com"});
> </script>
> ```

> [tab] User sign-up
>
> Use this if customers sign up on your platform before paying. Partnero creates the customer and links it to
> the partner at sign-up, so every later Stripe purchase by that customer is attributed automatically.
>
> For that to work Partnero has to recognise the payer, so the customer must pay in Stripe under the **same
> email address** you sent at sign-up — or you must pass the customer key in Stripe metadata, as described in
> [Attribution from your own backend](#attribution-from-your-own-backend).
>
> Run this immediately after the user signs up. Attribution is read from the `partnero_partner` cookie:
>
> ```html theme={"system"}
> <script>
> po('customers', 'signup', {
>   data: {
>     key: 'customer_123456',
>     name: 'John',
>     email: 'john.doe@partnero.com'
>   }
> });
> </script>
> ```
>
> Or create the customer from your backend, passing the partner key you read from the cookie:
>
> ```bash theme={"system"}
> curl -X POST https://api.partnero.com/v1/customers \
>   -H "Authorization: Bearer YOUR_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "partner": {
>       "key": "PARTNER_KEY_FROM_COOKIE"
>     },
>     "key": "customer_123456",
>     "email": "customer@partnero.com",
>     "name": "John Doe"
>   }'
> ```
>
> Your API key is in the app under **Integration** → **API**. Keep it server-side.

> [!NOTE]
>
> In a refer-a-friend program the cookie is `partnero_referral` instead of `partnero_partner`, and the referrer
> is sent as `referring_customer.key`. The Payment Links script is identical.

## What gets tracked

Once both steps are done, Partnero records one-off purchases, subscription renewals and any other charges your
referred customers make, and reverses the commission automatically when a payment is refunded.

Commissions are calculated on the amount after discounts and without tax. One-time purchases through Checkout or
Payment Links also leave out shipping. Partial refunds reduce the commission proportionally. See
[What commissions are calculated on](https://docs.partnero.com/knowledge-base/commissions-rewards/what-commissions-are-calculated-on.md).

## Attribution from your own backend

When a visitor arrives through a referral link, PartneroJS stores the partner key in a first-party cookie named
`partnero_partner` (`partnero_referral` in a refer-a-friend program). That cookie is where the partner key comes
from — read it on your server from the incoming request headers.

If you create Stripe charges server-side, pass the key in Stripe metadata instead of relying on Partnero to
match the customer:

* `partner_key` — the value from the cookie. Attributes the sale to that partner even when no customer record
  exists yet.
* `customer_key` — the same key you used when creating the customer in Partnero.

Partnero reads both from the checkout session, the charge, and the Stripe customer object. If your Stripe
metadata already uses a different field name for the customer, map it instead of renaming your own field:
open the Stripe integration in the app and set **Stripe integration mapping**.

```php theme={"system"}
$stripe->charges->create([
    'amount' => 2000,
    'currency' => 'usd',
    'source' => 'tok_visa',
    'metadata' => [
        'customer_key' => 'customer_123456',
        'partner_key' => $_COOKIE['partnero_partner'] ?? null,
    ],
]);
```

The customer key must match the one you sent to Partnero. A mismatch means the sale is recorded against nobody.

## Coupons

The Stripe integration can also sync coupons and promotion codes between Stripe and Partnero, so a partner's
discount code attributes the sale. See [Create and use Stripe coupons](https://docs.partnero.com/integrations/create-and-use-stripe-coupons.md).

## Troubleshooting

> [accordion] Purchases are not appearing in Partnero
>
> Check step 2 actually ran. Open the customer in Partnero and confirm it exists and has a partner attached.
> A payment Partnero cannot tie to a customer is not attributed to anyone.

> [accordion] The customer exists but the sale is attributed to nobody
>
> Partnero could not recognise the payer. Confirm the email used in Stripe is the same one you sent at
> sign-up — a different billing email is the usual cause. If you pass `customer_key` in metadata, compare it
> against the key in Partnero character for character.

> [accordion] Payment Links are not carrying attribution
>
> The script must sit on the page containing the link, below the link markup and above the closing `</body>`
> tag. If your links use a custom domain, pass `stripe_payment_links_domain`.

> [accordion] Nothing is tracked after a renewal
>
> Renewals arrive as `invoice.payment_succeeded`, which requires Stripe to be authorized (step 1). Creating the
> customer alone is not enough.

## Next steps

> [card] [Stripe coupons](https://docs.partnero.com/integrations/create-and-use-stripe-coupons.md)
>
> Attribute sales from a partner's discount code

> [card] [Transactions API](https://docs.partnero.com/api-reference/transactions/create.md)
>
> Record transactions yourself


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.