Use cases
SaaS subscriptions
A team signs up on your site, chooses a plan, pays on Stripe's page, and your product switches the plan on. Later they add seats, switch to yearly, or cancel, in your billing page or Ducat's portal. This is exactly how ducatpay.dev sells its own Growth plan.
Step by step
Make your plans
One price per plan and interval, matched on your own metadata.plan so a deploy script makes only the missing ones.
POST /v1/prices
One customer per team
Made the first time the team opens checkout, kept on the team's row.
POST /v1/customers
Checkout
Send the team to Stripe's page with your price and the number of seats.
POST /v1/checkout-sessions
Switch the plan on
On the success page, then from every event: read the subscription back and set the team's plan from its status.
GET /v1/subscriptions/{id}
Billing page
Plan and status, invoices with Stripe's pages, cancel at the period's end and undo.
GET /v1/customers/{id}/invoices
Self-serve changes
A portal link where the customer switches plan, sets seats and replaces their card.
POST /v1/customers/{id}/portal-sessions
In code
TypeScript
// ducat(): the small fetch helper from the quickstart
const ON = new Set(["active", "trialing"]);
export async function applySubscription(subId: string) {
const sub = await ducat("GET", `/v1/subscriptions/${subId}`);
await db.teams.update(sub.metadata.team, {
plan: planByPrice(sub.items[0]?.price),
seats: sub.items[0]?.quantity,
paid: ON.has(sub.status),
endsAt: sub.cancel_at_period_end ? sub.current_period_end : null,
});
}Python
# ducat(): the small helper from the quickstart
ON = {"active", "trialing"}
def apply_subscription(sub_id: str) -> None:
sub = ducat("GET", f"/v1/subscriptions/{sub_id}")
item = (sub["items"] or [{}])[0]
db.teams.update(sub["metadata"]["team"],
plan=plan_by_price(item.get("price")),
seats=item.get("quantity"),
paid=sub["status"] in ON,
ends_at=sub["current_period_end"] if sub["cancel_at_period_end"] else None)curl
curl -s https://api.ducatpay.dev/v1/checkout-sessions/cs_test_… -H "authorization: Bearer $DUCAT_TOKEN"
# → {"status": "complete", "payment_status": "paid", "subscription": "sub_…", …}
curl -s https://api.ducatpay.dev/v1/subscriptions/sub_… -H "authorization: Bearer $DUCAT_TOKEN"
# → {"status": "active", "items": [{"price": "price_…", "quantity": 3}], "metadata": {"team": "org_acme"}, …}Every change reaches you
Renewals, failed payments, plan changes and cancellations made anywhere, the portals included, arrive as events: pushed and signed, or polled.
Good to know
- Set the team's state from the subscription as Ducat answers it now, never from the event's contents: the same event twice, or out of order, then changes nothing.
- past_due: keep the plan on for a grace period you choose and show “update your card” with a portal link.
- The selling guide walks every request, and Ducat's own test suite runs the guide's steps in order.
Features it uses
Checkout
Available in test modeSend a customer to Stripe's hosted payment page for a subscription or a one-off payment, and know when it's paid.
Subscriptions
Available in test modePlans per seat or flat, trials, plan changes with a prorated preview, cancel at the period's end, and dunning.
Invoices
Available in test modeEvery invoice with Stripe's hosted page and PDF, for your billing page, and credit notes when you owe one back.
Customer portal
Available in test modeA one-hour link where your customer switches plan, changes seats, cancels, replaces their card and sets tax details.
Webhooks
Available in test modeEvery event pushed to your endpoint, signed, in order, at least once, with retries; or polled with a cursor.
Usage billing
BetaMeters that sum, count or keep the last value; metered prices on them; usage reported once per identifier.
Start building in test mode
Sign up, make a key, and take a test payment in a few minutes. No card needed.