Stripe-Konfigurationsfehler in abo-upgrade.php sauber abfangen

billing_stripe_price_id() und der komplette abo-upgrade.php-Ablauf warfen
bisher eine ungefangene RuntimeException (Fatal Error), sobald
STRIPE_SECRET_KEY nicht gesetzt ist (z. B. lokale Dev-Umgebung ohne echte
Stripe-Zugangsdaten) - bestand bereits im alten Code, ist durch die neue
Tarif-Vergleichstabelle mit mehr Buchen-Buttons aber leichter auslösbar
geworden. Jetzt: sauberer 502 'Bezahldienst nicht verfuegbar' statt
Fatal-Error-Seite.

Erstmals lokal per HTTP end-to-end gegen echten Dev-Server + MariaDB
getestet (PHP 8.3 + MariaDB 11.4 als portable Binaries installiert, siehe
docs/dev-mysql.md): eigener Test-Mandant mit 12 aktiven Teilnehmern,
Tarif-Tabelle korrekt gerendert (5 Tarife, Pflicht-Upgrade-Hinweis, Buchen-
Buttons, Enterprise-Anfrage-Link), Buchung von 'free' bei Ueberschreitung
korrekt mit 400 abgelehnt, Buchung eines bezahlten Tarifs ohne Stripe-Key
jetzt sauber mit 502 statt Fatal-Error-Crash. Alle bestehenden
Regressionstests weiterhin gruen: Golden Master (104), Billing-Capacity
(10), M8-Isolation (10), M8-Rollenmatrix (55).
This commit is contained in:
2026-07-20 20:38:12 +00:00
parent dd2277c803
commit bafa5e7e61
2 changed files with 98 additions and 80 deletions
+10 -2
View File
@@ -27,7 +27,10 @@ function billing_plans(): array
/**
* Resolves the Stripe Price id for a plan by its lookup_key. Returns null
* for plans without a Stripe price (free, enterprise) or on API failure.
* for plans without a Stripe price (free, enterprise), on API failure, or
* when Stripe isn't configured at all (missing STRIPE_SECRET_KEY, e.g. in
* a local/dev environment) - callers already treat null as "not available
* right now", so this degrades gracefully instead of a fatal error.
*/
function billing_stripe_price_id(string $planCode): ?string
{
@@ -37,7 +40,12 @@ function billing_stripe_price_id(string $planCode): ?string
return null;
}
$result = stripe_request('GET', 'prices', ['lookup_keys' => [$lookupKey], 'active' => 'true']);
try {
$result = stripe_request('GET', 'prices', ['lookup_keys' => [$lookupKey], 'active' => 'true']);
} catch (RuntimeException $e) {
return null;
}
if ($result['ok'] && !empty($result['data']['data'][0]['id'])) {
return (string)$result['data']['data'][0]['id'];
}