Initial Spark Install

This commit is contained in:
Deon George
2017-11-03 16:26:07 +11:00
commit b1a5807eb3
766 changed files with 128896 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
<?php
namespace Laravel\Spark\Http\Requests\Auth;
use Laravel\Spark\Contracts\Http\Requests\Auth\RegisterRequest as Contract;
class BraintreeRegisterRequest extends RegisterRequest implements Contract
{
/**
* Get the validator for the request.
*
* @return \Illuminate\Validation\Validator
*/
public function validator()
{
return $this->registerValidator(['braintree_type', 'braintree_token']);
}
}

View File

@@ -0,0 +1,141 @@
<?php
namespace Laravel\Spark\Http\Requests\Auth;
use Laravel\Spark\Spark;
use Laravel\Spark\Invitation;
use Illuminate\Foundation\Http\FormRequest;
use Laravel\Spark\Contracts\Interactions\Auth\CreateUser;
use Laravel\Spark\Contracts\Repositories\CouponRepository;
class RegisterRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validator for a registration request.
*
* @param array $paymentAttributes
* @return \Illuminate\Validation\Validator
*/
protected function registerValidator(array $paymentAttributes)
{
$validator = $this->baseValidator();
// If a paid plan is selected, we will validate the given required fields which
// are typically the Stripe / Braintree tokens. If the selected plan is free
// of course we will not need to validate that these fields are available.
$validator->sometimes($paymentAttributes, 'required', function ($input) {
return $this->plan() && $this->plan()->price > 0;
});
return $this->after($validator);
}
/**
* Get the base validator instance for a register request.
*
* @return \Illuminate\Validation\Validator
*/
public function baseValidator()
{
$validator = Spark::interact(
CreateUser::class.'@validator', [$this]
);
$allPlanIdList = Spark::activePlanIdList().','.Spark::activeTeamPlanIdList();
$validator->sometimes('plan', 'required|in:'.$allPlanIdList, function () {
return Spark::needsCardUpFront();
});
return $validator;
}
/**
* Setup the "after" callabck for the validator.
*
* @param \Illuminate\Validation\Validator $validator
* @return \Illuminate\Validation\Validator
*/
protected function after($validator)
{
return $validator->after(function ($validator) {
if ($this->coupon) {
$this->validateCoupon($validator);
}
if ($this->invitation) {
$this->validateInvitation($validator);
}
});
}
/**
* Validate the coupon on the request.
*
* @param \Illuminate\Validation\Validator $validator
* @return void
*/
protected function validateCoupon($validator)
{
if (! app(CouponRepository::class)->valid($this->coupon)) {
$validator->errors()->add('coupon', 'This coupon code is invalid.');
}
}
/**
* Validate the invitation code on the request.
*
* @param \Illuminate\Validation\Validator $validator
* @return void
*/
protected function validateInvitation($validator)
{
if (! $this->invitation()) {
$validator->errors()->add('invitation', 'This invitation code is invalid.');
}
}
/**
* Determine if the request contains a paid plan.
*
* @return bool
*/
public function hasPaidPlan()
{
return $this->plan() && $this->plan()->price > 0;
}
/**
* Get the full plan array for the specified plan.
*
* @return \Laravel\Spark\Plan|null
*/
public function plan()
{
if ($this->plan) {
return Spark::plans()->merge(Spark::teamPlans())->where('id', $this->plan)->first();
}
}
/**
* Get the full invitation instance.
*
* @return \Laravel\Spark\Invitation
*/
public function invitation()
{
if ($this->invitation) {
return Invitation::where('token', $this->invitation)->first();
}
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Laravel\Spark\Http\Requests\Auth;
use Laravel\Spark\Spark;
use Laravel\Spark\Http\Requests\ValidatesBillingAddresses;
use Laravel\Spark\Contracts\Http\Requests\Auth\RegisterRequest as Contract;
class StripeRegisterRequest extends RegisterRequest implements Contract
{
use ValidatesBillingAddresses;
/**
* 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;
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\API;
class CreateTokenRequest extends TokenRequest
{
//
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\API;
use Laravel\Spark\Spark;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Http\FormRequest;
class TokenRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validator for the request.
*
* @return \Illuminate\Validation\Validator
*/
public function validator()
{
return $this->validateAbilities(Validator::make($this->all(), [
'name' => 'required|max:255',
], $this->messages()));
}
/**
* 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;
}
/**
* Set custom messages for validator errors.
*
* @return array
*/
public function messages()
{
return [
'abilities.required' => 'Please select at least one ability.',
];
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\API;
class UpdateTokenRequest extends TokenRequest
{
//
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\PaymentMethod;
use Illuminate\Foundation\Http\FormRequest;
use Laravel\Spark\Contracts\Http\Requests\Settings\PaymentMethod\UpdatePaymentMethodRequest;
class UpdateBraintreePaymentMethodRequest extends FormRequest implements UpdatePaymentMethodRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'braintree_type' => 'required',
'braintree_token' => 'required',
];
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\PaymentMethod;
use Laravel\Spark\Spark;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Laravel\Spark\Http\Requests\ValidatesBillingAddresses;
use Laravel\Spark\Contracts\Http\Requests\Settings\PaymentMethod\UpdatePaymentMethodRequest;
class UpdateStripePaymentMethodRequest extends FormRequest implements UpdatePaymentMethodRequest
{
use ValidatesBillingAddresses;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validator for the request.
*
* @return \Illuminate\Validation\Validator
*/
public function validator()
{
$validator = Validator::make($this->all(), [
'stripe_token' => 'required',
]);
if (Spark::collectsBillingAddress()) {
$this->validateBillingAddress($validator);
}
return $validator;
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\Security;
use Illuminate\Foundation\Http\FormRequest;
class EnableTwoFactorAuthRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'country_code' => 'required|numeric',
'phone' => 'required|numeric',
];
}
/**
* Get data to be validated from the request.
*
* @return array
*/
protected function validationData()
{
if ($this->phone) {
$this->merge(['phone' => preg_replace('/[^0-9]/', '', $this->phone)]);
}
return $this->all();
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\Subscription;
use Laravel\Spark\Spark;
use Illuminate\Support\Facades\Validator;
use Laravel\Spark\Contracts\Http\Requests\Settings\Subscription\CreateSubscriptionRequest as Contract;
class CreateBraintreeSubscriptionRequest extends CreateSubscriptionRequest implements Contract
{
/**
* Get the validator for the request.
*
* @return \Illuminate\Validation\Validator
*/
public function validator()
{
$validator = Validator::make($this->all(), [
'braintree_type' => 'required',
'braintree_token' => 'required',
'plan' => 'required|in:'.Spark::activePlanIdList()
]);
return $validator->after(function ($validator) {
$this->validatePlanEligibility($validator);
if ($this->coupon) {
$this->validateCoupon($validator);
}
});
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\Subscription;
use Laravel\Spark\Spark;
use Illuminate\Support\Facades\Validator;
use Laravel\Spark\Http\Requests\ValidatesBillingAddresses;
use Laravel\Spark\Contracts\Http\Requests\Settings\Subscription\CreateSubscriptionRequest as Contract;
class CreateStripeSubscriptionRequest extends CreateSubscriptionRequest implements Contract
{
use ValidatesBillingAddresses;
/**
* Get the validator for the request.
*
* @return \Illuminate\Validation\Validator
*/
public function validator()
{
$validator = Validator::make($this->all(), [
'stripe_token' => 'required',
'plan' => 'required|in:'.Spark::activePlanIdList(),
'vat_id' => 'nullable|max:50|vat_id',
]);
if (Spark::collectsBillingAddress()) {
$this->validateBillingAddress($validator);
}
return $validator->after(function ($validator) {
$this->validatePlanEligibility($validator);
if ($this->coupon) {
$this->validateCoupon($validator);
}
});
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\Subscription;
use Illuminate\Foundation\Http\FormRequest;
use Laravel\Spark\Contracts\Repositories\CouponRepository;
class CreateSubscriptionRequest extends FormRequest
{
use DeterminesPlanEligibility;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Validate the coupon on the request.
*
* @param \Illuminate\Validation\Validator $validator
* @return void
*/
protected function validateCoupon($validator)
{
if (! app(CouponRepository::class)->valid($this->coupon)) {
$validator->errors()->add('coupon', 'This coupon code is invalid.');
}
}
}

View File

@@ -0,0 +1,113 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\Subscription;
use Laravel\Spark\Spark;
use Laravel\Spark\Exceptions\IneligibleForPlan;
trait DeterminesPlanEligibility
{
/**
* Validate that the plan is eligible based on team restrictions.
*
* @param \Illuminate\Validation\Validator $validator
* @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')
);
}
}
/**
* Determine if the user is eligible to move to a given plan.
*
* @param \Laravel\Spark\Plan $plan
* @return bool
*/
protected function userIsEligibleForPlan($plan)
{
return ! $this->exceedsMaximumTeams($plan) &&
! $this->exceedsMaximumTeamMembers($plan) &&
! $this->exceedsMaximumCollaborators($plan);
}
/**
* Determine if the user exceeds the maximum teams.
*
* @param \Laravel\Spark\Plan $plan
* @return bool
*/
protected function exceedsMaximumTeams($plan)
{
if (is_null($plan->teams)) {
return false;
}
return $plan->teams < $this->user()->ownedTeams()->count();
}
/**
* Determine if the user exceeds the maximum team members for the plan.
*
* @param \Laravel\Spark\Plan $plan
* @return bool
*/
protected function exceedsMaximumTeamMembers($plan)
{
if (is_null($plan->teamMembers)) {
return false;
}
return ! is_null($this->user()->teams->first(function ($team) use ($plan) {
return $plan->teamMembers < $team->totalPotentialUsers();
}));
}
/**
* Determine if the user exceeds the maximum total collaborators for the plan.
*
* @param \Laravel\Spark\Plan $plan
* @return bool
*/
protected function exceedsMaximumCollaborators($plan)
{
return ! is_null($plan->collaborators) &&
$plan->collaborators < $this->user()->totalPotentialCollaborators();
}
/**
* Call the custom plan eligibility checker callback.
*
* @param \Illuminate\Validation\Validator $validator
* @param \Laravel\Spark\Plan $plan
* @return void
*/
protected function callCustomCallback($validator, $plan)
{
try {
if (! Spark::eligibleForPlan($this->user(), $plan)) {
$validator->errors()->add('plan', 'You are not eligible for this plan.');
}
} catch (IneligibleForPlan $e) {
$validator->errors()->add('plan', $e->getMessage());
}
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\Subscription;
use Laravel\Spark\Spark;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Http\FormRequest;
class UpdateSubscriptionRequest extends FormRequest
{
use DeterminesPlanEligibility;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* 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);
});
}
}

View File

@@ -0,0 +1,131 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\Teams;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Http\FormRequest;
class CreateInvitationRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return $this->user()->ownsTeam($this->team);
}
/**
* Get the validator for the request.
*
* @return \Illuminate\Validation\Validator
*/
public function validator()
{
$validator = Validator::make($this->all(), [
'email' => 'required|email|max:255',
]);
$validator->after(function ($validator) {
$this->validateMaxTeamMembersNotExceeded($validator);
});
return $validator->after(function ($validator) {
return $this->verifyEmailNotAlreadyOnTeam($validator, $this->team)
->verifyEmailNotAlreadyInvited($validator, $this->team);
});
}
/**
* Verify that the maximum number of team members hasn't been exceeded.
*
* @param \Illuminate\Validation\Validator $validator
* @return void
*/
protected function validateMaxTeamMembersNotExceeded($validator)
{
if ($plan = $this->user()->sparkPlan()) {
$this->validateMaxTeamMembersNotExceededForPlan($validator, $plan);
}
if ($plan = $this->team->sparkPlan()) {
$this->validateMaxTeamMembersNotExceededForPlan($validator, $plan);
}
}
/**
* Verify the team member limit hasn't been exceeded for the given plan.
*
* @param \Illuminate\Validation\Validator $validator
* @param \Laravel\Spark\Plan $plan
* @return void
*/
protected function validateMaxTeamMembersNotExceededForPlan($validator, $plan)
{
if (is_null($plan->teamMembers) && is_null($plan->collaborators)) {
return;
}
if ($this->exceedsMaxTeamMembers($plan) || $this->exceedsMaxCollaborators($plan)) {
$validator->errors()->add('email', 'Please upgrade your subscription to add more team members.');
}
}
/**
* Determine if the request will exceed the max allowed team members.
*
* @param \Laravel\Spark\Plan $plan
* @return bool
*/
protected function exceedsMaxTeamMembers($plan)
{
return ! is_null($plan->teamMembers) &&
$plan->teamMembers <= $this->team->totalPotentialUsers();
}
/**
* Determine if the request will exceed the max allowed collaborators.
*
* @param \Laravel\Spark\Plan $plan
* @return bool
*/
protected function exceedsMaxCollaborators($plan)
{
return ! is_null($plan->collaborators) &&
$plan->collaborators <= $this->user()->totalPotentialCollaborators();
}
/**
* Verify that the given e-mail is not already on the team.
*
* @param \Illuminate\Validation\Validator $validator
* @param \Laravel\Spark\Team $team
* @return $this
*/
protected function verifyEmailNotAlreadyOnTeam($validator, $team)
{
if ($team->users()->where('email', $this->email)->exists()) {
$validator->errors()->add('email', 'That user is already on the team.');
}
return $this;
}
/**
* Verify that the given e-mail is not already invited.
*
* @param \Illuminate\Validation\Validator $validator
* @param \Laravel\Spark\Team $team
* @return $this
*/
protected function verifyEmailNotAlreadyInvited($validator, $team)
{
if ($team->invitations()->where('email', $this->email)->exists()) {
$validator->errors()->add('email', 'That user is already invited to the team.');
}
return $this;
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\Teams;
use Illuminate\Foundation\Http\FormRequest;
class RemoveTeamMemberRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
$team = $this->route('team');
$member = $this->route('team_member');
return ($this->user()->ownsTeam($team) && $this->user()->id !== $member->id) ||
(! $this->user()->ownsTeam($team) && $this->user()->id === $member->id);
}
/**
* Get the validation rules for the request.
*
* @return array
*/
public function rules()
{
return [];
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\Teams\Subscription;
use Laravel\Spark\Contracts\Http\Requests\Settings\Teams\Subscription\CreateSubscriptionRequest as Contract;
class CreateBraintreeSubscriptionRequest extends CreateSubscriptionRequest implements Contract
{
/**
* Get the validator for the request.
*
* @return \Illuminate\Validation\Validator
*/
public function validator()
{
return $this->baseValidator([
'braintree_type' => 'required',
'braintree_token' => 'required',
]);
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\Teams\Subscription;
use Laravel\Spark\Spark;
use Laravel\Spark\Http\Requests\ValidatesBillingAddresses;
use Laravel\Spark\Contracts\Http\Requests\Settings\Teams\Subscription\CreateSubscriptionRequest as Contract;
class CreateStripeSubscriptionRequest extends CreateSubscriptionRequest implements Contract
{
use ValidatesBillingAddresses;
/**
* Get the validator for the request.
*
* @return \Illuminate\Validation\Validator
*/
public function validator()
{
$validator = $this->baseValidator([
'stripe_token' => 'required',
'vat_id' => 'nullable|max:50|vat_id',
]);
if (Spark::collectsBillingAddress()) {
$this->validateBillingAddress($validator);
}
return $validator;
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\Teams\Subscription;
use Laravel\Spark\Spark;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Laravel\Spark\Contracts\Repositories\CouponRepository;
class CreateSubscriptionRequest extends FormRequest
{
use DeterminesTeamPlanEligibility;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return $this->user() && $this->user()->ownsTeam($this->route('team'));
}
/**
* Get the validator instance for the request.
*
* @param array $rules
* @return \Illuminate\Validation\Validator
*/
public function baseValidator(array $rules)
{
$validator = Validator::make($this->all(), array_merge([
'plan' => 'required|in:'.Spark::activeTeamPlanIdList()
], $rules));
return $validator->after(function ($validator) {
$this->validatePlanEligibility($validator);
if ($this->coupon) {
$this->validateCoupon($validator);
}
});
}
/**
* Validate the coupon on the request.
*
* @param \Illuminate\Validation\Validator $validator
* @return void
*/
protected function validateCoupon($validator)
{
if (! app(CouponRepository::class)->valid($this->coupon)) {
$validator->errors()->add('coupon', 'This coupon code is invalid.');
}
}
/**
* Get the Spark plan associated with the request.
*
* @return \Laravel\Spark\Plan
*/
public function plan()
{
return Spark::teamPlans()->where('id', $this->plan)->first();
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\Teams\Subscription;
use Laravel\Spark\Spark;
use Laravel\Spark\Exceptions\IneligibleForPlan;
trait DeterminesTeamPlanEligibility
{
/**
* Validate that the plan is eligible based on team restrictions.
*
* @param \Illuminate\Validation\Validator $validator
* @return void
*/
protected function validatePlanEligibility($validator)
{
$plan = Spark::teamPlans()->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->teamIsEligibleForPlan($this->route('team'), $plan)) {
$validator->errors()->add(
'plan', 'This team has too many team members for the selected plan.'
);
}
}
/**
* Determine if the team is eligible to move to a given plan.
*
* @param \Laravel\Spark\Team $team
* @param \Laravel\Spark\Plan $plan
* @return bool
*/
protected function teamIsEligibleForPlan($team, $plan)
{
return ! $this->exceedsMaximumTeamMembers($team, $plan);
}
/**
* Determine if the team exceeds the maximum team members for the plan.
*
* @param \Laravel\Spark\Team $team
* @param \Laravel\Spark\Plan $plan
* @return bool
*/
protected function exceedsMaximumTeamMembers($team, $plan)
{
return ! is_null($plan->teamMembers)
? $plan->teamMembers < $team->totalPotentialUsers() : false;
}
/**
* Call the custom plan eligibility checker callback.
*
* @param \Illuminate\Validation\Validator $validator
* @param \Laravel\Spark\Plan $plan
* @return void
*/
protected function callCustomCallback($validator, $plan)
{
try {
if (! Spark::eligibleForTeamPlan($this->route('team'), $plan)) {
$validator->errors()->add('plan', 'This team is not eligible for this plan.');
}
} catch (IneligibleForPlan $e) {
$validator->errors()->add('plan', $e->getMessage());
}
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\Teams\Subscription;
use Laravel\Spark\Spark;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Http\FormRequest;
class UpdateSubscriptionRequest extends FormRequest
{
use DeterminesTeamPlanEligibility;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return $this->user()->ownsTeam($this->route('team'));
}
/**
* Get the validator for the request.
*
* @return \Illuminate\Validation\Validator
*/
public function validator()
{
$validator = Validator::make($this->all(), [
'plan' => 'required|in:'.Spark::activeTeamPlanIdList()
]);
return $validator->after(function ($validator) {
$this->validatePlanEligibility($validator);
});
}
/**
* Get the Spark plan associated with the request.
*
* @return \Laravel\Spark\Plan
*/
public function plan()
{
return Spark::teamPlans()->where('id', $this->plan)->first();
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Laravel\Spark\Http\Requests\Settings\Teams;
use Illuminate\Foundation\Http\FormRequest;
class UpdateTeamPhotoRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return $this->user()->ownsTeam($this->route('team'));
}
/**
* Get the validation rules for the request.
*
* @return array
*/
public function rules()
{
return [
'photo' => 'required|image|max:4000'
];
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace Laravel\Spark\Http\Requests;
use Laravel\Spark\Services\Stripe as StripeService;
trait ValidatesBillingAddresses
{
/**
* Merges billing address validation rules into the given validator.
*
* @param \Illuminate\Validation\Validator $validator
* @return void
*/
protected function validateBillingAddress($validator)
{
$this->mergeCardCountryIntoRequest();
$validator->addRules([
'address' => 'required|max:255',
'address_line_2' => 'max:255',
'city' => 'required|max:255',
'state' => 'required|max:255|state:'.$this->country,
'zip' => 'required|max:25',
'country' => 'required|max:2|country',
]);
$validator->after(function ($validator) {
$this->validateLocation($validator);
});
}
/**
* Merge the billing card country into the request.
*
* @return void
*/
protected function mergeCardCountryIntoRequest()
{
if (! $this->stripe_token) {
return;
}
$this->merge(['card_country' => app(StripeService::class)->countryForToken(
$this->stripe_token
)]);
}
/**
* Validate that the request's location information agrees.
*
* @param \Illuminate\Validation\Validator $validator
* @return void
*/
protected function validateLocation($validator)
{
if (! app(StripeService::class)->tokenIsForCountry($this->stripe_token, $this->country)) {
$validator->errors()->add(
'country', 'This country does not match the origin country of your card.'
);
}
}
}