Attribute revenue with custom payment providers
Use DataFast's Payment API to create payments and attribute revenue to your traffic sources.
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.
How it works
- Capture visitor ID: Pass the cookie
datafast_visitor_id
when creating checkout sessions - Handle webhooks: Listen for successful payment events from your provider
- Send to DataFast: Use our Payment API to attribute revenue to the visitor
// Send payment data to DataFast
await fetch('https://datafa.st/api/v1/payments', {
method: 'POST',
headers: {
'Authorization': `Bearer ${DATAFAST_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: 'customer@example.com',
amount: 29.99,
currency: 'USD',
transaction_id: 'unique_payment_id',
datafast_visitor_id: visitor_id_from_checkout,
}),
});
When to use this method
- Custom payment processors
- Payment providers not directly supported by DataFast
- Complex payment flows requiring manual tracking
Important notes
- Duplicate payment events are ignored automatically
- Works with any payment flow as long as you capture the visitor ID
- See the Payment API documentation for all available fields
Example: DodoPayments Integration
Already using DodoPayments? Add this to your existing setup:
1. Add visitor ID to checkout metadata
// In your existing checkout creation
const payment = await dodopayments.payments.create({
// ... existing config
metadata: {
datafast_visitor_id: cookies().get('datafast_visitor_id')?.value,
},
});
2. Send to DataFast in your webhook
// In your existing payment.succeeded handler
if (paymentData.metadata?.datafast_visitor_id) {
await fetch('https://datafa.st/api/v1/payments', {
method: 'POST',
headers: { 'Authorization': `Bearer ${DATAFAST_API_KEY}` },
body: JSON.stringify({
email: paymentData.customer.email,
amount: paymentData.total_amount / 100,
currency: paymentData.currency,
transaction_id: paymentData.payment_id,
datafast_visitor_id: paymentData.metadata.datafast_visitor_id,
}),
});
}
After implementing this setup, you should see revenue data in your DataFast dashboard with full attribution to marketing channels. If you need help, contact us at marc@datafa.st.