Scheduling infrastructure for absolutely everyone.
Without checkout session premium username isnt possbole (#5296)
Hariom Balhara77d339ae8f1e
diff --git a/packages/trpc/server/routers/viewer.tsx b/packages/trpc/server/routers/viewer.tsxindex 50ff7be931e..c8d08fc435f 100644--- a/packages/trpc/server/routers/viewer.tsx+++ b/packages/trpc/server/routers/viewer.tsx@@ -942,14 +942,20 @@ const loggedInViewerRouter = createProtectedRouter()// Checking the status of payment directly from stripe allows to avoid the situation where the user has got the refund or maybe something else happened asyncly at stripe but our DB thinks it's still paid for// TODO: Test the case where one time payment is refunded.const premiumUsernameCheckoutSessionId = metadata?.checkoutSessionId;- if (premiumUsernameCheckoutSessionId) {+ if (isPremiumUsername) {+ // You can't have premium username without every going to a checkout session+ if (!premiumUsernameCheckoutSessionId) {+ throw new TRPCError({+ code: "BAD_REQUEST",+ message: "You need to pay for premium username",+ });+ }const checkoutSession = await stripe.checkout.sessions.retrieve(premiumUsernameCheckoutSessionId);const canUserHavePremiumUsername = checkoutSession.payment_status == "paid";-- if (isPremiumUsername && !canUserHavePremiumUsername) {+ if (!canUserHavePremiumUsername) {throw new TRPCError({code: "BAD_REQUEST",- message: "You need to pay for premium username",+ message: "Your last checkout session for premium username is not paid",});}}