habulaj commited on
Commit
8825b34
·
verified ·
1 Parent(s): 8093d40

Update routes/subscription.py

Browse files
Files changed (1) hide show
  1. routes/subscription.py +29 -0
routes/subscription.py CHANGED
@@ -98,6 +98,35 @@ async def stripe_webhook(request: Request):
98
  logger.info(f"💰 Estilista recebe: R$ {stylist_amount / 100:.2f}")
99
  logger.info(f"🏛️ Plataforma fica com: R$ {platform_amount / 100:.2f}")
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  return {
102
  "status": "success",
103
  "total_paid": amount_paid / 100,
 
98
  logger.info(f"💰 Estilista recebe: R$ {stylist_amount / 100:.2f}")
99
  logger.info(f"🏛️ Plataforma fica com: R$ {platform_amount / 100:.2f}")
100
 
101
+ # 🔹 Inserir dados na tabela Subscriptions no Supabase
102
+ subscription_data = {
103
+ "stylist_id": stylist_id,
104
+ "customer_id": user_id,
105
+ "active": True, # Como o pagamento foi bem-sucedido, a assinatura está ativa
106
+ "created_at": datetime.datetime.utcnow() # Hora atual (UTC)
107
+ }
108
+
109
+ # Configuração do cabeçalho de autenticação para o Supabase
110
+ supabase_headers = {
111
+ "Authorization": f"Bearer {SUPABASE_KEY}",
112
+ "apikey": SUPABASE_KEY,
113
+ "Content-Type": "application/json"
114
+ }
115
+
116
+ # Inserir nova linha na tabela Subscriptions
117
+ subscription_url = f"{SUPABASE_URL}/rest/v1/Subscriptions"
118
+ response_subscription = requests.post(
119
+ subscription_url,
120
+ headers=supabase_headers,
121
+ json=subscription_data
122
+ )
123
+
124
+ # Verificando a resposta da inserção
125
+ if response_subscription.status_code == 201:
126
+ logger.info(f"✅ Subscription added successfully for user {user_id}")
127
+ else:
128
+ logger.error(f"❌ Failed to add subscription: {response_subscription.status_code} - {response_subscription.text}")
129
+
130
  return {
131
  "status": "success",
132
  "total_paid": amount_paid / 100,