Creem
Version 0.0.1 · Owners: @benallfree
Creem is a payment processor for Billing. Buyers pay on Creem's hosted checkout page, Creem's webhooks keep Billing's items current, and owners manage cards and receipts in Creem's customer portal.
Creem is always the merchant of record: it collects and files sales tax and VAT and handles disputes.
Install · Configure · Use · Integrations · Example
Install
extkit.Setup(app, []extkit.Extension{settings.New(), billing.New(billing.Config{}), creem.New(creem.Config{})}, nil, nil)
The module is pocketone.dev/ext/creem. It talks to Creem's API over plain HTTP, with no Creem SDK.
Configure
Open Billing → Settings in the dashboard. Creem's section is below Billing's own.
| Setting | What it does |
|---|---|
| API key | Your Creem API key, from Developers in Creem's dashboard. A test-mode key (creem_test_, shown with Test Mode on) uses Creem's test API, test-api.creem.io. |
| Webhook secret | The secret of the webhook below, from Developers → Webhooks. Test mode has its own webhooks and secret. |
Test checks the key with one read call.
In Creem, add a webhook (Developers → Webhooks) at the webhook URL shown on the settings page
(<your app>/api/_c/billing/v1/webhook?provider=creem), with these events:
checkout.completedsubscription.active,subscription.trialing,subscription.paid,subscription.updatesubscription.scheduled_cancel,subscription.canceled,subscription.expiredsubscription.past_due,subscription.unpaid,subscription.pausedrefund.created,dispute.created
Creem sends webhooks only to a public HTTPS address. To try it on your own machine, put the app behind a tunnel
(ngrok, cloudflared) and use the tunnel's address.
Each product on Billing → Products names its Creem product: prices: {"creem": "prod_..."}. A Creem product
carries its own price. A subscription product needs a recurring Creem product, a one-time product a one-time one;
Check prices tells you if one doesn't match.
Use
Billing is the API; this extension only answers it. What Billing's calls do at Creem:
| Billing | Creem |
|---|---|
checkout |
A checkout for the product and its units, request_id and the metadata's reference set to Billing's checkout. The buyer's email is filled in, or their Creem customer when they bought before. Discount codes and trial days pass through. |
portal |
A customer portal link for the owner's Creem customer. |
cancel |
Cancels now, or schedules the cancel for the end of the period. |
resume |
Undoes a scheduled cancel. |
quantity |
Updates the subscription item's units. |
plan |
Upgrades the subscription to another product. |
refund |
Refunds a one-time purchase, or a subscription's last paid transaction, in full. |
For quantity and plan, proration now charges the difference at once, next_period adds it to the next
payment, and none doesn't prorate.
A one-time purchase is identified by the checkout that made it (ch_...), which Creem's refund and dispute events
name. Creem refunds only in full: a refund with an amount is refused as unsupported. A refund or dispute on a
subscription's payment reaches Billing through the subscription's own events.
Creem's statuses map to Billing's as follows: scheduled_cancel is cancelling until the period ends, expired (the
period ended unpaid while Creem still retries) is past due, unpaid is unpaid, and canceled is ended. Creem has no
links to single objects in its dashboard, so Billing shows none.
Integrations
| Extension | How they fit |
|---|---|
| Billing | Creem provides payments/v1, the processor contract Billing uses. Several processors can be installed; Billing's settings pick the one that takes new checkouts. |
| Settings | Creem's settings are a section on Billing → Settings. |
| KV | The keys are stored privately in the key-value store, never readable over its API. |
Example
// Command example runs one PocketOne app that sells through Creem: billing (ext/billing) with Creem as its only
// processor.
//
// go run ./example serve
//
// Then, in the dashboard ([email protected] / password): Billing → Settings, paste a test-mode API key
// (creem_test_...), and add a product on Billing → Products with prices {"creem": "prod_..."}. Creem sends webhooks only
// to a public HTTPS address, so put the app behind a tunnel (ngrok, cloudflared), add
// <tunnel>/api/_c/billing/v1/webhook?provider=creem as a test-mode webhook and paste its secret. As [email protected],
// POST /api/_c/billing/v1/checkout {"product": "<key>"}, open the URL it returns and pay with one of Creem's test
// cards.
//
// Logins (ext/devusers, local testing only): dashboard [email protected] / password, app user [email protected] / password.
package main
import (
"log"
"ganigeorgiev.com/pocketbase/pocketbase"
"pocketone.dev/ext/billing"
"pocketone.dev/ext/creem"
"pocketone.dev/ext/devusers"
"pocketone.dev/ext/extkit"
"pocketone.dev/ext/settings"
)
func main() {
app := pocketbase.New()
devusers.Register(app) // local testing: superuser [email protected] and user [email protected], password "password"
exts := []extkit.Extension{settings.New(), billing.New(billing.Config{}), creem.New(creem.Config{})}
if _, err := extkit.Setup(app, exts, nil, nil); err != nil {
log.Fatal(err)
}
if err := app.Start(); err != nil {
log.Fatal(err)
}
}
License
MIT
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.