Kundenansicht neu P7: Wechsel Fassung 6, Betrieb ohne Sofortbeginn-Zeitstempel

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-10-16 20:03:46 +00:00
1 parent 99e1987bc4
commit 4e0e42f633
3 files changed
+242 -12

No files matched your search

+9 -4
View File
@@ -341,7 +341,8 @@ const DETAILS_MAX = 2000
/**
* Wechsel ins Wartungs-Abo (Button "Zahlungspflichtig bestellen"). consent: { termsVersion, consentAt,
* consentIp, consentUserAgent, earlyStartConsentAt } - ohne Zustimmung zum Sofortbeginn kein Wechsel (400, F16).
* consentIp, consentUserAgent, earlyStartConsentAt, kundenart? } - ohne Zustimmung zum Sofortbeginn kein Wechsel (400, F16); einzige Ausnahme
* kundenart 'unternehmen' (Fassung 6, Betrieb): dann ohne Zeitstempel, der Grund steht als details.kundenart im Ereignis.
* prorationDate: Zeitpunkt der Vorschau (previewProblem). Voraussetzungen wie previewSwitch (409). Mit
* options.expectedAmountCents (Route: angezeigter Betrag) rechnet der Server die Vorschau nach; weicht der Betrag
* ab, 409 ohne Aenderung bei Stripe.
@@ -355,7 +356,8 @@ export async function switchToWartung(customerId, consent, prorationDate, { expe
if (!consent?.termsVersion || !consent?.consentAt) {
throw httpError(400, 'Bitte stimmen Sie den Vertragsbedingungen zu, um zu wechseln.')
}
if (!consent.earlyStartConsentAt) {
// Fassung 6: Ein Betrieb (consent.kundenart 'unternehmen', vom Server aus dem Kundendokument) braucht kein Haekchen und bekommt keinen Zeitstempel
if (!consent.earlyStartConsentAt && consent.kundenart !== 'unternehmen') {
throw httpError(400, 'Bitte bestätigen Sie, dass wir sofort mit dem Wartungs-Abo beginnen sollen.')
}
const problem = previewProblem(prorationDate)
@@ -392,7 +394,8 @@ async function performSwitch(customerId, current, consent, prorationDate, expect
termStartAt: switchedAt,
termsVersion: consent.termsVersion,
termsAcceptedAt: consent.consentAt,
earlyStartConsentAt: consent.earlyStartConsentAt,
// leer (Betrieb, Fassung 6): Stripe loescht den Schluessel, ein Betrieb erbt den Zeitstempel des Hosting-Abschlusses nicht
earlyStartConsentAt: consent.earlyStartConsentAt || '',
consentIp: String(consent.consentIp || '').slice(0, 64),
consentUserAgent: String(consent.consentUserAgent || '').slice(0, 300),
switchedFrom: 'hosting',
@@ -448,6 +451,8 @@ async function performSwitch(customerId, current, consent, prorationDate, expect
previousMetadata: Object.fromEntries(
RESTORABLE_METADATA.map((key) => [key, stripeSub.metadata?.[key] == null ? null : String(stripeSub.metadata[key]).slice(0, 300)])
),
// Fassung 6: Grund fuer den fehlenden Zeitstempel (Betrieb)
...(consent.kundenart === 'unternehmen' ? { kundenart: 'unternehmen' } : {}),
}
// Gewuenschte Funktion (nur Bequemlichkeit): der Nachweis darf dadurch nie zu gross werden
if (funktion && JSON.stringify({ ...details, funktion }).length <= DETAILS_MAX) details.funktion = funktion
@@ -512,7 +517,7 @@ async function recordSwitchEvent({ doc, customerId, consent, status, details })
consentAt: consent.consentAt,
consentIp: consent.consentIp || null,
consentUserAgent: consent.consentUserAgent || null,
earlyStartConsentAt: consent.earlyStartConsentAt,
earlyStartConsentAt: consent.earlyStartConsentAt || '',
},
status,
})