From e4dcb3ef6f465aa1f5f419d3c43040645fdec9a7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 5 Jul 2020 22:08:28 +1000 Subject: [PATCH 01/10] Company TOKEN ID --- app/Transformers/CompanyTokenTransformer.php | 1 + composer.lock | 54 ++++++++------------ 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/app/Transformers/CompanyTokenTransformer.php b/app/Transformers/CompanyTokenTransformer.php index 55ace4cf00..6f0b10f057 100644 --- a/app/Transformers/CompanyTokenTransformer.php +++ b/app/Transformers/CompanyTokenTransformer.php @@ -42,6 +42,7 @@ class CompanyTokenTransformer extends EntityTransformer public function transform(CompanyToken $company_token) { return [ + 'id' => $this->encodePrimaryKey($company_token->id), 'token' => $company_token->token, 'name' => $company_token->name ?: '', 'updated_at' => (int)$company_token->updated_at, diff --git a/composer.lock b/composer.lock index f360c0e37a..6b23f442e8 100644 --- a/composer.lock +++ b/composer.lock @@ -762,16 +762,16 @@ }, { "name": "czproject/git-php", - "version": "v3.18.0", + "version": "v3.18.1", "source": { "type": "git", "url": "https://github.com/czproject/git-php.git", - "reference": "ed442216a2f981f894ac6ddb1a2091a826f809e6" + "reference": "db664a8d5a1fbfd33e1cdd6ae65bc411bd18dc73" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/czproject/git-php/zipball/ed442216a2f981f894ac6ddb1a2091a826f809e6", - "reference": "ed442216a2f981f894ac6ddb1a2091a826f809e6", + "url": "https://api.github.com/repos/czproject/git-php/zipball/db664a8d5a1fbfd33e1cdd6ae65bc411bd18dc73", + "reference": "db664a8d5a1fbfd33e1cdd6ae65bc411bd18dc73", "shasum": "" }, "require": { @@ -800,7 +800,7 @@ "keywords": [ "git" ], - "time": "2020-06-30T14:58:07+00:00" + "time": "2020-07-03T08:02:12+00:00" }, { "name": "dacastro4/laravel-gmail", @@ -1089,20 +1089,6 @@ "sqlserver", "sqlsrv" ], - "funding": [ - { - "url": "https://www.doctrine-project.org/sponsorship.html", - "type": "custom" - }, - { - "url": "https://www.patreon.com/phpdoctrine", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdbal", - "type": "tidelift" - } - ], "time": "2020-04-20T17:19:26+00:00" }, { @@ -3301,16 +3287,16 @@ }, { "name": "livewire/livewire", - "version": "v1.2.0", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/livewire/livewire.git", - "reference": "874ba1b8d6b12efa472147697942fe2f78a5d371" + "reference": "611327efd235c462badf67e901934866ec01395e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/livewire/livewire/zipball/874ba1b8d6b12efa472147697942fe2f78a5d371", - "reference": "874ba1b8d6b12efa472147697942fe2f78a5d371", + "url": "https://api.github.com/repos/livewire/livewire/zipball/611327efd235c462badf67e901934866ec01395e", + "reference": "611327efd235c462badf67e901934866ec01395e", "shasum": "" }, "require": { @@ -3360,7 +3346,7 @@ "type": "github" } ], - "time": "2020-06-08T15:12:38+00:00" + "time": "2020-07-03T12:45:59+00:00" }, { "name": "maennchen/zipstream-php", @@ -3701,16 +3687,16 @@ }, { "name": "nesbot/carbon", - "version": "2.36.0", + "version": "2.36.1", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "d0b65958d9942fd1b501fdb0800c67e8323aa08d" + "reference": "ee7378a36cc62952100e718bcc58be4c7210e55f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/d0b65958d9942fd1b501fdb0800c67e8323aa08d", - "reference": "d0b65958d9942fd1b501fdb0800c67e8323aa08d", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/ee7378a36cc62952100e718bcc58be4c7210e55f", + "reference": "ee7378a36cc62952100e718bcc58be4c7210e55f", "shasum": "" }, "require": { @@ -3786,7 +3772,7 @@ "type": "tidelift" } ], - "time": "2020-06-25T20:20:01+00:00" + "time": "2020-07-04T12:29:56+00:00" }, { "name": "nikic/php-parser", @@ -5662,16 +5648,16 @@ }, { "name": "sentry/sentry", - "version": "2.4.0", + "version": "2.4.1", "source": { "type": "git", "url": "https://github.com/getsentry/sentry-php.git", - "reference": "e44561875e0d724bac3d9cdb705bf58847acd425" + "reference": "407573e22e6cc46b72cff07c117eeb16bf3a17de" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/getsentry/sentry-php/zipball/e44561875e0d724bac3d9cdb705bf58847acd425", - "reference": "e44561875e0d724bac3d9cdb705bf58847acd425", + "url": "https://api.github.com/repos/getsentry/sentry-php/zipball/407573e22e6cc46b72cff07c117eeb16bf3a17de", + "reference": "407573e22e6cc46b72cff07c117eeb16bf3a17de", "shasum": "" }, "require": { @@ -5755,7 +5741,7 @@ "type": "custom" } ], - "time": "2020-05-20T20:49:38+00:00" + "time": "2020-07-03T09:58:40+00:00" }, { "name": "sentry/sentry-laravel", From 09e1043c13d3f54519994caa3957a5966284c5c9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 6 Jul 2020 08:21:39 +1000 Subject: [PATCH 02/10] expose user_id on company token transformer: --- app/Transformers/CompanyTokenTransformer.php | 1 + composer.lock | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/Transformers/CompanyTokenTransformer.php b/app/Transformers/CompanyTokenTransformer.php index 6f0b10f057..89eb6b61ee 100644 --- a/app/Transformers/CompanyTokenTransformer.php +++ b/app/Transformers/CompanyTokenTransformer.php @@ -43,6 +43,7 @@ class CompanyTokenTransformer extends EntityTransformer { return [ 'id' => $this->encodePrimaryKey($company_token->id), + 'user_id' => $this->encodePrimaryKey($company_token->user_id), 'token' => $company_token->token, 'name' => $company_token->name ?: '', 'updated_at' => (int)$company_token->updated_at, diff --git a/composer.lock b/composer.lock index 6b23f442e8..65cde2fc85 100644 --- a/composer.lock +++ b/composer.lock @@ -1089,6 +1089,20 @@ "sqlserver", "sqlsrv" ], + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdbal", + "type": "tidelift" + } + ], "time": "2020-04-20T17:19:26+00:00" }, { From 95a2eab410df8808d8ac18fbd3e2695ad365ff0d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 6 Jul 2020 08:28:19 +1000 Subject: [PATCH 03/10] checking latest version logging --- app/Console/Kernel.php | 1 - app/Jobs/Util/VersionCheck.php | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 5327459eb9..58342ac5c3 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -56,7 +56,6 @@ class Kernel extends ConsoleKernel if(Ninja::isHosted()) { $schedule->job(new AdjustEmailQuota())->daily(); $schedule->job(new SendFailedEmails())->daily(); - $schedule->job(new CheckDbStatus())->everyFiveMinutes(); } /* Run queue's in shared hosting with this*/ if (Ninja::isSelfHost()) { diff --git a/app/Jobs/Util/VersionCheck.php b/app/Jobs/Util/VersionCheck.php index 1873e3ea1d..ad7017db01 100644 --- a/app/Jobs/Util/VersionCheck.php +++ b/app/Jobs/Util/VersionCheck.php @@ -36,6 +36,8 @@ class VersionCheck implements ShouldQueue { $version_file = file_get_contents(config('ninja.version_url')); + info("latest version = {$version_file}"); + if ($version_file) { Account::whereNotNull('id')->update(['latest_version' => $version_file]); } From 94a98f744ee19f520c31cc9463b588800aa57834 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 6 Jul 2020 09:34:25 +1000 Subject: [PATCH 04/10] Triggered actions on invoice --- app/Http/Controllers/InvoiceController.php | 2 + app/Services/Invoice/InvoiceService.php | 8 ++++ app/Services/Invoice/TriggeredActions.php | 44 ++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 app/Services/Invoice/TriggeredActions.php diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index c2a3e946be..e93eda2846 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -215,6 +215,8 @@ class InvoiceController extends BaseController event(new InvoiceWasCreated($invoice, $invoice->company)); + $invoice = $invoice->service()->triggeredActions($request)->save(); + return $this->itemResponse($invoice); } diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index f0b3158618..45e1e80d67 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -22,6 +22,7 @@ use App\Services\Invoice\HandleCancellation; use App\Services\Invoice\HandleReversal; use App\Services\Invoice\MarkInvoicePaid; use App\Services\Invoice\MarkSent; +use App\Services\Invoice\TriggeredActions; use App\Services\Invoice\UpdateBalance; use Illuminate\Support\Carbon; @@ -136,6 +137,13 @@ class InvoiceService return $this; } + public function triggeredActions($request) + { + $this->invoice = (new TriggeredActions($this->invoice, $request))->run(); + + return $this; + } + public function markViewed() { $this->invoice->last_viewed = Carbon::now()->format('Y-m-d H:i'); diff --git a/app/Services/Invoice/TriggeredActions.php b/app/Services/Invoice/TriggeredActions.php new file mode 100644 index 0000000000..dc0271797a --- /dev/null +++ b/app/Services/Invoice/TriggeredActions.php @@ -0,0 +1,44 @@ +request = $request; + + $this->invoice = $invoice; + } + + public function run() + { + //the request may have buried in it additional actions we should automatically perform on the invoice + } +} From f4a66dd75bcfcf62a083d0f22d34de6cce340e56 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 6 Jul 2020 13:12:08 +1000 Subject: [PATCH 05/10] Triggered actions --- app/Services/Invoice/TriggeredActions.php | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/app/Services/Invoice/TriggeredActions.php b/app/Services/Invoice/TriggeredActions.php index dc0271797a..3253fefec4 100644 --- a/app/Services/Invoice/TriggeredActions.php +++ b/app/Services/Invoice/TriggeredActions.php @@ -11,8 +11,11 @@ namespace App\Services\Invoice; +use App\Events\Invoice\InvoiceWasEmailed; use App\Events\Payment\PaymentWasCreated; use App\Factory\PaymentFactory; +use App\Helpers\Email\InvoiceEmail; +use App\Jobs\Invoice\EmailInvoice; use App\Models\Client; use App\Models\Invoice; use App\Models\Payment; @@ -40,5 +43,36 @@ class TriggeredActions extends AbstractService public function run() { //the request may have buried in it additional actions we should automatically perform on the invoice + + if($request->has('send_email')) { + + } + + if($request->has('auto_bill')) { + + } + + if($request->has('paid')) { + + } + } + + private function sendEmail() + { + + $reminder_template = $this->invoice->calculateTemplate(); + + $this->invoice->invitations->load('contact.client.country','invoice.client.country','invoice.company')->each(function ($invitation) use($reminder_template){ + + $email_builder = (new InvoiceEmail())->build($invitation, $reminder_template); + + EmailInvoice::dispatch($email_builder, $invitation, $this->invoice->company); + + }); + + if ($this->invoice->invitations->count() > 0) { + event(new InvoiceWasEmailed($this->invoice->invitations->first(), $this->invoice->company)); + } + } } From d6b58fe5b8bd83ee4b96960b0e6407ded3b62e06 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 6 Jul 2020 14:12:04 +1000 Subject: [PATCH 06/10] Fixes for testS --- app/Services/Invoice/TriggeredActions.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Services/Invoice/TriggeredActions.php b/app/Services/Invoice/TriggeredActions.php index 3253fefec4..5d1d53b7c2 100644 --- a/app/Services/Invoice/TriggeredActions.php +++ b/app/Services/Invoice/TriggeredActions.php @@ -44,17 +44,19 @@ class TriggeredActions extends AbstractService { //the request may have buried in it additional actions we should automatically perform on the invoice - if($request->has('send_email')) { + if($this->request->has('send_email')) { } - if($request->has('auto_bill')) { + if($this->request->has('auto_bill')) { } - if($request->has('paid')) { + if($this->request->has('paid')) { } + + return $this->invoice; } private function sendEmail() From 1deb503929cc4761006624b7cc578726a7e01076 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 6 Jul 2020 14:16:24 +1000 Subject: [PATCH 07/10] Fixes for Quote PDF servicE --- app/Services/Quote/GetQuotePdf.php | 51 +++++++++++++++++++++++++++++ app/Services/Quote/QuoteService.php | 5 ++- 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 app/Services/Quote/GetQuotePdf.php diff --git a/app/Services/Quote/GetQuotePdf.php b/app/Services/Quote/GetQuotePdf.php new file mode 100644 index 0000000000..92a46ef599 --- /dev/null +++ b/app/Services/Quote/GetQuotePdf.php @@ -0,0 +1,51 @@ +quote = $quote; + + $this->contact = $contact; + } + + public function run() + { + if (!$this->contact) { + $this->contact = $this->quote->client->primary_contact()->first(); + } + + $invitation = $this->quote->invitations->where('client_contact_id', $this->contact->id)->first(); + + $path = $this->quote->client->invoice_filepath(); + + $file_path = $path . $this->quote->number . '.pdf'; + + $disk = config('filesystems.default'); + + $file = Storage::disk($disk)->exists($file_path); + + if (!$file) { + $file_path = CreateQuotePdf::dispatchNow($invitation); + } + + return Storage::disk($disk)->path($file_path); + } +} diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index 71424e31c6..20f7f84e6f 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -16,6 +16,7 @@ use App\Models\Invoice; use App\Models\Quote; use App\Repositories\QuoteRepository; use App\Services\Quote\CreateInvitations; +use App\Services\Quote\GetQuotePdf; class QuoteService { @@ -65,9 +66,7 @@ class QuoteService public function getQuotePdf($contact = null) { - $get_invoice_pdf = new GetQuotePdf(); - - return $get_invoice_pdf($this->quote, $contact); + return (new GetQuotePdf($this->quote, $contact))->run(); } public function sendEmail($contact = null) :QuoteService From 4c321d41c35ab7dc28c33cb3aaa419ddbed2820d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 6 Jul 2020 21:22:36 +1000 Subject: [PATCH 08/10] Change subscriptions to webhooks --- app/Console/Commands/DemoMode.php | 16 +- ...criptionFactory.php => WebhookFactory.php} | 20 +- ...criptionFilters.php => WebhookFilters.php} | 34 +- ...onController.php => WebhookController.php} | 333 +++++++----------- .../BulkWebhookRequest.php} | 4 +- .../CreateWebhookRequest.php} | 4 +- .../DestroyWebhookRequest.php} | 4 +- .../EditWebhookRequest.php} | 4 +- .../ShowWebhookRequest.php} | 4 +- .../StoreWebhookRequest.php} | 4 +- .../UpdateWebhookRequest.php} | 4 +- ...criptionHandler.php => WebhookHandler.php} | 4 +- app/Models/Payment.php | 8 +- app/Models/{Subscription.php => Webhook.php} | 2 +- app/Observers/ClientObserver.php | 9 +- app/Observers/ExpenseObserver.php | 9 +- app/Observers/InvoiceObserver.php | 9 +- app/Observers/PaymentObserver.php | 7 +- app/Observers/QuoteObserver.php | 9 +- app/Observers/TaskObserver.php | 9 +- .../PayPalExpressPaymentDriver.php | 2 +- app/PaymentDrivers/Stripe/SOFORT.php | 2 +- ...bscriptionPolicy.php => WebhookPolicy.php} | 4 +- app/Providers/AuthServiceProvider.php | 6 +- app/Services/Payment/DeletePayment.php | 4 +- app/Transformers/CompanyTokenTransformer.php | 1 + app/Transformers/SubscriptionTransformer.php | 39 -- app/Transformers/WebhookTransformer.php | 39 ++ composer.lock | 14 - ..._05_084934_company_too_large_attribute.php | 8 + resources/lang/en/texts.php | 3 + routes/api.php | 5 +- ...criptionAPITest.php => WebhookAPITest.php} | 20 +- 33 files changed, 281 insertions(+), 363 deletions(-) rename app/Factory/{SubscriptionFactory.php => WebhookFactory.php} (51%) rename app/Filters/{SubscriptionFilters.php => WebhookFilters.php} (78%) rename app/Http/Controllers/{SubscriptionController.php => WebhookController.php} (56%) rename app/Http/Requests/{Subscription/BulkSubscriptionRequest.php => Webhook/BulkWebhookRequest.php} (90%) rename app/Http/Requests/{Subscription/ShowSubscriptionRequest.php => Webhook/CreateWebhookRequest.php} (85%) rename app/Http/Requests/{Subscription/DestroySubscriptionRequest.php => Webhook/DestroyWebhookRequest.php} (84%) rename app/Http/Requests/{Subscription/EditSubscriptionRequest.php => Webhook/EditWebhookRequest.php} (85%) rename app/Http/Requests/{Subscription/CreateSubscriptionRequest.php => Webhook/ShowWebhookRequest.php} (85%) rename app/Http/Requests/{Subscription/StoreSubscriptionRequest.php => Webhook/StoreWebhookRequest.php} (89%) rename app/Http/Requests/{Subscription/UpdateSubscriptionRequest.php => Webhook/UpdateWebhookRequest.php} (90%) rename app/Jobs/Util/{SubscriptionHandler.php => WebhookHandler.php} (95%) rename app/Models/{Subscription.php => Webhook.php} (97%) rename app/Policies/{SubscriptionPolicy.php => WebhookPolicy.php} (81%) delete mode 100644 app/Transformers/SubscriptionTransformer.php create mode 100644 app/Transformers/WebhookTransformer.php rename tests/Feature/{SubscriptionAPITest.php => WebhookAPITest.php} (82%) diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index cafec284f0..c2ac9e0caa 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -307,8 +307,12 @@ class DemoMode extends Command $invoice = InvoiceFactory::create($client->company->id, $client->user->id);//stub the company and user_id $invoice->client_id = $client->id; -// $invoice->date = $faker->date(); - $dateable = Carbon::now()->subDays(rand(0, 90)); + + if((bool)rand(0,1)) + $dateable = Carbon::now()->subDays(rand(0, 90)); + else + $dateable = Carbon::now()->addDays(rand(0, 90)); + $invoice->date = $dateable; $invoice->line_items = $this->buildLineItems(rand(1, 10)); @@ -411,7 +415,13 @@ class DemoMode extends Command //$quote = QuoteFactory::create($client->company->id, $client->user->id);//stub the company and user_id $quote =factory(\App\Models\Quote::class)->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]); - $quote->date = $faker->date(); + + if((bool)rand(0,1)) + $dateable = Carbon::now()->subDays(rand(0, 90)); + else + $dateable = Carbon::now()->addDays(rand(0, 90)); + + $quote->date = $dateable; $quote->client_id = $client->id; $quote->setRelation('client', $client); diff --git a/app/Factory/SubscriptionFactory.php b/app/Factory/WebhookFactory.php similarity index 51% rename from app/Factory/SubscriptionFactory.php rename to app/Factory/WebhookFactory.php index eb62417bc2..45b1d1f71b 100644 --- a/app/Factory/SubscriptionFactory.php +++ b/app/Factory/WebhookFactory.php @@ -11,19 +11,19 @@ namespace App\Factory; -use App\Models\Subscription; +use App\Models\Webhook; -class SubscriptionFactory +class WebhookFactory { - public static function create(int $company_id, int $user_id) :Subscription + public static function create(int $company_id, int $user_id) :Webhook { - $subscription = new Subscription; - $subscription->company_id = $company_id; - $subscription->user_id = $user_id; - $subscription->target_url = ''; - $subscription->event_id = 1; - $subscription->format = 'JSON'; + $webhook = new Webhook; + $webhook->company_id = $company_id; + $webhook->user_id = $user_id; + $webhook->target_url = ''; + $webhook->event_id = 1; + $webhook->format = 'JSON'; - return $subscription; + return $webhook; } } diff --git a/app/Filters/SubscriptionFilters.php b/app/Filters/WebhookFilters.php similarity index 78% rename from app/Filters/SubscriptionFilters.php rename to app/Filters/WebhookFilters.php index 17125707b0..8822e334f0 100644 --- a/app/Filters/SubscriptionFilters.php +++ b/app/Filters/WebhookFilters.php @@ -11,7 +11,7 @@ namespace App\Filters; -use App\Models\Subscription; +use App\Models\Webhook; use App\Models\User; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Facades\DB; @@ -20,7 +20,7 @@ use Illuminate\Support\Facades\Gate; /** * TokenFilters */ -class SubscriptionFilters extends QueryFilters +class WebhookFilters extends QueryFilters { /** @@ -38,7 +38,7 @@ class SubscriptionFilters extends QueryFilters } return $this->builder->where(function ($query) use ($filter) { - $query->where('subscriptions.target_url', 'like', '%'.$filter.'%'); + $query->where('webhooks.target_url', 'like', '%'.$filter.'%'); }); } @@ -55,7 +55,7 @@ class SubscriptionFilters extends QueryFilters return $this->builder; } - $table = 'subscriptions'; + $table = 'webhooks'; $filters = explode(',', $filter); return $this->builder->where(function ($query) use ($filters, $table) { @@ -102,19 +102,19 @@ class SubscriptionFilters extends QueryFilters */ public function baseQuery(int $company_id, User $user) : Builder { - $query = DB::table('subscriptions') - ->join('companies', 'companies.id', '=', 'subscriptions.company_id') - ->where('subscriptions.company_id', '=', $company_id) + $query = DB::table('webhooks') + ->join('companies', 'companies.id', '=', 'webhooks.company_id') + ->where('webhooks.company_id', '=', $company_id) //->whereRaw('(designs.name != "" or contacts.first_name != "" or contacts.last_name != "" or contacts.email != "")') // filter out buy now invoices ->select( - 'subscriptions.id', - 'subscriptions.target_url', - 'subscriptions.event_id', - 'subscriptions.created_at', - 'subscriptions.created_at as token_created_at', - 'subscriptions.deleted_at', - 'subscriptions.format', - 'subscriptions.user_id', + 'webhooks.id', + 'webhooks.target_url', + 'webhooks.event_id', + 'webhooks.created_at', + 'webhooks.created_at as token_created_at', + 'webhooks.deleted_at', + 'webhooks.format', + 'webhooks.user_id', ); @@ -122,8 +122,8 @@ class SubscriptionFilters extends QueryFilters * If the user does not have permissions to view all invoices * limit the user to only the invoices they have created */ - if (Gate::denies('view-list', Subscription::class)) { - $query->where('subscriptions.user_id', '=', $user->id); + if (Gate::denies('view-list', Webhook::class)) { + $query->where('webhooks.user_id', '=', $user->id); } diff --git a/app/Http/Controllers/SubscriptionController.php b/app/Http/Controllers/WebhookController.php similarity index 56% rename from app/Http/Controllers/SubscriptionController.php rename to app/Http/Controllers/WebhookController.php index e133d7e547..8ae5f6103e 100644 --- a/app/Http/Controllers/SubscriptionController.php +++ b/app/Http/Controllers/WebhookController.php @@ -12,27 +12,27 @@ namespace App\Http\Controllers; -use App\Factory\SubscriptionFactory; -use App\Filters\SubscriptionFilters; -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\Factory\WebhookFactory; +use App\Filters\WebhookFilters; +use App\Http\Requests\Webhook\CreateWebhookRequest; +use App\Http\Requests\Webhook\DestroyWebhookRequest; +use App\Http\Requests\Webhook\EditWebhookRequest; +use App\Http\Requests\Webhook\ShowWebhookRequest; +use App\Http\Requests\Webhook\StoreWebhookRequest; +use App\Http\Requests\Webhook\UpdateWebhookRequest; +use App\Models\Webhook; use App\Repositories\BaseRepository; -use App\Transformers\SubscriptionTransformer; +use App\Transformers\WebhookTransformer; use App\Utils\Traits\MakesHash; use Illuminate\Http\Request; -class SubscriptionController extends BaseController +class WebhookController extends BaseController { use MakesHash; - protected $entity_type = Subscription::class; + protected $entity_type = Webhook::class; - protected $entity_transformer = SubscriptionTransformer::class; + protected $entity_transformer = WebhookTransformer::class; public $base_repo; @@ -45,13 +45,13 @@ class SubscriptionController extends BaseController /** * @OA\Get( - * path="/api/v1/subscriptions", - * operationId="getSubscriptions", - * tags={"subscriptions"}, - * summary="Gets a list of subscriptions", - * description="Lists subscriptions, search and filters allow fine grained lists to be generated. + * path="/api/v1/webhooks", + * operationId="getWebhooks", + * tags={"webhooks"}, + * summary="Gets a list of Webhooks", + * description="Lists Webhooks, search and filters allow fine grained lists to be generated. * - * Query parameters can be added to performed more fine grained filtering of the subscriptions, these are handled by the SubscriptionFilters class which defines the methods available", + * Query parameters can be added to performed more fine grained filtering of the Webhooks, these are handled by the WebhookFilters class which defines the methods available", * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), @@ -59,11 +59,11 @@ class SubscriptionController extends BaseController * @OA\Parameter(ref="#/components/parameters/index"), * @OA\Response( * response=200, - * description="A list of subscriptions", + * description="A list of Webhooks", * @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/Subscription"), + * @OA\JsonContent(ref="#/components/schemas/Webhook"), * ), * @OA\Response( * response=422, @@ -79,11 +79,11 @@ class SubscriptionController extends BaseController * ) * */ - public function index(SubscriptionFilters $filters) + public function index(WebhookFilters $filters) { - $subscriptions = Subscription::filter($filters); + $webhooks = Webhook::filter($filters); - return $this->listResponse($subscriptions); + return $this->listResponse($webhooks); } /** @@ -94,11 +94,11 @@ class SubscriptionController extends BaseController * * * @OA\Get( - * path="/api/v1/subscriptions/{id}", - * operationId="showSubscription", - * tags={"subscriptions"}, - * summary="Shows a subscription", - * description="Displays a subscription by id", + * path="/api/v1/webhooks/{id}", + * operationId="showWebhook", + * tags={"webhooks"}, + * summary="Shows a Webhook", + * description="Displays a Webhook 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"), @@ -106,7 +106,7 @@ class SubscriptionController extends BaseController * @OA\Parameter( * name="id", * in="path", - * description="The Subscription Hashed ID", + * description="The Webhook Hashed ID", * example="D2J234DFA", * required=true, * @OA\Schema( @@ -116,11 +116,11 @@ class SubscriptionController extends BaseController * ), * @OA\Response( * response=200, - * description="Returns the subscription object", + * description="Returns the Webhook 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/Subscription"), + * @OA\JsonContent(ref="#/components/schemas/Webhook"), * ), * @OA\Response( * response=422, @@ -136,9 +136,9 @@ class SubscriptionController extends BaseController * ) * */ - public function show(ShowSubscriptionRequest $request, Subscription $subscription) + public function show(ShowWebhookRequest $request, Webhook $webhook) { - return $this->itemResponse($subscription); + return $this->itemResponse($webhook); } /** @@ -149,11 +149,11 @@ class SubscriptionController extends BaseController * * * @OA\Get( - * path="/api/v1/subscriptions/{id}/edit", - * operationId="editSubscription", - * tags={"subscriptions"}, - * summary="Shows a subscription for editting", - * description="Displays a subscription by id", + * path="/api/v1/webhooks/{id}/edit", + * operationId="editWebhook", + * tags={"webhooks"}, + * summary="Shows a Webhook for editting", + * description="Displays a Webhook 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"), @@ -161,7 +161,7 @@ class SubscriptionController extends BaseController * @OA\Parameter( * name="id", * in="path", - * description="The Subscription Hashed ID", + * description="The Webhook Hashed ID", * example="D2J234DFA", * required=true, * @OA\Schema( @@ -171,11 +171,11 @@ class SubscriptionController extends BaseController * ), * @OA\Response( * response=200, - * description="Returns the subscription object", + * description="Returns the Webhook 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/Subscription"), + * @OA\JsonContent(ref="#/components/schemas/Webhook"), * ), * @OA\Response( * response=422, @@ -191,26 +191,26 @@ class SubscriptionController extends BaseController * ) * */ - public function edit(EditSubscriptionRequest $request, Subscription $subscription) + public function edit(EditWebhookRequest $request, Webhook $webhook) { - return $this->itemResponse($subscription); + return $this->itemResponse($webhook); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request - * @param App\Models\Subscription $subscription + * @param App\Models\Webhook $Webhook * @return \Illuminate\Http\Response * * * * @OA\Put( - * path="/api/v1/subscriptions/{id}", - * operationId="updateSubscription", - * tags={"subscriptions"}, - * summary="Updates a subscription", - * description="Handles the updating of a subscription by id", + * path="/api/v1/webhooks/{id}", + * operationId="updateWebhook", + * tags={"webhooks"}, + * summary="Updates a Webhook", + * description="Handles the updating of a Webhook 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"), @@ -218,7 +218,7 @@ class SubscriptionController extends BaseController * @OA\Parameter( * name="id", * in="path", - * description="The Subscription Hashed ID", + * description="The Webhook Hashed ID", * example="D2J234DFA", * required=true, * @OA\Schema( @@ -228,11 +228,11 @@ class SubscriptionController extends BaseController * ), * @OA\Response( * response=200, - * description="Returns the subscription object", + * description="Returns the Webhook 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/Subscription"), + * @OA\JsonContent(ref="#/components/schemas/Webhook"), * ), * @OA\Response( * response=422, @@ -248,16 +248,16 @@ class SubscriptionController extends BaseController * ) * */ - public function update(UpdateSubscriptionRequest $request, Subscription $subscription) + public function update(UpdateWebhookRequest $request, Webhook $webhook) { - if ($request->entityIsDeleted($subscription)) { + if ($request->entityIsDeleted($webhook)) { return $request->disallowUpdate(); } - $subscription->fill($request->all()); - $subscription->save(); + $webhook->fill($request->all()); + $webhook->save(); - return $this->itemResponse($subscription); + return $this->itemResponse($webhook); } /** @@ -268,10 +268,10 @@ class SubscriptionController extends BaseController * * * @OA\Get( - * path="/api/v1/subscriptions/create", - * operationId="getSubscriptionsCreate", - * tags={"subscriptions"}, - * summary="Gets a new blank subscription object", + * path="/api/v1/webhooks/create", + * operationId="getWebhooksCreate", + * tags={"webhooks"}, + * summary="Gets a new blank Webhook 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"), @@ -279,11 +279,11 @@ class SubscriptionController extends BaseController * @OA\Parameter(ref="#/components/parameters/include"), * @OA\Response( * response=200, - * description="A blank subscription object", + * description="A blank Webhook 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/Subscription"), + * @OA\JsonContent(ref="#/components/schemas/Webhook"), * ), * @OA\Response( * response=422, @@ -299,13 +299,13 @@ class SubscriptionController extends BaseController * ) * */ - public function create(CreateSubscriptionRequest $request) + public function create(CreateWebhookRequest $request) { - $subscription = SubscriptionFactory::create(auth()->user()->company()->id, auth()->user()->id); - $subscription->fill($request->all()); - $subscription->save(); + $webhook = WebhookFactory::create(auth()->user()->company()->id, auth()->user()->id); + $webhook->fill($request->all()); + $webhook->save(); - return $this->itemResponse($subscription); + return $this->itemResponse($webhook); } /** @@ -317,22 +317,22 @@ class SubscriptionController extends BaseController * * * @OA\Post( - * path="/api/v1/subscriptions", - * operationId="storeSubscription", - * tags={"subscriptions"}, - * summary="Adds a subscription", - * description="Adds an subscription to a company", + * path="/api/v1/webhooks", + * operationId="storeWebhook", + * tags={"webhooks"}, + * summary="Adds a Webhook", + * description="Adds an Webhook to a company", * @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 subscription object", + * description="Returns the saved Webhook 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/Subscription"), + * @OA\JsonContent(ref="#/components/schemas/Webhook"), * ), * @OA\Response( * response=422, @@ -348,13 +348,27 @@ class SubscriptionController extends BaseController * ) * */ - public function store(StoreSubscriptionRequest $request) + public function store(StoreWebhookRequest $request) { - $subscription = SubscriptionFactory::create(auth()->user()->company()->id, auth()->user()->id); - $subscription->fill($request->all()); - $subscription->save(); + $event_id = $request->input('event_id'); + $target_url = $request->input('target_url'); - return $this->itemResponse($subscription); + if (!in_array($event_id, Webhook::$valid_events)) { + return response()->json("Invalid event", 400); + } + + $webhook = new Webhook; + $webhook->company_id = auth()->user()->company()->id; + $webhook->user_id = auth()->user()->id; + $webhook->event_id = $event_id; + $webhook->target_url = $target_url; + $webhook->save(); + + if (!$webhook->id) { + return response()->json('Failed to create Webhook', 400); + } + + return $this->itemResponse($webhook); } /** @@ -365,11 +379,11 @@ class SubscriptionController extends BaseController * * * @OA\Delete( - * path="/api/v1/subscriptions/{id}", - * operationId="deleteSubscription", - * tags={"subscriptions"}, - * summary="Deletes a subscription", - * description="Handles the deletion of a subscription by id", + * path="/api/v1/Webhooks/{id}", + * operationId="deleteWebhook", + * tags={"Webhooks"}, + * summary="Deletes a Webhook", + * description="Handles the deletion of a Webhook 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"), @@ -377,7 +391,7 @@ class SubscriptionController extends BaseController * @OA\Parameter( * name="id", * in="path", - * description="The Subscription Hashed ID", + * description="The Webhook Hashed ID", * example="D2J234DFA", * required=true, * @OA\Schema( @@ -406,26 +420,26 @@ class SubscriptionController extends BaseController * ) * */ - public function destroy(DestroySubscriptionRequest $request, Subscription $subscription) + public function destroy(DestroyWebhookRequest $request, Webhook $webhook) { //may not need these destroy routes as we are using actions to 'archive/delete' - $subscription->delete(); + $webhook->delete(); - return $this->itemResponse($subscription); + return $this->itemResponse($webhook); } /** * Perform bulk actions on the list view * - * @param BulkSubscriptionRequest $request + * @param BulkWebhookRequest $request * @return \Illuminate\Http\Response * * * @OA\Post( - * path="/api/v1/subscriptions/bulk", - * operationId="bulkSubscriptions", - * tags={"subscriptions"}, - * summary="Performs bulk actions on an array of subscriptions", + * path="/api/v1/webhooks/bulk", + * operationId="bulkWebhooks", + * tags={"webhooks"}, + * summary="Performs bulk actions on an array of Webhooks", * description="", * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), @@ -448,11 +462,11 @@ class SubscriptionController extends BaseController * ), * @OA\Response( * response=200, - * description="The Subscription User response", + * description="The Webhook User response", * @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/Subscription"), + * @OA\JsonContent(ref="#/components/schemas/Webhook"), * ), * @OA\Response( * response=422, @@ -471,129 +485,18 @@ class SubscriptionController extends BaseController $action = request()->input('action'); $ids = request()->input('ids'); - $subscriptions = Subscription::withTrashed()->find($this->transformKeys($ids)); - $subscriptions->each(function ($subscription, $key) use ($action) { - if (auth()->user()->can('edit', $subscription)) { - $this->base_repo->{$action}($subscription); + $webhooks = Webhook::withTrashed()->find($this->transformKeys($ids)); + + + $webhooks->each(function ($webhook, $key) use ($action) { + if (auth()->user()->can('edit', $webhook)) { + $this->base_repo->{$action}($webhook); } }); - return $this->listResponse(Subscription::withTrashed()->whereIn('id', $this->transformKeys($ids))); + return $this->listResponse(Webhook::withTrashed()->whereIn('id', $this->transformKeys($ids))); } - /** - * Store a newly created resource in storage. - * - * @OA\Post( - * path="/api/v1/hooks", - * operationId="storeHook", - * tags={"hooks"}, - * summary="Adds a hook", - * description="Adds a hooks to a company", - * @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 hooks 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/Subscription"), - * ), - * @OA\Response( - * response=422, - * description="Validation error", - * @OA\JsonContent(ref="#/components/schemas/ValidationError"), - * - * ), - * @OA\Response( - * response="default", - * description="Unexpected Error", - * @OA\JsonContent(ref="#/components/schemas/Error"), - * ), - * ) - * - */ - public function subscribe(StoreSubscriptionRequest $request) - { - $event_id = $request->input('event_id'); - $target_url = $request->input('target_url'); - - if (!in_array($event_id, Subscription::$valid_events)) { - return response()->json("Invalid event", 400); - } - - $subscription = new Subscription; - $subscription->company_id = auth()->user()->company()->id; - $subscription->user_id = auth()->user()->id; - $subscription->event_id = $event_id; - $subscription->target_url = $target_url; - $subscription->save(); - - if (!$subscription->id) { - return response()->json('Failed to create subscription', 400); - } - - return $this->itemResponse($subscription); - } - - /** - * Remove the specified resource from storage. - * - * @param int $id - * @return \Illuminate\Http\Response - * - * - * @OA\Delete( - * path="/api/v1/hooks/{subscription_id}", - * operationId="deleteHook", - * tags={"hooks"}, - * summary="Deletes a hook", - * description="Handles the deletion of a hook by id", - * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), - * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), - * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), - * @OA\Parameter(ref="#/components/parameters/include"), - * @OA\Parameter( - * name="subscription_id", - * in="path", - * description="The Subscription Hashed ID", - * example="D2J234DFA", - * required=true, - * @OA\Schema( - * type="string", - * format="string", - * ), - * ), - * @OA\Response( - * response=200, - * description="Returns a HTTP status", - * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), - * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), - * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), - * ), - * @OA\Response( - * response=422, - * description="Validation error", - * @OA\JsonContent(ref="#/components/schemas/ValidationError"), - * - * ), - * @OA\Response( - * response="default", - * description="Unexpected Error", - * @OA\JsonContent(ref="#/components/schemas/Error"), - * ), - * ) - * - */ - public function unsubscribe(DestroySubscriptionRequest $request, Subscription $subscription) - { - $subscription->delete(); - - return $this->itemResponse($subscription); - } } diff --git a/app/Http/Requests/Subscription/BulkSubscriptionRequest.php b/app/Http/Requests/Webhook/BulkWebhookRequest.php similarity index 90% rename from app/Http/Requests/Subscription/BulkSubscriptionRequest.php rename to app/Http/Requests/Webhook/BulkWebhookRequest.php index 3fc119941e..ade367a2d0 100644 --- a/app/Http/Requests/Subscription/BulkSubscriptionRequest.php +++ b/app/Http/Requests/Webhook/BulkWebhookRequest.php @@ -1,12 +1,12 @@ entity->company_id) + $subscriptions = Webhook::where('company_id', $this->entity->company_id) ->where('event_id', $this->event_id) ->get(); diff --git a/app/Models/Payment.php b/app/Models/Payment.php index ef94c316da..b902d17441 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -35,7 +35,7 @@ class Payment extends BaseModel use Refundable; const STATUS_PENDING = 1; - const STATUS_VOIDED = 2; + const STATUS_CANCELLED = 2; const STATUS_FAILED = 3; const STATUS_COMPLETED = 4; const STATUS_PARTIALLY_REFUNDED = 5; @@ -167,7 +167,7 @@ class Payment extends BaseModel case self::STATUS_PENDING: return '
'.ctrans('texts.payment_status_1').'
'; break; - case self::STATUS_VOIDED: + case self::STATUS_CANCELLED: return '
'.ctrans('texts.payment_status_2').'
'; break; case self::STATUS_FAILED: @@ -248,7 +248,7 @@ class Payment extends BaseModel public function isVoided() { - return $this->status_id == self::STATUS_VOIDED; + return $this->status_id == self::STATUS_CANCELLED; } public function isPartiallyRefunded() @@ -274,7 +274,7 @@ class Payment extends BaseModel } $this->refunded = $this->amount; - $this->status_id = self::STATUS_VOIDED; + $this->status_id = self::STATUS_CANCELLED; $this->save(); event(new PaymentWasVoided($this)); diff --git a/app/Models/Subscription.php b/app/Models/Webhook.php similarity index 97% rename from app/Models/Subscription.php rename to app/Models/Webhook.php index 60b29bb72f..0b4b3a1e39 100644 --- a/app/Models/Subscription.php +++ b/app/Models/Webhook.php @@ -14,7 +14,7 @@ namespace App\Models; use App\Models\Filterable; use Illuminate\Database\Eloquent\SoftDeletes; -class Subscription extends BaseModel +class Webhook extends BaseModel { use SoftDeletes; use Filterable; diff --git a/app/Observers/ClientObserver.php b/app/Observers/ClientObserver.php index e4d93ed158..d602083fc1 100644 --- a/app/Observers/ClientObserver.php +++ b/app/Observers/ClientObserver.php @@ -12,9 +12,10 @@ namespace App\Observers; use App\Events\Client\ClientWasCreated; -use App\Jobs\Util\SubscriptionHandler; +use App\Jobs\Util\WebhookHandler; use App\Models\Client; use App\Models\Subscription; +use App\Models\Webhook; class ClientObserver { @@ -28,7 +29,7 @@ class ClientObserver { event(new ClientWasCreated($client, $client->company)); - SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_CLIENT, $client); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_CLIENT, $client); } /** @@ -39,7 +40,7 @@ class ClientObserver */ public function updated(Client $client) { - SubscriptionHandler::dispatch(Subscription::EVENT_UPDATE_CLIENT, $client); + WebhookHandler::dispatch(Webhook::EVENT_UPDATE_CLIENT, $client); } /** @@ -50,7 +51,7 @@ class ClientObserver */ public function deleted(Client $client) { - SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_CLIENT, $client); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_CLIENT, $client); } diff --git a/app/Observers/ExpenseObserver.php b/app/Observers/ExpenseObserver.php index 74e9fd1a13..381f31abab 100644 --- a/app/Observers/ExpenseObserver.php +++ b/app/Observers/ExpenseObserver.php @@ -11,9 +11,10 @@ namespace App\Observers; -use App\Jobs\Util\SubscriptionHandler; +use App\Jobs\Util\WebhookHandler; use App\Models\Expense; use App\Models\Subscription; +use App\Models\Webhook; class ExpenseObserver { @@ -25,7 +26,7 @@ class ExpenseObserver */ public function created(Expense $expense) { - SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_EXPENSE, $expense); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_EXPENSE, $expense); } /** @@ -36,7 +37,7 @@ class ExpenseObserver */ public function updated(Expense $expense) { - SubscriptionHandler::dispatch(Subscription::EVENT_UPDATE_EXPENSE, $expense); + WebhookHandler::dispatch(Webhook::EVENT_UPDATE_EXPENSE, $expense); } /** @@ -47,7 +48,7 @@ class ExpenseObserver */ public function deleted(Expense $expense) { - SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_EXPENSE, $expense); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_EXPENSE, $expense); } /** diff --git a/app/Observers/InvoiceObserver.php b/app/Observers/InvoiceObserver.php index dcd427bfd7..0d0e369ac9 100644 --- a/app/Observers/InvoiceObserver.php +++ b/app/Observers/InvoiceObserver.php @@ -11,9 +11,10 @@ namespace App\Observers; -use App\Jobs\Util\SubscriptionHandler; +use App\Jobs\Util\WebhookHandler; use App\Models\Invoice; use App\Models\Subscription; +use App\Models\Webhook; class InvoiceObserver { @@ -25,7 +26,7 @@ class InvoiceObserver */ public function created(Invoice $invoice) { - SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_INVOICE, $invoice); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice); } /** @@ -36,7 +37,7 @@ class InvoiceObserver */ public function updated(Invoice $invoice) { - SubscriptionHandler::dispatch(Subscription::EVENT_UPDATE_INVOICE, $invoice); + WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice); } /** @@ -47,7 +48,7 @@ class InvoiceObserver */ public function deleted(Invoice $invoice) { - SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_INVOICE, $invoice); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice); } /** diff --git a/app/Observers/PaymentObserver.php b/app/Observers/PaymentObserver.php index 9f8ca33546..19859359be 100644 --- a/app/Observers/PaymentObserver.php +++ b/app/Observers/PaymentObserver.php @@ -12,9 +12,10 @@ namespace App\Observers; use App\Events\Payment\PaymentWasCreated; -use App\Jobs\Util\SubscriptionHandler; +use App\Jobs\Util\WebhookHandler; use App\Models\Payment; use App\Models\Subscription; +use App\Models\Webhook; class PaymentObserver { @@ -26,7 +27,7 @@ class PaymentObserver */ public function created(Payment $payment) { - SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_PAYMENT, $payment); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment); } /** @@ -47,7 +48,7 @@ class PaymentObserver */ public function deleted(Payment $payment) { - SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_PAYMENT, $payment); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment); } /** diff --git a/app/Observers/QuoteObserver.php b/app/Observers/QuoteObserver.php index 3661d3c207..44e3fff0d9 100644 --- a/app/Observers/QuoteObserver.php +++ b/app/Observers/QuoteObserver.php @@ -11,9 +11,10 @@ namespace App\Observers; -use App\Jobs\Util\SubscriptionHandler; +use App\Jobs\Util\WebhookHandler; use App\Models\Quote; use App\Models\Subscription; +use App\Models\Webhook; class QuoteObserver { @@ -25,7 +26,7 @@ class QuoteObserver */ public function created(Quote $quote) { - SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_QUOTE, $quote); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_QUOTE, $quote); } /** @@ -36,7 +37,7 @@ class QuoteObserver */ public function updated(Quote $quote) { - SubscriptionHandler::dispatch(Subscription::EVENT_UPDATE_QUOTE, $quote); + WebhookHandler::dispatch(Webhook::EVENT_UPDATE_QUOTE, $quote); } /** @@ -47,7 +48,7 @@ class QuoteObserver */ public function deleted(Quote $quote) { - SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_QUOTE, $quote); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_QUOTE, $quote); } /** diff --git a/app/Observers/TaskObserver.php b/app/Observers/TaskObserver.php index 40b25075a7..fe4d0f3fe7 100644 --- a/app/Observers/TaskObserver.php +++ b/app/Observers/TaskObserver.php @@ -11,9 +11,10 @@ namespace App\Observers; -use App\Jobs\Util\SubscriptionHandler; +use App\Jobs\Util\WebhookHandler; use App\Models\Subscription; use App\Models\Task; +use App\Models\Webhook; class TaskObserver { @@ -25,7 +26,7 @@ class TaskObserver */ public function created(Task $task) { - SubscriptionHandler::dispatch(Subscription::EVENT_CREATE_TASK, $task); + WebhookHandler::dispatch(Webhook::EVENT_CREATE_TASK, $task); } /** @@ -36,7 +37,7 @@ class TaskObserver */ public function updated(Task $task) { - SubscriptionHandler::dispatch(Subscription::EVENT_UPDATE_TASK, $task); + WebhookHandler::dispatch(Webhook::EVENT_UPDATE_TASK, $task); } /** @@ -47,7 +48,7 @@ class TaskObserver */ public function deleted(Task $task) { - SubscriptionHandler::dispatch(Subscription::EVENT_DELETE_TASK, $task); + WebhookHandler::dispatch(Webhook::EVENT_DELETE_TASK, $task); } /** diff --git a/app/PaymentDrivers/PayPalExpressPaymentDriver.php b/app/PaymentDrivers/PayPalExpressPaymentDriver.php index e2b8b01f02..4440e1911b 100644 --- a/app/PaymentDrivers/PayPalExpressPaymentDriver.php +++ b/app/PaymentDrivers/PayPalExpressPaymentDriver.php @@ -131,7 +131,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver $transaction_reference = $response->getTransactionReference() ?: $request->input('token'); if ($response->isCancelled()) { - return redirect()->route('client.invoices.index')->with('warning', ctrans('texts.status_voided')); + return redirect()->route('client.invoices.index')->with('warning', ctrans('texts.status_cancelled')); } elseif ($response->isSuccessful()) { SystemLogger::dispatch( [ diff --git a/app/PaymentDrivers/Stripe/SOFORT.php b/app/PaymentDrivers/Stripe/SOFORT.php index fc47742bb4..f2e521f4fd 100644 --- a/app/PaymentDrivers/Stripe/SOFORT.php +++ b/app/PaymentDrivers/Stripe/SOFORT.php @@ -102,6 +102,6 @@ class SOFORT public function processUnsuccessfulPayment($state) { - return redirect()->route('client.invoices.index')->with('warning', ctrans('texts.status_voided')); + return redirect()->route('client.invoices.index')->with('warning', ctrans('texts.status_cancelled')); } } diff --git a/app/Policies/SubscriptionPolicy.php b/app/Policies/WebhookPolicy.php similarity index 81% rename from app/Policies/SubscriptionPolicy.php rename to app/Policies/WebhookPolicy.php index 65201bbe88..11c620ef81 100644 --- a/app/Policies/SubscriptionPolicy.php +++ b/app/Policies/WebhookPolicy.php @@ -12,9 +12,9 @@ namespace App\Policies; /** - * Class SubscriptionPolicy + * Class WebhookPolicy * @package App\Policies */ -class SubscriptionPolicy extends EntityPolicy +class WebhookPolicy extends EntityPolicy { } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 5996bae848..6f6909681c 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -28,10 +28,10 @@ use App\Models\Product; use App\Models\Quote; use App\Models\RecurringInvoice; use App\Models\RecurringQuote; -use App\Models\Subscription; use App\Models\TaxRate; use App\Models\User; use App\Models\Vendor; +use App\Models\Webhook; use App\Policies\ActivityPolicy; use App\Policies\ClientPolicy; use App\Policies\CompanyGatewayPolicy; @@ -49,10 +49,10 @@ use App\Policies\ProductPolicy; use App\Policies\QuotePolicy; use App\Policies\RecurringInvoicePolicy; use App\Policies\RecurringQuotePolicy; -use App\Policies\SubscriptionPolicy; use App\Policies\TaxRatePolicy; use App\Policies\UserPolicy; use App\Policies\VendorPolicy; +use App\Policies\WebhookPolicy; use Auth; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Gate; @@ -82,7 +82,7 @@ class AuthServiceProvider extends ServiceProvider Quote::class => QuotePolicy::class, RecurringInvoice::class => RecurringInvoicePolicy::class, RecurringQuote::class => RecurringQuotePolicy::class, - Subscription::class => SubscriptionPolicy::class, + Webhook::class => WebhookPolicy::class, TaxRate::class => TaxRatePolicy::class, User::class => UserPolicy::class, Vendor::class => VendorPolicy::class, diff --git a/app/Services/Payment/DeletePayment.php b/app/Services/Payment/DeletePayment.php index f4ad8fbb23..548237a909 100644 --- a/app/Services/Payment/DeletePayment.php +++ b/app/Services/Payment/DeletePayment.php @@ -38,7 +38,7 @@ class DeletePayment public function run() { - return $this->setStatus(Payment::STATUS_VOIDED) //sets status of payment + return $this->setStatus(Payment::STATUS_CANCELLED) //sets status of payment ->updateCreditables() //return the credits first ->adjustInvoices() ->updateClient() @@ -109,7 +109,7 @@ class DeletePayment private function setStatus($status) { - $this->payment->status_id = Payment::STATUS_VOIDED; + $this->payment->status_id = Payment::STATUS_CANCELLED; return $this; } diff --git a/app/Transformers/CompanyTokenTransformer.php b/app/Transformers/CompanyTokenTransformer.php index 89eb6b61ee..cd41378703 100644 --- a/app/Transformers/CompanyTokenTransformer.php +++ b/app/Transformers/CompanyTokenTransformer.php @@ -46,6 +46,7 @@ class CompanyTokenTransformer extends EntityTransformer 'user_id' => $this->encodePrimaryKey($company_token->user_id), 'token' => $company_token->token, 'name' => $company_token->name ?: '', + 'is_system' =>(bool)$company_token->is_system, 'updated_at' => (int)$company_token->updated_at, 'archived_at' => (int)$company_token->deleted_at, 'created_at' => (int)$company_token->created_at, diff --git a/app/Transformers/SubscriptionTransformer.php b/app/Transformers/SubscriptionTransformer.php deleted file mode 100644 index b27d8d172d..0000000000 --- a/app/Transformers/SubscriptionTransformer.php +++ /dev/null @@ -1,39 +0,0 @@ - (string) $this->encodePrimaryKey($subscription->id), - 'company_id' => (string) $this->encodePrimaryKey($subscription->company_id), - 'user_id' => (string) $this->encodePrimaryKey($subscription->user_id), - 'archived_at' => (int)$subscription->deleted_at, - 'updated_at' => (int)$subscription->updated_at, - 'created_at' => (int)$subscription->created_at, - 'is_deleted' => (bool)$subscription->is_deleted, - 'target_url' => $subscription->target_url ? (string) $subscription->target_url : '', - 'event_id' => (string) $subscription->event_id, - 'format' => (string) $subscription->format, - ]; - } -} diff --git a/app/Transformers/WebhookTransformer.php b/app/Transformers/WebhookTransformer.php new file mode 100644 index 0000000000..4ffff6398b --- /dev/null +++ b/app/Transformers/WebhookTransformer.php @@ -0,0 +1,39 @@ + (string) $this->encodePrimaryKey($webhook->id), + 'company_id' => (string) $this->encodePrimaryKey($webhook->company_id), + 'user_id' => (string) $this->encodePrimaryKey($webhook->user_id), + 'archived_at' => (int)$webhook->deleted_at, + 'updated_at' => (int)$webhook->updated_at, + 'created_at' => (int)$webhook->created_at, + 'is_deleted' => (bool)$webhook->is_deleted, + 'target_url' => $webhook->target_url ? (string) $webhook->target_url : '', + 'event_id' => (string) $webhook->event_id, + 'format' => (string) $webhook->format, + ]; + } +} diff --git a/composer.lock b/composer.lock index 65cde2fc85..6b23f442e8 100644 --- a/composer.lock +++ b/composer.lock @@ -1089,20 +1089,6 @@ "sqlserver", "sqlsrv" ], - "funding": [ - { - "url": "https://www.doctrine-project.org/sponsorship.html", - "type": "custom" - }, - { - "url": "https://www.patreon.com/phpdoctrine", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdbal", - "type": "tidelift" - } - ], "time": "2020-04-20T17:19:26+00:00" }, { diff --git a/database/migrations/2020_07_05_084934_company_too_large_attribute.php b/database/migrations/2020_07_05_084934_company_too_large_attribute.php index a87cdbec2f..7086b7139c 100644 --- a/database/migrations/2020_07_05_084934_company_too_large_attribute.php +++ b/database/migrations/2020_07_05_084934_company_too_large_attribute.php @@ -13,9 +13,17 @@ class CompanyTooLargeAttribute extends Migration */ public function up() { + Schema::table('companies', function (Blueprint $table) { $table->boolean('is_large')->default(0); }); + + Schema::table('company_tokens', function (Blueprint $table) { + $table->boolean('is_system')->default(0); + }); + + Schema::rename('subscriptions', 'webhooks'); + } /** diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index d3367910f1..1edee92a32 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -3234,6 +3234,9 @@ return [ 'enable_only_for_development' => 'Enable only for development', 'test_pdf' => 'Test PDF', + 'status_cancelled' => 'Cancelled', 'checkout_authorize_label' => 'Checkout.com can be can saved as payment method for future use, once you complete your first transaction. Don\'t forget to check "Save card" during payment process.', + + ]; diff --git a/routes/api.php b/routes/api.php index ee263086ff..650d953553 100644 --- a/routes/api.php +++ b/routes/api.php @@ -135,8 +135,9 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a /*Subscription and Webhook routes */ Route::post('hooks', 'SubscriptionController@subscribe')->name('hooks.subscribe'); Route::delete('hooks/{subscription_id}', 'SubscriptionController@unsubscribe')->name('hooks.unsubscribe'); - Route::resource('subscriptions', 'SubscriptionController'); - Route::post('subscriptions/bulk', 'SubscriptionController@bulk')->name('subscriptions.bulk'); + + Route::resource('webhooks', 'WebhookController'); + Route::post('webhooks/bulk', 'WebhookController@bulk')->name('webhooks.bulk'); /*Company Ledger */ Route::get('company_ledger', 'CompanyLedgerController@index')->name('company_ledger.index'); diff --git a/tests/Feature/SubscriptionAPITest.php b/tests/Feature/WebhookAPITest.php similarity index 82% rename from tests/Feature/SubscriptionAPITest.php rename to tests/Feature/WebhookAPITest.php index c52b9b228e..128f4752bf 100644 --- a/tests/Feature/SubscriptionAPITest.php +++ b/tests/Feature/WebhookAPITest.php @@ -15,10 +15,10 @@ use Tests\TestCase; /** * @test - * @covers App\Http\Controllers\SubscriptionController + * @covers App\Http\Controllers\WebhookController */ -class SubscriptionAPITest extends TestCase +class WebhookAPITest extends TestCase { use MakesHash; use DatabaseTransactions; @@ -41,17 +41,17 @@ class SubscriptionAPITest extends TestCase $this->withoutExceptionHandling(); } - public function testSubscriptionGetRoute() + public function testWebhookGetRoute() { $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, - ])->get('/api/v1/subscriptions'); + ])->get('/api/v1/webhooks'); $response->assertStatus(200); } - public function testSubscriptionPostRoute() + public function testWebhookPostRoute() { $data = [ 'target_url' => 'http://hook.com', @@ -62,7 +62,7 @@ class SubscriptionAPITest extends TestCase $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, - ])->post('/api/v1/subscriptions', $data); + ])->post('/api/v1/webhooks', $data); $response->assertStatus(200); @@ -77,7 +77,7 @@ class SubscriptionAPITest extends TestCase $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, - ])->put('/api/v1/subscriptions/'.$arr['data']['id'], $data); + ])->put('/api/v1/webhooks/'.$arr['data']['id'], $data); $response->assertStatus(200); @@ -88,7 +88,7 @@ class SubscriptionAPITest extends TestCase $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, - ])->delete('/api/v1/subscriptions/'.$arr['data']['id']); + ])->delete('/api/v1/webhooks/'.$arr['data']['id']); $arr = $response->json(); @@ -103,7 +103,7 @@ class SubscriptionAPITest extends TestCase $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token - ])->post('/api/v1/subscriptions/bulk?action=restore', $data); + ])->post('/api/v1/webhooks/bulk?action=restore', $data); $arr = $response->json(); @@ -113,7 +113,7 @@ class SubscriptionAPITest extends TestCase $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token - ])->post('/api/v1/subscriptions/bulk?action=delete', $data); + ])->post('/api/v1/webhooks/bulk?action=delete', $data); $arr = $response->json(); From d236dd6ff629c8c6352c0ff1cbd82160dec26a07 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 6 Jul 2020 21:42:42 +1000 Subject: [PATCH 09/10] Fixes for observers --- app/Console/Commands/DemoMode.php | 26 +++++++++++++++++--------- app/Jobs/Util/WebhookHandler.php | 3 +-- app/Observers/ClientObserver.php | 1 - app/Observers/ExpenseObserver.php | 1 - app/Observers/InvoiceObserver.php | 1 - app/Observers/PaymentObserver.php | 1 - app/Observers/QuoteObserver.php | 1 - app/Observers/TaskObserver.php | 1 - 8 files changed, 18 insertions(+), 17 deletions(-) diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index c2ac9e0caa..286a121fe3 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -177,36 +177,44 @@ class DemoMode extends Command $client = $company->clients->random(); $this->info('creating invoice for client #'.$client->id); - $this->createInvoice($client); + + for($y=0; $y<($this->count); $y++){ + $this->info("creating invoice #{$y} for client #".$client->id); + $this->createInvoice($client); + } $client = $company->clients->random(); - $this->info('creating credit for client #'.$client->id); - $this->createCredit($client); + for($y=0; $y<($this->count); $y++){ + $this->info("creating credit #{$y} for client #".$client->id); + $this->createCredit($client); + } $client = $company->clients->random(); - $this->info('creating quote for client #'.$client->id); - $this->createQuote($client); + for($y=0; $y<($this->count); $y++){ + $this->info("creating quote #{$y} for client #".$client->id); + $this->createQuote($client); + } $client = $company->clients->random(); - $this->info('creating expense for client #'.$client->id); + $this->info("creating expense for client #".$client->id); $this->createExpense($client); $client = $company->clients->random(); - $this->info('creating vendor for client #'.$client->id); + $this->info("creating vendor for client #".$client->id); $this->createVendor($client); $client = $company->clients->random(); - $this->info('creating task for client #'.$client->id); + $this->info("creating task for client #".$client->id); $this->createTask($client); $client = $company->clients->random(); - $this->info('creating project for client #'.$client->id); + $this->info("creating project for client #".$client->id); $this->createProject($client); } diff --git a/app/Jobs/Util/WebhookHandler.php b/app/Jobs/Util/WebhookHandler.php index 537beff56a..0212fc08a4 100644 --- a/app/Jobs/Util/WebhookHandler.php +++ b/app/Jobs/Util/WebhookHandler.php @@ -2,7 +2,6 @@ namespace App\Jobs\Util; -use App\Models\Subscription; use App\Transformers\ArraySerializer; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -45,7 +44,7 @@ class WebhookHandler implements ShouldQueue //info("i got past the check"); - $subscriptions = Webhook::where('company_id', $this->entity->company_id) + $subscriptions = \App\Models\Webhook::where('company_id', $this->entity->company_id) ->where('event_id', $this->event_id) ->get(); diff --git a/app/Observers/ClientObserver.php b/app/Observers/ClientObserver.php index d602083fc1..e13e1d7f1f 100644 --- a/app/Observers/ClientObserver.php +++ b/app/Observers/ClientObserver.php @@ -14,7 +14,6 @@ namespace App\Observers; use App\Events\Client\ClientWasCreated; use App\Jobs\Util\WebhookHandler; use App\Models\Client; -use App\Models\Subscription; use App\Models\Webhook; class ClientObserver diff --git a/app/Observers/ExpenseObserver.php b/app/Observers/ExpenseObserver.php index 381f31abab..db34d1af77 100644 --- a/app/Observers/ExpenseObserver.php +++ b/app/Observers/ExpenseObserver.php @@ -13,7 +13,6 @@ namespace App\Observers; use App\Jobs\Util\WebhookHandler; use App\Models\Expense; -use App\Models\Subscription; use App\Models\Webhook; class ExpenseObserver diff --git a/app/Observers/InvoiceObserver.php b/app/Observers/InvoiceObserver.php index 0d0e369ac9..d3b2e773c2 100644 --- a/app/Observers/InvoiceObserver.php +++ b/app/Observers/InvoiceObserver.php @@ -13,7 +13,6 @@ namespace App\Observers; use App\Jobs\Util\WebhookHandler; use App\Models\Invoice; -use App\Models\Subscription; use App\Models\Webhook; class InvoiceObserver diff --git a/app/Observers/PaymentObserver.php b/app/Observers/PaymentObserver.php index 19859359be..27f57fc1b7 100644 --- a/app/Observers/PaymentObserver.php +++ b/app/Observers/PaymentObserver.php @@ -14,7 +14,6 @@ namespace App\Observers; use App\Events\Payment\PaymentWasCreated; use App\Jobs\Util\WebhookHandler; use App\Models\Payment; -use App\Models\Subscription; use App\Models\Webhook; class PaymentObserver diff --git a/app/Observers/QuoteObserver.php b/app/Observers/QuoteObserver.php index 44e3fff0d9..616dae724a 100644 --- a/app/Observers/QuoteObserver.php +++ b/app/Observers/QuoteObserver.php @@ -13,7 +13,6 @@ namespace App\Observers; use App\Jobs\Util\WebhookHandler; use App\Models\Quote; -use App\Models\Subscription; use App\Models\Webhook; class QuoteObserver diff --git a/app/Observers/TaskObserver.php b/app/Observers/TaskObserver.php index fe4d0f3fe7..fa2dafacc5 100644 --- a/app/Observers/TaskObserver.php +++ b/app/Observers/TaskObserver.php @@ -12,7 +12,6 @@ namespace App\Observers; use App\Jobs\Util\WebhookHandler; -use App\Models\Subscription; use App\Models\Task; use App\Models\Webhook; From 2281b8490ef30e3c485f5fbdf1d9b636edf2e35e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 6 Jul 2020 21:44:12 +1000 Subject: [PATCH 10/10] minor fix for tokens --- app/Repositories/TokenRepository.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Repositories/TokenRepository.php b/app/Repositories/TokenRepository.php index 82543528f1..d63cb6f54a 100644 --- a/app/Repositories/TokenRepository.php +++ b/app/Repositories/TokenRepository.php @@ -37,7 +37,8 @@ class TokenRepository extends BaseRepository public function save(array $data, CompanyToken $company_token) { $company_token->fill($data); - + $company_token->is_system = true; + $company_token->save(); return $company_token;