# Sales

How Stripe payments become Purchase events, how refunds change them, and how to tie each payment to the ad that brought it.

Each paid charge on the connected account becomes one `Purchase` event worth what the buyer paid, net of refunds. It counts in [campaign results](/guides/campaign-results) and [ad rules](/guides/ad-rules) once it is tied to a campaign.

## Tie a payment to its ad

Put the visit's click id or UTM tags in the payment's metadata. Zernio reads the `zrn`, `gclid`, `fbclid` and `utm_*` keys, and `landing_url` for the page the visit landed on:

```bash
curl https://api.stripe.com/v1/checkout/sessions \
  -u "$STRIPE_SECRET_KEY:" \
  -d mode=payment \
  -d "line_items[0][price]=price_123" \
  -d "line_items[0][quantity]=1" \
  -d success_url=https://example.com/thanks \
  -d "metadata[zrn]=ZRN_FROM_THE_LANDING_URL" \
  -d "metadata[utm_campaign]=fall-sale"
```

Zernio looks in this order and stops at the first one that has them:

1. The PaymentIntent's metadata.
2. The Checkout Session that took the payment.
3. For a subscription payment, the subscription's metadata, then the Checkout Session that started it. Set `subscription_data.metadata` so every renewal carries it.

A payment without any of these is still stored and counts in totals, but not on a campaign.

## Read the sales

Stripe sales are events with source `stripe`. Read them with `GET /v1/events?source=stripe`, or per campaign in campaign results. On **Connections**, **View sales** on the Stripe account lists the latest ones with their campaign.

Each event's `eventId` is `stripe:` followed by the Zernio account id and the Stripe charge id.

## Subscriptions

A subscription adds two events to the `Purchase` of each payment:

| Event | When | Value |
|---|---|---|
| `StartTrial` | The subscription starts on a trial | None |
| `Subscribe` | Its first invoice that takes money, including when a trial converts | What that invoice took |

Every payment, renewals included, stays a `Purchase`, so campaign results count the subscription's revenue. `StartTrial` and `Subscribe` do not add to revenue.

## Send sales to ad platforms

Off by default. Turn it on with **Send to ad platforms** in **View sales**, or:

```bash
curl -X PATCH "https://zernio.com/api/v1/accounts/ACCOUNT_ID/stripe-settings" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "forwardSales": true }'
```

Then each new customer goes through the profile's [forwarding rules](/conversions/create-forwarding-rule) that take the `stripe` source:

| Payment | Sent as |
|---|---|
| A one-off sale | `Purchase` |
| A subscription's first payment | `Subscribe`, not also `Purchase`, so a platform never counts it twice |
| A trial start | `StartTrial` |
| A renewal or a refund | Nothing |

The event id is the same as the stored one, so a platform that also gets the sale from your pixel with that id counts it once.

## How it behaves

- Every paid charge counts: Checkout, Payment Links, invoices, subscription renewals and charges made with the API.
- A partial refund stores the sale again at its new value. A full refund retracts it.
- Customer email and phone are hashed before they are stored.
- The amount keeps the charge's currency. Campaign results convert it to the ad account's currency.

## Related

- [Conversions API](/products/conversions-api)
- [Campaign results](/guides/campaign-results)