Prerequisites
- The Go SDK installed and
SOLVAPAY_SECRET_KEYandSOLVAPAY_PRODUCT_REFset. See Installation. - A product with at least one plan in SolvaPay Console. Use sandbox while you build.
1) Make a function paid
Payable wraps a function so that each call is decided by the paywall first:
- If the customer’s plan allows the call, your function runs, and the call is recorded as usage when it returns.
- If it doesn’t, your function does not run, and the call returns a
*PaywallError. ItsGatesays what the customer has to do and where to pay.
POST /reports:
main.go
PaidCall.CustomerRef says who is calling. Pass your own user id: the paywall finds the SolvaPay customer with that externalRef, or creates one on first use. You can also pass a SolvaPay customer reference (cus_…) directly. An empty CustomerRef fails with the code identity_required.
2) Run it
402 Payment Required and the gate:
message to the customer, or send them to checkoutUrl. Once they have a plan, the same request returns the report.
The gate’s
message is the same text the TypeScript and MCP paywalls use, so it also mentions the account MCP tool. On a plain HTTP API, show checkoutUrl instead if that line doesn’t fit.3) Handle the other errors
An error your function returns comes back unchanged, and the call is recorded as failed. Every error from the SDK itself is a*solvapay.Error (a *PaywallError unwraps to one, with the gate’s kind as its code). Branch on Code or Status, never on Message. See API client.
Options
PayableOptions says what a paid function is for:
Payable checks the product and the free allowance when you call it, so a misconfigured paid function fails at startup, not on its first call.
Next steps
- MCP server: sell the same function as an MCP tool, with sign-in and checkout built in.
- Webhooks: react to purchases and payments.
- The TypeScript equivalent of this page: Quick start.