I have different plans with different sets of restrictions. I’ve saved all those restrictions in an option set to determine if an action can be taken or not.
I also saved each Stripe subscription Plan ID in the option set to search which plan the user is currently subscribed to, but I don’t know if this is safe.
If not, what would your recommendation be to determine which plan a user is subscribed to?
You should have a data type in your app called subscriptions. It should have the product ID and Price ID from stripe saved on it, as well as a title, description and any other details relevant like the ‘features’ of the plan.
Then you can on your User data type have a field that is related to the subscription data type based on which subscription plan the user is on and call it ‘subscription plan’
Then when creating conditionals for actions that can be taken you use dynamic expression ‘current users subscription plan…’
I see I see. Every end of the payment period, I have a recurring workflow that replenishes a user’s credits. I’ll include a workflow to check if the payment went through. Thanks for that suggestion!
Quick question though. When the webhook triggers and I want to modify the current user’s subscription, can I use the expression “current user’s subscription” or do I have to search for users based on certain data retrieved from the webhook?
I’ve almost got everything setup, but I am experiencing one issue.
I have 2 webhooks. One to create the “subscription” data type and one to edit it.
The stripe events are [subscription.created] and [subscription.updated, subscription.canceled] respectively.
When the webhook triggers to create the new subscription, it doesn’t allow me to modify the user’s subscription field. This is happening because I can’t do a search for user with stripe customer ID yet since the user doesn’t have a Customer ID yet. Whenever I do it the second time, the user’s subscription field is changed.
Is there any other way I can search for the user so I can modify its “subscription” field?
When you run the api call to create the subscription, it provides a subscription ID which you should save in your DB somewhere so you can later search using it when the webhook triggers.