Developers
Integrate TenaBill from your backend
A merchant API key, signed webhooks and a typed .NET SDK are all you need to bill from your own app. Start in sandbox mode with Stripe test cards, so nothing here charges a real customer.
Four steps
- Create an API key.In the merchant console, open API keys and create one. The full value is shown once, so put it in your secret manager. Send it as the X-TenaBill-Api-Key header on every request from your server.
- Define what you sell.Add offerings in the catalog: subscriptions, one-time products or usage packs. For metered billing, create a meter and attach it to an offering.
- Listen for webhooks.Register an HTTPS endpoint, copy its signing secret when it is shown, and verify every delivery before you act on it.
- Fulfil on a paid invoice.A successful checkout call only means checkout started. Grant access when the invoice.paid event arrives. Read why.
Report metered usage
Every usage event carries an event id that acts as the dedupe key. TenaBill stores an id once per merchant, so a resend after a timeout never bills twice. Reusing an id with a different payload fails with HTTP 409.
POST /api/v1/usage/events
X-TenaBill-Api-Key: <your merchant API key>
Content-Type: application/json
{
"eventId": "api-call-8f3a2c",
"subscriptionId": "<subscription id>",
"meterId": "<meter id>",
"customerId": "<customer id>",
"quantity": 1,
"occurredAtUtc": "2026-10-17T14:30:00Z"
}The .NET SDK wraps this with retries that reuse the same id:
var http = new HttpClient { BaseAddress = new Uri("https://api.tenabill.com/") };
var usage = new TenaBillUsageClient(http, apiKey);
// Build the id from your own stable identifiers, never from a random value made at send time.
var eventId = UsageEventIds.Create("api", clientId, environment, requestId);
var result = await usage.ReportAsync(new UsageEvent(
eventId, subscriptionId, meterId, customerId, Quantity: 1m, DateTime.UtcNow));
// result.Duplicate is true when TenaBill had already stored this event id.Verify a webhook
Each delivery carries X-TenaBill-Event, X-TenaBill-Event-Id and X-TenaBill-Signature (t=timestamp,v1=hex). The signature is an HMAC-SHA256 over the timestamp, a dot and the raw body, keyed with your signing secret. Delivery is at least once, so deduplicate on the event id.
var evt = TenaBillWebhookVerifier.VerifyAndParse(
secret,
request.Headers["X-TenaBill-Signature"],
request.Headers["X-TenaBill-Event"],
request.Headers["X-TenaBill-Event-Id"],
rawBody);
if (evt.AsInvoicePaid() is { } paid)
{
// Fulfil once per X-TenaBill-Event-Id.
}Without the SDK, the same check in Node:
import { createHmac, timingSafeEqual } from 'node:crypto';
// rawBody must be the request body exactly as received; do not re-serialise it.
export function verifyTenaBill(secret, signatureHeader, rawBody, toleranceSeconds = 300) {
const parts = Object.fromEntries(signatureHeader.split(',').map((p) => p.split('=')));
const timestamp = Number(parts.t);
if (!Number.isFinite(timestamp)) return false;
if (Math.abs(Date.now() / 1000 - timestamp) > toleranceSeconds) return false;
const expected = createHmac('sha256', secret).update(timestamp + '.' + rawBody).digest('hex');
// v1 is the current secret; v1_previous is present while a rotation overlaps.
return [parts.v1, parts.v1_previous]
.filter(Boolean)
.some((candidate) => {
const a = Buffer.from(candidate);
const b = Buffer.from(expected);
return a.length === b.length && timingSafeEqual(a, b);
});
}Reference
- Merchant API reference generated from the live OpenAPI schema.
- Webhooks help lists every event and field. The same catalog is available as JSON Schema from the event-catalog endpoint.
- Billing webhooks: best practices
- Sandbox to live launch checklist
The SDK is a .NET library, and the webhook verifier shown above needs TenaBill.Sdk 0.4.0 or later. When we reviewed this page, nuget.org listed older versions, so ask us for the current package if you want it. Other languages call the REST API directly with the same API key header.