Guides
Sell a subscription in five calls
A monthly plan end to end in the sandbox. Create a product and a recurring price, open a checkout session in subscription mode, provision on the webhook, and give the customer the portal. With the MCP tool for each call.
This guide sells Pro at $29.00 a month. The buyer pays on ZeroPoint's hosted page, the card is saved and charged, and the subscription renews on it. Your app grants access from a webhook and sends the customer to the hosted portal to manage the plan. Every amount is integer cents. Read Subscriptions and invoices first for the statuses and rules.
Billing runs in test mode in this release: the first charge happens at checkout, and renewals run when you advance a test clock (Test your billing with test clocks and failure injection). Use a zp_test_ key.
Scopes: catalog:write, checkout_sessions:write, payment_methods:write, subscriptions:write, webhooks:write. New sandbox keys carry them all.
0. Set the merchant's billing settings
Set up billing in one step
Three things get a merchant moving from Stripe ready for its first subscription: its time zone, its subscription guard and a webhook endpoint that receives the billing events. Do them once per merchant, before the first subscription.
ZeroPoint's operator does it in one command, for one merchant:
It sets timezone (required, an IANA name), upcoming_days (default 3) and subscription_guard (required: off, price, product or customer), audited. For the webhook:
- A webhook endpoint belongs to your platform, not to one merchant: it receives the events of every merchant of the platform in that mode. The output says so.
- With no endpoint for the URL, it registers one for every billing event type and the payment and refund types, with
stripe_signature_headerandstripe_compatible_payloadon (--stripe-signature-header offif the URL still receives real Stripe deliveries), and prints its signing secret once. - An existing endpoint for the URL (the exact string) is never changed without an explicit flag. Missing types are listed and added only with
--add-event-types. Each Stripe flag changes only with--stripe-signature-header on|offor--stripe-compatible-payload on|off, and the output says what that changes for every delivery to the URL. The secret is kept unless--rotate-secret.
Run again, it changes only what differs. It ends with a checklist of what is still closed and why: live billing, the scheduler's own stops (on, halted, paused, the merchant's renewals paused, dry run), checkout's live switch, the live redirect hosts (checked only with --site-host), the endpoint's event types and its signed test delivery. It never opens any of them. Without --apply nothing is written; a live merchant also needs --live. A live merchant's settings are set this way, by the operator, before go-live: the API answers billing_unavailable for a live merchant until billing is switched on for your platform.
Your own code does the same with three calls:
Send each with your zp_test_ key and its own Idempotency-Key. Store the secret from the second answer: it is shown only there. The third sends a signed webhook.test to your endpoint; verify its signature in your receiver. List your endpoints first (GET /v1/webhooks) and change the one for your URL with PATCH /v1/webhooks/{id} rather than registering it twice; remember it serves every merchant of your platform in this mode, and that turning on stripe_compatible_payload changes the payload of every delivery to it. No MCP tool does all three, and register_webhook does not set the two Stripe flags: send the first two over REST (verify_webhook can send the third).
The settings
Two settings matter here:
timezone(an IANA name, defaultUTC): renewal dates, and the dates the checkout page and the portal show the customer, are days in this zone. With the default, a purchase at 10:30 PM in Chicago reads as the next day. A subscription keeps the zone it was created with, so set it first.subscription_guard(defaultproduct): stops a customer you identify buying the same thing twice. While they hold a live subscription (active,past_dueorunpaid), a new one is refused:priceto the same price;productto any price of the same product (Pro monthly blocks Pro yearly);customerto anything at this merchant (one subscription per customer: they change plans instead);offnever. A plan change is never blocked by the subscription being changed, so upgrades still work. The case most likely to surprise a merchant: every subscription is quantity 1, so under the default one customer record cannot hold the same product twice. A customer who buys it a second time on purpose (a parent paying for two children under onecustomer, or two locker rentals) is refused with409 subscription_exists. Use one customer per person (records that share the parent's email are still two buyers), and do not send the parent's user id asclient_reference_idon both (a shared reference says "the same buyer" and the second is refused), or setsubscription_guardtopriceorofffor this merchant.The default also refuses a subscription checkout session that names no buyer:
400 customer_identity_required, nothing created. Name the buyer one of three ways:customer,client_reference_idorcustomer_email(below). An integration written the plain Stripe way, with none of them, fails on its first session until it sends one or the merchant sets the guard tooff.productcompares products as your catalog has them: a monthly and a yearly price are "the same product" only when both sit under one product.client_reference_idis compared exactly (case and spaces count). A change of the guard applies to sessions created afterwards; a session opened before is not checked again for a buyer.
The merchant can be named in the ZeroPoint-Account header (Stripe-Account works too) or as "merchant_id": "mch_123" in the body, the same as every other route; with one merchant on the platform you may leave it out. The answer is the whole billing_settings object (every field is in Failed renewals and retries, "Billing settings"). Fields you leave out stay as they are. GET /v1/billing_settings with the same header (or ?merchant_id=mch_123) reads them; MCP: get_billing_settings. There is no MCP tool that changes them: send this REST call.
With subscription_guard at anything but off (so by default), every subscription-mode checkout session must name the buyer. The guard matches the customer record, not the email: by customer id, by client_reference_id, or by the customer_email you pass on a session that names no customer. Reuse one customer per user (never a new cus_ per checkout). Name the buyer with one of:
customer(cus_...), the ZeroPoint customer you created for this user;client_reference_id, your own id for the user, the same value every time for one buyer (never per location, campaign or household: every later buyer under a shared value is refused);customer_email, only an address your app has verified.
A session that names nobody is refused at create, and nothing is created:
A buyer who already has a live subscription the guard matches is refused at create too, naming the subscription they have; the message says which match (price, product or customer). Nothing is charged; send them to the portal (step 5) instead:
The full rules, including what the buyer sees on the page, are in Hosted checkout.
1. Create the product
MCP: create_product with merchant_id and name. Answer: the product, id prod_.... Call list_products first and reuse one that exists.
2. Create the monthly price
MCP: create_price. A price never changes; to change the amount, create a new price and archive the old one. In your app, find the price by its lookup key and its merchant (GET /v1/prices with lookup_keys=pro_monthly&merchant_id=mch_..., or send the merchant in the ZeroPoint-Account header; without one, a key that exists on more than one of your merchants answers 400 parameter_invalid), never by a hard-coded id. Only interval_count 1 is supported: every 1 month or every 1 year.
3. Open a checkout session in subscription mode
When the signed-in user presses Subscribe, your server creates the session and redirects the browser to url with a 303:
MCP: create_checkout_session with the same fields and a new request_key for this purchase. Answer: the session, id cs_..., status: open, and url. The page shows "Renews at $29.00 a month" and a Subscribe button. In the sandbox, open url in a regular browser and pay with test card 4761739001010010 (any future expiry, any CVV), or with no browser: POST /v1/test_helpers/checkout/sessions/{id}/confirm with {"card": "tok_visa", "email": "buyer@example.com"} and an Idempotency-Key (MCP confirm_checkout_session), which runs the page's own confirm and makes the same subscription, invoice, events and webhooks (sandbox, "Test card tokens"). email is the address the buyer would type on the page: it is needed when the session names no email, as this one does (only client_reference_id), and ignored when the session has customer_email or names a customer that has an email; without it the answer is 400 parameter_missing (param: email).
Rules:
- Exactly one line, a recurring catalog price,
quantity: 1. A first invoice of $0 (a 100 percent off code) is refused: indiscountsat create it answers400 parameter_unavailable, and on the page the code is turned down with nothing changed. Use a code that leaves at least 1 cent to pay. - Use the same key only to retry the same call; a new purchase gets a new key.
- A declined card leaves the session open for another card. A promotion code the buyer applied stays reserved for that session for 15 minutes after the last decline, then is released for others; the next attempt reserves it again.
- A payment whose outcome is unknown is never treated as declined: the page says the payment is being confirmed, and
409 checkout_outcome_unknownon a new session for the sameclient_reference_idmeans "wait". Do not open another session meanwhile.
4. Provision on the webhook
Register a receiver for the billing events (they are opt-in: an endpoint with empty event_types gets payment events only):
MCP: register_webhook, then verify_webhook. Keep the whsec_ secret it returns once.
Developing on your own machine? ZeroPoint cannot deliver to localhost. Register the endpoint at a public URL (or the hosted /sandbox/webhook-sink) and run the listen.mjs helper from the zeropoint.node.subscriptions snippet: it replays that endpoint's events to http://localhost:... signed with your secret exactly as a delivery is, so your verification code runs unchanged. Running the ZeroPoint server itself on your machine? It refuses every local and http endpoint, its own /sandbox/webhook-sink included, so pass listen the event types instead of a webhookId: it then needs no endpoint (the repository README, "Local development", has the command). A tunnel to your machine, or polling list_events, works too (Webhooks, "Developing locally").
Your handler, after verifying the ZeroPoint-Signature header over the raw body:
- Store
event.id; if you have seen it, answer 200 and stop. Deliveries repeat. checkout.session.completed: readclient_reference_id(your user) andsubscription(sub_...); store the subscription id on the user. Do not grant on the success redirect alone: the redirect can be faked or lost.customer.subscription.created,.updatedand.deleted: storestatusand grant or revoke by it. A paid checkout sendscustomer.subscription.createdalreadyactiveand nocustomer.subscription.updated; the first.updatedcomes at the next renewal, so a handler without.creatednever sees the purchase. Grant or revoke bystatus(activegrants;canceled,unpaidandincomplete_expiredrevoke;past_dueis your grace period). Overwrite your stored copy only whendata.object_versionis greater than or equal to the one you hold. If onlypayment_holdchanged, do nothing.invoice.payment_failed: readbilling_reasonfirst.subscription_cycle(a renewal): email the customer to update their card, with a link to your account page (step 5).subscription_update(a plan change that did not go through): the plan is unchanged and the invoice is voided next; tell the customer the change failed.subscription_create(a first payment throughPOST /v1/subscriptions): ask for another card and paylatest_invoice. Failed renewals and retries has the rest.invoice.upcoming: send your renewal reminder. ZeroPoint sends no email to your customers.
Ready-made pieces: get_snippet with zeropoint.node.webhook-receiver verifies and stores events durably, and zeropoint.node.subscriptions creates the step 3 session under your key (with your customer and a promotion_code when you have them; startPurchaseCheckout for a one-time price) and applies the stored events once each, a paid one-time purchase included (access by status, object_version overwrite rule, a durable outbox for your reminder, receipt and failed-payment emails). See Billing events for every event your handler can get.
Check the result with GET /v1/subscriptions/{subscription_id} (MCP get_subscription): status: active, items.data[0].price.id is your price, current_period_end is a month after current_period_start.
5. Give the customer the portal
On your account page, a Manage billing button posts to your server, which creates a portal session for the user's customer and redirects at once:
MCP: create_portal_session. The answer's url works once and expires after 5 minutes. Never email it, store it or show it. On the portal the customer cancels at period end (and undoes it), replaces the card and pays an open invoice; you receive customer.subscription.updated for each change.
What next
- Renew it: Test your billing with test clocks and failure injection.
integration_checklistmarksrenew_on_test_clockdone after a paid renewal on a clock. - Plans of different prices: Upgrades, downgrades and cancel.
- Declines: Failed renewals and retries.
- Porting Stripe code: Coming from Stripe.