openrtc-template-billing
v0.1.0
Published
Thin BillingAdapter interface + provider adapters (Stripe, Polar, Lemon Squeezy) for OpenRTC starter templates.
Readme
openrtc-template-billing
Thin billing abstraction for the OpenRTC starter templates: checkout, customer portal, current subscription, metered usage, webhooks. Provider differences (merchant of record, id models, signature schemes) stay inside each adapter.
| Provider | Factory | Notes |
| --- | --- | --- |
| Stripe (default) | stripeAdapter({ stripe, webhookSecret, priceToPlan }) | inject new Stripe(secret); customerRef round-trips via subscription metadata; usage via Stripe Meters |
| Polar | polarAdapter({ accessToken, webhookSecret, priceToPlan }) | merchant of record; uses external customer ids; usage via event ingestion |
| Lemon Squeezy | lemonSqueezyAdapter({ apiKey, storeId, signingSecret, priceToPlan, resolveProviderIds }) | merchant of record; requires the template to persist provider ids from webhooks |
priceId in plans.ts means: Stripe price id, Polar product id, or
Lemon Squeezy variant id, depending on the configured provider.
Bring your own
import type { BillingAdapter } from 'openrtc-template-billing';
export const myBilling: BillingAdapter = {
id: 'custom',
async createCheckout({ customerRef, priceId, successUrl }) { /* ... */ },
async customerPortalUrl({ customerRef, returnUrl }) { /* ... */ },
async getSubscription(customerRef) { return { planId: 'free', status: 'none' }; },
async reportUsage() {},
async handleWebhook(request) { return { events: [] }; },
};