Without checkout session premium username isnt possbole (#5296)

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: alannnc <alannnc@gmail.com>
bugfix/5309-cal-296-icalendar-timezone-is-off-doubles
Hariom Balhara 2022-11-01 04:37:51 +05:30 committed by GitHub
parent ac9b2d0577
commit 77d339ae8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 5 deletions

View File

@ -942,16 +942,22 @@ 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 // 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. // TODO: Test the case where one time payment is refunded.
const premiumUsernameCheckoutSessionId = metadata?.checkoutSessionId; const premiumUsernameCheckoutSessionId = metadata?.checkoutSessionId;
if (premiumUsernameCheckoutSessionId) { if (isPremiumUsername) {
const checkoutSession = await stripe.checkout.sessions.retrieve(premiumUsernameCheckoutSessionId); // You can't have premium username without every going to a checkout session
const canUserHavePremiumUsername = checkoutSession.payment_status == "paid"; if (!premiumUsernameCheckoutSessionId) {
if (isPremiumUsername && !canUserHavePremiumUsername) {
throw new TRPCError({ throw new TRPCError({
code: "BAD_REQUEST", code: "BAD_REQUEST",
message: "You need to pay for premium username", message: "You need to pay for premium username",
}); });
} }
const checkoutSession = await stripe.checkout.sessions.retrieve(premiumUsernameCheckoutSessionId);
const canUserHavePremiumUsername = checkoutSession.payment_status == "paid";
if (!canUserHavePremiumUsername) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Your last checkout session for premium username is not paid",
});
}
} }
const updatedUser = await prisma.user.update({ const updatedUser = await prisma.user.update({