Add Billing to your app
Billing and the processors aren't in the stock pocketone binary. You add them in a small Go program that builds
your own: every standard extension, plus Billing and the processors you sell through. Your pb_hooks, pb_pages
and pb_migrations work exactly as before.
1. Make the program
In your app's folder, next to pb_data:
go mod init example.com/myapp
go get pocketone.dev/ext/standard pocketone.dev/ext/billing pocketone.dev/ext/stripe
// main.go
package main
import (
"log"
"ganigeorgiev.com/pocketbase/pocketbase"
"pocketone.dev/ext/billing"
"pocketone.dev/ext/jsvm"
"pocketone.dev/ext/standard"
"pocketone.dev/ext/stripe"
)
func main() {
set := standard.New()
set.Add(
billing.New(billing.Config{}),
stripe.New(stripe.Config{}),
)
app := set.NewApp(pocketbase.Config{}, jsvm.Config{HooksDir: "pb_hooks"})
if err := app.Start(); err != nil {
log.Fatal(err)
}
}
Swap stripe for paddle (pocketone.dev/ext/paddle) or creem (pocketone.dev/ext/creem), or add more than
one. Billing needs the Settings and KV extensions, which the standard set already has. To read pocketone.yaml
the way the stock binary does, build the app with standard.AppFromConfig as
Standard extensions shows.
2. Run it
go run . serve
The first start adds Billing's collections: _billing_products, _billing_items (one per subscription, order or
manual grant), _billing_events (every webhook) and _billing_checkouts. $billing is now in your pages and
pb_hooks.
Build it for a server the usual Go way (GOOS=linux GOARCH=amd64 go build -o myapp .) and run ./myapp serve where you
ran pocketone serve.
3. Set it up in the dashboard
Open the dashboard and go to Billing → Settings.
| Setting | What it does |
|---|---|
| Checkout processor | Which installed processor takes new checkouts. Leave it empty when only one is installed. |
| Owner collection | The auth collection whose records buy (users). |
| Signed-out checkout (pay first) | Visitors can buy before they have an account. See Pay first. |
| Success URL, Cancel URL | Where the processor sends buyers back. Both default to the Application URL. |
| Proration | How quantity and plan changes are charged when the caller doesn't say: now, at the next period, or not at all. |
| API URL | The base of webhook and checkout-page URLs when the Application URL doesn't reach this app's API. |
| Reconcile daily | Re-reads every item that hasn't ended from its processor once a day and fixes anything that drifted. |
Each processor's section is on the same page: its keys, a Test button, and the webhook URL to paste into the processor's dashboard. Follow your processor's page: Stripe, Paddle or Creem.
Then add what you sell: Products and prices.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.