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
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2021-03-10 01:08:58 +01:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2021-03-10 01:08:58 +01:00
|
|
|
*/
|
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()
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
$rules = [
|
|
|
|
'name' => ['required', Rule::unique('subscriptions')->where('company_id', auth()->user()->company()->id)],
|
2022-11-24 04:33:18 +01:00
|
|
|
'group_id' => ['bail','sometimes', 'nullable', Rule::exists('group_settings','id')->where('company_id', auth()->user()->company()->id)],
|
|
|
|
'assigned_user_id' => ['bail','sometimes', 'nullable', Rule::exists('users','id')->where('account_id', auth()->user()->account_id)],
|
|
|
|
'product_ids' => 'bail|sometimes|nullable|string',
|
|
|
|
'recurring_product_ids' => 'bail|sometimes|nullable|string',
|
|
|
|
'is_recurring' => 'bail|sometimes|bool',
|
|
|
|
'frequency_id' => 'bail|required_with:recurring_product_ids',
|
|
|
|
'auto_bill' => 'bail|sometimes|nullable|string',
|
|
|
|
'promo_code' => 'bail|sometimes|nullable|string',
|
|
|
|
'promo_discount' => 'bail|sometimes|numeric',
|
|
|
|
'is_amount_discount' => 'bail|sometimes|bool',
|
|
|
|
'allow_cancellation' => 'bail|sometimes|bool',
|
|
|
|
'per_set_enabled' => 'bail|sometimes|bool',
|
|
|
|
'min_seats_limit' => 'bail|sometimes|numeric',
|
|
|
|
'max_seats_limit' => 'bail|sometimes|numeric',
|
|
|
|
'trial_enabled' => 'bail|sometimes|bool',
|
|
|
|
'trial_duration' => 'bail|sometimes|numeric',
|
|
|
|
'allow_query_overrides' => 'bail|sometimes|bool',
|
|
|
|
'allow_plan_changes' => 'bail|sometimes|bool',
|
|
|
|
'refund_period' => 'bail|sometimes|numeric',
|
|
|
|
'webhook_configuration' => 'bail|array',
|
|
|
|
'webhook_configuration.post_purchase_url' => 'bail|sometimes|nullable|string',
|
|
|
|
'webhook_configuration.post_purchase_rest_method' => 'bail|sometimes|nullable|string',
|
|
|
|
'webhook_configuration.post_purchase_headers' => 'bail|sometimes|array',
|
|
|
|
'registration_required' => 'bail|sometimes|bool',
|
|
|
|
'optional_recurring_product_ids' => 'bail|sometimes|nullable|string',
|
|
|
|
'optional_product_ids' => 'bail|sometimes|nullable|string',
|
|
|
|
'use_inventory_management' => 'bail|sometimes|bool'
|
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
|
|
|
|
2022-06-24 03:55:41 +02:00
|
|
|
public function prepareForValidation()
|
2021-03-29 12:43:42 +02:00
|
|
|
{
|
|
|
|
$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
|
|
|
}
|