/** * Get all of the available roles that may be assigned to team members. * * @return \Illuminate\Http\Response */ public function getTeamRoles() { $roles = []; foreach (Spark::roles() as $key => $value) { $roles[] = ['value' => $key, 'text' => $value]; } return response()->json($roles); }
/** * Notify the given user about a new invoice. * * @param \Illuminate\Contracts\Auth\Authenticatable $user * @param \Laravel\Cashier\Invoice $invoice * @return void */ public function notify(Authenticatable $user, Invoice $invoice) { $invoiceData = array_merge(['vendor' => 'Vendor', 'product' => 'Product', 'vat' => new HtmlString(nl2br(e($user->extra_billing_info)))], Spark::generateInvoicesWith()); $data = compact('user', 'invoice', 'invoiceData'); Mail::send('emails.billing.invoice', $data, function ($message) use($user, $invoice, $invoiceData) { $message->to($user->email, $user->name)->subject('Your ' . $invoiceData['product'] . ' Invoice')->attachData($invoice->pdf($invoiceData), 'invoice.pdf'); }); }
/** * Create a new team for the given user and data. * * @param \Illuminate\Contracts\Auth\Authenticatable $user * @param array $data * @return \App\Teams\Team */ public function create($user, array $data) { $class = Spark::model('teams', Team::class); $team = new $class(['name' => $data['name']]); $team->owner_id = $user->id; $team->save(); $team = $user->teams()->attach($team, ['role' => 'owner']); return $team; }
/** * Show the settings dashboard. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function show(Request $request) { $data = ['activeTab' => $request->get('tab', Spark::firstSettingsTabKey()), 'invoices' => [], 'user' => $this->users->getCurrentUser()]; if (Auth::user()->stripe_id) { $data['invoices'] = Cache::remember('spark:invoices:' . Auth::id(), 30, function () { return Auth::user()->invoices(); }); } return view('settings.dashboard', $data); }
/** * 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); } }
/** * 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); } }
/** * Download the given invoice for the user. * * @param string $invoiceId * @return \Illuminate\Http\Response */ public function downloadInvoice(Request $request, $invoiceId) { $data = array_merge(['vendor' => 'Vendor', 'product' => 'Product', 'vat' => new ViewExpression(nl2br(e($request->user()->extra_billing_info)))], Spark::generateInvoicesWith()); return Auth::user()->downloadInvoice($invoiceId, $data); }
/** * Disable two-factor authentication for the user. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function disableTwoFactorAuth(Request $request) { Spark::twoFactorProvider()->delete(Auth::user()); Auth::user()->save(); return $this->users->getCurrentUser(); }
/** * Show the application registration form. * * @param \Illuminate\Http\Request * @return \Illuminate\Http\Response */ public function showRegistrationForm(Request $request) { if (Spark::forcingPromotion() && !$request->query('coupon')) { if (count($request->query()) > 0) { return redirect($request->fullUrl() . '&coupon=' . Spark::forcedPromotion()); } else { return redirect($request->fullUrl() . '?coupon=' . Spark::forcedPromotion()); } } if (count($this->plans->paid()) > 0) { return view('auth.registration.subscription'); } else { return view('auth.registration.simple'); } }
/** * Customize the subscription plans for the application. * * @return void */ protected function customizeSubscriptionPlans() { Spark::free()->features(['Feature 1', 'Feature 2', 'Feature 3']); Spark::plan('Spark Test 1', 'spark-test-1')->price(9.99)->trialDays(15)->features(['Feature 1', 'Feature 2', 'Feature 3']); }
/** * Get the tab configuration for the "subscription" tab. * * @param bool $force * @return \App\Ux\Settings\Tab|null */ public function subscription($force = false) { return new Tab('Subscription', 'settings.tabs.subscription', 'fa-credit-card', function () use($force) { return count(Spark::plans()->paid()) > 0 || $force; }); }
/** * Join the team with the given ID. * * @param int $teamId * @return void */ public function joinTeamById($teamId) { $this->teams()->attach([$teamId], ['role' => Spark::defaultRole()]); $this->currentTeam(); event(new JoinedTeam($this, $this->teams()->find($teamId))); }
/** * Get the team that owns the invitation. */ public function team() { return $this->belongsTo(Spark::model('teams', Team::class), 'team_id'); }
/** * Validate a team update request. * * @param \Illuminate\Http\Request $request * @return void */ protected function validateTeamMemberUpdate(Request $request, $team, $user) { if (Spark::$validateTeamMemberUpdatesWith) { $this->callCustomValidator(Spark::$validateTeamMemberUpdatesWith, $request, [$team, $user]); } else { $availableRoles = implode(',', array_except(array_keys(Spark::roles()), 'owner')); $this->validate($request, ['role' => 'required|in:' . $availableRoles]); } }