1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Client Subscription scaffolding

This commit is contained in:
David Bomba 2021-03-10 11:08:58 +11:00
parent c863a2defd
commit 00eefcd781
32 changed files with 960 additions and 4 deletions

View File

@ -0,0 +1,410 @@
<?php
/**
* 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
*/
namespace App\Http\Controllers;
use App\Events\ClientSubscription\ClientSubscriptionWasCreated;
use App\Factory\ClientSubscriptionFactory;
use App\Http\Requests\ClientSubscription\CreateClientSubscriptionRequest;
use App\Http\Requests\ClientSubscription\DestroyClientSubscriptionRequest;
use App\Http\Requests\ClientSubscription\EditClientSubscriptionRequest;
use App\Http\Requests\ClientSubscription\ShowClientSubscriptionRequest;
use App\Http\Requests\ClientSubscription\StoreClientSubscriptionRequest;
use App\Http\Requests\ClientSubscription\UpdateClientSubscriptionRequest;
use App\Models\ClientSubscription;
use App\Repositories\ClientSubscriptionRepository;
use App\Transformers\ClientSubscriptionTransformer;
use App\Utils\Ninja;
class ClientSubscriptionController extends BaseController
{
protected $entity_type = ClientSubscription::class;
protected $entity_transformer = ClientSubscriptionTransformer::class;
protected $client_subscription_repo;
public function __construct(ClientSubscriptionRepository $client_subscription_repo)
{
parent::__construct();
$this->client_subscription_repo = $client_subscription_repo;
}
/**
* Show the list of ClientSubscriptions.
*
* @return Response
*
* @OA\Get(
* path="/api/v1/client_subscriptions",
* operationId="getClientSubscriptions",
* tags={"client_subscriptions"},
* summary="Gets a list of client_subscriptions",
* description="Lists client_subscriptions.",
*
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Response(
* response=200,
* description="A list of client_subscriptions",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/ClientSubscription"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function index(): \Illuminate\Http\Response
{
$client_subscriptions = ClientSubscription::query()->company();
return $this->listResponse($client_subscriptions);
}
/**
* Show the form for creating a new resource.
*
* @param CreateClientSubscriptionRequest $request The request
*
* @return Response
*
*
* @OA\Get(
* path="/api/v1/client_subscriptions/create",
* operationId="getClientSubscriptionsCreate",
* tags={"client_subscriptions"},
* summary="Gets a new blank client_subscriptions object",
* description="Returns a blank object with default values",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Response(
* response=200,
* description="A blank client_subscriptions object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/ClientSubscription"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function create(CreateClientSubscriptionRequest $request): \Illuminate\Http\Response
{
$client_subscription = ClientSubscriptionFactory::create(auth()->user()->company()->id, auth()->user()->id);
return $this->itemResponse($client_subscription);
}
/**
* Store a newly created resource in storage.
*
* @param StoreClientSubscriptionRequest $request The request
*
* @return Response
*
*
* @OA\Post(
* path="/api/v1/client_subscriptions",
* operationId="storeClientSubscription",
* tags={"client_subscriptions"},
* summary="Adds a client_subscriptions",
* description="Adds an client_subscriptions to the system",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Response(
* response=200,
* description="Returns the saved client_subscriptions object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/ClientSubscription"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function store(StoreClientSubscriptionRequest $request): \Illuminate\Http\Response
{
$client_subscription = $this->client_subscription_repo->save($request->all(), ClientSubscriptionFactory::create(auth()->user()->company()->id, auth()->user()->id));
event(new ClientsubscriptionWasCreated($client_subscription, $client_subscription->company, Ninja::eventVars()));
return $this->itemResponse($client_subscription);
}
/**
* Display the specified resource.
*
* @param ShowClientSubscriptionRequest $request The request
* @param Invoice $client_subscription The invoice
*
* @return Response
*
*
* @OA\Get(
* path="/api/v1/client_subscriptions/{id}",
* operationId="showClientSubscription",
* tags={"client_subscriptions"},
* summary="Shows an client_subscriptions",
* description="Displays an client_subscriptions by id",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The ClientSubscription Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns the ClientSubscription object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/ClientSubscription"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function show(ShowClientSubscriptionRequest $request, ClientSubscription $client_subscription): \Illuminate\Http\Response
{
return $this->itemResponse($client_subscription);
}
/**
* Show the form for editing the specified resource.
*
* @param EditClientSubscriptionRequest $request The request
* @param Invoice $client_subscription The invoice
*
* @return Response
*
* @OA\Get(
* path="/api/v1/client_subscriptions/{id}/edit",
* operationId="editClientSubscription",
* tags={"client_subscriptions"},
* summary="Shows an client_subscriptions for editting",
* description="Displays an client_subscriptions by id",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The ClientSubscription Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns the invoice object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/ClientSubscription"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function edit(EditClientSubscriptionRequest $request, ClientSubscription $client_subscription): \Illuminate\Http\Response
{
return $this->itemResponse($client_subscription);
}
/**
* Update the specified resource in storage.
*
* @param UpdateClientSubscriptionRequest $request The request
* @param ClientSubscription $client_subscription The invoice
*
* @return Response
*
*
* @OA\Put(
* path="/api/v1/client_subscriptions/{id}",
* operationId="updateClientSubscription",
* tags={"client_subscriptions"},
* summary="Updates an client_subscriptions",
* description="Handles the updating of an client_subscriptions by id",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The ClientSubscription Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns the client_subscriptions object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/ClientSubscription"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function update(UpdateClientSubscriptionRequest $request, ClientSubscription $client_subscription)
{
if ($request->entityIsDeleted($client_subscription)) {
return $request->disallowUpdate();
}
$client_subscription = $this->client_subscription_repo->save($request->all(), $client_subscription);
return $this->itemResponse($client_subscription);
}
/**
* Remove the specified resource from storage.
*
* @param DestroyClientSubscriptionRequest $request
* @param ClientSubscription $invoice
*
* @return Response
*
* @throws \Exception
* @OA\Delete(
* path="/api/v1/client_subscriptions/{id}",
* operationId="deleteClientSubscription",
* tags={"client_subscriptions"},
* summary="Deletes a client_subscriptions",
* description="Handles the deletion of an client_subscriptions by id",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The ClientSubscription Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns a HTTP status",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function destroy(DestroyClientSubscriptionRequest $request, ClientSubscription $client_subscription): \Illuminate\Http\Response
{
$this->client_subscription_repo->delete($client_subscription);
return $this->itemResponse($client_subscription->fresh());
}
}

View File

@ -26,7 +26,10 @@
* @OA\Property(property="plan_map", type="string", example="1", description="map describing the available upgrade/downgrade plans for this subscription"),
* @OA\Property(property="refund_period", type="integer", example="2", description="______"),
* @OA\Property(property="webhook_configuration", type="string", example="2", description="______"),
* @OA\Property(property="is_deleted", type="boolean", example="2", description="______"),
* @OA\Property(property="is_deleted", type="boolean", example="true", description="______"),
* @OA\Property(property="archived_at", type="number", format="integer", example="1434342123", description="Timestamp"),
* @OA\Property(property="created_at", type="number", format="integer", example="134341234234", description="Timestamp"),
* @OA\Property(property="updated_at", type="number", format="integer", example="134341234234", description="Timestamp"),
* )
*/

View File

@ -0,0 +1,19 @@
<?php
/**
* @OA\Schema(
* schema="ClientSubscription",
* type="object",
* @OA\Property(property="id", type="string", example="Opnel5aKBz", description="______"),
* @OA\Property(property="subscription_id", type="string", example="Opnel5aKBz", description="______"),
* @OA\Property(property="recurring_invoice_id", type="string", example="Opnel5aKBz", description="______"),
* @OA\Property(property="company_id", type="string", example="Opnel5aKBz", description="______"),
* @OA\Property(property="client_id", type="string", example="Opnel5aKBz", description="______"),
* @OA\Property(property="trial_started", type="string", example="10-10-2021", description="______"),
* @OA\Property(property="trial_ends", type="string", example="12-10-2021", description="______"),
* @OA\Property(property="is_deleted", type="boolean", example="true", description="______"),
* @OA\Property(property="archived_at", type="number", format="integer", example="1434342123", description="Timestamp"),
* @OA\Property(property="created_at", type="number", format="integer", example="134341234234", description="Timestamp"),
* @OA\Property(property="updated_at", type="number", format="integer", example="134341234234", description="Timestamp"),
* )
*/

View File

@ -1,4 +1,13 @@
<?php
/**
* 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
*/
namespace App\Http\Requests\BillingSubscription;

View File

@ -1,4 +1,13 @@
<?php
/**
* 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
*/
namespace App\Http\Requests\BillingSubscription;

View File

@ -1,4 +1,13 @@
<?php
/**
* 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
*/
namespace App\Http\Requests\BillingSubscription;

View File

@ -1,4 +1,13 @@
<?php
/**
* 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
*/
namespace App\Http\Requests\BillingSubscription;

View File

@ -1,4 +1,13 @@
<?php
/**
* 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
*/
namespace App\Http\Requests\BillingSubscription;

View File

@ -1,4 +1,13 @@
<?php
/**
* 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
*/
namespace App\Http\Requests\BillingSubscription;

View File

@ -0,0 +1,40 @@
<?php
/**
* 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
*/
namespace App\Http\Requests\ClientSubscription;
use App\Http\Requests\Request;
use App\Models\ClientSubscription;
class CreateClientSubscriptionRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return auth()->user()->can('create', ClientSubscription::class);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* 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
*/
namespace App\Http\Requests\ClientSubscription;
use App\Http\Requests\Request;
use Illuminate\Foundation\Http\FormRequest;
class DestroyClientSubscriptionRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->user()->can('edit', $this->client_subscription);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* 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
*/
namespace App\Http\Requests\ClientSubscription;
use App\Http\Requests\Request;
use Illuminate\Foundation\Http\FormRequest;
class EditClientSubscriptionRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->user()->can('edit', $this->client_subscription);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* 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
*/
namespace App\Http\Requests\ClientSubscription;
use App\Http\Requests\Request;
use Illuminate\Foundation\Http\FormRequest;
class ShowClientSubscriptionRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('view', $this->client_subscription);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* 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
*/
namespace App\Http\Requests\ClientSubscription;
use App\Http\Requests\Request;
use App\Models\ClientSubscription;
class StoreClientSubscriptionRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->user()->can('create', ClientSubscription::class);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [];
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* 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
*/
namespace App\Http\Requests\ClientSubscription;
use App\Http\Requests\Request;
use App\Utils\Traits\ChecksEntityStatus;
class UpdateClientSubscriptionRequest extends Request
{
use ChecksEntityStatus;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->user()->can('edit', $this->client_subscription);
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

View File

@ -70,6 +70,10 @@ class Request extends FormRequest
public function decodePrimaryKeys($input)
{
if (array_key_exists('subscription_id', $input) && is_string($input['subscription_id'])) {
$input['subscription_id'] = $this->decodePrimaryKey($input['subscription_id']);
}
if (array_key_exists('assigned_user_id', $input) && is_string($input['assigned_user_id'])) {
$input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']);
}

View File

@ -9,13 +9,47 @@
* @license https://opensource.org/licenses/AAL
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ClientSubscription extends Model
class ClientSubscription extends BaseModel
{
use HasFactory;
protected $fillable = [
// 'subscription_id',
// 'recurring_invoice_id',
// 'client_id',
// 'trial_started',
// 'trial_ends',
// 'is_deleted',
];
protected $casts = [
'is_deleted' => 'boolean',
'updated_at' => 'timestamp',
'created_at' => 'timestamp',
'deleted_at' => 'timestamp',
];
public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Company::class);
}
public function recurring_invoice(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(RecurringInvoice::class);
}
public function client(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Client::class);
}
public function subscription(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(BillingSubscription::class);
}
}

View File

@ -159,6 +159,16 @@ class Company extends BaseModel
return $this->hasMany(ExpenseCategory::class)->withTrashed();
}
public function client_subscriptions()
{
return $this->hasMany(ClientSubscription::class)->withTrashed();
}
public function billing_subscriptions()
{
return $this->hasMany(BillingSubscription::class)->withTrashed();
}
public function task_statuses()
{
return $this->hasMany(TaskStatus::class)->withTrashed();

View File

@ -77,6 +77,7 @@ class Credit extends BaseModel
'design_id',
'assigned_user_id',
'exchange_rate',
'subscription_id',
];
protected $casts = [

View File

@ -91,6 +91,7 @@ class Invoice extends BaseModel
'design_id',
'assigned_user_id',
'exchange_rate',
'subscription_id',
];
protected $casts = [

View File

@ -78,6 +78,7 @@ class Quote extends BaseModel
'design_id',
'assigned_user_id',
'exchange_rate',
'subscription_id',
];
protected $casts = [

View File

@ -0,0 +1,31 @@
<?php
/**
* 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
*/
namespace App\Policies;
use App\Models\User;
/**
* Class ClientSubscriptionPolicy.
*/
class ClientSubscriptionPolicy extends EntityPolicy
{
/**
* Checks if the user has create permissions.
*
* @param User $user
* @return bool
*/
public function create(User $user) : bool
{
return $user->isAdmin() || $user->hasPermission('create_client_subscription') || $user->hasPermission('create_all');
}
}

View File

@ -14,6 +14,7 @@ namespace App\Providers;
use App\Models\Activity;
use App\Models\BillingSubscription;
use App\Models\Client;
use App\Models\ClientSubscription;
use App\Models\Company;
use App\Models\CompanyGateway;
use App\Models\CompanyToken;
@ -40,6 +41,7 @@ use App\Models\Webhook;
use App\Policies\ActivityPolicy;
use App\Policies\BillingSubscriptionPolicy;
use App\Policies\ClientPolicy;
use App\Policies\ClientSubscriptionPolicy;
use App\Policies\CompanyGatewayPolicy;
use App\Policies\CompanyPolicy;
use App\Policies\CompanyTokenPolicy;
@ -77,6 +79,7 @@ class AuthServiceProvider extends ServiceProvider
Activity::class => ActivityPolicy::class,
BillingSubscription::class => BillingSubscriptionPolicy::class,
Client::class => ClientPolicy::class,
ClientSubscription::class => ClientSubscriptionPolicy::class,
Company::class => CompanyPolicy::class,
CompanyToken::class => CompanyTokenPolicy::class,
CompanyGateway::class => CompanyGatewayPolicy::class,

View File

@ -0,0 +1,28 @@
<?php
/**
* 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
*/
namespace App\Repositories;
use App\Models\ClientSubscription;
class ClientSubscriptionRepository extends BaseRepository
{
public function save($data, ClientSubscription $client_subscription): ?ClientSubscription
{
$client_subscription
->fill($data)
->save();
return $client_subscription;
}
}

View File

@ -0,0 +1,78 @@
<?php
/**
* 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
*/
namespace App\Transformers;
use App\Models\BillingSubscription;
use App\Models\Client;
use App\Models\ClientSubscription;
use App\Models\RecurringInvoice;
use App\Utils\Traits\MakesHash;
class ClientSubscriptionTransformer extends EntityTransformer
{
use MakesHash;
/**
* @var array
*/
protected $defaultIncludes = [];
/**
* @var array
*/
protected $availableIncludes = [
'client',
'recurring_invoice',
'subscription',
];
public function transform(ClientSubscription $client_subscription): array
{
return [
'id' => $this->encodePrimaryKey($client_subscription->id),
'subscription_id' => $this->encodePrimaryKey($client_subscription->subscription_id),
'company_id' => $this->encodePrimaryKey($client_subscription->company_id),
'recurring_invoice_id' => $this->encodePrimaryKey($client_subscription->recurring_invoice_id),
'client_id' => $this->encodePrimaryKey($client_subscription->client_id),
'trial_started' => (string)$client_subscription->trial_started ?: '',
'trial_ends' => (string)$client_subscription->trial_ends ?: '',
'is_deleted' => (bool)$client_subscription->is_deleted,
'created_at' => (int)$client_subscription->created_at,
'updated_at' => (int)$client_subscription->updated_at,
'archived_at' => (int)$client_subscription->deleted_at,
];
}
public function includeClient(ClientSubscription $client_subscription): \League\Fractal\Resource\Item
{
$transformer = new ClientTransformer($this->serializer);
return $this->includeItem($client_subscription->client, $transformer, Client::class);
}
public function includeRecurringInvoice(ClientSubscription $client_subscription): \League\Fractal\Resource\Item
{
$transformer = new RecurringInvoiceTransformer($this->serializer);
return $this->includeItem($client_subscription->recurring_invoice, $transformer, RecurringInvoice::class);
}
public function includeSubscription(ClientSubscription $client_subscription): \League\Fractal\Resource\Item
{
$transformer = new BillingSubscriptionTransformer($this->serializer);
return $this->includeItem($client_subscription->subscription, $transformer, BillingSubscription::class);
}
}

View File

@ -13,7 +13,9 @@ namespace App\Transformers;
use App\Models\Account;
use App\Models\Activity;
use App\Models\BillingSubscription;
use App\Models\Client;
use App\Models\ClientSubscription;
use App\Models\Company;
use App\Models\CompanyGateway;
use App\Models\CompanyLedger;
@ -90,6 +92,7 @@ class CompanyTransformer extends EntityTransformer
'system_logs',
'expense_categories',
'task_statuses',
'client_subscriptions',
];
/**
@ -358,4 +361,18 @@ class CompanyTransformer extends EntityTransformer
return $this->includeCollection($company->system_logs, $transformer, SystemLog::class);
}
public function includeClientSubscriptions(Company $company)
{
$transformer = new ClientSubscriptionTransformer($this->serializer);
return $this->includeCollection($company->client_subscriptions, $transformer, ClientSubscription::class);
}
public function includeBillingSubscriptions(Company $company)
{
$transformer = new BillingSubscriptionTransformer($this->serializer);
return $this->includeCollection($company->billing_subscriptions, $transformer, BillingSubscription::class);
}
}

View File

@ -137,6 +137,7 @@ class CreditTransformer extends EntityTransformer
'entity_type' => 'credit',
'exchange_rate' => (float) $credit->exchange_rate,
'paid_to_date' => (float) $credit->paid_to_date,
'subscription_id' => $this->encodePrimaryKey($credit->subscription_id),
];
}
}

View File

@ -141,6 +141,7 @@ class InvoiceTransformer extends EntityTransformer
'reminder3_sent' => $invoice->reminder3_sent ?: '',
'reminder_last_sent' => $invoice->reminder_last_sent ?: '',
'paid_to_date' => (float) $invoice->paid_to_date,
'subscription_id' => $this->encodePrimaryKey($invoice->subscription_id),
];
}

View File

@ -139,6 +139,8 @@ class QuoteTransformer extends EntityTransformer
'exchange_rate' => (float) $quote->exchange_rate,
'paid_to_date' => (float) $quote->paid_to_date,
'project_id' => $this->encodePrimaryKey($quote->project_id),
'subscription_id' => $this->encodePrimaryKey($quote->subscription_id),
];
}
}

View File

@ -46,15 +46,20 @@ class CreateBillingSubscriptionsTable extends Migration
Schema::create('client_subscriptions', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('company_id');
$table->unsignedInteger('subscription_id');
$table->unsignedInteger('recurring_invoice_id');
$table->unsignedInteger('client_id');
$table->unsignedInteger('trial_started')->nullable();
$table->unsignedInteger('trial_ends')->nullable();
$table->boolean('is_deleted')->default(false);
$table->softDeletes('deleted_at', 6);
$table->timestamps();
$table->foreign('subscription_id')->references('id')->on('billing_subscriptions');
$table->foreign('recurring_invoice_id')->references('id')->on('recurring_invoices');
$table->foreign('client_id')->references('id')->on('clients');
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->index(['company_id', 'deleted_at']);
});
}

View File

@ -16,6 +16,18 @@ class AddCurrencyIdToBillingSubscriptionsTable extends Migration
Schema::table('billing_subscriptions', function (Blueprint $table) {
$table->unsignedInteger('currency_id')->nullable();
});
Schema::table('invoices', function (Blueprint $table) {
$table->unsignedInteger('subscription_id')->nullable();
});
Schema::table('quotes', function (Blueprint $table) {
$table->unsignedInteger('subscription_id')->nullable();
});
Schema::table('credits', function (Blueprint $table) {
$table->unsignedInteger('subscription_id')->nullable();
});
}
/**

View File

@ -174,6 +174,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
// Route::delete('hooks/{subscription_id}', 'SubscriptionController@unsubscribe')->name('hooks.unsubscribe');
Route::resource('billing_subscriptions', 'BillingSubscriptionController');
Route::resource('cliente_subscriptions', 'ClientSubscriptionController');
});
Route::match(['get', 'post'], 'payment_webhook/{company_key}/{company_gateway_id}', 'PaymentWebhookController')