W
Wasp-languglybeanhead

I am trying to understand the subsciptionStatus logic in stripe.ts

I am just wondering what could be the reason we don't want to update subscriptionStatus as soon as chekcout.session.completed along with hasPaid and subscriptionTier (line 46 and 48). I am writing a logic where after a user sign up for subscription with subscription_data.trial_periods_days , I then check whether a subscription is active or not, and re-direct them to the hidden page like so: on DemoAppPage.tsx:
No description
No description
No description
U
uglybeanhead41d ago
i followed openSaas documentation but it seems to be saying 2 different things: 1. for checking subscriptionStatus https://docs.opensaas.sh/guides/authorization/ (first pic) and the other check for hasPaid (second pic ) https://docs.opensaas.sh/general/user-overview/#subscription-statuses
OpenSaaS.sh
Authorization
Open SaaS is a free, open-source, full-stack SaaS starter kit for React + NodeJS.
OpenSaaS.sh
User Overview
Open SaaS is a free, open-source, full-stack SaaS starter kit for React + NodeJS.
No description
No description
U
uglybeanhead41d ago
I will just check the hasPAid and subscriptionTier to grant access for now. I am still trying to understand all these series of events that are triggered after signing up.
M
martinsos40d ago
@Vinny (@Wasp) will be the best person to answer this one!
VW
Vinny (@Wasp)40d ago
good question. ok so for a subscription, what happens when someone pays, and their paymenst go through successfully for 3 months? The hasPaid property will be true, and their subscription status will active But what happens, let's say, when their credit card has expired and their payment hasn't gone through on the fourth month? the hasPaid property is still true but their subscipriton status will be pastDue i realize that hasSubscribed maybe be a better name in this case. perhaps we should change it. hmm or perhaps we don't need hasPaid at all, and can only rely on subscriptionStatus.... let me check @martinsos what do you think would be the best approach here? 1. use the hasPaid flag on a user as an overall indicator if the person has started a subscription or not, and have it live next to
user.subscriptionStatus = 'active' | 'past_due' | 'canceled' | 'deleted'
user.subscriptionStatus = 'active' | 'past_due' | 'canceled' | 'deleted'
or... 2. drop the hasPaid flag and use user.subscipritonStatus === undefined to check if a user has or hasn't started a subscription
user.subscriptionStatus = undefined | 'active' | 'past_due' | 'canceled' | 'deleted'
user.subscriptionStatus = undefined | 'active' | 'past_due' | 'canceled' | 'deleted'
I think going with number 2, dropping the hasPaid flag, is the better option in the end
U
uglybeanhead40d ago
Hi Vinny, thanks for your input! Initially I checked if the subscriptionStatus is active to re-direct the user to access a hidden page, line 87 is not simultaneously triggered right after chekcout.session.completed, so it still stays null and the hidden page stays hidden
No description
VW
Vinny (@Wasp)40d ago
you can't do that within the webhook. the webhook is only on the server you need to be doing client-side authorization https://docs.opensaas.sh/guides/authorization/#client-side-authorization but it sounds like invoice.paid is not being triggered because your webhook is not listening for that event follow the instructions here https://docs.opensaas.sh/guides/stripe-testing/#testing-webhooks-via-the-stripe-cli and test if your webhook is listening for the invoice.paid event by running this command in another terminal window:
stripe trigger invoice.paid
stripe trigger invoice.paid
more details here >>https://docs.opensaas.sh/guides/stripe-testing/#testing-webhooks-via-the-stripe-cli let me know if you have any other questions 🙂
U
uglybeanhead40d ago
Hi Vinny, I actually wrote that logic in the clientside - where the DemoAppPage.tsx is. And also did all steps in the document , webhook is listening to the invoice.paid event but the status is not updated. Here are the screen shots:
No description
No description
VW
Vinny (@Wasp)40d ago
can you put a console.log(event.type) statement on line 88 and share what it says when you chrckout? also, where is your userStripeId being defined? are you still listening for 'checkout.session.completed' events?
U
uglybeanhead40d ago
No description
U
uglybeanhead40d ago
userStripeId defined on the top of the webhook, i have not changed a thing from the template instripe.ts, and yes, I am listening to checkout.session.completed
No description
U
uglybeanhead40d ago
looks like the template provided only update status when ebent customer.subscription.updated:
No description
M
MEE640d ago
Wohooo @uglybeanhead, you just became a Waspeteer level 2!
U
uglybeanhead40d ago
I guess i will add a line that update status when invoice.paid ? nope, does not work
VW
Vinny (@Wasp)40d ago
Wait. Let’s back up. Can you show me what the result of the console.log is? In the terminal where you ran wasp start. Ah sorry. I see it now Ok can you define a the user update function to a variable and log that to the console as well? const updatedUser = await context.entities.User.updateMany() While you’re at it log the userStripeId to the console as well. I have a feeling you’re not able to find the user in your db Btw which auth method are you using?
U
uglybeanhead40d ago
you are right the userStripeId is not defined, but why is that? (also from the third pic, customer.subscription.updated was not triggered) I use google Auth
No description
No description
No description
U
uglybeanhead40d ago
No description
U
uglybeanhead40d ago
No description
U
uglybeanhead40d ago
but the database is updated tho
VW
Vinny (@Wasp)40d ago
Try this. Copy this line userStripeId = session.customer as string; and paste it right under line 87. Then see what happens
U
uglybeanhead40d ago
No description
No description
U
uglybeanhead40d ago
No description
U
uglybeanhead40d ago
i suspect customer.subscription.updated was not triggered in the event, maybe that's why it was never updated I am looking into each event log which version of api are you using?
VW
Vinny (@Wasp)40d ago
Whichever is in the template
U
uglybeanhead40d ago
welp. i use the new one 2023-10-16. My apologies, Vinny.
VW
Vinny (@Wasp)40d ago
No worries! That must be the issue. It seems the checkout.session.completed doesn’t fire first in that version, which was causing the issue. Glad we got it fixed though 🙂
Want results from more Discord servers?
Add your server
More Posts
Need RecommendationsIf i have a simple saas idea and wanted to design a landing page to collect emails, what email servInstallation troubleI am a first-timer to using WASP and code in general, so getting confused by this message below, wouPost-query errors about failing to resolve an import.Hey there! We're building something that involves creating appointments, assigning technicians, and Running alongside separate authed API?Has anyone ran WASP front end alongside a separate API? My plan is to run WASP as the front end inteDB errorSo i got this app made from mageGPT. but when i try to open or run it i get that error. while makRepetitive Undetected Syntax Error with MageAIHey guys, I've been testing out the MageAI app generator and at first it worked fine but since then Unable to get react working.Hi, Thanks for such an amazing framework. I generated an app with Mage and tried to run it. WhileHot Reloading?Hi everyone, does Wasp come with hot reloading? I generated a templated SaaS app and hot reloading dnothing shows up in localhost:3000 after wasp startHi everyone, as the picture shows, it says Port 3001 is already in use, opens localhost:3000 and I cFile-Manager troubleshootingHello, I generated a Files-Manager app using usemage.ai, I specified wanting to use MongoDB could foAdd a new entity into the saas templateI copied Task and gave it a new name (=workflow). Now it fails during the wasp db migrate-dev. It hOpenSaas setup 'Role postgres does not exist'Hi! I'm a bit stuck on the initial steps for openSaaS. Running on a fresh Ubuntu 22.04 VPS and folloWhat does this mean ?I was following this tutorial https://wasp-lang.dev/blog/2023/11/21/guide-windows-development-wasp-wTeams/GroupsHow would one extend the user and permissions model to have groups of users with shared access to auAxios ErrorI have been following the wasp tutorial, in the fifth chapter, I am getting this axios error. Can anphone verification?So I’ve been playing with wasp and I enjoy it, and am planning on launching my app soon. But I was wWasp/OpenSaas Typescript vs JavascriptHey everyone. I'm new to Wasp and OpenSaas and have been playing around with it a bit, as well as reError building after migrating Wasp to 0.12I am getting the below error after migrating Wasp to 0.12, I am using NodeJS 20. Below is the error,Unable to run "wasp start db" in my terminalCommand is not recognized. I manually added the path to the System Variables as instructed but the cMulti-modal “AI_agent”I want to build a Multi-modal LAM-app {Large Action/Agentic Model} that leverages the state of the a