mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
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:
parent
64a43fbb51
commit
abd3a89bc9
@ -11,7 +11,7 @@
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Jobs\Cron\BillingSubscriptionCron;
|
||||
use App\Jobs\Cron\SubscriptionCron;
|
||||
use App\Jobs\Cron\RecurringInvoicesCron;
|
||||
use App\Jobs\Ninja\AdjustEmailQuota;
|
||||
use App\Jobs\Ninja\CompanySizeCheck;
|
||||
@ -54,7 +54,7 @@ class Kernel extends ConsoleKernel
|
||||
|
||||
$schedule->job(new UpdateExchangeRates)->daily()->withoutOverlapping();
|
||||
|
||||
$schedule->job(new BillingSubscriptionCron)->daily()->withoutOverlapping();
|
||||
$schedule->job(new SubscriptionCron)->daily()->withoutOverlapping();
|
||||
|
||||
$schedule->job(new RecurringInvoicesCron)->hourly()->withoutOverlapping();
|
||||
|
||||
|
@ -13,12 +13,12 @@
|
||||
namespace App\DataMapper\Billing;
|
||||
|
||||
|
||||
class BillingContextMapper
|
||||
class SubscriptionContextMapper
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $billing_subscription_id;
|
||||
public $subscription_id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@ -39,7 +39,7 @@ class BillingContextMapper
|
||||
* @var string[]
|
||||
*/
|
||||
public $casts = [
|
||||
'billing_subscription_id' => 'integer',
|
||||
'subscription_id' => 'integer',
|
||||
'email' => 'string',
|
||||
'client_id' => 'integer',
|
||||
'invoice_id' => 'integer',
|
@ -109,7 +109,7 @@ class CompanySettings extends BaseSettings
|
||||
|
||||
public $shared_invoice_quote_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_date = ''; //@implemented
|
||||
public $counter_padding = 4; //@implemented
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events\BillingSubscription;
|
||||
namespace App\Events\Subscription;
|
||||
|
||||
use App\Models\BillingSubscription;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\Company;
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
@ -12,14 +12,14 @@ use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class BillingSubscriptionWasCreated
|
||||
class SubscriptionWasCreated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @var BillingSubscription
|
||||
* @var Subscription
|
||||
*/
|
||||
public $billing_subscription;
|
||||
public $subscription;
|
||||
|
||||
/**
|
||||
* @var Company
|
||||
@ -36,9 +36,9 @@ class BillingSubscriptionWasCreated
|
||||
*
|
||||
* @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->event_vars = $event_vars;
|
||||
}
|
@ -11,14 +11,13 @@
|
||||
|
||||
namespace App\Factory;
|
||||
|
||||
use App\Models\Subscription;
|
||||
|
||||
use App\Models\BillingSubscription;
|
||||
|
||||
class BillingSubscriptionFactory
|
||||
class SubscriptionFactory
|
||||
{
|
||||
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->user_id = $user_id;
|
||||
|
@ -13,23 +13,23 @@
|
||||
namespace App\Http\Controllers\ClientPortal;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\BillingSubscription;
|
||||
use App\Models\Subscription;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
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')) {
|
||||
$this->setLocale($request->query('locale'));
|
||||
}
|
||||
|
||||
return view('billing-portal.purchase', [
|
||||
'billing_subscription' => $billing_subscription,
|
||||
'subscription' => $subscription,
|
||||
'hash' => Str::uuid()->toString(),
|
||||
'request_data' => $request->all(),
|
||||
]);
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @OA\Schema(
|
||||
* schema="BillingSubscription",
|
||||
* schema="Subscription",
|
||||
* type="object",
|
||||
* @OA\Property(property="id", type="string", example="Opnel5aKBz", description="______"),
|
||||
* @OA\Property(property="user_id", type="string", example="Opnel5aKBz", description="______"),
|
||||
|
@ -12,45 +12,45 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\BillingSubscription\BillingSubscriptionWasCreated;
|
||||
use App\Factory\BillingSubscriptionFactory;
|
||||
use App\Http\Requests\BillingSubscription\CreateBillingSubscriptionRequest;
|
||||
use App\Http\Requests\BillingSubscription\DestroyBillingSubscriptionRequest;
|
||||
use App\Http\Requests\BillingSubscription\EditBillingSubscriptionRequest;
|
||||
use App\Http\Requests\BillingSubscription\ShowBillingSubscriptionRequest;
|
||||
use App\Http\Requests\BillingSubscription\StoreBillingSubscriptionRequest;
|
||||
use App\Http\Requests\BillingSubscription\UpdateBillingSubscriptionRequest;
|
||||
use App\Models\BillingSubscription;
|
||||
use App\Repositories\BillingSubscriptionRepository;
|
||||
use App\Transformers\BillingSubscriptionTransformer;
|
||||
use App\Events\Subscription\SubscriptionWasCreated;
|
||||
use App\Factory\SubscriptionFactory;
|
||||
use App\Http\Requests\Subscription\CreateSubscriptionRequest;
|
||||
use App\Http\Requests\Subscription\DestroySubscriptionRequest;
|
||||
use App\Http\Requests\Subscription\EditSubscriptionRequest;
|
||||
use App\Http\Requests\Subscription\ShowSubscriptionRequest;
|
||||
use App\Http\Requests\Subscription\StoreSubscriptionRequest;
|
||||
use App\Http\Requests\Subscription\UpdateSubscriptionRequest;
|
||||
use App\Models\Subscription;
|
||||
use App\Repositories\SubscriptionRepository;
|
||||
use App\Transformers\SubscriptionTransformer;
|
||||
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();
|
||||
|
||||
$this->billing_subscription_repo = $billing_subscription_repo;
|
||||
$this->subscription_repo = $subscription_repo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the list of BillingSubscriptions.
|
||||
* Show the list of Subscriptions.
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
* @OA\Get(
|
||||
* path="/api/v1/billing_subscriptions",
|
||||
* operationId="getBillingSubscriptions",
|
||||
* tags={"billing_subscriptions"},
|
||||
* summary="Gets a list of billing_subscriptions",
|
||||
* description="Lists billing_subscriptions.",
|
||||
* path="/api/v1/subscriptions",
|
||||
* operationId="getSubscriptions",
|
||||
* tags={"subscriptions"},
|
||||
* summary="Gets a list of subscriptions",
|
||||
* description="Lists subscriptions.",
|
||||
*
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||
@ -58,11 +58,11 @@ class BillingSubscriptionController extends BaseController
|
||||
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||
* @OA\Response(
|
||||
* 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-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/BillingSubscription"),
|
||||
* @OA\JsonContent(ref="#/components/schemas/Subscription"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
@ -79,24 +79,24 @@ class BillingSubscriptionController extends BaseController
|
||||
|
||||
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.
|
||||
*
|
||||
* @param CreateBillingSubscriptionRequest $request The request
|
||||
* @param CreateSubscriptionRequest $request The request
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
*
|
||||
* @OA\Get(
|
||||
* path="/api/v1/billing_subscriptions/create",
|
||||
* operationId="getBillingSubscriptionsCreate",
|
||||
* tags={"billing_subscriptions"},
|
||||
* summary="Gets a new blank billing_subscriptions object",
|
||||
* path="/api/v1/subscriptions/create",
|
||||
* operationId="getSubscriptionsCreate",
|
||||
* tags={"subscriptions"},
|
||||
* summary="Gets a new blank 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"),
|
||||
@ -104,11 +104,11 @@ class BillingSubscriptionController extends BaseController
|
||||
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||
* @OA\Response(
|
||||
* 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-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/BillingSubscription"),
|
||||
* @OA\JsonContent(ref="#/components/schemas/Subscription"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* 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.
|
||||
*
|
||||
* @param StoreBillingSubscriptionRequest $request The request
|
||||
* @param StoreSubscriptionRequest $request The request
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
*
|
||||
* @OA\Post(
|
||||
* path="/api/v1/billing_subscriptions",
|
||||
* operationId="storeBillingSubscription",
|
||||
* tags={"billing_subscriptions"},
|
||||
* summary="Adds a billing_subscriptions",
|
||||
* description="Adds an billing_subscriptions to the system",
|
||||
* path="/api/v1/subscriptions",
|
||||
* operationId="storeSubscription",
|
||||
* tags={"subscriptions"},
|
||||
* summary="Adds a subscriptions",
|
||||
* description="Adds an 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 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-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/BillingSubscription"),
|
||||
* @OA\JsonContent(ref="#/components/schemas/Subscription"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* 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.
|
||||
*
|
||||
* @param ShowBillingSubscriptionRequest $request The request
|
||||
* @param Invoice $billing_subscription The invoice
|
||||
* @param ShowSubscriptionRequest $request The request
|
||||
* @param Invoice $subscription The invoice
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
*
|
||||
* @OA\Get(
|
||||
* path="/api/v1/billing_subscriptions/{id}",
|
||||
* operationId="showBillingSubscription",
|
||||
* tags={"billing_subscriptions"},
|
||||
* summary="Shows an billing_subscriptions",
|
||||
* description="Displays an billing_subscriptions by id",
|
||||
* path="/api/v1/subscriptions/{id}",
|
||||
* operationId="showSubscription",
|
||||
* tags={"subscriptions"},
|
||||
* summary="Shows an subscriptions",
|
||||
* description="Displays an 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"),
|
||||
@ -200,7 +200,7 @@ class BillingSubscriptionController extends BaseController
|
||||
* @OA\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* description="The BillingSubscription Hashed ID",
|
||||
* description="The Subscription Hashed ID",
|
||||
* example="D2J234DFA",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
@ -210,11 +210,11 @@ class BillingSubscriptionController extends BaseController
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* 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-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/BillingSubscription"),
|
||||
* @OA\JsonContent(ref="#/components/schemas/Subscription"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* 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.
|
||||
*
|
||||
* @param EditBillingSubscriptionRequest $request The request
|
||||
* @param Invoice $billing_subscription The invoice
|
||||
* @param EditSubscriptionRequest $request The request
|
||||
* @param Invoice $subscription The invoice
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
* @OA\Get(
|
||||
* path="/api/v1/billing_subscriptions/{id}/edit",
|
||||
* operationId="editBillingSubscription",
|
||||
* tags={"billing_subscriptions"},
|
||||
* summary="Shows an billing_subscriptions for editting",
|
||||
* description="Displays an billing_subscriptions by id",
|
||||
* path="/api/v1/subscriptions/{id}/edit",
|
||||
* operationId="editSubscription",
|
||||
* tags={"subscriptions"},
|
||||
* summary="Shows an subscriptions for editting",
|
||||
* description="Displays an 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"),
|
||||
@ -255,7 +255,7 @@ class BillingSubscriptionController extends BaseController
|
||||
* @OA\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* description="The BillingSubscription Hashed ID",
|
||||
* description="The Subscription Hashed ID",
|
||||
* example="D2J234DFA",
|
||||
* required=true,
|
||||
* @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-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/BillingSubscription"),
|
||||
* @OA\JsonContent(ref="#/components/schemas/Subscription"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* 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.
|
||||
*
|
||||
* @param UpdateBillingSubscriptionRequest $request The request
|
||||
* @param BillingSubscription $billing_subscription The invoice
|
||||
* @param UpdateSubscriptionRequest $request The request
|
||||
* @param Subscription $subscription The invoice
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
*
|
||||
* @OA\Put(
|
||||
* path="/api/v1/billing_subscriptions/{id}",
|
||||
* operationId="updateBillingSubscription",
|
||||
* tags={"billing_subscriptions"},
|
||||
* summary="Updates an billing_subscriptions",
|
||||
* description="Handles the updating of an billing_subscriptions by id",
|
||||
* path="/api/v1/subscriptions/{id}",
|
||||
* operationId="updateSubscription",
|
||||
* tags={"subscriptions"},
|
||||
* summary="Updates an subscriptions",
|
||||
* description="Handles the updating of an 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"),
|
||||
@ -311,7 +311,7 @@ class BillingSubscriptionController extends BaseController
|
||||
* @OA\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* description="The BillingSubscription Hashed ID",
|
||||
* description="The Subscription Hashed ID",
|
||||
* example="D2J234DFA",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
@ -321,11 +321,11 @@ class BillingSubscriptionController extends BaseController
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* 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-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/BillingSubscription"),
|
||||
* @OA\JsonContent(ref="#/components/schemas/Subscription"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* 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();
|
||||
}
|
||||
|
||||
$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.
|
||||
*
|
||||
* @param DestroyBillingSubscriptionRequest $request
|
||||
* @param BillingSubscription $invoice
|
||||
* @param DestroySubscriptionRequest $request
|
||||
* @param Subscription $invoice
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
* @throws \Exception
|
||||
* @OA\Delete(
|
||||
* path="/api/v1/billing_subscriptions/{id}",
|
||||
* operationId="deleteBillingSubscription",
|
||||
* tags={"billing_subscriptions"},
|
||||
* summary="Deletes a billing_subscriptions",
|
||||
* description="Handles the deletion of an billing_subscriptions by id",
|
||||
* path="/api/v1/subscriptions/{id}",
|
||||
* operationId="deleteSubscription",
|
||||
* tags={"subscriptions"},
|
||||
* summary="Deletes a subscriptions",
|
||||
* description="Handles the deletion of an 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"),
|
||||
@ -373,7 +373,7 @@ class BillingSubscriptionController extends BaseController
|
||||
* @OA\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* description="The BillingSubscription Hashed ID",
|
||||
* description="The Subscription Hashed ID",
|
||||
* example="D2J234DFA",
|
||||
* required=true,
|
||||
* @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());
|
||||
}
|
||||
}
|
@ -612,7 +612,9 @@ class UserController extends BaseController
|
||||
return response()->json(['message', 'Cannot detach owner.'],400);
|
||||
|
||||
$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();
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Factory\ClientFactory;
|
||||
use App\Models\BillingSubscription;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Invoice;
|
||||
use App\Repositories\ClientContactRepository;
|
||||
@ -55,11 +55,11 @@ class BillingPortalPurchase extends Component
|
||||
public $password;
|
||||
|
||||
/**
|
||||
* Instance of billing subscription.
|
||||
* Instance of subscription.
|
||||
*
|
||||
* @var BillingSubscription
|
||||
* @var Subscription
|
||||
*/
|
||||
public $billing_subscription;
|
||||
public $subscription;
|
||||
|
||||
/**
|
||||
* Instance of client contact.
|
||||
@ -186,8 +186,8 @@ class BillingPortalPurchase extends Component
|
||||
*/
|
||||
protected function createBlankClient()
|
||||
{
|
||||
$company = $this->billing_subscription->company;
|
||||
$user = $this->billing_subscription->user;
|
||||
$company = $this->subscription->company;
|
||||
$user = $this->subscription->user;
|
||||
|
||||
$client_repo = new ClientRepository(new ClientContactRepository());
|
||||
|
||||
@ -224,7 +224,7 @@ class BillingPortalPurchase extends Component
|
||||
*/
|
||||
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->steps['show_start_trial'] = true;
|
||||
|
||||
@ -274,11 +274,11 @@ class BillingPortalPurchase extends Component
|
||||
'client_contact_id' => $this->contact->hashed_id,
|
||||
]],
|
||||
'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,
|
||||
];
|
||||
|
||||
$this->invoice = $this->billing_subscription
|
||||
$this->invoice = $this->subscription
|
||||
->service()
|
||||
->createInvoice($data)
|
||||
->service()
|
||||
@ -287,12 +287,12 @@ class BillingPortalPurchase extends Component
|
||||
->save();
|
||||
|
||||
Cache::put($this->hash, [
|
||||
'billing_subscription_id' => $this->billing_subscription->id,
|
||||
'subscription_id' => $this->subscription->id,
|
||||
'email' => $this->email ?? $this->contact->email,
|
||||
'client_id' => $this->contact->client->id,
|
||||
'invoice_id' => $this->invoice->id,
|
||||
'quantity' => $this->quantity,
|
||||
'subscription_id' => $this->billing_subscription->id,
|
||||
'subscription_id' => $this->subscription->id,
|
||||
now()->addMinutes(60)]
|
||||
);
|
||||
|
||||
@ -306,7 +306,7 @@ class BillingPortalPurchase extends Component
|
||||
*/
|
||||
public function handleTrial()
|
||||
{
|
||||
return $this->billing_subscription->service()->startTrial([
|
||||
return $this->subscription->service()->startTrial([
|
||||
'email' => $this->email ?? $this->contact->email,
|
||||
'quantity' => $this->quantity,
|
||||
'contact_id' => $this->contact->id,
|
||||
@ -325,17 +325,17 @@ class BillingPortalPurchase extends Component
|
||||
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;
|
||||
}
|
||||
|
||||
if ($option == 'increment') {
|
||||
$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->price = (int)$this->price - $this->billing_subscription->product->price;
|
||||
$this->price = (int)$this->price - $this->subscription->product->price;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,12 +9,12 @@
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\BillingSubscription;
|
||||
namespace App\Http\Requests\Subscription;
|
||||
|
||||
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.
|
||||
@ -23,7 +23,7 @@ class CreateBillingSubscriptionRequest extends Request
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->user()->can('create', BillingSubscription::class);
|
||||
return auth()->user()->can('create', Subscription::class);
|
||||
}
|
||||
|
||||
/**
|
@ -9,12 +9,12 @@
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\BillingSubscription;
|
||||
namespace App\Http\Requests\Subscription;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class EditBillingSubscriptionRequest extends Request
|
||||
class DestroySubscriptionRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
@ -23,7 +23,7 @@ class EditBillingSubscriptionRequest extends Request
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return auth()->user()->can('edit', $this->billing_subscription);
|
||||
return auth()->user()->can('edit', $this->subscription);
|
||||
}
|
||||
|
||||
/**
|
@ -9,12 +9,12 @@
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\BillingSubscription;
|
||||
namespace App\Http\Requests\Subscription;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class DestroyBillingSubscriptionRequest extends Request
|
||||
class EditSubscriptionRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
@ -23,7 +23,7 @@ class DestroyBillingSubscriptionRequest extends Request
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return auth()->user()->can('edit', $this->billing_subscription);
|
||||
return auth()->user()->can('edit', $this->subscription);
|
||||
}
|
||||
|
||||
/**
|
@ -9,12 +9,12 @@
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\BillingSubscription;
|
||||
namespace App\Http\Requests\Subscription;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ShowBillingSubscriptionRequest extends Request
|
||||
class ShowSubscriptionRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
@ -23,7 +23,7 @@ class ShowBillingSubscriptionRequest extends Request
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('view', $this->billing_subscription);
|
||||
return auth()->user()->can('view', $this->subscription);
|
||||
}
|
||||
|
||||
/**
|
@ -9,12 +9,12 @@
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\BillingSubscription;
|
||||
namespace App\Http\Requests\Subscription;
|
||||
|
||||
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.
|
||||
@ -23,7 +23,7 @@ class StoreBillingSubscriptionRequest extends Request
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return auth()->user()->can('create', BillingSubscription::class);
|
||||
return auth()->user()->can('create', Subscription::class);
|
||||
}
|
||||
|
||||
/**
|
@ -9,12 +9,12 @@
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\BillingSubscription;
|
||||
namespace App\Http\Requests\Subscription;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Utils\Traits\ChecksEntityStatus;
|
||||
|
||||
class UpdateBillingSubscriptionRequest extends Request
|
||||
class UpdateSubscriptionRequest extends Request
|
||||
{
|
||||
use ChecksEntityStatus;
|
||||
|
||||
@ -25,7 +25,7 @@ class UpdateBillingSubscriptionRequest extends Request
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return auth()->user()->can('edit', $this->billing_subscription);
|
||||
return auth()->user()->can('edit', $this->subscription);
|
||||
}
|
||||
|
||||
/**
|
@ -12,11 +12,10 @@
|
||||
namespace App\Jobs\Cron;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\ClientSubscription;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class BillingSubscriptionCron
|
||||
class SubscriptionCron
|
||||
{
|
||||
use Dispatchable;
|
||||
|
||||
@ -52,11 +51,13 @@ class BillingSubscriptionCron
|
||||
|
||||
private function loopSubscriptions()
|
||||
{
|
||||
$client_subs = ClientSubscription::whereNull('deleted_at')
|
||||
->cursor()
|
||||
->each(function ($cs){
|
||||
$this->processSubscription($cs);
|
||||
});
|
||||
//looop recurring invoices with subscription id
|
||||
|
||||
// $client_subs = ClientSubscription::whereNull('deleted_at')
|
||||
// ->cursor()
|
||||
// ->each(function ($cs){
|
||||
// $this->processSubscription($cs);
|
||||
// });
|
||||
}
|
||||
|
||||
/* Our daily cron should check
|
@ -159,15 +159,10 @@ class Company extends BaseModel
|
||||
{
|
||||
return $this->hasMany(ExpenseCategory::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function client_subscriptions()
|
||||
|
||||
public function subscriptions()
|
||||
{
|
||||
return $this->hasMany(ClientSubscription::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function billing_subscriptions()
|
||||
{
|
||||
return $this->hasMany(BillingSubscription::class)->withTrashed();
|
||||
return $this->hasMany(Subscription::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function task_statuses()
|
||||
|
@ -11,12 +11,12 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\BillingSubscription\BillingSubscriptionService;
|
||||
use App\Services\Subscription\SubscriptionService;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class BillingSubscription extends BaseModel
|
||||
class Subscription extends BaseModel
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
@ -56,7 +56,7 @@ class BillingSubscription extends BaseModel
|
||||
|
||||
public function service()
|
||||
{
|
||||
return new BillingSubscriptionService($this);
|
||||
return new SubscriptionService($this);
|
||||
}
|
||||
|
||||
public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
@ -11,17 +11,17 @@
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\BillingSubscription;
|
||||
use App\Models\Subscription;
|
||||
|
||||
class BillingSubscriptionObserver
|
||||
class SubscriptionObserver
|
||||
{
|
||||
/**
|
||||
* Handle the billing_subscription "created" event.
|
||||
*
|
||||
* @param BillingSubscription $billing_subscription
|
||||
* @param Subscription $billing_subscription
|
||||
* @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.
|
||||
*
|
||||
* @param BillingSubscription $billing_subscription
|
||||
* @param Subscription $billing_subscription
|
||||
* @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.
|
||||
*
|
||||
* @param BillingSubscription $billing_subscription
|
||||
* @param Subscription $billing_subscription
|
||||
* @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.
|
||||
*
|
||||
* @param BillingSubscription $billing_subscription
|
||||
* @param Subscription $billing_subscription
|
||||
* @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.
|
||||
*
|
||||
* @param BillingSubscription $billing_subscription
|
||||
* @param Subscription $billing_subscription
|
||||
* @return void
|
||||
*/
|
||||
public function forceDeleted(BillingSubscription $billing_subscription)
|
||||
public function forceDeleted(Subscription $subscription)
|
||||
{
|
||||
//
|
||||
}
|
@ -30,7 +30,7 @@ use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentHash;
|
||||
use App\Models\SystemLog;
|
||||
use App\Services\BillingSubscription\BillingSubscriptionService;
|
||||
use App\Services\Subscription\SubscriptionService;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\SystemLogTrait;
|
||||
@ -242,9 +242,9 @@ class BaseDriver extends AbstractPaymentDriver
|
||||
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
|
||||
|
||||
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();
|
||||
|
@ -14,9 +14,9 @@ namespace App\Policies;
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* Class BillingSubscriptionPolicy.
|
||||
* Class SubscriptionPolicy.
|
||||
*/
|
||||
class BillingSubscriptionPolicy extends EntityPolicy
|
||||
class SubscriptionPolicy extends EntityPolicy
|
||||
{
|
||||
/**
|
||||
* Checks if the user has create permissions.
|
||||
@ -26,6 +26,6 @@ class BillingSubscriptionPolicy extends EntityPolicy
|
||||
*/
|
||||
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');
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\Account;
|
||||
use App\Models\BillingSubscription;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientSubscription;
|
||||
use App\Models\Company;
|
||||
@ -28,7 +28,7 @@ use App\Models\Quote;
|
||||
use App\Models\Task;
|
||||
use App\Models\User;
|
||||
use App\Observers\AccountObserver;
|
||||
use App\Observers\BillingSubscriptionObserver;
|
||||
use App\Observers\SubscriptionObserver;
|
||||
use App\Observers\ClientObserver;
|
||||
use App\Observers\ClientSubscriptionObserver;
|
||||
use App\Observers\CompanyGatewayObserver;
|
||||
@ -80,7 +80,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
Schema::defaultStringLength(191);
|
||||
|
||||
Account::observe(AccountObserver::class);
|
||||
BillingSubscription::observe(BillingSubscriptionObserver::class);
|
||||
Subscription::observe(SubscriptionObserver::class);
|
||||
Client::observe(ClientObserver::class);
|
||||
ClientSubscription::observe(ClientSubscriptionObserver::class);
|
||||
Company::observe(CompanyObserver::class);
|
||||
|
@ -12,9 +12,8 @@
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\BillingSubscription;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientSubscription;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Models\CompanyToken;
|
||||
@ -39,7 +38,7 @@ use App\Models\User;
|
||||
use App\Models\Vendor;
|
||||
use App\Models\Webhook;
|
||||
use App\Policies\ActivityPolicy;
|
||||
use App\Policies\BillingSubscriptionPolicy;
|
||||
use App\Policies\SubscriptionPolicy;
|
||||
use App\Policies\ClientPolicy;
|
||||
use App\Policies\ClientSubscriptionPolicy;
|
||||
use App\Policies\CompanyGatewayPolicy;
|
||||
@ -77,9 +76,8 @@ class AuthServiceProvider extends ServiceProvider
|
||||
*/
|
||||
protected $policies = [
|
||||
Activity::class => ActivityPolicy::class,
|
||||
BillingSubscription::class => BillingSubscriptionPolicy::class,
|
||||
Subscription::class => SubscriptionPolicy::class,
|
||||
Client::class => ClientPolicy::class,
|
||||
ClientSubscription::class => ClientSubscriptionPolicy::class,
|
||||
Company::class => CompanyPolicy::class,
|
||||
CompanyToken::class => CompanyTokenPolicy::class,
|
||||
CompanyGateway::class => CompanyGatewayPolicy::class,
|
||||
|
@ -13,16 +13,16 @@
|
||||
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)
|
||||
->save();
|
||||
|
||||
return $billing_subscription;
|
||||
return $subscription;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,13 +9,13 @@
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Services\BillingSubscription;
|
||||
namespace App\Services\Subscription;
|
||||
|
||||
use App\DataMapper\InvoiceItem;
|
||||
use App\Factory\InvoiceFactory;
|
||||
use App\Factory\InvoiceToRecurringInvoiceFactory;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Models\BillingSubscription;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\ClientSubscription;
|
||||
use App\Models\Invoice;
|
||||
@ -27,20 +27,20 @@ use App\Utils\Traits\CleanLineItems;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
|
||||
class BillingSubscriptionService
|
||||
class SubscriptionService
|
||||
{
|
||||
use MakesHash;
|
||||
use CleanLineItems;
|
||||
|
||||
/** @var billing_subscription */
|
||||
private $billing_subscription;
|
||||
/** @var subscription */
|
||||
private $subscription;
|
||||
|
||||
/** @var 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)
|
||||
@ -70,16 +70,16 @@ class BillingSubscriptionService
|
||||
{
|
||||
// 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");
|
||||
|
||||
$contact = ClientContact::with('client')->find($data['contact_id']);
|
||||
|
||||
$cs = new ClientSubscription();
|
||||
$cs->subscription_id = $this->billing_subscription->id;
|
||||
$cs->company_id = $this->billing_subscription->company_id;
|
||||
$cs->subscription_id = $this->subscription->id;
|
||||
$cs->company_id = $this->subscription->company_id;
|
||||
$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->client_id = $contact->client->id;
|
||||
$cs->save();
|
||||
@ -89,8 +89,8 @@ class BillingSubscriptionService
|
||||
//execute any webhooks
|
||||
$this->triggerWebhook();
|
||||
|
||||
if(strlen($this->billing_subscription->webhook_configuration->post_purchase_url) >=1)
|
||||
return redirect($this->billing_subscription->webhook_configuration->post_purchase_url);
|
||||
if(strlen($this->subscription->webhook_configuration->post_purchase_url) >=1)
|
||||
return redirect($this->subscription->webhook_configuration->post_purchase_url);
|
||||
|
||||
return redirect('/client/subscription/'.$cs->hashed_id);
|
||||
}
|
||||
@ -102,7 +102,7 @@ class BillingSubscriptionService
|
||||
|
||||
$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 = [];
|
||||
|
||||
$product = $this->billing_subscription->product;
|
||||
$product = $this->subscription->product;
|
||||
|
||||
$item = new InvoiceItem;
|
||||
$item->quantity = $data['quantity'];
|
||||
@ -139,7 +139,7 @@ class BillingSubscriptionService
|
||||
|
||||
|
||||
//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);
|
||||
|
||||
return $line_items;
|
||||
@ -153,16 +153,16 @@ class BillingSubscriptionService
|
||||
private function createPromoLine($data)
|
||||
{
|
||||
|
||||
$product = $this->billing_subscription->product;
|
||||
$product = $this->subscription->product;
|
||||
$discounted_amount = 0;
|
||||
$discount = 0;
|
||||
$amount = $data['quantity'] * $product->cost;
|
||||
|
||||
if ($this->billing_subscription->is_amount_discount == true) {
|
||||
$discount = $this->billing_subscription->promo_discount;
|
||||
if ($this->subscription->is_amount_discount == true) {
|
||||
$discount = $this->subscription->promo_discount;
|
||||
}
|
||||
else {
|
||||
$discount = round($amount * ($this->billing_subscription->promo_discount / 100), 2);
|
||||
$discount = round($amount * ($this->subscription->promo_discount / 100), 2);
|
||||
}
|
||||
|
||||
$discounted_amount = $amount - $discount;
|
||||
@ -203,8 +203,8 @@ class BillingSubscriptionService
|
||||
//is this a recurring or one off subscription.
|
||||
|
||||
$cs = new ClientSubscription();
|
||||
$cs->subscription_id = $this->billing_subscription->id;
|
||||
$cs->company_id = $this->billing_subscription->company_id;
|
||||
$cs->subscription_id = $this->subscription->id;
|
||||
$cs->company_id = $this->subscription->company_id;
|
||||
|
||||
$cs->invoice_id = $payment_hash->billing_context->invoice_id;
|
||||
$cs->client_id = $payment_hash->billing_context->client_id;
|
||||
@ -212,10 +212,10 @@ class BillingSubscriptionService
|
||||
|
||||
//if is_recurring
|
||||
//create recurring invoice from invoice
|
||||
if($this->billing_subscription->is_recurring)
|
||||
if($this->subscription->is_recurring)
|
||||
{
|
||||
$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->save();
|
||||
$cs->recurring_invoice_id = $recurring_invoice->id;
|
||||
@ -236,15 +236,15 @@ class BillingSubscriptionService
|
||||
//hit the webhook to after a successful onboarding
|
||||
|
||||
$body = [
|
||||
'billing_subscription' => $this->billing_subscription,
|
||||
'subscription' => $this->subscription,
|
||||
'client_subscription' => $this->client_subscription,
|
||||
'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]
|
||||
]);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ namespace App\Transformers;
|
||||
|
||||
use App\Models\Account;
|
||||
use App\Models\Activity;
|
||||
use App\Models\BillingSubscription;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientSubscription;
|
||||
use App\Models\Company;
|
||||
@ -92,7 +92,7 @@ class CompanyTransformer extends EntityTransformer
|
||||
'system_logs',
|
||||
'expense_categories',
|
||||
'task_statuses',
|
||||
'client_subscriptions',
|
||||
'billing_subscriptions',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -362,17 +362,10 @@ class CompanyTransformer extends EntityTransformer
|
||||
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);
|
||||
}
|
||||
|
||||
public function includeBillingSubscriptions(Company $company)
|
||||
{
|
||||
$transformer = new BillingSubscriptionTransformer($this->serializer);
|
||||
|
||||
return $this->includeCollection($company->billing_subscriptions, $transformer, BillingSubscription::class);
|
||||
return $this->includeCollection($company->billing_subscriptions, $transformer, Subscription::class);
|
||||
}
|
||||
}
|
||||
|
69
app/Transformers/SubscriptionTransformer.php
Normal file
69
app/Transformers/SubscriptionTransformer.php
Normal 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,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -12,17 +12,17 @@
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\BillingSubscription;
|
||||
use App\Models\Subscription;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class BillingSubscriptionFactory extends Factory
|
||||
class SubscriptionFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = BillingSubscription::class;
|
||||
protected $model = Subscription::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
@ -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()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@ -176,7 +176,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
|
||||
// Route::post('hooks', 'SubscriptionController@subscribe')->name('hooks.subscribe');
|
||||
// Route::delete('hooks/{subscription_id}', 'SubscriptionController@unsubscribe')->name('hooks.unsubscribe');
|
||||
|
||||
Route::resource('billing_subscriptions', 'BillingSubscriptionController');
|
||||
Route::resource('subscriptions', 'SubscriptionController');
|
||||
Route::resource('cliente_subscriptions', 'ClientSubscriptionController');
|
||||
});
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\BillingSubscription;
|
||||
use App\Models\Subscription;
|
||||
use App\Models\Product;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@ -24,9 +24,9 @@ use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers App\Http\Controllers\BillingSubscriptionController
|
||||
* @covers App\Http\Controllers\SubscriptionController
|
||||
*/
|
||||
class BillingSubscriptionApiTest extends TestCase
|
||||
class SubscriptionApiTest extends TestCase
|
||||
{
|
||||
use MakesHash;
|
||||
use DatabaseTransactions;
|
||||
@ -45,27 +45,30 @@ class BillingSubscriptionApiTest extends TestCase
|
||||
Model::reguard();
|
||||
}
|
||||
|
||||
public function testBillingSubscriptionsGet()
|
||||
public function testSubscriptionsGet()
|
||||
{
|
||||
$product = Product::factory()->create([
|
||||
'company_id' => $this->company->id,
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
$billing_subscription = BillingSubscription::factory()->create([
|
||||
$billing_subscription = Subscription::factory()->create([
|
||||
'product_id' => $product->id,
|
||||
'company_id' => $this->company->id,
|
||||
]);
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'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);
|
||||
}
|
||||
|
||||
public function testBillingSubscriptionsPost()
|
||||
public function testSubscriptionsPost()
|
||||
{
|
||||
$product = Product::factory()->create([
|
||||
'company_id' => $this->company->id,
|
||||
@ -75,12 +78,12 @@ class BillingSubscriptionApiTest extends TestCase
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'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);
|
||||
}
|
||||
|
||||
public function testBillingSubscriptionPut()
|
||||
public function testSubscriptionPut()
|
||||
{
|
||||
$product = Product::factory()->create([
|
||||
'company_id' => $this->company->id,
|
||||
@ -89,13 +92,13 @@ class BillingSubscriptionApiTest extends TestCase
|
||||
|
||||
$response1 = $this
|
||||
->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)
|
||||
->json();
|
||||
|
||||
$response2 = $this
|
||||
->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)
|
||||
->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
|
||||
/var/www/html/app/Transformers/BillingSubscriptionTransformer.php:35
|
||||
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/SubscriptionTransformer.php:35
|
||||
/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:235
|
||||
/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([
|
||||
@ -119,14 +122,14 @@ class BillingSubscriptionApiTest extends TestCase
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
$billing_subscription = BillingSubscription::factory()->create([
|
||||
$billing_subscription = Subscription::factory()->create([
|
||||
'product_id' => $product->id,
|
||||
'company_id' => $this->company->id,
|
||||
]);
|
||||
|
||||
$response = $this
|
||||
->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)
|
||||
->json();
|
||||
|
Loading…
x
Reference in New Issue
Block a user