laravel-subscriptions icon indicating copy to clipboard operation
laravel-subscriptions copied to clipboard

Feature Usage seems to be wrong

Open jimiero opened this issue 10 months ago • 9 comments

Hello @mckenziearts ,

I think this method here may be wrong

public function canUseFeature(string $featureSlug): bool
    {

        $featureValue = $this->getFeatureValue($featureSlug);

        $usage = $this->usage()->byFeatureSlug($featureSlug)->first();

        if ($featureValue === 'true') {
            return true;
        }

        // If the feature value is zero, let's return false since
        // there's no uses available. (useful to disable countable features)
        if (! $usage || $usage->expired() || $featureValue === null || $featureValue === '0' || $featureValue === 'false') {
            return false;
        }

        // Check for available uses
        return $this->getFeatureRemainings($featureSlug) > 0;
    }

why will it fail if there's not usages done already ?

lets say user purchase a plan with feature "contacts" with limit 30

Then if you do

$user->subscription->canUseFeature('contacts')

it will return false, because he never made use of that feature...

jimiero avatar Dec 06 '24 14:12 jimiero