NT-Problem: Unhandled exception: get
Root Cause: Die Stripe-Python-Bibliothek auf INT hat keine .get() Methode auf Stripe-Objekten. Wenn session.get("payment_status") aufgerufen wird, sucht Python via __getattr__ nach einem Feld namens "get" → AttributeError("get").
Bestätigung: In routeBilling.py gab es bereits einen hasattr(session, "get")-Check (Zeile 998) — jemand kannte das Problem.
Fix: Alle Stripe-Objekte werden sofort nach dem API-Call in dict() konvertiert
This commit is contained in:
parent
ef39d01e16
commit
b142c0fa6c
4 changed files with 20 additions and 13 deletions
|
|
@ -994,8 +994,9 @@ def _handleSubscriptionCheckoutCompleted(session, eventId: str) -> None:
|
|||
from modules.security.rootAccess import getRootUser
|
||||
from datetime import datetime, timezone
|
||||
|
||||
metadata = {}
|
||||
if hasattr(session, "get"):
|
||||
if not isinstance(session, dict):
|
||||
session = dict(session)
|
||||
|
||||
metadata = session.get("metadata") or {}
|
||||
subscriptionRecordId = metadata.get("subscriptionRecordId")
|
||||
mandateId = metadata.get("mandateId")
|
||||
|
|
@ -1009,7 +1010,7 @@ def _handleSubscriptionCheckoutCompleted(session, eventId: str) -> None:
|
|||
try:
|
||||
from modules.shared.stripeClient import getStripeClient
|
||||
stripe = getStripeClient()
|
||||
subObj = stripe.Subscription.retrieve(stripeSub)
|
||||
subObj = dict(stripe.Subscription.retrieve(stripeSub))
|
||||
metadata = subObj.get("metadata") or {}
|
||||
subscriptionRecordId = metadata.get("subscriptionRecordId")
|
||||
mandateId = metadata.get("mandateId")
|
||||
|
|
@ -1041,7 +1042,7 @@ def _handleSubscriptionCheckoutCompleted(session, eventId: str) -> None:
|
|||
try:
|
||||
from modules.shared.stripeClient import getStripeClient
|
||||
stripe = getStripeClient()
|
||||
stripeSub = stripe.Subscription.retrieve(stripeSubId, expand=["items"])
|
||||
stripeSub = dict(stripe.Subscription.retrieve(stripeSubId, expand=["items"]))
|
||||
|
||||
if stripeSub.get("current_period_start"):
|
||||
stripeData["currentPeriodStart"] = datetime.fromtimestamp(
|
||||
|
|
@ -1054,8 +1055,11 @@ def _handleSubscriptionCheckoutCompleted(session, eventId: str) -> None:
|
|||
|
||||
from modules.serviceCenter.services.serviceSubscription.stripeBootstrap import getStripePricesForPlan
|
||||
priceMapping = getStripePricesForPlan(planKey)
|
||||
for item in stripeSub.get("items", {}).get("data", []):
|
||||
priceId = item.get("price", {}).get("id", "")
|
||||
items = stripeSub.get("items") or {}
|
||||
if not isinstance(items, dict):
|
||||
items = dict(items)
|
||||
for item in items.get("data", []):
|
||||
priceId = (item.get("price") or {}).get("id", "")
|
||||
if priceMapping and priceId == priceMapping.stripePriceIdUsers:
|
||||
stripeData["stripeItemIdUsers"] = item["id"]
|
||||
elif priceMapping and priceId == priceMapping.stripePriceIdInstances:
|
||||
|
|
|
|||
|
|
@ -284,7 +284,8 @@ def verifyCheckout(
|
|||
try:
|
||||
from modules.shared.stripeClient import getStripeClient
|
||||
stripe = getStripeClient()
|
||||
session = stripe.checkout.Session.retrieve(data.sessionId)
|
||||
rawSession = stripe.checkout.Session.retrieve(data.sessionId)
|
||||
session = dict(rawSession)
|
||||
except Exception as e:
|
||||
logger.error("Failed to retrieve checkout session %s: %s", data.sessionId, e)
|
||||
raise HTTPException(status_code=400, detail="Invalid session ID")
|
||||
|
|
|
|||
|
|
@ -425,7 +425,7 @@ class SubscriptionService:
|
|||
try:
|
||||
from modules.shared.stripeClient import getStripeClient
|
||||
stripe = getStripeClient()
|
||||
stripeSub = stripe.Subscription.modify(stripeSubId, cancel_at_period_end=True)
|
||||
stripeSub = dict(stripe.Subscription.modify(stripeSubId, cancel_at_period_end=True))
|
||||
pUrl = (stripeSub.get("metadata") or {}).get("platformUrl", "")
|
||||
except Exception as e:
|
||||
logger.error("Failed to set cancel_at_period_end for %s: %s", stripeSubId, e)
|
||||
|
|
@ -488,7 +488,7 @@ class SubscriptionService:
|
|||
try:
|
||||
from modules.shared.stripeClient import getStripeClient
|
||||
stripe = getStripeClient()
|
||||
stripeSub = stripe.Subscription.retrieve(stripeSubId)
|
||||
stripeSub = dict(stripe.Subscription.retrieve(stripeSubId))
|
||||
pUrl = (stripeSub.get("metadata") or {}).get("platformUrl", "")
|
||||
stripe.Subscription.cancel(stripeSubId)
|
||||
except Exception as e:
|
||||
|
|
@ -673,7 +673,8 @@ def _buildInvoiceSummaryHtml(
|
|||
stripe = getStripeClient()
|
||||
invoices = stripe.Invoice.list(subscription=stripeSubId, limit=1)
|
||||
if invoices.data:
|
||||
hostedUrl = invoices.data[0].get("hosted_invoice_url", "")
|
||||
inv = dict(invoices.data[0]) if not isinstance(invoices.data[0], dict) else invoices.data[0]
|
||||
hostedUrl = inv.get("hosted_invoice_url", "")
|
||||
if hostedUrl:
|
||||
invoiceLink = (
|
||||
f'<p style="margin:12px 0 0 0;font-size:14px;">'
|
||||
|
|
@ -714,7 +715,8 @@ def _buildCancelSummaryHtml(subRecord: Dict[str, Any], platformUrl: str = "") ->
|
|||
stripe = getStripeClient()
|
||||
invoices = stripe.Invoice.list(subscription=stripeSubId, limit=1)
|
||||
if invoices.data:
|
||||
hostedUrl = invoices.data[0].get("hosted_invoice_url", "")
|
||||
inv = dict(invoices.data[0]) if not isinstance(invoices.data[0], dict) else invoices.data[0]
|
||||
hostedUrl = inv.get("hosted_invoice_url", "")
|
||||
if hostedUrl:
|
||||
parts.append(
|
||||
f'<p style="margin:4px 0;font-size:14px;">'
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ def _findExistingStripePrice(stripe, productId: str, unitAmount: int, interval:
|
|||
def _getStripePriceAmount(stripe, priceId: str) -> Optional[int]:
|
||||
"""Retrieve the unit_amount (in Rappen) of an existing Stripe Price."""
|
||||
try:
|
||||
price = stripe.Price.retrieve(priceId)
|
||||
price = dict(stripe.Price.retrieve(priceId))
|
||||
return price.get("unit_amount") if price else None
|
||||
except Exception:
|
||||
return None
|
||||
|
|
|
|||
Loading…
Reference in a new issue