# Payments API

Record a payment, renewal or refund with POST /api/v1/payments and attribute it to the visitor's visits: every field, examples and responses.

```
POST https://supranalytics.app/api/v1/payments
```

Records a payment and attributes it to the visitor's visits. For providers without a built-in webhook; see [Revenue attribution](https://supranalytics.app/docs/revenue-attribution.md).

## Body

| Field | Type | Description |
| --- | --- | --- |
| `amount` | number, required | In major units: 29.99, not 2999. 0 or more. |
| `transaction_id` | string, required | Your id for the payment. Sending it again updates the same payment instead of adding one. |
| `currency` | string | ISO code, like USD or EUR. Defaults to the website's currency. |
| `visitor_id` | string | The supr_visitor_id cookie. Also accepted as supr_visitor_id. |
| `session_id` | string | The supr_session_id cookie, to credit that exact visit. Also supr_session_id. |
| `email` | string | The customer's email. Matches the visitor when there's no visitor_id. |
| `name` | string | The customer's name. |
| `customer_id` | string | Your customer id. Later payments with it are credited to the same visitor. |
| `renewal` | boolean | true for a subscription renewal (counted as revenue, not as a new customer). |
| `refunded` | boolean | true marks the payment with this transaction_id as refunded. |
| `timestamp` | string or number | When it was paid (ISO date or milliseconds). Defaults to now. |
| `provider` | string | A label for where it came from, like paddle. Defaults to api. |

## Examples

Payment:

```
curl -X POST https://supranalytics.app/api/v1/payments \
  -H "Authorization: Bearer pk_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"amount": 29.99, "currency": "USD", "transaction_id": "order_123", "visitor_id": "6f1c2a9e-…", "email": "ada@example.com"}'
```

Renewal:

```
curl -X POST https://supranalytics.app/api/v1/payments \
  -H "Authorization: Bearer pk_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"amount": 29.99, "transaction_id": "invoice_456", "customer_id": "cus_42", "renewal": true}'
```

Refund:

```
curl -X POST https://supranalytics.app/api/v1/payments \
  -H "Authorization: Bearer pk_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"amount": 29.99, "transaction_id": "order_123", "refunded": true}'
```

## Responses

| Status | Body |
| --- | --- |
| `200` | { "ok": true, "visitorId": "…", "attributed": true, "duplicate": false } |
| `200 (refund)` | { "ok": true, "refunded": "\<payment id>" } |
| `400` | { "error": "transaction_id is required" } |

`attributed` says whether the payment was tied to a visit; `duplicate` that the transaction was already known (retries are safe).

---

This page on the web: https://supranalytics.app/docs/api/payments
Every documentation page: https://supranalytics.app/docs.md
