Source: https://datafa.st/docs/payments-api
Markdown source: https://datafa.st/docs/payments-api.md
Description: Track and attribute revenue from any payment provider using DataFast's Payment API. Perfect for custom payment solutions or unsupported providers.

# Attribute revenue with custom payment providers

← [Revenue attribution guide](/docs/revenue-attribution-guide)

> If you're using Stripe, LemonSqueezy, or Polar, you don't need to use this endpoint. We automatically track payments if you have [connected your payment provider](/docs/connect-payment-provider).

# Attribute revenue with custom payment providers

Use DataFast's Payment API to create payments and attribute revenue to your traffic sources.

## How it works

When you receive a successful payment, make an API call to DataFast's [Payment API](/docs/api-create-payment). That's it!

```javascript
// Send payment data to DataFast's API
await fetch('https://datafa.st/api/v1/payments', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${DATAFAST_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    amount: 29.99,
    currency: 'USD',
    transaction_id: 'txn_98hj',
    datafast_visitor_id: '3cff4252-fa96-4gec-8b1b-bs695e763b65', // available in the cookie, like request.cookies.datafast_visitor_id
  }),
});
```

> You'll need an [API key](/docs/api-introduction) for your website.

Here's a recommended flow:

1. **Capture DataFast's visitor ID**, a unique identifier for each visitor, from the cookie `datafast_visitor_id`. Store it in your database or pass it to your payment provider when creating checkout sessions (metadata).
2. **Send payment data to DataFast** using our [Payment API](/docs/api-create-payment) when you receive a successful payment (your webhook handler, a success page, etc.)

For more details, see the [Payment API documentation](/docs/api-create-payment).
