2021-03-08 15:19:45 +01:00
|
|
|
<?php
|
2021-03-10 01:08:58 +01:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2021-03-08 15:19:45 +01:00
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
namespace App\Http\Requests\Subscription;
|
2021-03-08 15:19:45 +01:00
|
|
|
|
|
|
|
use App\Http\Requests\Request;
|
2021-03-25 11:55:59 +01:00
|
|
|
use App\Models\Subscription;
|
2021-03-27 22:45:46 +01:00
|
|
|
use Illuminate\Validation\Rule;
|
2021-03-08 15:19:45 +01:00
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
class StoreSubscriptionRequest extends Request
|
2021-03-08 15:19:45 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
2021-03-25 11:55:59 +01:00
|
|
|
return auth()->user()->can('create', Subscription::class);
|
2021-03-08 15:19:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
2021-04-06 00:19:27 +02:00
|
|
|
$rules = [
|
2021-04-14 04:51:22 +02:00
|
|
|
'product_ids' => ['sometimes'],
|
|
|
|
'recurring_product_ids' => ['sometimes'],
|
2021-03-08 15:19:45 +01:00
|
|
|
'assigned_user_id' => ['sometimes'],
|
|
|
|
'is_recurring' => ['sometimes'],
|
2021-04-14 04:51:22 +02:00
|
|
|
'frequency_id' => ['required_with:recurring_product_ids'],
|
2021-03-08 15:19:45 +01:00
|
|
|
'auto_bill' => ['sometimes'],
|
|
|
|
'promo_code' => ['sometimes'],
|
|
|
|
'promo_discount' => ['sometimes'],
|
|
|
|
'is_amount_discount' => ['sometimes'],
|
|
|
|
'allow_cancellation' => ['sometimes'],
|
|
|
|
'per_set_enabled' => ['sometimes'],
|
|
|
|
'min_seats_limit' => ['sometimes'],
|
|
|
|
'max_seats_limit' => ['sometimes'],
|
|
|
|
'trial_enabled' => ['sometimes'],
|
|
|
|
'trial_duration' => ['sometimes'],
|
|
|
|
'allow_query_overrides' => ['sometimes'],
|
|
|
|
'allow_plan_changes' => ['sometimes'],
|
|
|
|
'refund_period' => ['sometimes'],
|
2021-03-30 11:41:58 +02:00
|
|
|
'webhook_configuration' => ['array'],
|
2021-04-01 11:56:50 +02:00
|
|
|
'name' => ['required', Rule::unique('subscriptions')->where('company_id', auth()->user()->company()->id)]
|
2021-03-08 15:19:45 +01:00
|
|
|
];
|
2021-04-06 00:19:27 +02:00
|
|
|
|
|
|
|
return $this->globalRules($rules);
|
|
|
|
|
2021-03-08 15:19:45 +01:00
|
|
|
}
|
2021-03-29 12:43:42 +02:00
|
|
|
|
|
|
|
protected function prepareForValidation()
|
|
|
|
{
|
|
|
|
$input = $this->all();
|
|
|
|
|
2021-04-06 00:21:55 +02:00
|
|
|
$input = $this->decodePrimaryKeys($input);
|
|
|
|
|
2021-03-29 12:43:42 +02:00
|
|
|
$this->replace($input);
|
|
|
|
}
|
2021-03-08 15:19:45 +01:00
|
|
|
}
|