Billing API
monetr's hosted service charges for itself through Stripe, and these three endpoints are how the app hands you off to Stripe and picks you back up afterwards. monetr never sees a card number: both endpoints that matter return a Stripe URL for the browser to go to.
These endpoints are part of monetr's paid hosted service. If you're self-hosting with billing disabled, all three return
404 with {"error": "billing is not enabled"}. That's a hard check at the top of each handler, before anything else
happens.
All three reject API keys. They're reachable only from the monetr web app while signed in. A long lived credential shouldn't be able to start a subscription or open a billing portal on its own.
POST Start a checkout
Creates a Stripe checkout session and returns where to send the browser.
In the app: The subscribe button on the "your subscription isn't active" screen.
Auth: Not available to API keys.
Body
Errors
GET Finish a checkout
Called when Stripe sends the user back to monetr. It checks with Stripe whether the payment actually went through and updates the account, then tells the client where to go.
In the app: The page Stripe redirects to after checkout, which reads the answer and either lets you in or sends you back to subscribe.
Auth: Not available to API keys.
Path parameters
Responses
Payment went through:
It didn't, or hasn't yet:
Both are 200. Check isActive, not the status code. An inactive answer isn't necessarily failure either, Stripe's
webhook may not have landed yet.
Errors
GET Open the billing portal
Returns a URL to Stripe's billing portal, where someone can change their card, see invoices or cancel.
In the app: The manage subscription button on the subscription settings page.
Auth: Not available to API keys.
Response
Send the browser there. The link is short lived and single use, so fetch a fresh one each time rather than storing it.