當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。