Buchungskalender: Abschluss – Kleinigkeiten Server (Betrag/Waehrung, Erstattungs-Webhook, Obergrenze, Zaehler, Cache, Kommentare, Setup-Check)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6d35674c1e
commit
1d9515823c
13 files changed
+123
-14
No files matched your search
@@ -91,6 +91,12 @@ export async function beendeOffeneZahlung(ctx, anfrage) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Stimmt eine bezahlte Sitzung mit der Buchung ueberein: Betrag = Brutto der Anfrage (Cent), Waehrung eur? Sonst gilt sie nicht als Bezahlung. */
|
||||
export function zahlungPasst(anfrage, session) {
|
||||
const brutto = anfrage?.summen?.bruttoCent
|
||||
return Number.isInteger(brutto) && session?.amount_total === brutto && String(session?.currency ?? '').toLowerCase() === 'eur'
|
||||
}
|
||||
|
||||
/** Volle Rueckerstattung einer Zahlung, die zu keiner offenen Buchung mehr passt (nach Storno, Ablauf oder doppelt gezahlt). */
|
||||
export async function erstatteUeberzaehligeZahlung(ctx, paymentIntentId) {
|
||||
const accountId = ctx?.einstellungen?.stripeAccountId
|
||||
@@ -153,6 +159,11 @@ export async function schliesseAbWennBezahlt(ctx, anfrage, { now = new Date(), e
|
||||
merkeAbgleich(schluessel, { at: nowMs, abgelaufen: session?.status === 'expired' })
|
||||
if (session?.status === 'complete' && session.payment_status === 'paid') {
|
||||
const pi = typeof session.payment_intent === 'string' ? session.payment_intent : session.payment_intent?.id
|
||||
if (!zahlungPasst(anfrage, session)) {
|
||||
console.warn(`[unterkunft] Abgleich: Betrag oder Währung weicht ab (Buchung ${anfrage.nummer}), Zahlung wird erstattet`)
|
||||
await erstatteUeberzaehligeZahlung(ctx, pi)
|
||||
return anfrage
|
||||
}
|
||||
return await verbucheZahlung(ctx, anfrage.$id, pi, { now })
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
Reference in new issue
Block a user