mirror of
http://88.130.71.182:3000/BlitTech/contexta_be.git
synced 2026-06-12 23:23:21 +00:00
fixed stripe get error
This commit is contained in:
@@ -85,11 +85,11 @@ async def stripe_webhook(
|
|||||||
else:
|
else:
|
||||||
import json
|
import json
|
||||||
logger.warning("Stripe webhook received without signature verification (dev mode only)")
|
logger.warning("Stripe webhook received without signature verification (dev mode only)")
|
||||||
event = json.loads(payload)
|
event = stripe.Event.construct_from(json.loads(payload), stripe.api_key)
|
||||||
|
|
||||||
supabase = get_supabase()
|
supabase = get_supabase()
|
||||||
event_type = event.get("type", "")
|
event_type = event.type
|
||||||
event_id = event.get("id", "")
|
event_id = event.id
|
||||||
|
|
||||||
# Idempotency check: skip already-processed events
|
# Idempotency check: skip already-processed events
|
||||||
if event_id:
|
if event_id:
|
||||||
@@ -102,11 +102,11 @@ async def stripe_webhook(
|
|||||||
return {"received": True}
|
return {"received": True}
|
||||||
|
|
||||||
if event_type == "checkout.session.completed":
|
if event_type == "checkout.session.completed":
|
||||||
session = event["data"]["object"]
|
session = event.data.object
|
||||||
user_id = session.get("metadata", {}).get("user_id")
|
user_id = (session.metadata or {}).get("user_id")
|
||||||
plan = session.get("metadata", {}).get("plan", "starter")
|
plan = (session.metadata or {}).get("plan", "starter")
|
||||||
customer_id = session.get("customer")
|
customer_id = session.customer
|
||||||
subscription_id = session.get("subscription")
|
subscription_id = session.subscription
|
||||||
|
|
||||||
if user_id:
|
if user_id:
|
||||||
supabase.table("subscriptions").upsert({
|
supabase.table("subscriptions").upsert({
|
||||||
@@ -118,9 +118,9 @@ async def stripe_webhook(
|
|||||||
}, on_conflict="user_id").execute()
|
}, on_conflict="user_id").execute()
|
||||||
|
|
||||||
elif event_type in ("customer.subscription.updated", "customer.subscription.deleted"):
|
elif event_type in ("customer.subscription.updated", "customer.subscription.deleted"):
|
||||||
sub_obj = event["data"]["object"]
|
sub_obj = event.data.object
|
||||||
customer_id = sub_obj.get("customer")
|
customer_id = sub_obj.customer
|
||||||
status = sub_obj.get("status", "canceled")
|
status = sub_obj.status or "canceled"
|
||||||
|
|
||||||
existing = supabase.table("subscriptions").select("*").eq("stripe_customer_id", customer_id).execute()
|
existing = supabase.table("subscriptions").select("*").eq("stripe_customer_id", customer_id).execute()
|
||||||
if existing.data:
|
if existing.data:
|
||||||
|
|||||||
Reference in New Issue
Block a user