Update routes/subscription.py
Browse files- routes/subscription.py +5 -9
routes/subscription.py
CHANGED
@@ -833,10 +833,8 @@ def create_checkout_session(
|
|
833 |
if not user_token:
|
834 |
raise HTTPException(status_code=401, detail="Missing User-key header")
|
835 |
|
836 |
-
# 🔹 1. Validate client token and get user_id
|
837 |
user_id = verify_token(user_token)
|
838 |
|
839 |
-
# 🔹 2. Get stylist data from Supabase
|
840 |
response_stylist = requests.get(
|
841 |
f"{SUPABASE_URL}/rest/v1/User?id=eq.{data.id}",
|
842 |
headers=SUPABASE_HEADERS
|
@@ -853,7 +851,6 @@ def create_checkout_session(
|
|
853 |
if not stylist_stripe_id or not price_id:
|
854 |
raise HTTPException(status_code=400, detail="Stylist profile is incomplete")
|
855 |
|
856 |
-
# 🔹 3. Get client data from Supabase
|
857 |
response_user = requests.get(
|
858 |
f"{SUPABASE_URL}/rest/v1/User?id=eq.{user_id}",
|
859 |
headers=SUPABASE_HEADERS
|
@@ -868,12 +865,10 @@ def create_checkout_session(
|
|
868 |
if not user_stripe_id:
|
869 |
raise HTTPException(status_code=400, detail="Client does not have a Stripe Customer ID")
|
870 |
|
871 |
-
# 🔹 4. Get price details from Stripe
|
872 |
price_data = stripe.Price.retrieve(price_id)
|
873 |
-
price_amount = price_data.unit_amount / 100
|
874 |
currency = price_data.currency.upper()
|
875 |
|
876 |
-
# 🔹 5. Create a subscription
|
877 |
subscription = stripe.Subscription.create(
|
878 |
customer=user_stripe_id,
|
879 |
items=[{"price": price_id}],
|
@@ -884,11 +879,11 @@ def create_checkout_session(
|
|
884 |
"stylist_stripe_id": stylist_stripe_id,
|
885 |
"user_id": user_id,
|
886 |
"user_stripe_id": user_stripe_id,
|
887 |
-
"price_id": price_id
|
|
|
888 |
}
|
889 |
)
|
890 |
|
891 |
-
# Also add metadata to the payment intent
|
892 |
payment_intent = subscription.latest_invoice.payment_intent
|
893 |
stripe.PaymentIntent.modify(
|
894 |
payment_intent.id,
|
@@ -897,7 +892,8 @@ def create_checkout_session(
|
|
897 |
"stylist_stripe_id": stylist_stripe_id,
|
898 |
"user_id": user_id,
|
899 |
"user_stripe_id": user_stripe_id,
|
900 |
-
"price_id": price_id
|
|
|
901 |
}
|
902 |
)
|
903 |
|
|
|
833 |
if not user_token:
|
834 |
raise HTTPException(status_code=401, detail="Missing User-key header")
|
835 |
|
|
|
836 |
user_id = verify_token(user_token)
|
837 |
|
|
|
838 |
response_stylist = requests.get(
|
839 |
f"{SUPABASE_URL}/rest/v1/User?id=eq.{data.id}",
|
840 |
headers=SUPABASE_HEADERS
|
|
|
851 |
if not stylist_stripe_id or not price_id:
|
852 |
raise HTTPException(status_code=400, detail="Stylist profile is incomplete")
|
853 |
|
|
|
854 |
response_user = requests.get(
|
855 |
f"{SUPABASE_URL}/rest/v1/User?id=eq.{user_id}",
|
856 |
headers=SUPABASE_HEADERS
|
|
|
865 |
if not user_stripe_id:
|
866 |
raise HTTPException(status_code=400, detail="Client does not have a Stripe Customer ID")
|
867 |
|
|
|
868 |
price_data = stripe.Price.retrieve(price_id)
|
869 |
+
price_amount = price_data.unit_amount / 100
|
870 |
currency = price_data.currency.upper()
|
871 |
|
|
|
872 |
subscription = stripe.Subscription.create(
|
873 |
customer=user_stripe_id,
|
874 |
items=[{"price": price_id}],
|
|
|
879 |
"stylist_stripe_id": stylist_stripe_id,
|
880 |
"user_id": user_id,
|
881 |
"user_stripe_id": user_stripe_id,
|
882 |
+
"price_id": price_id,
|
883 |
+
"consultations": data.consultations
|
884 |
}
|
885 |
)
|
886 |
|
|
|
887 |
payment_intent = subscription.latest_invoice.payment_intent
|
888 |
stripe.PaymentIntent.modify(
|
889 |
payment_intent.id,
|
|
|
892 |
"stylist_stripe_id": stylist_stripe_id,
|
893 |
"user_id": user_id,
|
894 |
"user_stripe_id": user_stripe_id,
|
895 |
+
"price_id": price_id,
|
896 |
+
"consultations": data.consultations
|
897 |
}
|
898 |
)
|
899 |
|