Skip to content

Commit

Permalink
Without checkout session premium username isnt possbole (#5296)
Browse files Browse the repository at this point in the history
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: alannnc <[email protected]>
  • Loading branch information
3 people authored Oct 31, 2022
1 parent ac9b2d0 commit 77d339a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/trpc/server/routers/viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
}
}
Expand Down

0 comments on commit 77d339a

Please sign in to comment.