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](https://cdn.answeroverflow.com/1214979651462500412/image.png)
![No description](https://cdn.answeroverflow.com/1214979651752038400/image.png)
![No description](https://cdn.answeroverflow.com/1214979652033187960/image.png)
32 Replies
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](https://cdn.answeroverflow.com/1214985845774487613/image.png)
![No description](https://cdn.answeroverflow.com/1214985846059696148/image.png)
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.
@Vinny (@Wasp) will be the best person to answer this one!
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
or...
2. drop the hasPaid
flag and use user.subscipritonStatus === undefined
to check if a user has or hasn't started a subscription
I think going with number 2, dropping the hasPaid
flag, is the better option in the endHi 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](https://cdn.answeroverflow.com/1215311846928814150/image.png)
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:
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 🙂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](https://cdn.answeroverflow.com/1215329148373958677/image.png)
![No description](https://cdn.answeroverflow.com/1215329148831141918/image.png)
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?![No description](https://cdn.answeroverflow.com/1215334361277407232/image.png)
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](https://cdn.answeroverflow.com/1215335876843012106/image.png)
looks like the template provided only update status when ebent customer.subscription.updated:
![No description](https://cdn.answeroverflow.com/1215336830317232148/image.png)
Wohooo @uglybeanhead, you just became a Waspeteer level 2!
I guess i will add a line that update status when invoice.paid ?
nope, does not work
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?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](https://cdn.answeroverflow.com/1215353944260214815/image.png)
![No description](https://cdn.answeroverflow.com/1215353944570724392/image.png)
![No description](https://cdn.answeroverflow.com/1215353944868655175/image.png)