bpuig / laravel-subby

Laravel Plan and Subscriptions manager.
https://bpuig.github.io/laravel-subby
MIT License
104 stars 42 forks source link

Subscribing to a non-active plan #63

Closed boryn closed 3 years ago

boryn commented 3 years ago

I wonder if

$plan = Plan::find(2);
$user->newSubscription('main', $plan);

should be possible if plan of id=2 has is_active set to 0? Or it's better to leave it to developer

bpuig commented 3 years ago

We have to always think that there is user side, but also there can be admin side to the app, so I need to be careful of not closing and restricting too much the package.

So one can do because knows plan 2 exists and is active:

$plan = Plan::find(2);
$user->newSubscription('main', $plan);

But also manage the same endpoint for both admin and user perspective, so Super Admin can assign plan to users but users only to themselves.

$isSuperAdmin = auth()->user()->hasRole('Super Admin');

$user = ($isSuperAdmin) ? User::findOrFail($request->user_id) : auth()->user();

$plan = ($isSuperAdmin) ? Plan::findOrFail($request->plan_id) : Plan::where('id', $request->plan_id)->where('is_active', true)->firstOrFail();

$user->newSubscription('main', $plan);

If an error is thrown when calling newSubscription because plan is not active it can be a pain to create the subscription from an admin perspective, because maybe there are "secret plans" that you do not want to be active to the public but able to the admin to attach a subscription.

boryn commented 3 years ago

Totally understood, the library should not limit subscribing to not active plans.