Payments and goals
Record one-off payments and server-side goals with faurya.payments and faurya.goals.
Payments and goals
The simplest way to get revenue into Faurya: one call per payment. Use this when you want revenue and attribution, and do not need MRR, subscribers or churn. For those, use Subscriptions and invoices.
All examples assume the client from Getting started:
import { createFauryaBilling } from "@faurya/billing";
const faurya = createFauryaBilling();Record a payment
const result = await faurya.payments.create({
transaction_id: "order_456",
amount: 29.99,
currency: "USD",
faurya_visitor_id: visitorId,
faurya_session_id: sessionId,
metadata: { plan: "pro", coupon: "LAUNCH" },
});
console.log(result.amount_usd); // the amount converted to USD at today's rate| Field | Required | Notes |
|---|---|---|
transaction_id | Yes | Your order or payment id. Must be unique for your site. |
amount | Yes | Major units, greater than 0: 29.99 is $29.99, 2500 is ¥2,500. |
faurya_visitor_id | Yes | From the faurya_visitor_id cookie. |
currency | No | ISO code such as USD, EUR, INR. Default USD. |
faurya_session_id | No | From the faurya_session_id cookie. |
status | No | succeeded (default) or failed. Failed payments never count as revenue. |
occurred_at | No | ISO 8601 time, e.g. 2026-03-01T09:14:00Z. Defaults to now. |
metadata | No | Up to 10 entries of strings, numbers, booleans or null. |
Recording a payment from a webhook
Payment webhooks arrive without the visitor's cookies. Save the visitor id when checkout starts, then read it back when the webhook confirms the payment:
// 1. When the visitor starts checkout
const session = await paymentProvider.checkout.create({
amount: 4900,
metadata: { faurya_visitor_id: req.cookies.faurya_visitor_id },
});
// 2. In your payment webhook
await faurya.payments.create({
transaction_id: event.payment.id,
amount: event.payment.amount / 100,
currency: event.payment.currency,
faurya_visitor_id: event.payment.metadata.faurya_visitor_id,
});A payment is recorded only once
Each transaction_id is accepted once. If you send it again, the call throws a FauryaValidationError with the code DUPLICATE_TRANSACTION. That makes webhook re-deliveries harmless — you can treat that error as "already recorded":
import { FauryaApiError } from "@faurya/billing";
try {
await faurya.payments.create(payment);
} catch (error) {
if (error instanceof FauryaApiError && error.code === "DUPLICATE_TRANSACTION") {
return; // already in Faurya
}
throw error;
}For the same reason the SDK never automatically retries a payment after a timeout or server error — it could have landed. If you retry it yourself, the duplicate check keeps it from counting twice.
Delete payments
Remove payments you recorded with payments.create — for example test payments, or a refunded order you would rather not show.
// One payment
await faurya.payments.delete({ transaction_id: "order_456" });
// Every payment from one visitor
await faurya.payments.delete({ faurya_visitor_id: visitorId });
// Every payment in a time range
await faurya.payments.delete({
startAt: "2026-03-01T00:00:00Z",
endAt: "2026-03-02T00:00:00Z",
});Pass at least one filter; calling it with none is refused before anything is sent. The result tells you how many were removed in deleted.
Deleting is permanent, and a deleted transaction_id can never be recorded
again. If you want to track refunds properly instead of hiding the payment,
use the Billing API refunds.
Record a goal
Goals are the conversions you care about — signup, trial_started, demo_booked. Recording them from your server is useful when the action finishes in your backend rather than in the browser.
await faurya.goals.create({
faurya_visitor_id: visitorId,
name: "signup",
metadata: { plan: "pro", source: "pricing_page" },
});faurya_visitor_idandnameare required. The visitor must already have visited your site.faurya_session_idandmetadataare optional.
Goals show up in your dashboard and can be used in funnels. See Custom goals for naming tips and the browser-side alternative.
When to move to the Billing API
payments.create tells Faurya that money arrived. It doesn't know about subscriptions, renewals, plan changes, refunds or cancellations. If you need MRR, subscriber counts or churn, send your billing data with Subscriptions and invoices instead.
You can use both on the same site, but don't send the same payment through both — a transaction id used in one is refused by the other.