Subscriptions (#5248)

* Fixes for converting quote to invoice

* Fixes for naming PDFs

* Refresh entity prior to sending

* Fixes for subscriptions

* Add in required use

* Fixes for notifications

* Fixes for notifications

* Add with trasheD

* Rename BillingSubscriptions to Subscriptions

* Refactoring subscriptions
This commit is contained in:
David Bomba 2021-03-25 21:55:59 +11:00 committed by GitHub
parent 64a43fbb51
commit abd3a89bc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 365 additions and 343 deletions

View File

@ -11,7 +11,7 @@
namespace App\Console; namespace App\Console;
use App\Jobs\Cron\BillingSubscriptionCron; use App\Jobs\Cron\SubscriptionCron;
use App\Jobs\Cron\RecurringInvoicesCron; use App\Jobs\Cron\RecurringInvoicesCron;
use App\Jobs\Ninja\AdjustEmailQuota; use App\Jobs\Ninja\AdjustEmailQuota;
use App\Jobs\Ninja\CompanySizeCheck; use App\Jobs\Ninja\CompanySizeCheck;
@ -54,7 +54,7 @@ class Kernel extends ConsoleKernel
$schedule->job(new UpdateExchangeRates)->daily()->withoutOverlapping(); $schedule->job(new UpdateExchangeRates)->daily()->withoutOverlapping();
$schedule->job(new BillingSubscriptionCron)->daily()->withoutOverlapping(); $schedule->job(new SubscriptionCron)->daily()->withoutOverlapping();
$schedule->job(new RecurringInvoicesCron)->hourly()->withoutOverlapping(); $schedule->job(new RecurringInvoicesCron)->hourly()->withoutOverlapping();

View File

@ -13,12 +13,12 @@
namespace App\DataMapper\Billing; namespace App\DataMapper\Billing;
class BillingContextMapper class SubscriptionContextMapper
{ {
/** /**
* @var int * @var int
*/ */
public $billing_subscription_id; public $subscription_id;
/** /**
* @var string * @var string
@ -39,7 +39,7 @@ class BillingContextMapper
* @var string[] * @var string[]
*/ */
public $casts = [ public $casts = [
'billing_subscription_id' => 'integer', 'subscription_id' => 'integer',
'email' => 'string', 'email' => 'string',
'client_id' => 'integer', 'client_id' => 'integer',
'invoice_id' => 'integer', 'invoice_id' => 'integer',

View File

@ -109,7 +109,7 @@ class CompanySettings extends BaseSettings
public $shared_invoice_quote_counter = false; //@implemented public $shared_invoice_quote_counter = false; //@implemented
public $shared_invoice_credit_counter = false; //@implemented public $shared_invoice_credit_counter = false; //@implemented
public $recurring_number_prefix = 'R'; //@implemented public $recurring_number_prefix = ''; //@implemented
public $reset_counter_frequency_id = '0'; //@implemented public $reset_counter_frequency_id = '0'; //@implemented
public $reset_counter_date = ''; //@implemented public $reset_counter_date = ''; //@implemented
public $counter_padding = 4; //@implemented public $counter_padding = 4; //@implemented

View File

@ -1,8 +1,8 @@
<?php <?php
namespace App\Events\BillingSubscription; namespace App\Events\Subscription;
use App\Models\BillingSubscription; use App\Models\Subscription;
use App\Models\Company; use App\Models\Company;
use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\InteractsWithSockets;
@ -12,14 +12,14 @@ use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
class BillingSubscriptionWasCreated class SubscriptionWasCreated
{ {
use Dispatchable, InteractsWithSockets, SerializesModels; use Dispatchable, InteractsWithSockets, SerializesModels;
/** /**
* @var BillingSubscription * @var Subscription
*/ */
public $billing_subscription; public $subscription;
/** /**
* @var Company * @var Company
@ -36,9 +36,9 @@ class BillingSubscriptionWasCreated
* *
* @return void * @return void
*/ */
public function __construct(BillingSubscription $billing_subscription, Company $company, array $event_vars) public function __construct(Subscription $subscription, Company $company, array $event_vars)
{ {
$this->billing_subscription = $billing_subscription; $this->subscription = $subscription;
$this->company = $company; $this->company = $company;
$this->event_vars = $event_vars; $this->event_vars = $event_vars;
} }

View File

@ -11,14 +11,13 @@
namespace App\Factory; namespace App\Factory;
use App\Models\Subscription;
use App\Models\BillingSubscription; class SubscriptionFactory
class BillingSubscriptionFactory
{ {
public static function create(int $company_id, int $user_id): BillingSubscription public static function create(int $company_id, int $user_id): Subscription
{ {
$billing_subscription = new BillingSubscription(); $billing_subscription = new Subscription();
$billing_subscription->company_id = $company_id; $billing_subscription->company_id = $company_id;
$billing_subscription->user_id = $user_id; $billing_subscription->user_id = $user_id;

View File

@ -13,23 +13,23 @@
namespace App\Http\Controllers\ClientPortal; namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\BillingSubscription; use App\Models\Subscription;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str; use Illuminate\Support\Str;
class BillingSubscriptionPurchaseController extends Controller class SubscriptionPurchaseController extends Controller
{ {
public function index(BillingSubscription $billing_subscription, Request $request) public function index(Subscription $subscription, Request $request)
{ {
if ($request->has('locale')) { if ($request->has('locale')) {
$this->setLocale($request->query('locale')); $this->setLocale($request->query('locale'));
} }
return view('billing-portal.purchase', [ return view('billing-portal.purchase', [
'billing_subscription' => $billing_subscription, 'subscription' => $subscription,
'hash' => Str::uuid()->toString(), 'hash' => Str::uuid()->toString(),
'request_data' => $request->all(), 'request_data' => $request->all(),
]); ]);

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* @OA\Schema( * @OA\Schema(
* schema="BillingSubscription", * schema="Subscription",
* type="object", * type="object",
* @OA\Property(property="id", type="string", example="Opnel5aKBz", description="______"), * @OA\Property(property="id", type="string", example="Opnel5aKBz", description="______"),
* @OA\Property(property="user_id", type="string", example="Opnel5aKBz", description="______"), * @OA\Property(property="user_id", type="string", example="Opnel5aKBz", description="______"),

View File

@ -12,45 +12,45 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Events\BillingSubscription\BillingSubscriptionWasCreated; use App\Events\Subscription\SubscriptionWasCreated;
use App\Factory\BillingSubscriptionFactory; use App\Factory\SubscriptionFactory;
use App\Http\Requests\BillingSubscription\CreateBillingSubscriptionRequest; use App\Http\Requests\Subscription\CreateSubscriptionRequest;
use App\Http\Requests\BillingSubscription\DestroyBillingSubscriptionRequest; use App\Http\Requests\Subscription\DestroySubscriptionRequest;
use App\Http\Requests\BillingSubscription\EditBillingSubscriptionRequest; use App\Http\Requests\Subscription\EditSubscriptionRequest;
use App\Http\Requests\BillingSubscription\ShowBillingSubscriptionRequest; use App\Http\Requests\Subscription\ShowSubscriptionRequest;
use App\Http\Requests\BillingSubscription\StoreBillingSubscriptionRequest; use App\Http\Requests\Subscription\StoreSubscriptionRequest;
use App\Http\Requests\BillingSubscription\UpdateBillingSubscriptionRequest; use App\Http\Requests\Subscription\UpdateSubscriptionRequest;
use App\Models\BillingSubscription; use App\Models\Subscription;
use App\Repositories\BillingSubscriptionRepository; use App\Repositories\SubscriptionRepository;
use App\Transformers\BillingSubscriptionTransformer; use App\Transformers\SubscriptionTransformer;
use App\Utils\Ninja; use App\Utils\Ninja;
class BillingSubscriptionController extends BaseController class SubscriptionController extends BaseController
{ {
protected $entity_type = BillingSubscription::class; protected $entity_type = Subscription::class;
protected $entity_transformer = BillingSubscriptionTransformer::class; protected $entity_transformer = SubscriptionTransformer::class;
protected $billing_subscription_repo; protected $subscription_repo;
public function __construct(BillingSubscriptionRepository $billing_subscription_repo) public function __construct(SubscriptionRepository $subscription_repo)
{ {
parent::__construct(); parent::__construct();
$this->billing_subscription_repo = $billing_subscription_repo; $this->subscription_repo = $subscription_repo;
} }
/** /**
* Show the list of BillingSubscriptions. * Show the list of Subscriptions.
* *
* @return Response * @return Response
* *
* @OA\Get( * @OA\Get(
* path="/api/v1/billing_subscriptions", * path="/api/v1/subscriptions",
* operationId="getBillingSubscriptions", * operationId="getSubscriptions",
* tags={"billing_subscriptions"}, * tags={"subscriptions"},
* summary="Gets a list of billing_subscriptions", * summary="Gets a list of subscriptions",
* description="Lists billing_subscriptions.", * description="Lists subscriptions.",
* *
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"), * @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
@ -58,11 +58,11 @@ class BillingSubscriptionController extends BaseController
* @OA\Parameter(ref="#/components/parameters/include"), * @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Response( * @OA\Response(
* response=200, * response=200,
* description="A list of billing_subscriptions", * description="A list of subscriptions",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), * @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-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/BillingSubscription"), * @OA\JsonContent(ref="#/components/schemas/Subscription"),
* ), * ),
* @OA\Response( * @OA\Response(
* response=422, * response=422,
@ -79,24 +79,24 @@ class BillingSubscriptionController extends BaseController
public function index(): \Illuminate\Http\Response public function index(): \Illuminate\Http\Response
{ {
$billing_subscriptions = BillingSubscription::query()->company(); $subscriptions = Subscription::query()->company();
return $this->listResponse($billing_subscriptions); return $this->listResponse($subscriptions);
} }
/** /**
* Show the form for creating a new resource. * Show the form for creating a new resource.
* *
* @param CreateBillingSubscriptionRequest $request The request * @param CreateSubscriptionRequest $request The request
* *
* @return Response * @return Response
* *
* *
* @OA\Get( * @OA\Get(
* path="/api/v1/billing_subscriptions/create", * path="/api/v1/subscriptions/create",
* operationId="getBillingSubscriptionsCreate", * operationId="getSubscriptionsCreate",
* tags={"billing_subscriptions"}, * tags={"subscriptions"},
* summary="Gets a new blank billing_subscriptions object", * summary="Gets a new blank subscriptions object",
* description="Returns a blank object with default values", * description="Returns a blank object with default values",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"), * @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
@ -104,11 +104,11 @@ class BillingSubscriptionController extends BaseController
* @OA\Parameter(ref="#/components/parameters/include"), * @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Response( * @OA\Response(
* response=200, * response=200,
* description="A blank billing_subscriptions object", * description="A blank subscriptions object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), * @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-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/BillingSubscription"), * @OA\JsonContent(ref="#/components/schemas/Subscription"),
* ), * ),
* @OA\Response( * @OA\Response(
* response=422, * response=422,
@ -123,38 +123,38 @@ class BillingSubscriptionController extends BaseController
* ), * ),
* ) * )
*/ */
public function create(CreateBillingSubscriptionRequest $request): \Illuminate\Http\Response public function create(CreateSubscriptionRequest $request): \Illuminate\Http\Response
{ {
$billing_subscription = BillingSubscriptionFactory::create(auth()->user()->company()->id, auth()->user()->id); $subscription = SubscriptionFactory::create(auth()->user()->company()->id, auth()->user()->id);
return $this->itemResponse($billing_subscription); return $this->itemResponse($subscription);
} }
/** /**
* Store a newly created resource in storage. * Store a newly created resource in storage.
* *
* @param StoreBillingSubscriptionRequest $request The request * @param StoreSubscriptionRequest $request The request
* *
* @return Response * @return Response
* *
* *
* @OA\Post( * @OA\Post(
* path="/api/v1/billing_subscriptions", * path="/api/v1/subscriptions",
* operationId="storeBillingSubscription", * operationId="storeSubscription",
* tags={"billing_subscriptions"}, * tags={"subscriptions"},
* summary="Adds a billing_subscriptions", * summary="Adds a subscriptions",
* description="Adds an billing_subscriptions to the system", * description="Adds an subscriptions to the system",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"), * @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"), * @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"), * @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Response( * @OA\Response(
* response=200, * response=200,
* description="Returns the saved billing_subscriptions object", * description="Returns the saved subscriptions object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), * @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-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/BillingSubscription"), * @OA\JsonContent(ref="#/components/schemas/Subscription"),
* ), * ),
* @OA\Response( * @OA\Response(
* response=422, * response=422,
@ -169,30 +169,30 @@ class BillingSubscriptionController extends BaseController
* ), * ),
* ) * )
*/ */
public function store(StoreBillingSubscriptionRequest $request): \Illuminate\Http\Response public function store(StoreSubscriptionRequest $request): \Illuminate\Http\Response
{ {
$billing_subscription = $this->billing_subscription_repo->save($request->all(), BillingSubscriptionFactory::create(auth()->user()->company()->id, auth()->user()->id)); $subscription = $this->subscription_repo->save($request->all(), SubscriptionFactory::create(auth()->user()->company()->id, auth()->user()->id));
event(new BillingsubscriptionWasCreated($billing_subscription, $billing_subscription->company, Ninja::eventVars())); event(new SubscriptionWasCreated($subscription, $subscription->company, Ninja::eventVars()));
return $this->itemResponse($billing_subscription); return $this->itemResponse($subscription);
} }
/** /**
* Display the specified resource. * Display the specified resource.
* *
* @param ShowBillingSubscriptionRequest $request The request * @param ShowSubscriptionRequest $request The request
* @param Invoice $billing_subscription The invoice * @param Invoice $subscription The invoice
* *
* @return Response * @return Response
* *
* *
* @OA\Get( * @OA\Get(
* path="/api/v1/billing_subscriptions/{id}", * path="/api/v1/subscriptions/{id}",
* operationId="showBillingSubscription", * operationId="showSubscription",
* tags={"billing_subscriptions"}, * tags={"subscriptions"},
* summary="Shows an billing_subscriptions", * summary="Shows an subscriptions",
* description="Displays an billing_subscriptions by id", * description="Displays an subscriptions by id",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"), * @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"), * @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
@ -200,7 +200,7 @@ class BillingSubscriptionController extends BaseController
* @OA\Parameter( * @OA\Parameter(
* name="id", * name="id",
* in="path", * in="path",
* description="The BillingSubscription Hashed ID", * description="The Subscription Hashed ID",
* example="D2J234DFA", * example="D2J234DFA",
* required=true, * required=true,
* @OA\Schema( * @OA\Schema(
@ -210,11 +210,11 @@ class BillingSubscriptionController extends BaseController
* ), * ),
* @OA\Response( * @OA\Response(
* response=200, * response=200,
* description="Returns the BillingSubscription object", * description="Returns the Subscription object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), * @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-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/BillingSubscription"), * @OA\JsonContent(ref="#/components/schemas/Subscription"),
* ), * ),
* @OA\Response( * @OA\Response(
* response=422, * response=422,
@ -229,25 +229,25 @@ class BillingSubscriptionController extends BaseController
* ), * ),
* ) * )
*/ */
public function show(ShowBillingSubscriptionRequest $request, BillingSubscription $billing_subscription): \Illuminate\Http\Response public function show(ShowSubscriptionRequest $request, Subscription $subscription): \Illuminate\Http\Response
{ {
return $this->itemResponse($billing_subscription); return $this->itemResponse($subscription);
} }
/** /**
* Show the form for editing the specified resource. * Show the form for editing the specified resource.
* *
* @param EditBillingSubscriptionRequest $request The request * @param EditSubscriptionRequest $request The request
* @param Invoice $billing_subscription The invoice * @param Invoice $subscription The invoice
* *
* @return Response * @return Response
* *
* @OA\Get( * @OA\Get(
* path="/api/v1/billing_subscriptions/{id}/edit", * path="/api/v1/subscriptions/{id}/edit",
* operationId="editBillingSubscription", * operationId="editSubscription",
* tags={"billing_subscriptions"}, * tags={"subscriptions"},
* summary="Shows an billing_subscriptions for editting", * summary="Shows an subscriptions for editting",
* description="Displays an billing_subscriptions by id", * description="Displays an subscriptions by id",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"), * @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"), * @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
@ -255,7 +255,7 @@ class BillingSubscriptionController extends BaseController
* @OA\Parameter( * @OA\Parameter(
* name="id", * name="id",
* in="path", * in="path",
* description="The BillingSubscription Hashed ID", * description="The Subscription Hashed ID",
* example="D2J234DFA", * example="D2J234DFA",
* required=true, * required=true,
* @OA\Schema( * @OA\Schema(
@ -269,7 +269,7 @@ class BillingSubscriptionController extends BaseController
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), * @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-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/BillingSubscription"), * @OA\JsonContent(ref="#/components/schemas/Subscription"),
* ), * ),
* @OA\Response( * @OA\Response(
* response=422, * response=422,
@ -284,26 +284,26 @@ class BillingSubscriptionController extends BaseController
* ), * ),
* ) * )
*/ */
public function edit(EditBillingSubscriptionRequest $request, BillingSubscription $billing_subscription): \Illuminate\Http\Response public function edit(EditSubscriptionRequest $request, Subscription $subscription): \Illuminate\Http\Response
{ {
return $this->itemResponse($billing_subscription); return $this->itemResponse($subscription);
} }
/** /**
* Update the specified resource in storage. * Update the specified resource in storage.
* *
* @param UpdateBillingSubscriptionRequest $request The request * @param UpdateSubscriptionRequest $request The request
* @param BillingSubscription $billing_subscription The invoice * @param Subscription $subscription The invoice
* *
* @return Response * @return Response
* *
* *
* @OA\Put( * @OA\Put(
* path="/api/v1/billing_subscriptions/{id}", * path="/api/v1/subscriptions/{id}",
* operationId="updateBillingSubscription", * operationId="updateSubscription",
* tags={"billing_subscriptions"}, * tags={"subscriptions"},
* summary="Updates an billing_subscriptions", * summary="Updates an subscriptions",
* description="Handles the updating of an billing_subscriptions by id", * description="Handles the updating of an subscriptions by id",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"), * @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"), * @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
@ -311,7 +311,7 @@ class BillingSubscriptionController extends BaseController
* @OA\Parameter( * @OA\Parameter(
* name="id", * name="id",
* in="path", * in="path",
* description="The BillingSubscription Hashed ID", * description="The Subscription Hashed ID",
* example="D2J234DFA", * example="D2J234DFA",
* required=true, * required=true,
* @OA\Schema( * @OA\Schema(
@ -321,11 +321,11 @@ class BillingSubscriptionController extends BaseController
* ), * ),
* @OA\Response( * @OA\Response(
* response=200, * response=200,
* description="Returns the billing_subscriptions object", * description="Returns the subscriptions object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), * @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-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/BillingSubscription"), * @OA\JsonContent(ref="#/components/schemas/Subscription"),
* ), * ),
* @OA\Response( * @OA\Response(
* response=422, * response=422,
@ -340,32 +340,32 @@ class BillingSubscriptionController extends BaseController
* ), * ),
* ) * )
*/ */
public function update(UpdateBillingSubscriptionRequest $request, BillingSubscription $billing_subscription) public function update(UpdateSubscriptionRequest $request, Subscription $subscription)
{ {
if ($request->entityIsDeleted($billing_subscription)) { if ($request->entityIsDeleted($subscription)) {
return $request->disallowUpdate(); return $request->disallowUpdate();
} }
$billing_subscription = $this->billing_subscription_repo->save($request->all(), $billing_subscription); $subscription = $this->subscription_repo->save($request->all(), $subscription);
return $this->itemResponse($billing_subscription); return $this->itemResponse($subscription);
} }
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
* *
* @param DestroyBillingSubscriptionRequest $request * @param DestroySubscriptionRequest $request
* @param BillingSubscription $invoice * @param Subscription $invoice
* *
* @return Response * @return Response
* *
* @throws \Exception * @throws \Exception
* @OA\Delete( * @OA\Delete(
* path="/api/v1/billing_subscriptions/{id}", * path="/api/v1/subscriptions/{id}",
* operationId="deleteBillingSubscription", * operationId="deleteSubscription",
* tags={"billing_subscriptions"}, * tags={"subscriptions"},
* summary="Deletes a billing_subscriptions", * summary="Deletes a subscriptions",
* description="Handles the deletion of an billing_subscriptions by id", * description="Handles the deletion of an subscriptions by id",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"), * @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"), * @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
@ -373,7 +373,7 @@ class BillingSubscriptionController extends BaseController
* @OA\Parameter( * @OA\Parameter(
* name="id", * name="id",
* in="path", * in="path",
* description="The BillingSubscription Hashed ID", * description="The Subscription Hashed ID",
* example="D2J234DFA", * example="D2J234DFA",
* required=true, * required=true,
* @OA\Schema( * @OA\Schema(
@ -401,10 +401,10 @@ class BillingSubscriptionController extends BaseController
* ), * ),
* ) * )
*/ */
public function destroy(DestroyBillingSubscriptionRequest $request, BillingSubscription $billing_subscription): \Illuminate\Http\Response public function destroy(DestroySubscriptionRequest $request, Subscription $subscription): \Illuminate\Http\Response
{ {
$this->billing_subscription_repo->delete($billing_subscription); $this->subscription_repo->delete($subscription);
return $this->itemResponse($billing_subscription->fresh()); return $this->itemResponse($subscription->fresh());
} }
} }

View File

@ -612,7 +612,9 @@ class UserController extends BaseController
return response()->json(['message', 'Cannot detach owner.'],400); return response()->json(['message', 'Cannot detach owner.'],400);
$company_user = CompanyUser::whereUserId($user->id) $company_user = CompanyUser::whereUserId($user->id)
->whereCompanyId(auth()->user()->companyId())->first(); ->whereCompanyId(auth()->user()->companyId())
->withTrashed()
->first();
$token = $company_user->token->where('company_id', $company_user->company_id)->where('user_id', $company_user->user_id)->first(); $token = $company_user->token->where('company_id', $company_user->company_id)->where('user_id', $company_user->user_id)->first();

View File

@ -12,7 +12,7 @@
namespace App\Http\Livewire; namespace App\Http\Livewire;
use App\Factory\ClientFactory; use App\Factory\ClientFactory;
use App\Models\BillingSubscription; use App\Models\Subscription;
use App\Models\ClientContact; use App\Models\ClientContact;
use App\Models\Invoice; use App\Models\Invoice;
use App\Repositories\ClientContactRepository; use App\Repositories\ClientContactRepository;
@ -55,11 +55,11 @@ class BillingPortalPurchase extends Component
public $password; public $password;
/** /**
* Instance of billing subscription. * Instance of subscription.
* *
* @var BillingSubscription * @var Subscription
*/ */
public $billing_subscription; public $subscription;
/** /**
* Instance of client contact. * Instance of client contact.
@ -186,8 +186,8 @@ class BillingPortalPurchase extends Component
*/ */
protected function createBlankClient() protected function createBlankClient()
{ {
$company = $this->billing_subscription->company; $company = $this->subscription->company;
$user = $this->billing_subscription->user; $user = $this->subscription->user;
$client_repo = new ClientRepository(new ClientContactRepository()); $client_repo = new ClientRepository(new ClientContactRepository());
@ -224,7 +224,7 @@ class BillingPortalPurchase extends Component
*/ */
protected function getPaymentMethods(ClientContact $contact): self protected function getPaymentMethods(ClientContact $contact): self
{ {
if ($this->billing_subscription->trial_enabled) { if ($this->subscription->trial_enabled) {
$this->heading_text = ctrans('texts.plan_trial'); $this->heading_text = ctrans('texts.plan_trial');
$this->steps['show_start_trial'] = true; $this->steps['show_start_trial'] = true;
@ -274,11 +274,11 @@ class BillingPortalPurchase extends Component
'client_contact_id' => $this->contact->hashed_id, 'client_contact_id' => $this->contact->hashed_id,
]], ]],
'user_input_promo_code' => $this->coupon, 'user_input_promo_code' => $this->coupon,
'coupon' => empty($this->billing_subscription->promo_code) ? '' : $this->coupon, 'coupon' => empty($this->subscription->promo_code) ? '' : $this->coupon,
'quantity' => $this->quantity, 'quantity' => $this->quantity,
]; ];
$this->invoice = $this->billing_subscription $this->invoice = $this->subscription
->service() ->service()
->createInvoice($data) ->createInvoice($data)
->service() ->service()
@ -287,12 +287,12 @@ class BillingPortalPurchase extends Component
->save(); ->save();
Cache::put($this->hash, [ Cache::put($this->hash, [
'billing_subscription_id' => $this->billing_subscription->id, 'subscription_id' => $this->subscription->id,
'email' => $this->email ?? $this->contact->email, 'email' => $this->email ?? $this->contact->email,
'client_id' => $this->contact->client->id, 'client_id' => $this->contact->client->id,
'invoice_id' => $this->invoice->id, 'invoice_id' => $this->invoice->id,
'quantity' => $this->quantity, 'quantity' => $this->quantity,
'subscription_id' => $this->billing_subscription->id, 'subscription_id' => $this->subscription->id,
now()->addMinutes(60)] now()->addMinutes(60)]
); );
@ -306,7 +306,7 @@ class BillingPortalPurchase extends Component
*/ */
public function handleTrial() public function handleTrial()
{ {
return $this->billing_subscription->service()->startTrial([ return $this->subscription->service()->startTrial([
'email' => $this->email ?? $this->contact->email, 'email' => $this->email ?? $this->contact->email,
'quantity' => $this->quantity, 'quantity' => $this->quantity,
'contact_id' => $this->contact->id, 'contact_id' => $this->contact->id,
@ -325,17 +325,17 @@ class BillingPortalPurchase extends Component
return $this->quantity; return $this->quantity;
} }
if ($this->quantity >= $this->billing_subscription->max_seats_limit && $option == 'increment') { if ($this->quantity >= $this->subscription->max_seats_limit && $option == 'increment') {
return $this->quantity; return $this->quantity;
} }
if ($option == 'increment') { if ($option == 'increment') {
$this->quantity++; $this->quantity++;
return $this->price = (int)$this->price + $this->billing_subscription->product->price; return $this->price = (int)$this->price + $this->subscription->product->price;
} }
$this->quantity--; $this->quantity--;
$this->price = (int)$this->price - $this->billing_subscription->product->price; $this->price = (int)$this->price - $this->subscription->product->price;
return 0; return 0;
} }

View File

@ -9,12 +9,12 @@
* @license https://opensource.org/licenses/AAL * @license https://opensource.org/licenses/AAL
*/ */
namespace App\Http\Requests\BillingSubscription; namespace App\Http\Requests\Subscription;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use App\Models\BillingSubscription; use App\Models\Subscription;
class CreateBillingSubscriptionRequest extends Request class CreateSubscriptionRequest extends Request
{ {
/** /**
* Determine if the user is authorized to make this request. * Determine if the user is authorized to make this request.
@ -23,7 +23,7 @@ class CreateBillingSubscriptionRequest extends Request
*/ */
public function authorize(): bool public function authorize(): bool
{ {
return auth()->user()->can('create', BillingSubscription::class); return auth()->user()->can('create', Subscription::class);
} }
/** /**

View File

@ -9,12 +9,12 @@
* @license https://opensource.org/licenses/AAL * @license https://opensource.org/licenses/AAL
*/ */
namespace App\Http\Requests\BillingSubscription; namespace App\Http\Requests\Subscription;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
class EditBillingSubscriptionRequest extends Request class DestroySubscriptionRequest extends Request
{ {
/** /**
* Determine if the user is authorized to make this request. * Determine if the user is authorized to make this request.
@ -23,7 +23,7 @@ class EditBillingSubscriptionRequest extends Request
*/ */
public function authorize() public function authorize()
{ {
return auth()->user()->can('edit', $this->billing_subscription); return auth()->user()->can('edit', $this->subscription);
} }
/** /**

View File

@ -9,12 +9,12 @@
* @license https://opensource.org/licenses/AAL * @license https://opensource.org/licenses/AAL
*/ */
namespace App\Http\Requests\BillingSubscription; namespace App\Http\Requests\Subscription;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
class DestroyBillingSubscriptionRequest extends Request class EditSubscriptionRequest extends Request
{ {
/** /**
* Determine if the user is authorized to make this request. * Determine if the user is authorized to make this request.
@ -23,7 +23,7 @@ class DestroyBillingSubscriptionRequest extends Request
*/ */
public function authorize() public function authorize()
{ {
return auth()->user()->can('edit', $this->billing_subscription); return auth()->user()->can('edit', $this->subscription);
} }
/** /**

View File

@ -9,12 +9,12 @@
* @license https://opensource.org/licenses/AAL * @license https://opensource.org/licenses/AAL
*/ */
namespace App\Http\Requests\BillingSubscription; namespace App\Http\Requests\Subscription;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
class ShowBillingSubscriptionRequest extends Request class ShowSubscriptionRequest extends Request
{ {
/** /**
* Determine if the user is authorized to make this request. * Determine if the user is authorized to make this request.
@ -23,7 +23,7 @@ class ShowBillingSubscriptionRequest extends Request
*/ */
public function authorize() : bool public function authorize() : bool
{ {
return auth()->user()->can('view', $this->billing_subscription); return auth()->user()->can('view', $this->subscription);
} }
/** /**

View File

@ -9,12 +9,12 @@
* @license https://opensource.org/licenses/AAL * @license https://opensource.org/licenses/AAL
*/ */
namespace App\Http\Requests\BillingSubscription; namespace App\Http\Requests\Subscription;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use App\Models\BillingSubscription; use App\Models\Subscription;
class StoreBillingSubscriptionRequest extends Request class StoreSubscriptionRequest extends Request
{ {
/** /**
* Determine if the user is authorized to make this request. * Determine if the user is authorized to make this request.
@ -23,7 +23,7 @@ class StoreBillingSubscriptionRequest extends Request
*/ */
public function authorize() public function authorize()
{ {
return auth()->user()->can('create', BillingSubscription::class); return auth()->user()->can('create', Subscription::class);
} }
/** /**

View File

@ -9,12 +9,12 @@
* @license https://opensource.org/licenses/AAL * @license https://opensource.org/licenses/AAL
*/ */
namespace App\Http\Requests\BillingSubscription; namespace App\Http\Requests\Subscription;
use App\Http\Requests\Request; use App\Http\Requests\Request;
use App\Utils\Traits\ChecksEntityStatus; use App\Utils\Traits\ChecksEntityStatus;
class UpdateBillingSubscriptionRequest extends Request class UpdateSubscriptionRequest extends Request
{ {
use ChecksEntityStatus; use ChecksEntityStatus;
@ -25,7 +25,7 @@ class UpdateBillingSubscriptionRequest extends Request
*/ */
public function authorize() public function authorize()
{ {
return auth()->user()->can('edit', $this->billing_subscription); return auth()->user()->can('edit', $this->subscription);
} }
/** /**

View File

@ -12,11 +12,10 @@
namespace App\Jobs\Cron; namespace App\Jobs\Cron;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use App\Models\ClientSubscription;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
class BillingSubscriptionCron class SubscriptionCron
{ {
use Dispatchable; use Dispatchable;
@ -52,11 +51,13 @@ class BillingSubscriptionCron
private function loopSubscriptions() private function loopSubscriptions()
{ {
$client_subs = ClientSubscription::whereNull('deleted_at') //looop recurring invoices with subscription id
->cursor()
->each(function ($cs){ // $client_subs = ClientSubscription::whereNull('deleted_at')
$this->processSubscription($cs); // ->cursor()
}); // ->each(function ($cs){
// $this->processSubscription($cs);
// });
} }
/* Our daily cron should check /* Our daily cron should check

View File

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

View File

@ -11,12 +11,12 @@
namespace App\Models; namespace App\Models;
use App\Services\BillingSubscription\BillingSubscriptionService; use App\Services\Subscription\SubscriptionService;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
class BillingSubscription extends BaseModel class Subscription extends BaseModel
{ {
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
@ -56,7 +56,7 @@ class BillingSubscription extends BaseModel
public function service() public function service()
{ {
return new BillingSubscriptionService($this); return new SubscriptionService($this);
} }
public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo

View File

@ -11,17 +11,17 @@
namespace App\Observers; namespace App\Observers;
use App\Models\BillingSubscription; use App\Models\Subscription;
class BillingSubscriptionObserver class SubscriptionObserver
{ {
/** /**
* Handle the billing_subscription "created" event. * Handle the billing_subscription "created" event.
* *
* @param BillingSubscription $billing_subscription * @param Subscription $billing_subscription
* @return void * @return void
*/ */
public function created(BillingSubscription $billing_subscription) public function created(Subscription $subscription)
{ {
// //
} }
@ -29,10 +29,10 @@ class BillingSubscriptionObserver
/** /**
* Handle the billing_subscription "updated" event. * Handle the billing_subscription "updated" event.
* *
* @param BillingSubscription $billing_subscription * @param Subscription $billing_subscription
* @return void * @return void
*/ */
public function updated(BillingSubscription $billing_subscription) public function updated(Subscription $subscription)
{ {
// //
} }
@ -40,10 +40,10 @@ class BillingSubscriptionObserver
/** /**
* Handle the billing_subscription "deleted" event. * Handle the billing_subscription "deleted" event.
* *
* @param BillingSubscription $billing_subscription * @param Subscription $billing_subscription
* @return void * @return void
*/ */
public function deleted(BillingSubscription $billing_subscription) public function deleted(Subscription $subscription)
{ {
// //
} }
@ -51,10 +51,10 @@ class BillingSubscriptionObserver
/** /**
* Handle the billing_subscription "restored" event. * Handle the billing_subscription "restored" event.
* *
* @param BillingSubscription $billing_subscription * @param Subscription $billing_subscription
* @return void * @return void
*/ */
public function restored(BillingSubscription $billing_subscription) public function restored(Subscription $subscription)
{ {
// //
} }
@ -62,10 +62,10 @@ class BillingSubscriptionObserver
/** /**
* Handle the billing_subscription "force deleted" event. * Handle the billing_subscription "force deleted" event.
* *
* @param BillingSubscription $billing_subscription * @param Subscription $billing_subscription
* @return void * @return void
*/ */
public function forceDeleted(BillingSubscription $billing_subscription) public function forceDeleted(Subscription $subscription)
{ {
// //
} }

View File

@ -30,7 +30,7 @@ use App\Models\Invoice;
use App\Models\Payment; use App\Models\Payment;
use App\Models\PaymentHash; use App\Models\PaymentHash;
use App\Models\SystemLog; use App\Models\SystemLog;
use App\Services\BillingSubscription\BillingSubscriptionService; use App\Services\Subscription\SubscriptionService;
use App\Utils\Ninja; use App\Utils\Ninja;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Utils\Traits\SystemLogTrait; use App\Utils\Traits\SystemLogTrait;
@ -242,9 +242,9 @@ class BaseDriver extends AbstractPaymentDriver
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
if (property_exists($this->payment_hash->data, 'billing_context')) { if (property_exists($this->payment_hash->data, 'billing_context')) {
$billing_subscription = \App\Models\BillingSubscription::find($this->payment_hash->data->billing_context->billing_subscription_id); $billing_subscription = \App\Models\Subscription::find($this->payment_hash->data->billing_context->billing_subscription_id);
(new BillingSubscriptionService($billing_subscription))->completePurchase($this->payment_hash); (new SubscriptionService($billing_subscription))->completePurchase($this->payment_hash);
} }
return $payment->service()->applyNumber()->save(); return $payment->service()->applyNumber()->save();

View File

@ -14,9 +14,9 @@ namespace App\Policies;
use App\Models\User; use App\Models\User;
/** /**
* Class BillingSubscriptionPolicy. * Class SubscriptionPolicy.
*/ */
class BillingSubscriptionPolicy extends EntityPolicy class SubscriptionPolicy extends EntityPolicy
{ {
/** /**
* Checks if the user has create permissions. * Checks if the user has create permissions.
@ -26,6 +26,6 @@ class BillingSubscriptionPolicy extends EntityPolicy
*/ */
public function create(User $user) : bool public function create(User $user) : bool
{ {
return $user->isAdmin() || $user->hasPermission('create_billing_subscription') || $user->hasPermission('create_all'); return $user->isAdmin() || $user->hasPermission('create_subscription') || $user->hasPermission('create_all');
} }
} }

View File

@ -12,7 +12,7 @@
namespace App\Providers; namespace App\Providers;
use App\Models\Account; use App\Models\Account;
use App\Models\BillingSubscription; use App\Models\Subscription;
use App\Models\Client; use App\Models\Client;
use App\Models\ClientSubscription; use App\Models\ClientSubscription;
use App\Models\Company; use App\Models\Company;
@ -28,7 +28,7 @@ use App\Models\Quote;
use App\Models\Task; use App\Models\Task;
use App\Models\User; use App\Models\User;
use App\Observers\AccountObserver; use App\Observers\AccountObserver;
use App\Observers\BillingSubscriptionObserver; use App\Observers\SubscriptionObserver;
use App\Observers\ClientObserver; use App\Observers\ClientObserver;
use App\Observers\ClientSubscriptionObserver; use App\Observers\ClientSubscriptionObserver;
use App\Observers\CompanyGatewayObserver; use App\Observers\CompanyGatewayObserver;
@ -80,7 +80,7 @@ class AppServiceProvider extends ServiceProvider
Schema::defaultStringLength(191); Schema::defaultStringLength(191);
Account::observe(AccountObserver::class); Account::observe(AccountObserver::class);
BillingSubscription::observe(BillingSubscriptionObserver::class); Subscription::observe(SubscriptionObserver::class);
Client::observe(ClientObserver::class); Client::observe(ClientObserver::class);
ClientSubscription::observe(ClientSubscriptionObserver::class); ClientSubscription::observe(ClientSubscriptionObserver::class);
Company::observe(CompanyObserver::class); Company::observe(CompanyObserver::class);

View File

@ -12,9 +12,8 @@
namespace App\Providers; namespace App\Providers;
use App\Models\Activity; use App\Models\Activity;
use App\Models\BillingSubscription; use App\Models\Subscription;
use App\Models\Client; use App\Models\Client;
use App\Models\ClientSubscription;
use App\Models\Company; use App\Models\Company;
use App\Models\CompanyGateway; use App\Models\CompanyGateway;
use App\Models\CompanyToken; use App\Models\CompanyToken;
@ -39,7 +38,7 @@ use App\Models\User;
use App\Models\Vendor; use App\Models\Vendor;
use App\Models\Webhook; use App\Models\Webhook;
use App\Policies\ActivityPolicy; use App\Policies\ActivityPolicy;
use App\Policies\BillingSubscriptionPolicy; use App\Policies\SubscriptionPolicy;
use App\Policies\ClientPolicy; use App\Policies\ClientPolicy;
use App\Policies\ClientSubscriptionPolicy; use App\Policies\ClientSubscriptionPolicy;
use App\Policies\CompanyGatewayPolicy; use App\Policies\CompanyGatewayPolicy;
@ -77,9 +76,8 @@ class AuthServiceProvider extends ServiceProvider
*/ */
protected $policies = [ protected $policies = [
Activity::class => ActivityPolicy::class, Activity::class => ActivityPolicy::class,
BillingSubscription::class => BillingSubscriptionPolicy::class, Subscription::class => SubscriptionPolicy::class,
Client::class => ClientPolicy::class, Client::class => ClientPolicy::class,
ClientSubscription::class => ClientSubscriptionPolicy::class,
Company::class => CompanyPolicy::class, Company::class => CompanyPolicy::class,
CompanyToken::class => CompanyTokenPolicy::class, CompanyToken::class => CompanyTokenPolicy::class,
CompanyGateway::class => CompanyGatewayPolicy::class, CompanyGateway::class => CompanyGatewayPolicy::class,

View File

@ -13,16 +13,16 @@
namespace App\Repositories; namespace App\Repositories;
use App\Models\BillingSubscription; use App\Models\Subscription;
class BillingSubscriptionRepository extends BaseRepository class SubscriptionRepository extends BaseRepository
{ {
public function save($data, BillingSubscription $billing_subscription): ?BillingSubscription public function save($data, Subscription $subscription): ?Subscription
{ {
$billing_subscription $subscription
->fill($data) ->fill($data)
->save(); ->save();
return $billing_subscription; return $subscription;
} }
} }

View File

@ -9,13 +9,13 @@
* @license https://opensource.org/licenses/AAL * @license https://opensource.org/licenses/AAL
*/ */
namespace App\Services\BillingSubscription; namespace App\Services\Subscription;
use App\DataMapper\InvoiceItem; use App\DataMapper\InvoiceItem;
use App\Factory\InvoiceFactory; use App\Factory\InvoiceFactory;
use App\Factory\InvoiceToRecurringInvoiceFactory; use App\Factory\InvoiceToRecurringInvoiceFactory;
use App\Jobs\Util\SystemLogger; use App\Jobs\Util\SystemLogger;
use App\Models\BillingSubscription; use App\Models\Subscription;
use App\Models\ClientContact; use App\Models\ClientContact;
use App\Models\ClientSubscription; use App\Models\ClientSubscription;
use App\Models\Invoice; use App\Models\Invoice;
@ -27,20 +27,20 @@ use App\Utils\Traits\CleanLineItems;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use GuzzleHttp\RequestOptions; use GuzzleHttp\RequestOptions;
class BillingSubscriptionService class SubscriptionService
{ {
use MakesHash; use MakesHash;
use CleanLineItems; use CleanLineItems;
/** @var billing_subscription */ /** @var subscription */
private $billing_subscription; private $subscription;
/** @var client_subscription */ /** @var client_subscription */
private $client_subscription; private $client_subscription;
public function __construct(BillingSubscription $billing_subscription) public function __construct(Subscription $subscription)
{ {
$this->billing_subscription = $billing_subscription; $this->subscription = $subscription;
} }
public function completePurchase(PaymentHash $payment_hash) public function completePurchase(PaymentHash $payment_hash)
@ -70,16 +70,16 @@ class BillingSubscriptionService
{ {
// Redirects from here work just fine. Livewire will respect it. // Redirects from here work just fine. Livewire will respect it.
if(!$this->billing_subscription->trial_enabled) if(!$this->subscription->trial_enabled)
return new \Exception("Trials are disabled for this product"); return new \Exception("Trials are disabled for this product");
$contact = ClientContact::with('client')->find($data['contact_id']); $contact = ClientContact::with('client')->find($data['contact_id']);
$cs = new ClientSubscription(); $cs = new ClientSubscription();
$cs->subscription_id = $this->billing_subscription->id; $cs->subscription_id = $this->subscription->id;
$cs->company_id = $this->billing_subscription->company_id; $cs->company_id = $this->subscription->company_id;
$cs->trial_started = time(); $cs->trial_started = time();
$cs->trial_ends = time() + $this->billing_subscription->trial_duration; $cs->trial_ends = time() + $this->subscription->trial_duration;
$cs->quantity = $data['quantity']; $cs->quantity = $data['quantity'];
$cs->client_id = $contact->client->id; $cs->client_id = $contact->client->id;
$cs->save(); $cs->save();
@ -89,8 +89,8 @@ class BillingSubscriptionService
//execute any webhooks //execute any webhooks
$this->triggerWebhook(); $this->triggerWebhook();
if(strlen($this->billing_subscription->webhook_configuration->post_purchase_url) >=1) if(strlen($this->subscription->webhook_configuration->post_purchase_url) >=1)
return redirect($this->billing_subscription->webhook_configuration->post_purchase_url); return redirect($this->subscription->webhook_configuration->post_purchase_url);
return redirect('/client/subscription/'.$cs->hashed_id); return redirect('/client/subscription/'.$cs->hashed_id);
} }
@ -102,7 +102,7 @@ class BillingSubscriptionService
$data['line_items'] = $this->cleanItems($this->createLineItems($data)); $data['line_items'] = $this->cleanItems($this->createLineItems($data));
return $invoice_repo->save($data, InvoiceFactory::create($this->billing_subscription->company_id, $this->billing_subscription->user_id)); return $invoice_repo->save($data, InvoiceFactory::create($this->subscription->company_id, $this->subscription->user_id));
} }
@ -115,7 +115,7 @@ class BillingSubscriptionService
$line_items = []; $line_items = [];
$product = $this->billing_subscription->product; $product = $this->subscription->product;
$item = new InvoiceItem; $item = new InvoiceItem;
$item->quantity = $data['quantity']; $item->quantity = $data['quantity'];
@ -139,7 +139,7 @@ class BillingSubscriptionService
//do we have a promocode? enter this as a line item. //do we have a promocode? enter this as a line item.
if(strlen($data['coupon']) >=1 && ($data['coupon'] == $this->billing_subscription->promo_code) && $this->billing_subscription->promo_discount > 0) if(strlen($data['coupon']) >=1 && ($data['coupon'] == $this->subscription->promo_code) && $this->subscription->promo_discount > 0)
$line_items[] = $this->createPromoLine($data); $line_items[] = $this->createPromoLine($data);
return $line_items; return $line_items;
@ -153,16 +153,16 @@ class BillingSubscriptionService
private function createPromoLine($data) private function createPromoLine($data)
{ {
$product = $this->billing_subscription->product; $product = $this->subscription->product;
$discounted_amount = 0; $discounted_amount = 0;
$discount = 0; $discount = 0;
$amount = $data['quantity'] * $product->cost; $amount = $data['quantity'] * $product->cost;
if ($this->billing_subscription->is_amount_discount == true) { if ($this->subscription->is_amount_discount == true) {
$discount = $this->billing_subscription->promo_discount; $discount = $this->subscription->promo_discount;
} }
else { else {
$discount = round($amount * ($this->billing_subscription->promo_discount / 100), 2); $discount = round($amount * ($this->subscription->promo_discount / 100), 2);
} }
$discounted_amount = $amount - $discount; $discounted_amount = $amount - $discount;
@ -203,8 +203,8 @@ class BillingSubscriptionService
//is this a recurring or one off subscription. //is this a recurring or one off subscription.
$cs = new ClientSubscription(); $cs = new ClientSubscription();
$cs->subscription_id = $this->billing_subscription->id; $cs->subscription_id = $this->subscription->id;
$cs->company_id = $this->billing_subscription->company_id; $cs->company_id = $this->subscription->company_id;
$cs->invoice_id = $payment_hash->billing_context->invoice_id; $cs->invoice_id = $payment_hash->billing_context->invoice_id;
$cs->client_id = $payment_hash->billing_context->client_id; $cs->client_id = $payment_hash->billing_context->client_id;
@ -212,10 +212,10 @@ class BillingSubscriptionService
//if is_recurring //if is_recurring
//create recurring invoice from invoice //create recurring invoice from invoice
if($this->billing_subscription->is_recurring) if($this->subscription->is_recurring)
{ {
$recurring_invoice = $this->convertInvoiceToRecurring($payment_hash); $recurring_invoice = $this->convertInvoiceToRecurring($payment_hash);
$recurring_invoice->frequency_id = $this->billing_subscription->frequency_id; $recurring_invoice->frequency_id = $this->subscription->frequency_id;
$recurring_invoice->next_send_date = $recurring_invoice->nextDateByFrequency(now()->format('Y-m-d')); $recurring_invoice->next_send_date = $recurring_invoice->nextDateByFrequency(now()->format('Y-m-d'));
$recurring_invoice->save(); $recurring_invoice->save();
$cs->recurring_invoice_id = $recurring_invoice->id; $cs->recurring_invoice_id = $recurring_invoice->id;
@ -236,15 +236,15 @@ class BillingSubscriptionService
//hit the webhook to after a successful onboarding //hit the webhook to after a successful onboarding
$body = [ $body = [
'billing_subscription' => $this->billing_subscription, 'subscription' => $this->subscription,
'client_subscription' => $this->client_subscription, 'client_subscription' => $this->client_subscription,
'client' => $this->client_subscription->client->toArray(), 'client' => $this->client_subscription->client->toArray(),
]; ];
$client = new \GuzzleHttp\Client(['headers' => $this->billing_subscription->webhook_configuration->post_purchase_headers]); $client = new \GuzzleHttp\Client(['headers' => $this->subscription->webhook_configuration->post_purchase_headers]);
$response = $client->{$this->billing_subscription->webhook_configuration->post_purchase_rest_method}($this->billing_subscription->post_purchase_url,[ $response = $client->{$this->subscription->webhook_configuration->post_purchase_rest_method}($this->subscription->post_purchase_url,[
RequestOptions::JSON => ['body' => $body] RequestOptions::JSON => ['body' => $body]
]); ]);

View File

@ -1,76 +0,0 @@
<?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\Utils\Traits\MakesHash;
class BillingSubscriptionTransformer extends EntityTransformer
{
use MakesHash;
/**
* @var array
*/
protected $defaultIncludes = [];
/**
* @var array
*/
protected $availableIncludes = [
'product',
];
public function transform(BillingSubscription $billing_subscription): array
{
$std = new \stdClass;
return [
'id' => $this->encodePrimaryKey($billing_subscription->id),
'user_id' => $this->encodePrimaryKey($billing_subscription->user_id),
'product_id' => $this->encodePrimaryKey($billing_subscription->product_id),
'assigned_user_id' => $this->encodePrimaryKey($billing_subscription->assigned_user_id),
'company_id' => $this->encodePrimaryKey($billing_subscription->company_id),
'is_recurring' => (bool)$billing_subscription->is_recurring,
'frequency_id' => (string)$billing_subscription->frequency_id,
'auto_bill' => (string)$billing_subscription->auto_bill,
'promo_code' => (string)$billing_subscription->promo_code,
'promo_discount' => (float)$billing_subscription->promo_discount,
'is_amount_discount' => (bool)$billing_subscription->is_amount_discount,
'allow_cancellation' => (bool)$billing_subscription->allow_cancellation,
'per_seat_enabled' => (bool)$billing_subscription->per_set_enabled,
'min_seats_limit' => (int)$billing_subscription->min_seats_limit,
'max_seats_limit' => (int)$billing_subscription->max_seats_limit,
'trial_enabled' => (bool)$billing_subscription->trial_enabled,
'trial_duration' => (int)$billing_subscription->trial_duration,
'allow_query_overrides' => (bool)$billing_subscription->allow_query_overrides,
'allow_plan_changes' => (bool)$billing_subscription->allow_plan_changes,
'plan_map' => (string)$billing_subscription->plan_map,
'refund_period' => (int)$billing_subscription->refund_period,
'webhook_configuration' => $billing_subscription->webhook_configuration ?: $std,
'purchase_page' => (string)route('client.subscription.purchase', $billing_subscription->hashed_id),
'is_deleted' => (bool)$billing_subscription->is_deleted,
'created_at' => (int)$billing_subscription->created_at,
'updated_at' => (int)$billing_subscription->updated_at,
'archived_at' => (int)$billing_subscription->deleted_at,
];
}
public function includeProduct(BillingSubscription $billing_subscription): \League\Fractal\Resource\Item
{
$transformer = new ProductTransformer($this->serializer);
return $this->includeItem($billing_subscription->product, $transformer, Product::class);
}
}

View File

@ -13,7 +13,7 @@ namespace App\Transformers;
use App\Models\Account; use App\Models\Account;
use App\Models\Activity; use App\Models\Activity;
use App\Models\BillingSubscription; use App\Models\Subscription;
use App\Models\Client; use App\Models\Client;
use App\Models\ClientSubscription; use App\Models\ClientSubscription;
use App\Models\Company; use App\Models\Company;
@ -92,7 +92,7 @@ class CompanyTransformer extends EntityTransformer
'system_logs', 'system_logs',
'expense_categories', 'expense_categories',
'task_statuses', 'task_statuses',
'client_subscriptions', 'billing_subscriptions',
]; ];
/** /**
@ -362,17 +362,10 @@ class CompanyTransformer extends EntityTransformer
return $this->includeCollection($company->system_logs, $transformer, SystemLog::class); return $this->includeCollection($company->system_logs, $transformer, SystemLog::class);
} }
public function includeClientSubscriptions(Company $company) public function includeSubscriptions(Company $company)
{ {
$transformer = new ClientSubscriptionTransformer($this->serializer); $transformer = new SubscriptionTransformer($this->serializer);
return $this->includeCollection($company->client_subscriptions, $transformer, ClientSubscription::class); return $this->includeCollection($company->billing_subscriptions, $transformer, Subscription::class);
}
public function includeBillingSubscriptions(Company $company)
{
$transformer = new BillingSubscriptionTransformer($this->serializer);
return $this->includeCollection($company->billing_subscriptions, $transformer, BillingSubscription::class);
} }
} }

View File

@ -0,0 +1,69 @@
<?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\Subscription;
use App\Utils\Traits\MakesHash;
class SubscriptionTransformer extends EntityTransformer
{
use MakesHash;
/**
* @var array
*/
protected $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
];
public function transform(Subscription $subscription): array
{
$std = new \stdClass;
return [
'id' => $this->encodePrimaryKey($subscription->id),
'user_id' => $this->encodePrimaryKey($subscription->user_id),
'product_id' => $this->encodePrimaryKey($subscription->product_id),
'assigned_user_id' => $this->encodePrimaryKey($subscription->assigned_user_id),
'company_id' => $this->encodePrimaryKey($subscription->company_id),
'is_recurring' => (bool)$subscription->is_recurring,
'frequency_id' => (string)$subscription->frequency_id,
'auto_bill' => (string)$subscription->auto_bill,
'promo_code' => (string)$subscription->promo_code,
'promo_discount' => (float)$subscription->promo_discount,
'is_amount_discount' => (bool)$subscription->is_amount_discount,
'allow_cancellation' => (bool)$subscription->allow_cancellation,
'per_seat_enabled' => (bool)$subscription->per_set_enabled,
'min_seats_limit' => (int)$subscription->min_seats_limit,
'max_seats_limit' => (int)$subscription->max_seats_limit,
'trial_enabled' => (bool)$subscription->trial_enabled,
'trial_duration' => (int)$subscription->trial_duration,
'allow_query_overrides' => (bool)$subscription->allow_query_overrides,
'allow_plan_changes' => (bool)$subscription->allow_plan_changes,
'plan_map' => (string)$subscription->plan_map,
'refund_period' => (int)$subscription->refund_period,
'webhook_configuration' => $subscription->webhook_configuration ?: $std,
'purchase_page' => (string)route('client.subscription.purchase', $subscription->hashed_id),
'is_deleted' => (bool)$subscription->is_deleted,
'created_at' => (int)$subscription->created_at,
'updated_at' => (int)$subscription->updated_at,
'archived_at' => (int)$subscription->deleted_at,
];
}
}

View File

@ -12,17 +12,17 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\BillingSubscription; use App\Models\Subscription;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
class BillingSubscriptionFactory extends Factory class SubscriptionFactory extends Factory
{ {
/** /**
* The name of the factory's corresponding model. * The name of the factory's corresponding model.
* *
* @var string * @var string
*/ */
protected $model = BillingSubscription::class; protected $model = Subscription::class;
/** /**
* Define the model's default state. * Define the model's default state.

View File

@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class RefactorBillingScriptionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::rename('billing_subscriptions', 'subscriptions');
Schema::table('subscriptions', function (Blueprint $table) {
$table->text('product_id')->change();
$table->text('recurring_product_ids');
});
Schema::table('subscriptions', function (Blueprint $table) {
$table->renameColumn('product_id', 'product_ids');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View File

@ -176,7 +176,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
// Route::post('hooks', 'SubscriptionController@subscribe')->name('hooks.subscribe'); // Route::post('hooks', 'SubscriptionController@subscribe')->name('hooks.subscribe');
// Route::delete('hooks/{subscription_id}', 'SubscriptionController@unsubscribe')->name('hooks.unsubscribe'); // Route::delete('hooks/{subscription_id}', 'SubscriptionController@unsubscribe')->name('hooks.unsubscribe');
Route::resource('billing_subscriptions', 'BillingSubscriptionController'); Route::resource('subscriptions', 'SubscriptionController');
Route::resource('cliente_subscriptions', 'ClientSubscriptionController'); Route::resource('cliente_subscriptions', 'ClientSubscriptionController');
}); });

View File

@ -11,7 +11,7 @@
namespace Tests\Feature; namespace Tests\Feature;
use App\Models\BillingSubscription; use App\Models\Subscription;
use App\Models\Product; use App\Models\Product;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
@ -24,9 +24,9 @@ use Tests\TestCase;
/** /**
* @test * @test
* @covers App\Http\Controllers\BillingSubscriptionController * @covers App\Http\Controllers\SubscriptionController
*/ */
class BillingSubscriptionApiTest extends TestCase class SubscriptionApiTest extends TestCase
{ {
use MakesHash; use MakesHash;
use DatabaseTransactions; use DatabaseTransactions;
@ -45,27 +45,30 @@ class BillingSubscriptionApiTest extends TestCase
Model::reguard(); Model::reguard();
} }
public function testBillingSubscriptionsGet() public function testSubscriptionsGet()
{ {
$product = Product::factory()->create([ $product = Product::factory()->create([
'company_id' => $this->company->id, 'company_id' => $this->company->id,
'user_id' => $this->user->id, 'user_id' => $this->user->id,
]); ]);
$billing_subscription = BillingSubscription::factory()->create([ $billing_subscription = Subscription::factory()->create([
'product_id' => $product->id, 'product_id' => $product->id,
'company_id' => $this->company->id, 'company_id' => $this->company->id,
]); ]);
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->get('/api/v1/billing_subscriptions/' . $this->encodePrimaryKey($billing_subscription->id)); ])->get('/api/v1/subscriptions/' . $this->encodePrimaryKey($billing_subscription->id));
// nlog($response);
$response->assertStatus(200); $response->assertStatus(200);
} }
public function testBillingSubscriptionsPost() public function testSubscriptionsPost()
{ {
$product = Product::factory()->create([ $product = Product::factory()->create([
'company_id' => $this->company->id, 'company_id' => $this->company->id,
@ -75,12 +78,12 @@ class BillingSubscriptionApiTest extends TestCase
$response = $this->withHeaders([ $response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'), 'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token, 'X-API-TOKEN' => $this->token,
])->post('/api/v1/billing_subscriptions', ['product_id' => $product->id, 'allow_cancellation' => true]); ])->post('/api/v1/subscriptions', ['product_id' => $product->id, 'allow_cancellation' => true]);
$response->assertStatus(200); $response->assertStatus(200);
} }
public function testBillingSubscriptionPut() public function testSubscriptionPut()
{ {
$product = Product::factory()->create([ $product = Product::factory()->create([
'company_id' => $this->company->id, 'company_id' => $this->company->id,
@ -89,13 +92,13 @@ class BillingSubscriptionApiTest extends TestCase
$response1 = $this $response1 = $this
->withHeaders(['X-API-SECRET' => config('ninja.api_secret'),'X-API-TOKEN' => $this->token]) ->withHeaders(['X-API-SECRET' => config('ninja.api_secret'),'X-API-TOKEN' => $this->token])
->post('/api/v1/billing_subscriptions', ['product_id' => $product->id]) ->post('/api/v1/subscriptions', ['product_id' => $product->id])
->assertStatus(200) ->assertStatus(200)
->json(); ->json();
$response2 = $this $response2 = $this
->withHeaders(['X-API-SECRET' => config('ninja.api_secret'),'X-API-TOKEN' => $this->token]) ->withHeaders(['X-API-SECRET' => config('ninja.api_secret'),'X-API-TOKEN' => $this->token])
->put('/api/v1/billing_subscriptions/' . $response1['data']['id'], ['allow_cancellation' => true]) ->put('/api/v1/subscriptions/' . $response1['data']['id'], ['allow_cancellation' => true])
->assertStatus(200) ->assertStatus(200)
->json(); ->json();
@ -103,15 +106,15 @@ class BillingSubscriptionApiTest extends TestCase
} }
/* /*
TypeError : Argument 1 passed to App\Transformers\BillingSubscriptionTransformer::transform() must be an instance of App\Models\BillingSubscription, bool given, called in /var/www/html/vendor/league/fractal/src/Scope.php on line 407 TypeError : Argument 1 passed to App\Transformers\SubscriptionTransformer::transform() must be an instance of App\Models\Subscription, bool given, called in /var/www/html/vendor/league/fractal/src/Scope.php on line 407
/var/www/html/app/Transformers/BillingSubscriptionTransformer.php:35 /var/www/html/app/Transformers/SubscriptionTransformer.php:35
/var/www/html/vendor/league/fractal/src/Scope.php:407 /var/www/html/vendor/league/fractal/src/Scope.php:407
/var/www/html/vendor/league/fractal/src/Scope.php:349 /var/www/html/vendor/league/fractal/src/Scope.php:349
/var/www/html/vendor/league/fractal/src/Scope.php:235 /var/www/html/vendor/league/fractal/src/Scope.php:235
/var/www/html/app/Http/Controllers/BaseController.php:395 /var/www/html/app/Http/Controllers/BaseController.php:395
/var/www/html/app/Http/Controllers/BillingSubscriptionController.php:408 /var/www/html/app/Http/Controllers/SubscriptionController.php:408
*/ */
public function testBillingSubscriptionDeleted() public function testSubscriptionDeleted()
{ {
$product = Product::factory()->create([ $product = Product::factory()->create([
@ -119,14 +122,14 @@ class BillingSubscriptionApiTest extends TestCase
'user_id' => $this->user->id, 'user_id' => $this->user->id,
]); ]);
$billing_subscription = BillingSubscription::factory()->create([ $billing_subscription = Subscription::factory()->create([
'product_id' => $product->id, 'product_id' => $product->id,
'company_id' => $this->company->id, 'company_id' => $this->company->id,
]); ]);
$response = $this $response = $this
->withHeaders(['X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token]) ->withHeaders(['X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token])
->delete('/api/v1/billing_subscriptions/' . $this->encodePrimaryKey($billing_subscription->id)) ->delete('/api/v1/subscriptions/' . $this->encodePrimaryKey($billing_subscription->id))
->assertStatus(200) ->assertStatus(200)
->json(); ->json();