1

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);
    }
}
Will
  • 465
  • 1
  • 3
  • 12
  • FWIY, I seem to have solved it by adding a third condition to the subscribed function: ```return ($defaultSubscription && $user->currentTeam->onGenericTrial()) || $user->currentTeam->subscribed($subscription, $plan) || $user->currentTeam->subscribed('DIY Free');``` But it feels janky and I can't see why that would be necessary if Spark has a freeTeamPlan concept. Why wouldn't that be considered? Or have I missed something? – Will Mar 19 '19 at 19:05

0 Answers0