W
Wasp5mo ago
haarismian

database subscriptiontier and subscriptionstatus do not get updated on stripe completion

database subscriptiontier and subscriptionstatus do not get updated on stripe completion
5 Replies
kapa.ai
kapa.ai5mo ago
Hi @haarismian. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the discussion in the Discord support thread, it seems like you're experiencing an issue where the subscriptionStatus and subscriptionTier in your database are not being updated upon the completion of a Stripe checkout session. This could be due to a few reasons: 1. The webhook for checkout.session.completed might not be firing as expected. Make sure you're listening for this event in your webhook setup. 2. The userStripeId might not be defined correctly. This is used to find the user in your database and update their subscription status. Make sure this is being defined and used correctly. 3. The version of the Stripe API you're using might be causing issues. It was noted in the thread that the checkout.session.completed event doesn't fire first in the newer version of the API (2023-10-16), which was causing the issue. Try using the version that's in the template. Here's a snippet of the suggested solution from the thread:
// Define the user update function to a variable and log that to the console
const updatedUser = await context.entities.User.updateMany()

// Log the userStripeId to the console
console.log(userStripeId)

// Copy this line and paste it right under line 87
userStripeId = session.customer as string;
// Define the user update function to a variable and log that to the console
const updatedUser = await context.entities.User.updateMany()

// Log the userStripeId to the console
console.log(userStripeId)

// Copy this line and paste it right under line 87
userStripeId = session.customer as string;
Remember to replace context, entities, User, updateMany, session, and customer with your actual variables and methods. If you're still having issues, I recommend adding console.log statements to your code to help debug and understand what's happening at each step of the process. For more details, please refer to the Discord support thread (https://discord.com/channels/686873244791210014/1214979650803998781). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @haarismian, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
haarismian
haarismianOP5mo ago
@kapa.ai the checkoutsessionid works fine
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- That's great to hear! If the checkoutSessionId is working fine, it means that the Stripe checkout session is being created and its ID is being correctly stored in your database. This is a crucial part of the payment process, as it allows you to track and manage the checkout session. If you have any other questions or run into any other issues, feel free to ask. Happy coding with Wasp! ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @haarismian, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
haarismian
haarismianOP5mo ago
@kapa.ai what do you mean about webhook? do I need to keep the stripe webhook running all the time?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- A webhook is a way for an app to provide other applications with real-time information. A webhook delivers data to other applications as it happens, meaning you get data immediately. In the context of Stripe, webhooks are used to notify your application when an event happens in your account, such as a successful payment or a failed subscription renewal. When you set up a webhook endpoint on your server, Stripe will send an HTTP request to that endpoint every time an event occurs. Your server then processes the incoming data and reacts accordingly, such as updating a user's subscription status in your database. In the context of your question, the Stripe webhook doesn't need to be "running" all the time. Instead, your server needs to be set up to listen for incoming HTTP requests at the webhook endpoint. When a request comes in, your server processes it and then goes back to waiting for the next one. In the case of Wasp and Stripe, you can set up a webhook endpoint in your Wasp application using the api feature. Here's an example from the Wasp documentation (https://wasp-lang.dev/docs/advanced/middleware-config#2-customize-api-specific-middleware):
api webhookCallback {
fn: import { webhookCallback } from "@src/apis",
middlewareConfigFn: import { webhookCallbackMiddlewareFn } from "@src/apis",
httpRoute: (POST, "/webhook/callback"),
auth: false
}
api webhookCallback {
fn: import { webhookCallback } from "@src/apis",
middlewareConfigFn: import { webhookCallbackMiddlewareFn } from "@src/apis",
httpRoute: (POST, "/webhook/callback"),
auth: false
}
In a production environment, you would need to update the webhook secret in the Stripe Dashboard to point to your server's URL, as discussed in the Discord support thread (https://discord.com/channels/686873244791210014/1220115828012351529). This allows Stripe to send webhook events to your live application. Remember, your server needs to be running and accessible from the internet for Stripe to send it webhook events. If your server is down or unreachable, Stripe will not be able to notify your application about events. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @haarismian, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Want results from more Discord servers?
Add your server