Update routes/subscription.py
Browse files- routes/subscription.py +10 -18
routes/subscription.py
CHANGED
@@ -86,27 +86,19 @@ async def create_price(
|
|
86 |
current_price_valid = True
|
87 |
logger.info(f"✅ Reusing existing price {price_id} (same amount) for user {user_id}")
|
88 |
else:
|
89 |
-
# 🔥 1º TENTATIVA: Tentar
|
90 |
try:
|
91 |
-
stripe.Price.modify(price_id, active=False)
|
92 |
-
|
93 |
-
logger.info(f"🗑️ Successfully deleted price {price_id}")
|
94 |
except stripe.error.InvalidRequestError:
|
95 |
-
logger.warning(f"⚠️ Failed to
|
96 |
-
|
97 |
-
# 🔥 2º TENTATIVA: Se não pode
|
98 |
try:
|
99 |
-
stripe.Price.modify(price_id,
|
100 |
-
logger.info(f"
|
101 |
-
except
|
102 |
-
logger.
|
103 |
-
|
104 |
-
# 🔥 3º TENTATIVA: Se não pode desativar, arquiva
|
105 |
-
try:
|
106 |
-
stripe.Price.modify(price_id, metadata={"archived": "true"})
|
107 |
-
logger.info(f"📦 Archived price {price_id}")
|
108 |
-
except Exception as e:
|
109 |
-
logger.error(f"❌ Could not archive price {price_id}: {e}")
|
110 |
|
111 |
except stripe.error.InvalidRequestError:
|
112 |
logger.warning(f"⚠️ Invalid price_id ({price_id}), creating a new one...")
|
|
|
86 |
current_price_valid = True
|
87 |
logger.info(f"✅ Reusing existing price {price_id} (same amount) for user {user_id}")
|
88 |
else:
|
89 |
+
# 🔥 1º TENTATIVA: Tentar desativar o preço antigo
|
90 |
try:
|
91 |
+
stripe.Price.modify(price_id, active=False)
|
92 |
+
logger.info(f"🔄 Deactivated old price {price_id}")
|
|
|
93 |
except stripe.error.InvalidRequestError:
|
94 |
+
logger.warning(f"⚠️ Failed to deactivate price {price_id}, trying to archive...")
|
95 |
+
|
96 |
+
# 🔥 2º TENTATIVA: Se não pode desativar, arquiva
|
97 |
try:
|
98 |
+
stripe.Price.modify(price_id, metadata={"archived": "true"})
|
99 |
+
logger.info(f"📦 Archived price {price_id}")
|
100 |
+
except Exception as e:
|
101 |
+
logger.error(f"❌ Could not archive price {price_id}: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
except stripe.error.InvalidRequestError:
|
104 |
logger.warning(f"⚠️ Invalid price_id ({price_id}), creating a new one...")
|