本文整理汇总了PHP中Laravel\Spark\Spark::plans方法的典型用法代码示例。如果您正苦于以下问题:PHP Spark::plans方法的具体用法?PHP Spark::plans怎么用?PHP Spark::plans使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Laravel\Spark\Spark
的用法示例。
在下文中一共展示了Spark::plans方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Create a new authentication controller instance.
*
* @param \Laravel\Spark\Contracts\Repositories\UserRepository $users
* @param \Laravel\Spark\Contracts\Repositories\TeamRepository $teams
* @return void
*/
public function __construct(UserRepository $users, TeamRepository $teams)
{
$this->users = $users;
$this->teams = $teams;
$this->plans = Spark::plans();
$this->middleware('guest', ['except' => 'getLogout']);
}
示例2: createSubscriptionOnStripe
/**
* Create the subscription on Stripe.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
protected function createSubscriptionOnStripe(Request $request, $user)
{
$plan = Spark::plans()->find($request->plan);
$subscription = $user->subscription($plan->id);
if ($plan->hasTrial()) {
$subscription->trialFor(Carbon::now()->addDays($plan->trialDays));
}
if ($request->coupon) {
$subscription->withCoupon($request->coupon);
}
$subscription->create($request->stripe_token, ['email' => $user->email]);
}
示例3: changeSubscriptionPlan
/**
* Change the user's subscription plan.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function changeSubscriptionPlan(Request $request)
{
$this->validate($request, ['plan' => 'required']);
$plan = Spark::plans()->find($request->plan);
if ($plan->price() === 0) {
$this->cancelSubscription();
} else {
Auth::user()->subscription($request->plan)->maintainTrial()->prorate()->swapAndInvoice();
}
event(new SubscriptionPlanChanged(Auth::user()));
return $this->users->getCurrentUser();
}
示例4: update
/**
* Update the subscription for the user.
*
* @param \Laravel\Spark\Http\Requests\UpdateSubscriptionRequest $request
* @return Response
*/
public function update(UpdateSubscriptionRequest $request)
{
$plan = Spark::plans()->where('id', $request->plan)->first();
// This method is used both for updating subscriptions and for resuming cancelled
// subscriptions that are still within their grace periods as this swap method
// will be used for either of these situations without causing any problems.
if ($plan->price === 0) {
return $this->destroy($request);
} else {
$request->user()->subscription()->swap($request->plan);
}
event(new SubscriptionUpdated($request->user()->fresh()));
}
示例5: changeSubscriptionPlan
/**
* Change the user's subscription plan.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function changeSubscriptionPlan(Request $request)
{
$this->validate($request, ['plan' => 'required']);
$plan = Spark::plans()->find($request->plan);
if ($plan->price() === 0) {
$this->cancelSubscription();
} elseif (Spark::$swapSubscriptionsWith) {
$this->callCustomUpdater(Spark::$swapSubscriptionsWith, $request, [Auth::user()]);
} else {
Auth::user()->subscription('main')->swap($request->plan);
}
event(new SubscriptionPlanChanged(Auth::user()));
return $this->users->getCurrentUser();
}
示例6: createSubscriptionOnStripe
/**
* Create the subscription on Stripe.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param \Stripe\Customer|null $stripeCustomer
* @return void
*/
public function createSubscriptionOnStripe(Request $request, $user, $stripeCustomer = null)
{
$plan = Spark::plans()->find($request->plan);
$subscription = $user->subscription($plan->id);
if ($plan->hasTrial() && $stripeCustomer === null) {
$subscription->trialFor(Carbon::now()->addDays($plan->trialDays));
}
if ($request->coupon) {
$subscription->withCoupon($request->coupon);
}
if (Spark::$createSubscriptionsWith) {
$this->callCustomUpdater(Spark::$createSubscriptionsWith, $request, [$user, $subscription, $stripeCustomer]);
} else {
$this->createDefaultSubscription($request, $user, $subscription, $stripeCustomer);
}
}
示例7: createSubscriptionOnStripe
/**
* Create the subscription on Stripe.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
public function createSubscriptionOnStripe(Request $request, $user)
{
$plan = Spark::plans()->find($request->plan);
$subscription = $user->newSubscription('main', $plan->id);
if ($plan->hasTrial() && !$user->stripe_id) {
$subscription->trialDays($plan->trialDays);
}
if ($request->coupon) {
$subscription->withCoupon($request->coupon);
}
if (Spark::$createSubscriptionsWith) {
$this->callCustomUpdater(Spark::$createSubscriptionsWith, $request, [$user, $subscription, $stripeCustomer]);
} else {
$subscription->create($request->stripe_token);
}
}
示例8: validatePlanEligibility
/**
* Validate that the plan is eligible based on team restrictions.
*
* @param \Illuminate\Validation\Validator $valdiator
* @return void
*/
protected function validatePlanEligibility($validator)
{
$plan = Spark::plans()->where('id', $this->plan)->first();
// If the desired plan is free, we will always need to let the user switch to that
// plan since we'll want the user to always be able to cancel this subscription
// without preventing them. So, we will just return here if it's a free plan.
if (!$plan || $plan->price === 0) {
return;
}
$this->callCustomCallback($validator, $plan);
// If the user is ineligible for a plan based on their team member or collaborator
// count, we will prevent them switching to this plan and send an error message
// back to the client informing them of this limitation and they can upgrade.
if (!$this->userIsEligibleForPlan($plan)) {
$validator->errors()->add('plan', trans('spark::validation.eligibility'));
}
}
示例9: getCouponForUser
/**
* Get the current coupon for the authenticated user.
*
* Used to display current discount on settings -> subscription tab.
*
* @return \Illuminate\Http\Response
*/
public function getCouponForUser()
{
Stripe::setApiKey(config('services.stripe.secret'));
if (count(Spark::plans()) === 0) {
abort(404);
}
try {
$customer = StripeCustomer::retrieve(Auth::user()->stripe_id);
if ($customer->discount) {
return response()->json(Coupon::fromStripeCoupon(StripeCoupon::retrieve($customer->discount->coupon->id)));
} else {
abort(404);
}
} catch (Exception $e) {
abort(404);
}
}
示例10: subscription
/**
* Get the tab configuration for the "subscription" tab.
*
* @param bool $force
* @return \Laravel\Spark\Ux\Settings\Tab|null
*/
public function subscription($force = false)
{
return new Tab('Subscription', 'spark::settings.tabs.subscription', 'fa-credit-card', function () use($force) {
return count(Spark::plans()->paid()) > 0 || $force;
});
}
示例11: plan
/**
* Get the full plan array for the specified plan.
*
* @return \Laravel\Spark\Plan|null
*/
public function plan()
{
if ($this->plan) {
return Spark::plans()->where('id', $this->plan)->first();
}
}
示例12: all
/**
* Get the all of the plans defined for the appliation.
*
* @return Response
*/
public function all()
{
return response()->json(Spark::plans());
}
示例13: availablePlans
/**
* Get the available billing plans for the given entity.
*
* @return \Illuminate\Support\Collection
*/
public function availablePlans()
{
return Spark::plans();
}