mirror of
http://88.130.71.182:3000/BlitTech/contexta_be.git
synced 2026-06-12 23:23:21 +00:00
updates Mar6
This commit is contained in:
@@ -11,7 +11,8 @@ router = APIRouter(prefix="/billing", tags=["Billing"])
|
||||
|
||||
PLAN_PRICE_IDS = {
|
||||
"starter": settings.stripe_starter_price_id,
|
||||
"pro": settings.stripe_pro_price_id,
|
||||
"business": settings.stripe_business_price_id,
|
||||
"agency": settings.stripe_agency_price_id,
|
||||
}
|
||||
|
||||
|
||||
@@ -70,15 +71,20 @@ async def stripe_webhook(
|
||||
stripe.api_key = settings.stripe_secret_key
|
||||
payload = await request.body()
|
||||
|
||||
if settings.stripe_webhook_secret and stripe_signature:
|
||||
if settings.stripe_webhook_secret:
|
||||
if not stripe_signature:
|
||||
raise HTTPException(status_code=400, detail="Missing Stripe signature")
|
||||
try:
|
||||
event = stripe.Webhook.construct_event(
|
||||
payload, stripe_signature, settings.stripe_webhook_secret
|
||||
)
|
||||
except stripe.error.SignatureVerificationError:
|
||||
raise HTTPException(status_code=400, detail="Invalid signature")
|
||||
elif settings.app_env == "production":
|
||||
raise HTTPException(status_code=500, detail="Webhook secret not configured")
|
||||
else:
|
||||
import json
|
||||
logger.warning("Stripe webhook received without signature verification (dev mode only)")
|
||||
event = json.loads(payload)
|
||||
|
||||
supabase = get_supabase()
|
||||
@@ -122,6 +128,18 @@ async def stripe_webhook(
|
||||
"visibility": "preview",
|
||||
}).eq("company_id", company.data[0]["id"]).execute()
|
||||
|
||||
# Send cancellation notification via n8n
|
||||
if settings.n8n_handoff_webhook_url:
|
||||
try:
|
||||
from app.services.n8n_service import send_notification
|
||||
await send_notification(
|
||||
event_type="subscription_canceled",
|
||||
data={"user_id": user_id},
|
||||
webhook_url=settings.n8n_handoff_webhook_url,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to send cancellation notification: {e}")
|
||||
|
||||
return {"received": True}
|
||||
|
||||
except HTTPException:
|
||||
|
||||
Reference in New Issue
Block a user