1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

Merge pull request #5059 from turbo124/billing_subscription_scaffold

Billing subscription scaffold
This commit is contained in:
David Bomba 2021-03-09 07:43:46 +11:00 committed by GitHub
commit a5b397d1ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 270 additions and 2 deletions

View File

@ -11,6 +11,7 @@
namespace App\Console;
use App\Jobs\Cron\BillingSubscriptionCron;
use App\Jobs\Cron\RecurringInvoicesCron;
use App\Jobs\Ninja\AdjustEmailQuota;
use App\Jobs\Ninja\CompanySizeCheck;
@ -53,6 +54,8 @@ class Kernel extends ConsoleKernel
$schedule->job(new UpdateExchangeRates)->daily()->withoutOverlapping();
$schedule->job(new BillingSubscriptionCron)->daily()->withoutOverlapping();
$schedule->job(new RecurringInvoicesCron)->hourly()->withoutOverlapping();
/* Run hosted specific jobs */

View File

@ -0,0 +1,71 @@
<?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\Jobs\Cron;
use App\Libraries\MultiDB;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Carbon;
class BillingSubscriptionCron
{
use Dispatchable;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
}
/**
* Execute the job.
*
* @return void
*/
public function handle() : void
{
if (! config('ninja.db.multi_db_enabled')) {
$this->loopSubscriptions();
} else {
//multiDB environment, need to
foreach (MultiDB::$dbs as $db) {
MultiDB::setDB($db);
$this->loopSubscriptions();
}
}
}
private function loopSubscriptions()
{
$client_subs = ClientSubscription::whereNull('deleted_at')
->cursor()
->each(function ($cs){
$this->processSubscription($cs);
});
}
/* Our daily cron should check
1. Is the subscription still in trial phase?
2. Check the recurring invoice and its remaining_cycles to see whether we need to cancel or perform any other function.
3. Any notifications that need to fire?
*/
private function processSubscription($client_subscription)
{
}
}

View File

@ -1,5 +1,4 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
@ -58,4 +57,5 @@ class BillingSubscription extends BaseModel
{
return $this->belongsTo(Product::class);
}
}

View File

@ -1,4 +1,14 @@
<?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\Models;

View File

@ -0,0 +1,72 @@
<?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\Observers;
use App\Models\BillingSubscription;
class BillingSubscriptionObserver
{
/**
* Handle the billing_subscription "created" event.
*
* @param BillingSubscription $billing_subscription
* @return void
*/
public function created(BillingSubscription $billing_subscription)
{
//
}
/**
* Handle the billing_subscription "updated" event.
*
* @param BillingSubscription $billing_subscription
* @return void
*/
public function updated(BillingSubscription $billing_subscription)
{
//
}
/**
* Handle the billing_subscription "deleted" event.
*
* @param BillingSubscription $billing_subscription
* @return void
*/
public function deleted(BillingSubscription $billing_subscription)
{
//
}
/**
* Handle the billing_subscription "restored" event.
*
* @param BillingSubscription $billing_subscription
* @return void
*/
public function restored(BillingSubscription $billing_subscription)
{
//
}
/**
* Handle the billing_subscription "force deleted" event.
*
* @param BillingSubscription $billing_subscription
* @return void
*/
public function forceDeleted(BillingSubscription $billing_subscription)
{
//
}
}

View File

@ -0,0 +1,72 @@
<?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\Observers;
use App\Models\ClientSubscription;
class ClientSubscriptionObserver
{
/**
* Handle the client_subscription "created" event.
*
* @param ClientSubscription $client_subscription
* @return void
*/
public function created(ClientSubscription $client_subscription)
{
//
}
/**
* Handle the client_subscription "updated" event.
*
* @param ClientSubscription $client_subscription
* @return void
*/
public function updated(ClientSubscription $client_subscription)
{
//
}
/**
* Handle the client_subscription "deleted" event.
*
* @param ClientSubscription $client_subscription
* @return void
*/
public function deleted(ClientSubscription $client_subscription)
{
//
}
/**
* Handle the client_subscription "restored" event.
*
* @param ClientSubscription $client_subscription
* @return void
*/
public function restored(ClientSubscription $client_subscription)
{
//
}
/**
* Handle the client_subscription "force deleted" event.
*
* @param ClientSubscription $client_subscription
* @return void
*/
public function forceDeleted(ClientSubscription $client_subscription)
{
//
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Policies;
use App\Models\User;
/**
* Class BillingSubscriptionPolicy.
*/
class BillingSubscriptionPolicy extends EntityPolicy
{
/**
* Checks if the user has create permissions.
*
* @param User $user
* @return bool
*/
public function create(User $user) : bool
{
return $user->isAdmin() || $user->hasPermission('create_billing_subscription') || $user->hasPermission('create_all');
}
}

View File

@ -12,7 +12,9 @@
namespace App\Providers;
use App\Models\Account;
use App\Models\BillingSubscription;
use App\Models\Client;
use App\Models\ClientSubscription;
use App\Models\Company;
use App\Models\CompanyGateway;
use App\Models\CompanyToken;
@ -26,7 +28,9 @@ use App\Models\Quote;
use App\Models\Task;
use App\Models\User;
use App\Observers\AccountObserver;
use App\Observers\BillingSubscriptionObserver;
use App\Observers\ClientObserver;
use App\Observers\ClientSubscriptionObserver;
use App\Observers\CompanyGatewayObserver;
use App\Observers\CompanyObserver;
use App\Observers\CompanyTokenObserver;
@ -75,9 +79,10 @@ class AppServiceProvider extends ServiceProvider
Schema::defaultStringLength(191);
User::observe(UserObserver::class);
Account::observe(AccountObserver::class);
BillingSubscription::observe(BillingSubscriptionObserver::class);
Client::observe(ClientObserver::class);
ClientSubscription::observe(ClientSubscriptionObserver::class);
Company::observe(CompanyObserver::class);
CompanyGateway::observe(CompanyGatewayObserver::class);
CompanyToken::observe(CompanyTokenObserver::class);
@ -89,6 +94,7 @@ class AppServiceProvider extends ServiceProvider
Proposal::observe(ProposalObserver::class);
Quote::observe(QuoteObserver::class);
Task::observe(TaskObserver::class);
User::observe(UserObserver::class);
// Queue::before(function (JobProcessing $event) {
// // \Log::info('Event Job '.$event->connectionName);

View File

@ -12,6 +12,7 @@
namespace App\Providers;
use App\Models\Activity;
use App\Models\BillingSubscription;
use App\Models\Client;
use App\Models\Company;
use App\Models\CompanyGateway;
@ -37,6 +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\ClientPolicy;
use App\Policies\CompanyGatewayPolicy;
use App\Policies\CompanyPolicy;
@ -73,6 +75,7 @@ class AuthServiceProvider extends ServiceProvider
*/
protected $policies = [
Activity::class => ActivityPolicy::class,
BillingSubscription::class => BillingSubscriptionPolicy::class,
Client::class => ClientPolicy::class,
Company::class => CompanyPolicy::class,
CompanyToken::class => CompanyTokenPolicy::class,