Update routes/subscription.py
Browse files- routes/subscription.py +20 -0
routes/subscription.py
CHANGED
@@ -85,6 +85,20 @@ def get_new_price_id(stylist_id: str):
|
|
85 |
if response.status_code == 200 and response.json():
|
86 |
return response.json()[0].get("price_id")
|
87 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
def verify_token(user_token: str) -> str:
|
90 |
"""
|
@@ -169,6 +183,12 @@ async def update_subscription(
|
|
169 |
|
170 |
logger.info(f"✅ Subscription {subscription_id} updated to new price {new_price_id}")
|
171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
return {
|
173 |
"message": "Subscription reactivated and updated successfully!",
|
174 |
"subscription_id": subscription_id,
|
|
|
85 |
if response.status_code == 200 and response.json():
|
86 |
return response.json()[0].get("price_id")
|
87 |
return None
|
88 |
+
|
89 |
+
def update_subscription_price_in_db(subscription_id: str, new_price_id: str):
|
90 |
+
"""
|
91 |
+
Atualiza a coluna 'price_id' na tabela 'Subscriptions' para o novo price_id correspondente.
|
92 |
+
"""
|
93 |
+
update_data = {"price_id": new_price_id}
|
94 |
+
|
95 |
+
response = requests.patch(
|
96 |
+
f"{SUPABASE_URL}/rest/v1/Subscriptions?sub_id=eq.{subscription_id}",
|
97 |
+
headers=SUPABASE_ROLE_HEADERS,
|
98 |
+
json=update_data
|
99 |
+
)
|
100 |
+
|
101 |
+
return response.status_code in [200, 204] # Retorna True se a atualização for bem-sucedida
|
102 |
|
103 |
def verify_token(user_token: str) -> str:
|
104 |
"""
|
|
|
183 |
|
184 |
logger.info(f"✅ Subscription {subscription_id} updated to new price {new_price_id}")
|
185 |
|
186 |
+
# 🔹 8. Atualizar o price_id na tabela Subscriptions
|
187 |
+
if update_subscription_price_in_db(subscription_id, new_price_id):
|
188 |
+
logger.info(f"✅ Subscription {subscription_id} price_id updated in database.")
|
189 |
+
else:
|
190 |
+
raise HTTPException(status_code=500, detail="Failed to update subscription price_id in database.")
|
191 |
+
|
192 |
return {
|
193 |
"message": "Subscription reactivated and updated successfully!",
|
194 |
"subscription_id": subscription_id,
|