Payment providers
Revenue from Stripe and Razorpay, tied to sources
Connect Stripe, Razorpay or Dodo Payments and every payment they take becomes revenue in Viakite, counted for the source of the visit that led to it. You don't send a revenue event from your site: the provider tells Viakite about each payment through a webhook. With Stripe or Dodo Payments, your subscriptions also give you MRR and churn by source and by plan.
How a payment finds its visit
Viakite counts visitors without cookies, so a payment only knows who paid through your own user id. When you create the payment, put the id you pass to identify in it under the key viakite_user_id. When the payment succeeds, Viakite:
- checks the webhook's signature against the signing secret you saved;
- keeps the payment once, by the provider's payment id, however many webhooks report it;
- finds the last visit of that user in the 30 days before the payment;
- stores a custom event named
Paymentwith the amount and currency, on that visit, with its source, campaign, location and device.
The Payment event counts everywhere revenue does: the Revenue page, revenue by source, the Sources page and the query endpoint. You can also use it as an event goal.
Payments without a user id don't count as revenue
A payment without viakite_user_id, or from a user Viakite hasn't seen in the 30 days before it, is counted as received on the settings page but is not stored as revenue. So identify must run on the pages your buyers visit before they pay.
Connect Stripe
Copy the webhook URL
Open Settings → Payment providers. The Stripe card shows the webhook URL of this project. You need the
analytics.managepermission to connect a provider.Add the endpoint in Stripe
In Stripe, open Developers → Webhooks and add an endpoint with that URL. Pick the events
checkout.session.completed,payment_intent.succeededandinvoice.paidfor payments, andcustomer.subscription.created,customer.subscription.updatedandcustomer.subscription.deletedfor MRR and churn. Viakite counts a payment once even when several events report it.Save the signing secret
Stripe shows the endpoint's signing secret, which starts with
whsec_. Back on the Stripe card, click Save signing secret and paste it. Viakite keeps it encrypted and never shows it again.Send the user id with each payment
Put the user id in the metadata of the Checkout Session and of the PaymentIntent, or, for a subscription, of the subscription:
checkout.ts1await stripe.checkout.sessions.create({2// …your line items, mode and URLs3metadata: { viakite_user_id: user.id },4// a one-off payment:5payment_intent_data: { metadata: { viakite_user_id: user.id } },6// or, with mode: "subscription":7// subscription_data: { metadata: { viakite_user_id: user.id } },8});
A Checkout Session counts when it completes with payment_status paid; a PaymentIntent when it succeeds, for the amount received. Payments made in Stripe's test mode are kept as test events, which reports leave out.
Subscriptions
Every paid invoice of a subscription is a payment, so the first payment and each renewal count as revenue, for the amount paid. A renewal finds its user in the subscription's metadata; when the invoice doesn't carry it, Viakite uses the user of the subscription it already knows from a customer.subscription.* event. An invoice of 0 (a free trial) isn't a payment. A PaymentIntent that pays an invoice is left to invoice.paid, so it isn't counted twice.
Connect Razorpay
Copy the webhook URL
Open Settings → Payment providers and copy the URL on the Razorpay card.
Add the webhook in Razorpay
In Razorpay, open Account & Settings → Webhooks and add a webhook with that URL. Choose a secret for it, and tick the events
payment.capturedandorder.paid.Save the same secret in Viakite
On the Razorpay card, click Save signing secret and paste the secret you chose.
Send the user id with each payment
Put the user id in the notes of the order (or of the payment):
order.ts1await razorpay.orders.create({2amount: 49900,3currency: "INR",4notes: { viakite_user_id: user.id },5});
A payment counts once it is captured. Razorpay subscriptions don't count for MRR yet.
Connect Dodo Payments
Copy the webhook URL
Open Settings → Payment providers and copy the URL on the Dodo Payments card.
Add the endpoint in Dodo Payments
In Dodo Payments, open Developer → Webhooks and add an endpoint with that URL. Subscribe to
payment.succeededfor payments, and tosubscription.active,subscription.renewed,subscription.updated,subscription.plan_changed,subscription.on_hold,subscription.paused,subscription.cancelled,subscription.expiredandsubscription.failedfor MRR and churn.Save the signing secret
Dodo shows the endpoint's signing secret, which starts with
whsec_. On the Dodo Payments card, click Save signing secret and paste it.Send the user id with each payment
Put the user id in the metadata of the subscription or the payment you create:
subscribe.ts1await dodo.subscriptions.create({2// …your product, billing and customer3metadata: { viakite_user_id: user.id },4});
Each payment.succeeded counts once, renewals included, for its total amount. A payment without viakite_user_id in its metadata takes the user of its subscription, when a subscription.* event named one. Webhooks are checked with Dodo's webhook-id, webhook-timestamp and webhook-signature headers, and refused when their timestamp is more than 5 minutes off.
Connect your live endpoint
Dodo's webhooks don't say whether they come from test mode, so payments from a test endpoint would count as real revenue. Connect the endpoint of your live mode.
Amounts and currencies
Providers send amounts in the currency's smallest unit (paise, cents); Viakite stores them in the main unit, so 49900 paise is ₹499. Revenue is shown in the project's currency, converted at the day's rate, as for revenue you send yourself.
Don't count a payment twice
If your site also sends revenue with track for the same purchases, each sale is counted twice. Once a provider is connected, stop sending revenue from your own code for its payments.
On the settings page
Each provider's card shows whether it is connected, the webhook URL and the events to send, and once connected:
- Payments received: every payment the provider reported.
- Tied to a visit: those counted as revenue.
- Last payment: when the last one arrived.
Replace secret saves a new signing secret; the old one stops working at once. Disconnect stops Viakite from accepting the provider's webhooks; revenue already counted stays in your reports.
Through the API
| Method | Path | What it does |
|---|---|---|
| GET | /v1/projects/{project}/payment-providers | Every provider, connected or not, with the webhook URL, the events and the counts |
| PUT | /v1/projects/{project}/payment-providers/{provider} | Connect stripe, razorpay or dodo: { "webhook_secret": "…" } |
| DELETE | /v1/projects/{project}/payment-providers/{provider} | Disconnect it |
| POST | /v1/projects/{project}/analytics/mrr | MRR and churn; see Revenue |
A webhook with a wrong signature is refused with 401 invalid_signature; a provider that isn't connected answers 404.