Author SHA1 Message Date
blandClaude Fable 5.1 a93f35792f kron beside portal: the money service, Vipps MobilePay, wired but not started
A `kron:` service on the vel's own NATS, its keys in kron.env and
nowhere else, published on 127.0.0.1:3080 for the host Caddy
(host-caddy/kron.vel.klingenbergbygg.no), and PAY_URL on portal so the
lint allows `payment:` without `by_hand`. kron.env.example names the
five settings; register-vipps-webhook.sh registers <PUBLIC_URL>/webhook
with Vipps and writes the secret it answers with into kron.env without
showing it. The README's Money section is the order to do it in.

On a branch, not main: deploy-tomtervel resets the checkout to
origin/main and brings the whole project up, and a kron service whose
env_file is not on the host yet would stop everything else with it.
Merge once kron.env is in place and bendik/kron has a tag to pin.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L5fbDkR5YogvJGebPtogQT
2026-11-04 18:05:26 +01:00
7 changed files with 128 additions and 0 deletions

No files matched your search

+2
View File
@@ -63,3 +63,5 @@ RUNNER_REGISTRATION_TOKEN=
# installed from the [uhhm] Arch registry. gdo hands the vel's mail to # installed from the [uhhm] Arch registry. gdo hands the vel's mail to
# the host's mail server; on kasse that is Klingenberg Bygg's postfix. # the host's mail server; on kasse that is Klingenberg Bygg's postfix.
GDO_RELEASE=v0.2.0 GDO_RELEASE=v0.2.0
# kron, the money service: a bendik/kron tag on Docker Hub.
KRON_RELEASE=0.1.0
+1
View File
@@ -6,3 +6,4 @@ nats/nats.conf
certs/ certs/
.kanidm-recovered .kanidm-recovered
gitea-oauth.secret gitea-oauth.secret
kron.env
+29
View File
@@ -122,6 +122,35 @@ whose `runs-on` matches that runner's host label, running
`nats --server nats://portal:$NATS_PASSWORD@127.0.0.1:4222 pub portal.content.reload ""`. `nats --server nats://portal:$NATS_PASSWORD@127.0.0.1:4222 pub portal.content.reload ""`.
Until then, `podman compose restart portal` picks up new content. Until then, `podman compose restart portal` picks up new content.
## Money: kron and Vipps MobilePay
Portal decides what is owed - a `payment:` on a state in the content -
and kron, the money service in this stack, asks Vipps MobilePay for
it, pushes it to the person's app, and reports back over NATS. Portal
then moves the record on (`then:`) by itself, as if the treasurer had
pressed the button. The treasurer's desk still works: money that came
to the account some other way is registered there as before.
To bring it up, once per environment:
1. `cp kron.env.example kron.env`, `chmod 600 kron.env`, and fill in
the four keys from the Vipps MobilePay portal (API-nøkler). Test
keys first: `VIPPS_ENV=test`, MSN 563326.
2. Host Caddy: copy `host-caddy/kron.vel.klingenbergbygg.no` into
`/etc/caddy/conf.d/` and `systemctl reload caddy`. Wildcard DNS
already points the name here.
3. `sh register-vipps-webhook.sh` - registers the webhook with Vipps
and writes `WEBHOOK_SECRET` into `kron.env`. Needs `jq`.
4. `podman compose up -d kron`, then `curl 127.0.0.1:3080/healthz`.
5. The content says what is owed: a `payment:` on the paying state in
`aggregates.yaml` in tomtervel/questions, without `by_hand`. The
content repo's lint needs `PAY_URL` set to allow that, the same as
the `portal` service here.
Production is the same five steps with the production keys and
`VIPPS_ENV=prod`. `KRON_RELEASE` in `.env` is a bendik/kron tag on
Docker Hub; bumping it is the upgrade.
## Upgrading portal ## Upgrading portal
Bump `PORTAL_RELEASE` in `.env` (a tag of uhhm/portal) and Bump `PORTAL_RELEASE` in `.env` (a tag of uhhm/portal) and
+27
View File
@@ -95,6 +95,11 @@ services:
# The namespace of everything this site keeps on NATS from portal 0.9. # The namespace of everything this site keeps on NATS from portal 0.9.
# Must not change: a new name is a new, empty site. # Must not change: a new name is a new, empty site.
SITE_NAME: tomtervel SITE_NAME: tomtervel
# The money service is there: the lint then allows `payment:` without
# `by_hand: true`. Nothing at run time reads it - a request is
# published whenever the content did not say by_hand - so the same
# variable has to be set where the content repo's lint runs.
PAY_URL: http://kron:3000
volumes: volumes:
- learn_cache:/app/learn-cache - learn_cache:/app/learn-cache
ports: ports:
@@ -135,6 +140,28 @@ services:
nats: nats:
condition: service_healthy condition: service_healthy
# The money service. Portal decides what is owed - a `payment:` on a
# state in the content - and publishes the request on this NATS; kron
# is what asks Vipps MobilePay for it, pushes it to the person's app,
# and says on the same NATS what became of it. One kron per site, its
# keys in kron.env and nowhere else. Host-published for kasse's host
# Caddy (kron.vel.klingenbergbygg.no -> here): Vipps has to reach
# /webhook over public HTTPS, and a person who paid by link lands on
# /returned/<id>.
kron:
image: docker.io/bendik/kron:${KRON_RELEASE}
restart: unless-stopped
env_file: kron.env
environment:
NATS_URL: nats://portal:${NATS_PASSWORD}@nats:4222
SITE_NAME: tomtervel
PUBLIC_URL: https://kron.${PORTAL_HOST}
ports:
- "127.0.0.1:3080:3000"
depends_on:
nats:
condition: service_healthy
# The Gitea Actions runner is a host service on kasse (pacman gitea-runner), # The Gitea Actions runner is a host service on kasse (pacman gitea-runner),
# registered against prosjekt.klingenbergbygg.no. It reaches this NATS via the # registered against prosjekt.klingenbergbygg.no. It reaches this NATS via the
# published 127.0.0.1:4222 port above, so no in-compose runner — and no # published 127.0.0.1:4222 port above, so no in-compose runner — and no
+6
View File
@@ -0,0 +1,6 @@
# kasse's host Caddy: /etc/caddy/conf.d/kron.vel.klingenbergbygg.no.
# Vipps MobilePay delivers webhooks here, and a person who paid by link
# comes back here; both go to the vel stack's kron (127.0.0.1:3080).
kron.vel.klingenbergbygg.no {
reverse_proxy 127.0.0.1:3080
}
+19
View File
@@ -0,0 +1,19 @@
# kron, the money service beside portal: Vipps MobilePay for Tomter Vel.
# Copy to kron.env (root, mode 600, like portal.env) and fill in the
# values from the Vipps MobilePay portal, API-nøkler. Never commit kron.env.
#
# Test first: VIPPS_ENV=test with the keys from "API-nøkler – test"
# (MSN 563326); production is the same five lines with the production
# keys and VIPPS_ENV=prod.
PROVIDER=vipps
VIPPS_ENV=test
VIPPS_MSN=563326
VIPPS_CLIENT_ID=
VIPPS_CLIENT_SECRET=
# Ocp-Apim-Subscription-Key (primær). The secondary exists so this one
# can be rotated without downtime; kron takes one at a time.
VIPPS_SUBSCRIPTION_KEY=
# From registering <PUBLIC_URL>/webhook with Vipps: register-vipps-webhook.sh
# fills this in. Until it is set every webhook is refused and payments
# settle by the sweep alone, which works but is slower.
WEBHOOK_SECRET=
+44
View File
@@ -0,0 +1,44 @@
#!/bin/sh
# Registers <PUBLIC_URL>/webhook with Vipps MobilePay's Webhooks API and
# puts the secret it answers with into kron.env as WEBHOOK_SECRET,
# without showing it. Run once per environment, as root, in this
# directory, after kron.env has the four keys and before kron starts.
#
# sh register-vipps-webhook.sh
#
# The events are the ones kron reads (src/provider/vipps.rs,
# seen_of_event): authorized, captured, expired, cancelled, aborted,
# terminated and refunded. kron does not register itself, by design:
# registering is a one-time act with a secret in the answer, and a
# service that could do it could also do it twice.
set -eu
[ -f kron.env ] || { echo "no kron.env here" >&2; exit 1; }
. ./kron.env
: "${VIPPS_CLIENT_ID:?}" "${VIPPS_CLIENT_SECRET:?}" "${VIPPS_SUBSCRIPTION_KEY:?}" "${VIPPS_MSN:?}"
public_url=$(grep -E '^PUBLIC_URL=' kron.env | cut -d= -f2- || true)
[ -n "$public_url" ] || public_url="https://kron.$(sed -n 's/^PORTAL_HOST=//p' .env)"
base=https://api.vipps.no
[ "${VIPPS_ENV:-test}" = test ] && base=https://apitest.vipps.no
token=$(curl -sf -X POST "$base/accesstoken/get" \
-H "client_id: $VIPPS_CLIENT_ID" -H "client_secret: $VIPPS_CLIENT_SECRET" \
-H "Ocp-Apim-Subscription-Key: $VIPPS_SUBSCRIPTION_KEY" -H "Merchant-Serial-Number: $VIPPS_MSN" \
| jq -r .access_token)
[ -n "$token" ] && [ "$token" != null ] || { echo "no access token: check the four keys" >&2; exit 1; }
answer=$(curl -sf -X POST "$base/webhooks/v1/webhooks" \
-H "Authorization: Bearer $token" \
-H "Ocp-Apim-Subscription-Key: $VIPPS_SUBSCRIPTION_KEY" -H "Merchant-Serial-Number: $VIPPS_MSN" \
-H 'Content-Type: application/json' \
-d "$(jq -n --arg url "$public_url/webhook" '{url: $url, events: [
"epayments.payment.authorized.v1", "epayments.payment.captured.v1",
"epayments.payment.expired.v1", "epayments.payment.cancelled.v1",
"epayments.payment.aborted.v1", "epayments.payment.terminated.v1",
"epayments.payment.refunded.v1"]}')")
id=$(printf '%s' "$answer" | jq -r .id)
secret=$(printf '%s' "$answer" | jq -r .secret)
[ -n "$secret" ] && [ "$secret" != null ] || { echo "registered nothing: $(printf '%s' "$answer" | jq -c 'del(.secret)')" >&2; exit 1; }
tmp=$(mktemp) && grep -v '^WEBHOOK_SECRET=' kron.env > "$tmp" && printf 'WEBHOOK_SECRET=%s\n' "$secret" >> "$tmp" \
&& cat "$tmp" > kron.env && rm -f "$tmp"
echo "webhook $id registered at $public_url/webhook; WEBHOOK_SECRET written to kron.env"