当前位置: 首页>>代码示例>>PHP>>正文


PHP Spark\Spark类代码示例

本文整理汇总了PHP中Laravel\Spark\Spark的典型用法代码示例。如果您正苦于以下问题:PHP Spark类的具体用法?PHP Spark怎么用?PHP Spark使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Spark类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: store

 /**
  * Create a discount for the given user.
  *
  * @param  Request  $request
  * @param  string  $userId
  * @return Response
  */
 public function store(Request $request, $userId)
 {
     $user = Spark::user()->where('id', $userId)->firstOrFail();
     $this->validate($request, ['type' => 'required|in:amount,percent', 'value' => 'required|integer', 'duration' => 'required|in:once,forever,repeating', 'months' => 'required_if:duration,repeating']);
     $coupon = StripeCoupon::create(['currency' => 'usd', 'amount_off' => $request->type == 'amount' ? $request->value * 100 : null, 'percent_off' => $request->type == 'percent' ? $request->value : null, 'duration' => $request->duration, 'duration_in_months' => $request->months, 'max_redemptions' => 1], config('services.stripe.secret'));
     $user->applyCoupon($coupon->id);
 }
开发者ID:defenestrator,项目名称:groid,代码行数:14,代码来源:DiscountController.php

示例2: current

 /**
  * Get the current discount for the given user.
  *
  * @param  Request  $request
  * @param  string  $userId
  * @return Response
  */
 public function current(Request $request, $userId)
 {
     $user = Spark::user()->where('id', $userId)->firstOrFail();
     if ($coupon = $this->coupons->forBillable($user)) {
         return response()->json($coupon->toArray());
     }
 }
开发者ID:defenestrator,项目名称:groid,代码行数:14,代码来源:CouponController.php

示例3: boot

 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     if (method_exists($this, 'customizeSpark')) {
         $this->customizeSpark();
     }
     if (method_exists($this, 'customizeRegistration')) {
         $this->customizeRegistration();
     }
     if (method_exists($this, 'customizeRoles')) {
         $this->customizeRoles();
     }
     if (method_exists($this, 'customizeProfileUpdates')) {
         $this->customizeProfileUpdates();
     }
     if (method_exists($this, 'customizeSubscriptionPlans')) {
         $this->customizeSubscriptionPlans();
     }
     if (method_exists($this, 'customizeSettingsTabs')) {
         $this->customizeSettingsTabs();
     }
     if ($this->twoFactorAuth) {
         Spark::withTwoFactorAuth();
     }
     Spark::generateInvoicesWith($this->invoiceWith);
 }
开发者ID:Braunson,项目名称:spark,代码行数:30,代码来源:AppServiceProvider.php

示例4: handle

 /**
  * {@inheritdoc}
  */
 public function handle($user, $plan, $fromRegistration, array $data)
 {
     $subscription = $user->newSubscription('default', $plan->id);
     // Here we will check if we need to skip trial or set trial days on the subscription
     // when creating it on the provider. By default, we will skip the trial when this
     // interaction is not from egistration since they have already usually trialed.
     if (!$fromRegistration) {
         $subscription->skipTrial();
     } elseif ($plan->trialDays > 0) {
         $subscription->trialDays($plan->trialDays);
     }
     if (isset($data['coupon'])) {
         $subscription->withCoupon($data['coupon']);
     }
     // Next, we need to check if this application is storing billing addresses and if so
     // we will update the billing address in the database so that any tax information
     // on the user will be up to date via the taxPercentage method on the billable.
     if (Spark::collectsBillingAddress()) {
         Spark::call(UserRepository::class . '@updateBillingAddress', [$user, $data]);
     }
     // If this application collects European VAT, we will store the VAT ID that was sent
     // with the request. It is used to determine if the VAT should get charged at all
     // when billing the customer. When it is present, VAT is not typically charged.
     if (Spark::collectsEuropeanVat()) {
         Spark::call(UserRepository::class . '@updateVatId', [$user, array_get($data, 'vat_id')]);
     }
     // Here we will create the actual subscription on the service and fire off the event
     // letting other listeners know a user has subscribed, which will allow any hooks
     // to fire that need to send the subscription data to any external metrics app.
     $subscription->create($data[$this->token]);
     event(new UserSubscribed($user = $user->fresh(), $plan, $fromRegistration));
     return $user;
 }
开发者ID:defenestrator,项目名称:groid,代码行数:36,代码来源:Subscribe.php

示例5: handle

 /**
  * Handle the event.
  *
  * @param  UserRegistered  $event
  * @return void
  */
 public function handle(UserRegistered $event)
 {
     if (!Spark::trialDays()) {
         return;
     }
     $this->notifications->create($event->user, ['icon' => 'fa-clock-o', 'body' => 'Your trial period will expire on ' . $event->user->trial_ends_at->format('F jS') . '.', 'action_text' => 'Subscribe', 'action_url' => '/settings#/subscription']);
 }
开发者ID:defenestrator,项目名称:groid,代码行数:13,代码来源:CreateTrialEndingNotification.php

示例6: handle

 /**
  * Determine if the authenticated user is a developer.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return \Illuminate\Http\Response
  */
 public function handle($request, $next)
 {
     if ($request->user() && Spark::developer($request->user()->email)) {
         return $next($request);
     }
     return $request->ajax() || $request->wantsJson() ? response('Unauthorized.', 401) : redirect()->guest('login');
 }
开发者ID:defenestrator,项目名称:groid,代码行数:14,代码来源:VerifyUserIsDeveloper.php

示例7: validator

 /**
  * Get the validator for the request.
  *
  * @return \Illuminate\Validation\Validator
  */
 public function validator()
 {
     $validator = Validator::make($this->all(), ['plan' => 'required|in:' . Spark::activePlanIdList()]);
     return $validator->after(function ($validator) {
         $this->validatePlanEligibility($validator);
     });
 }
开发者ID:defenestrator,项目名称:groid,代码行数:12,代码来源:UpdateSubscriptionRequest.php

示例8: handle

 /**
  * Verify the incoming request's user belongs to team.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return \Illuminate\Http\Response
  */
 public function handle($request, $next)
 {
     if (Spark::usesTeams() && $request->user() && !$request->user()->hasTeams()) {
         return redirect('missing-team');
     }
     return $next($request);
 }
开发者ID:defenestrator,项目名称:groid,代码行数:14,代码来源:VerifyUserHasTeam.php

示例9: handle

 /**
  * {@inheritdoc}
  */
 public function handle($team, $plan, array $data)
 {
     $subscription = $team->newSubscription('default', $plan->id);
     // Here we will fill the trial days for this team subscription. We will also set any
     // coupon on the subscription so that the team can receive a discount on the team
     // subscription. Then we will almost be ready to create the final subscription.
     $subscription->trialDays($plan->trialDays);
     if (isset($data['coupon'])) {
         $subscription->withCoupon($data['coupon']);
     }
     // Next, we need to check if this application is storing billing addresses and if so
     // we will update the billing address in the database so that any tax information
     // on the team will be up to date via the taxPercentage method on the billable.
     if (Spark::collectsBillingAddress()) {
         Spark::call(TeamRepository::class . '@updateBillingAddress', [$team, $data]);
     }
     // If this application collects European VAT, we will store the VAT ID that was sent
     // with the request. It is used to determine if the VAT should get charged at all
     // when billing the customer. When it is present, VAT is not typically charged.
     if (Spark::collectsEuropeanVat()) {
         Spark::call(TeamRepository::class . '@updateVatId', [$team, array_get($data, 'vat_id')]);
     }
     // Here we will create the actual subscription on the service and fire off the event
     // letting other listeners know a team has subscribed, which will allow any hooks
     // to fire that need to send the subscription data to any external metrics app.
     $subscription->create($data[$this->token]);
     event(new TeamSubscribed($team = $team->fresh(), $plan));
     return $team;
 }
开发者ID:defenestrator,项目名称:groid,代码行数:32,代码来源:SubscribeTeam.php

示例10: handle

 /**
  * Handle the event.
  *
  * @param  TeamCreated  $event
  * @return void
  */
 public function handle(TeamCreated $event)
 {
     if (!Spark::teamTrialDays()) {
         return;
     }
     $this->notifications->create($event->team->owner, ['icon' => 'fa-clock-o', 'body' => "The " . $event->team->name . " team's trial period will expire on " . $event->team->trial_ends_at->format('F jS') . '.', 'action_text' => 'Subscribe', 'action_url' => '/settings/teams/' . $event->team->id . '#/subscription']);
 }
开发者ID:defenestrator,项目名称:groid,代码行数:13,代码来源:CreateTrialEndingNotification.php

示例11: validator

 /**
  * Get the validator for the request.
  *
  * @return \Illuminate\Validation\Validator
  */
 public function validator()
 {
     $validator = $this->registerValidator(['stripe_token']);
     if (Spark::collectsBillingAddress() && $this->hasPaidPlan()) {
         $this->validateBillingAddress($validator);
     }
     return $validator;
 }
开发者ID:defenestrator,项目名称:groid,代码行数:13,代码来源:StripeRegisterRequest.php

示例12: validateAbilities

 /**
  * Configure the valdiator to validate the token abilities.
  *
  * @param  \Illuminate\Validation\Validator  $validator
  * @return \Illuminate\Validation\Validator
  */
 protected function validateAbilities($validator)
 {
     $abilities = implode(',', array_keys(Spark::tokensCan()));
     $validator->sometimes('abilities', 'required|array|in:' . $abilities, function () {
         return count(Spark::tokensCan()) > 0;
     });
     return $validator;
 }
开发者ID:defenestrator,项目名称:groid,代码行数:14,代码来源:TokenRequest.php

示例13: sendInvoiceNotification

 /**
  * Send an invoice notification e-mail.
  *
  * @param  mixed  $billable
  * @param  \Laravel\Cashier\Invoice
  * @return void
  */
 protected function sendInvoiceNotification($billable, $invoice)
 {
     $invoiceData = Spark::invoiceDataFor($billable);
     $data = compact('billable', 'invoice', 'invoiceData');
     Mail::send($this->emailView, $data, function ($message) use($billable, $invoice, $invoiceData) {
         $this->buildInvoiceMessage($message, $billable, $invoice, $invoiceData);
     });
 }
开发者ID:defenestrator,项目名称:groid,代码行数:15,代码来源:SendsInvoiceNotifications.php

示例14: interaction

 /**
  * Execute the given interaction.
  *
  * This performs the common validate and handle flow of some interactions.
  *
  * @param  Request  $request
  * @param  string  $interaction
  * @param  array  $parameters
  * @return void
  */
 public function interaction(Request $request, $interaction, array $parameters)
 {
     $validator = Spark::interact($interaction . '@validator', $parameters);
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     return Spark::interact($interaction, $parameters);
 }
开发者ID:defenestrator,项目名称:groid,代码行数:18,代码来源:Controller.php

示例15: subscribe

 /**
  * Subscribe the given user to a subscription plan.
  *
  * @param  RegisterRequest  $request
  * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
  * @return \Illuminate\Contracts\Auth\Authenticatable
  */
 protected function subscribe($request, $user)
 {
     if (!$request->hasPaidPlan()) {
         return $user;
     }
     Spark::interact(Subscribe::class, [$user, $request->plan(), true, $request->all()]);
     return $user;
 }
开发者ID:defenestrator,项目名称:groid,代码行数:15,代码来源:Register.php


注:本文中的Laravel\Spark\Spark类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。