lucasdotvin/laravel-soulbscription

Switching subscription plans can results in negative balance

martin-ro opened this issue ยท 3 comments

Hi, great package! I'm using it together with cashier and noticed an issue with feature consumption when switching plans.

Imagine a scenario where you have Plan A (100 min.) and Plan B (25 min.)

The user subscribes to Plan A, uses 50 minutes, and switches then to Plan B. The user has now (negative) -25 min. balance.

Maybe I missed something in the documentation?

Cheers

Hello, Martin! Thanks for reporting this! Could you elaborate and explain what you're trying to achieve? I believe some applications would benefit from this behavior, so maybe we need to create a configuration entry to define how the package should act in this case. Is your idea to erase the consumption after a plan switch? ๐Ÿค˜

Hi Lucas, probably not erasing the consumption but not allowing negative consumption for display? It could be done like this:

public function getRemainingCharges($featureName): float
    {
        if (empty($this->getFeature($featureName))) {
            return 0;
        }

        $currentConsumption = $this->getCurrentConsumption($featureName);
        $totalCharges = $this->getTotalCharges($featureName);

        return max($totalCharges - $currentConsumption, 0);
    }

I think it's just a better UX experience.

Oh, I got it! I'm gonna work on a setting entry for this behavior, then. Thanks for suggesting it! ๐Ÿš€