带有freeTeamPlan的Laravel的Spark'teamSubscribed'中间件出现问题

时间:2019-03-19 18:05:12

标签: laravel laravel-spark

任何人都知道为什么VerifyTeamIsSubscribed模型(->middleware('teamSubscribed');)不检查团队是否有免费计划吗?似乎只做onGenericTrial()只是检查trial_ends_at列是否在今天的日期之后,但是在免费计划中,该列应该为null(结果为false)。 (已编辑)

我的Spark服务提供商如下:

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

当然,由于tial_ends_at为空,因此VerifyTeamIsSubscribed类在onGenericTrial()上变为虚假,这是错误的:

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);
    }
}

0 个答案:

没有答案