Buchungskalender: Zahlung – Sitzung wiederverwenden, Zahlung nach Storno erstatten

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
knsoandClaude Opus 5.5 committed 2026-10-07 14:23:06 +00:00
1 parent ca0f762272
commit a94b50fbc1
5 files changed
+233 -52

No files matched your search

+4 -3
View File
@@ -416,7 +416,7 @@ router.get(
const ctx = await buchungsKontext(req, now, cors, { schreiben: false })
let a = await ladeMitToken(ctx, req.params.id, req.query.t)
// Rueckkehr von Stripe vor dem Webhook (oder Webhook verloren): einmal bei Stripe nachsehen
a = await schliesseAbWennBezahlt(ctx, a, { now })
a = await schliesseAbWennBezahlt(ctx, a, { now, erzwingen: req.query.wk_zahlung === 'ok' })
return { body: await buchungAntwort(ctx, a) }
},
BUCHUNG,
@@ -457,7 +457,7 @@ router.post(
async (req, now, cors) => {
const ctx = await buchungsKontext(req, now, cors, { schreiben: true })
let a = await ladeMitToken(ctx, req.params.id, req.query.t)
a = await schliesseAbWennBezahlt(ctx, a, { now })
a = await schliesseAbWennBezahlt(ctx, a, { now, erzwingen: true })
if (a.status !== 'gebucht' || a.zahlart !== 'online') throw fehlerMit(409, 'status_ungueltig')
try {
return { body: await checkoutFuer(ctx, a, { now, token: req.query.t }) }
@@ -483,7 +483,8 @@ router.get(
let modul
try {
modul = await import('../services/unterkunft/rechnungPdf.js')
} catch {
} catch (err) {
if (err?.code !== 'ERR_MODULE_NOT_FOUND') throw err
return { status: 501, body: { fehler: 'nicht_verfuegbar' } }
}
const pdf = modul.rechnungPdf(dok.inhalt, { art, nummer: dok.nummer, datum: dok.datum })
+2 -9
View File
@@ -3,11 +3,10 @@ import { config } from '../config.js'
import { getDocument, listDocuments, Query, updateDocument } from '../services/appwriteAdmin.js'
import { withLocks } from '../services/keyedLock.js'
import { statusAusKonto } from '../services/shop/connect.js'
import { markiereBezahlt } from '../services/unterkunft/ablauf.js'
import { UkFehler } from '../services/unterkunft/fehler.js'
import { ladeFuerProjekt } from '../services/unterkunft/kontext.js'
import { unterkunftModus } from '../services/unterkunft/schalter.js'
import { aktualisiereAnfrage, ladeAnfrage, ladeEinstellungen } from '../services/unterkunft/speicher.js'
import { verbucheZahlung } from '../services/unterkunft/zahlung.js'
/**
* Stripe-Ereignisse des Buchungskalenders. Kein eigener Endpunkt: routes/shopWebhook.js (Connect-Webhook, ein Endpunkt je Konto)
@@ -54,13 +53,7 @@ async function zahlungEingegangen(event, session, now) {
console.warn(`[unterkunft] Webhook: Betrag weicht ab (Buchung ${anfrage.nummer})`)
}
const pi = typeof session.payment_intent === 'string' ? session.payment_intent : session.payment_intent?.id
try {
await markiereBezahlt(ctx, anfrage.$id, { via: 'stripe', paymentIntentId: pi || undefined, now })
} catch (err) {
// Buchung inzwischen storniert o. Ae.: Stripe nicht endlos wiederholen lassen, der Vermieter erstattet von Hand
if (err instanceof UkFehler && err.status === 409) console.warn(`[unterkunft] Webhook: Zahlung fuer Buchung ${anfrage.nummer} im Status ${anfrage.status} eingegangen`)
else throw err
}
await verbucheZahlung(ctx, anfrage.$id, pi, { now })
}
async function erstattungGebucht(event, charge) {