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
This commit is contained in:
1 parent
f307d72907
commit
a93f35792f
7 files changed
+128
No files matched your search
Executable
+44
@@ -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"
|
||||
Reference in new issue
Block a user