Clean up Webhook Handler

This commit is contained in:
David Bomba 2021-09-26 20:17:09 +10:00
parent fb5b27323e
commit c581c183ac
2 changed files with 5 additions and 3 deletions

View File

@ -13,6 +13,7 @@ namespace App\Jobs\Util;
use App\Jobs\Util\SystemLogger; use App\Jobs\Util\SystemLogger;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use App\Models\Client as ClientModel;
use App\Models\SystemLog; use App\Models\SystemLog;
use App\Models\Webhook; use App\Models\Webhook;
use App\Transformers\ArraySerializer; use App\Transformers\ArraySerializer;
@ -147,11 +148,12 @@ class WebhookHandler implements ShouldQueue
private function resolveClient() private function resolveClient()
{ {
if($this->entity->client()->exists()){ //make sure it isn't an instance of the Client Model
if((!$this->entity instanceof ClientModel) && $this->entity->client()->exists()){
return $this->entity->client; return $this->entity->client;
} }
return $this->company->clients->first(); return $this->company->clients()->first();
} }
public function failed($exception) public function failed($exception)

View File

@ -287,7 +287,7 @@ class BaseDriver extends AbstractPaymentDriver
$invoices->each(function ($invoice) use ($fee_total) { $invoices->each(function ($invoice) use ($fee_total) {
if (collect($invoice->line_items)->contains('type_id', '3')) { if (collect($invoice->line_items)->contains('type_id', '3')) {
$invoice->service()->toggleFeesPaid()->deletePdf()->save(); $invoice->service()->toggleFeesPaid()->save();
$invoice->client->service()->updateBalance($fee_total)->save(); $invoice->client->service()->updateBalance($fee_total)->save();
$invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for invoice {$invoice->number}"); $invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for invoice {$invoice->number}");
} }