bpuig / laravel-subby

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

Better usage handling #78

Closed bpuig closed 3 years ago

bpuig commented 3 years ago

Right now you can record feature usage without issue and it gets renewed automatically if it hasExpired. But if you check it beforehand with canUseFeature, you will be denied usage because it hasExpired.

New logic should:

bpuig commented 3 years ago

Why are we able to?

$plan->features()->saveMany([
    new PlanFeature(['tag' => 'posts_per_social_profile', 'name' => 'Scheduled posts per profile', 'value' => 30, 'sort_order' => 10, 'resettable_period' => 1, 'resettable_interval' => 'month'])
]);

And set custom 'resettable_period' => 1, 'resettable_interval' => 'month'. Why is not inherited from plan?

Looks weird to me to have a plan with different period that it's features. Like, you pay monthly but your features are renewed every couple months? Right now I think it won't affect this PR. But does not look OK.

boryn commented 3 years ago

Paying subscription monthly and resetting features quaterly could be possible in some cases. I'd leave it as it is, this gives more flexibility for the features definition & usage.

boryn commented 3 years ago

And the other real life scenario is that someone pays for the year (so we have invoice_period set to '1' and invoice_interval set to 'year' at plans) but they consume the features on the monthly basis (so resettable_period set to '1' and resettable_interval set to 'month' in the plan_features).

boryn commented 3 years ago

Just as a side note. While it does not make sense to record feature when the user is not allowed to use it, it's good to be able to recordFeatureUsage() when feature is set to 'true' (not integer). For example we charge per "file conversion", the user has this permission and we count the real monthly usage.

bpuig commented 3 years ago

Just as a side note. While it does not make sense to record feature when the user is not allowed to use it, it's good to be able to recordFeatureUsage() when feature is set to 'true' (not integer). For example we charge per "file conversion", the user has this permission and we count the real monthly usage.

I don't think that is currently the way the package it's suposed to work. It does not support mettered use. You have to specify a "usage limit". One reason, among others, is that, when period has expired, it restarts the counter. You would not know how much did the subscriber use because it would be wiped and replaced with the new "1" used value.

boryn commented 3 years ago

Yes, that's true. It counts the usage, but only for the current period and when new appears, this information is lost...