Closed liran-co closed 4 years ago
Hey @liran-co. Define "add-on" please. I think you're just looking for a simple query with scopes?
// Check if the user has at least one active subscription
$user->subscriptions()->active()->count();
// Check if the user has at least one subscription (any state).
$user->subscriptions()->count();
"Add-on" doesn't really mean much in this context, it's just a way to think about the use case. In our case a user can subscribe to "live-chat" separately or as part of another subscription.
For example, if we had a Pro and Enterprise plan plus a "live-chat" add-on where the user could either purchase "live-chat" separately or with a Pro / Enterprise plan. In that case, if we wanted to check in our app whether or not they are subscribed to the "live-chat" add-on, we need to check three cases:
subscribed('live-chat')
subscribedToPlan('live-chat', 'pro')
subscribedToPlan('live-chat', 'enterprise')
Plus on top of this, if "live-chat" had a monthly or yearly option, we'd need to check for both pricing plans.
There's actually three issues here that are related:
name
of the subscription? Or should that still be something like default
? I think you've just modelled your subscription flow not really optimal. I'd tackle the add on with a subscription item instead. This might be a better question to ask on a support channel so I'm kindly directing you to one of these channels as this tracker is only for feature requests or bugs:
Sure...but either which way you model it doesn't solve the problem. Seems like this is the key to make this work: https://github.com/laravel/cashier/issues/956.
It's not since that only will rename a bunch of internal variables and methods. No structural changes will be applied for that issue.
Ideally we'd store the product id though, not just the plan id that way we can check if they are subscribed to a specific product, regardless of plan.
But that's stored for you? That's the stripe_id
that you need on a subscription I think.
That's the Stripe subscription id, not the product id though. Ideally we'd store a product_id
in addition to the stripe_plan
. Plans
live under Products
so doing so would provide us a way to check the existence of a subscription to a product without caring what pricing plan they are on.
Gotcha. I haven't had time to really dive deeply into Stripe products yet. It's only recently been released. I also don't think I'll get around to this soon tbh.
If there are multiple price plans available on a product, it seems the only way to check if a user is subscribed to a product is by using
subscribedToPlan
and passing in every price id. Is there any reason we can't check based on product? In most cases, we just need to check if a user is subscribed to a certain product, it doesn't matter what pricing plan they are on. If we added a new pricing tier (ex: "quarterly"), we'd need to redeploy our app to check for that.In theory the solution is to just check based on the
name
field, by usingsubscribed()
, but that doesn't work in the case that we have multiple products or addons in a single subscription (i.e. I wouldn't be able to check if they have the "live-chat" add-on).