farb
192
5
Spark

Trouble with 'teamSubscribed' middleware with freeTeamPlan

Posted 1 month ago by farb

Anyone know why the VerifyTeamIsSubscribed model (->middleware('teamSubscribed');) does not check if the team is on a free plan? It only seems to do onGenericTrial() which just checks if the trial_ends_at column is after today's date, but that should be null (result in false) on a free plan. (edited)

My spark service provider looks like:

            Spark::freeTeamPlan('DIY Free','test_1234diyfree')
                ->features($diyFree)
                ->yearly()
                ->attributes([
                    'planid'=>'plan_DIYMFree',
                    'free'=>1,
                    'category' => 'all',
                ])
                ->maxTeamMembers(3);

and the VerifyTeamIsSubscribed class gets tripped up on the onGenericTrial() where it gets false from that, of course, because the tial_ends_at is null:

class VerifyTeamIsSubscribed
{
    /**
     * Verify the incoming request's current team has a subscription.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string  $subscription
     * @param  string  $plan
     * @return \Illuminate\Http\Response
     */
    public function handle($request, $next, $subscription = 'default', $plan = null)
    {
        if ($this->subscribed($request->user(), $subscription, $plan, func_num_args() === 2)) {
            return $next($request);
        }

        return $request->ajax() || $request->wantsJson()
                                ? response('Subscription Required.', 402)
                                : redirect('/settings/'.Spark::teamsPrefix().'/'.$request->user()->currentTeam->id.'#/subscription');
    }

    /**
     * Determine if the given user's current team is subscribed to the given plan.
     *
     * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
     * @param  string  $subscription
     * @param  bool  $plan
     * @param  bool  $defaultSubscription
     * @return bool
     */
    protected function subscribed($user, $subscription, $plan, $defaultSubscription)
    {
        if (! $user || ! $user->currentTeam) {
            return false;
        }

        return ($defaultSubscription && $user->currentTeam->onGenericTrial()) ||
                $user->currentTeam->subscribed($subscription, $plan);
    }
}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.