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

# Transaction-based attribution

> Attribute commissions to different partners per transaction using payment metadata.

By default, Partnero uses **customer-based attribution** — a customer is permanently linked to one partner, and all their transactions generate commissions for that partner.

**Transaction-based attribution** changes this. Instead of looking at who the customer belongs to, Partnero looks for a `partner_key` in the payment metadata to decide which partner should receive the commission. This means the same customer can generate commissions for different partners on different transactions.

## When to use this

* A marketplace where the same buyer purchases from different sellers, each represented by a different partner
* A SaaS platform where customers can be upsold by different agencies, and each agency should earn commission on the deals they close
* A business where the referring partner is tracked at the payment level (e.g., stored in Stripe charge metadata) rather than at the customer level

## Setting up

1. In your affiliate program, go to **Settings** under **Program**
2. In the **Commission** section, expand **Commission options**
3. Under **Commission attribution model**, select **Transaction-based**
4. Click **Update**

> [!NOTE]
>
> This setting only affects how new incoming transactions are attributed. Existing customers and commissions are not modified.

## How it works

When a payment webhook arrives (or an API call is made), Partnero first finds the customer the usual way — by
customer key, integration customer ID or email, or a promotion code. Then:

1. If the customer **already existed in Partnero** before this payment, Partnero reads `partner_key` from the
   payment metadata.
2. It finds the active partner matching that key.
3. It finds or creates a customer record linked to that partner (see [Customer records](#customer-records)).
4. It calculates the commission for that partner.

If there's no `partner_key`, the transaction goes to the partner the customer is already linked to, as in
customer-based attribution.

> [!WARNING]
>
> `partner_key` only re-attributes payments from customers Partnero already knows. If the customer doesn't exist in
> Partnero yet, or is created by this same payment (for example from a promotion code), `partner_key` is ignored
> and the customer is attributed the usual way. If no customer can be found or created, the payment isn't tracked.
> To start tracking a new customer, create them first — through the tracking script, the
> [API](https://docs.partnero.com/api-reference/customers/create.md) or a promotion code.

### Customer records

To support the same real-world customer being linked to multiple partners, Partnero creates separate customer records with a composite identifier:

```
{customer_id}__pkey_{partner_identifier}
```

For example, Stripe customer `cus_123` attributed to partner `PARTNER_A` becomes `stripe_cus_123__pkey_PARTNER_A`. This happens automatically — no action required on your part.

## Examples

Imagine Stripe customer `cus_123`, who is already in Partnero and linked to Partner A, making three separate
purchases over time.

### Partner key is present

| Charge | `partner_key` in metadata | Result |
| - | - | - |
| First charge | `PARTNER_A` | Same partner as the existing customer record. Commission → **Partner A** |
| Second charge | `PARTNER_B` | Separate customer record created for Partner B. Commission → **Partner B** |
| Third charge | `PARTNER_B` | Partner B's customer record found. Commission → **Partner B** (no new record) |

Each partner gets commission only for the transactions that carry their key. The same Stripe customer generated commissions for two different partners.

### No partner key, invalid key or new customer

| Charge | `partner_key` in metadata | Result |
| - | - | - |
| Charge with no key | *(empty)* | The partner the customer is already linked to gets the commission |
| Charge with invalid key | `INVALID_KEY` | No active partner matches the key. **The charge isn't tracked** and no commission is created |
| First charge from a customer not yet in Partnero | `PARTNER_A` | `partner_key` is ignored. The customer is created and attributed the usual way, or the charge isn't tracked if they can't be |

> [!TIP]
>
> Referral links, promotion codes and customer matching keep working as before — they decide who a customer belongs
> to. `partner_key` only changes which partner earns from a specific payment by a customer who already exists.

## Integration guides

### Stripe

Add `partner_key` to the metadata of charges, subscriptions, invoices, or the Stripe customer object. Partnero checks all of these locations.

**Checkout Session:**

```javascript theme={"system"}
const session = await stripe.checkout.sessions.create({
  line_items: [{ price: 'price_xxx', quantity: 1 }],
  mode: 'payment',
  success_url: 'https://yoursite.com/success',
  cancel_url: 'https://yoursite.com/cancel',
  metadata: {
    partner_key: 'PARTNER_A'
  }
});
```

**Subscription:**

```javascript theme={"system"}
const subscription = await stripe.subscriptions.create({
  customer: 'cus_123',
  items: [{ price: 'price_xxx' }],
  metadata: {
    partner_key: 'PARTNER_A'
  }
});
```

**One-time charge:**

```javascript theme={"system"}
const charge = await stripe.charges.create({
  amount: 9999,
  currency: 'usd',
  customer: 'cus_123',
  metadata: {
    partner_key: 'PARTNER_A'
  }
});
```

**Stripe customer metadata** (applies to all future charges for this customer unless overridden per charge):

```javascript theme={"system"}
await stripe.customers.update('cus_123', {
  metadata: {
    partner_key: 'PARTNER_A'
  }
});
```

> [!TIP]
>
> Partnero checks metadata in this order: charge/invoice metadata → subscription metadata → Stripe customer metadata. A `partner_key` on a specific charge overrides one set on the customer.

### Paddle

Add `partner_key` to the `custom_data` object on transactions or subscriptions.

```javascript theme={"system"}
Paddle.Checkout.open({
  items: [{ priceId: 'pri_xxx', quantity: 1 }],
  customData: {
    partner_key: 'PARTNER_A'
  }
});
```

Or server-side:

```bash theme={"system"}
curl https://api.paddle.com/transactions \
  -H "Authorization: Bearer YOUR_PADDLE_KEY" \
  -d '{
    "items": [{"price_id": "pri_xxx", "quantity": 1}],
    "custom_data": {
      "partner_key": "PARTNER_A"
    }
  }'
```

### WooCommerce

Add `partner_key` to the order meta data. This can be done via a plugin, custom code, or the WooCommerce REST API.

```bash theme={"system"}
curl https://yourstore.com/wp-json/wc/v3/orders \
  -u consumer_key:consumer_secret \
  -d '{
    "meta_data": [
      {
        "key": "partner_key",
        "value": "PARTNER_A"
      }
    ]
  }'
```

### Chargebee

Partnero reads the partner key from the Chargebee customer custom fields `cf_partnero_partner` or `cf_referral_code`. Set these fields on the customer in Chargebee, and Partnero will use them for per-transaction attribution when transaction-based mode is enabled.

### API

When using the Partnero API directly, include the `partner` field in your transaction request. The customer is automatically created and linked to that partner.

```bash theme={"system"}
curl https://api.partnero.com/v1/transactions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "partner": {
      "key": "PARTNER_A"
    },
    "customer": {
      "key": "customer_123",
      "email": "customer@example.com"
    },
    "key": "invoice_789",
    "amount": 99.99,
    "action": "sale",
    "options": {
      "create_customer": true
    }
  }'
```

> [!NOTE]
>
> If the customer already exists, the transaction goes to the partner in the request, and a separate customer record
> is created for that partner if needed. If the customer doesn't exist yet, `options.create_customer: true` creates
> them linked to that partner; without it, the request fails because the customer isn't found. An unknown partner
> key also makes the request fail.

## Where `partner_key` is read from

| Integration | Metadata location |
| - | - |
| **Stripe** | Charge metadata → invoice/subscription metadata → Stripe customer metadata |
| **Paddle** | Transaction or subscription `custom_data` |
| **WooCommerce** | Order `meta_data` |
| **Chargebee** | Customer fields `cf_partnero_partner` or `cf_referral_code` |
| **API** | `partner` field in request body |

## Next steps

> [card] [Stripe integration](https://docs.partnero.com/integrations/stripe.md)
>
> Full Stripe setup guide

> [card] [Paddle integration](https://docs.partnero.com/integrations/paddle.md)
>
> Full Paddle setup guide

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

> [card] [Affiliate API](https://docs.partnero.com/guides/partner-programs/api-integration.md)
>
> Standard API integration guide


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