Fixes for webhook bug

This commit is contained in:
David Bomba 2021-07-20 08:39:04 +10:00
parent 46852794aa
commit 48c5c56a4a
2 changed files with 10 additions and 9 deletions

View File

@ -111,12 +111,9 @@ class WebhookHandler implements ShouldQueue
try { try {
$response = $client->post($subscription->target_url, [ $response = $client->post($subscription->target_url, [
RequestOptions::JSON => $data, // or 'json' => [...] RequestOptions::JSON => $data, // or 'json' => [...]
]); ]);
if ($response->getStatusCode() == 410 || $response->getStatusCode() == 200)
$subscription->delete();
SystemLogger::dispatch( SystemLogger::dispatch(
$response, $response,
@ -127,10 +124,13 @@ class WebhookHandler implements ShouldQueue
$this->company $this->company
); );
// if ($response->getStatusCode() == 410 || $response->getStatusCode() == 200)
// return true;// $subscription->delete();
} }
catch(\Exception $e){ catch(\Exception $e){
// nlog($e->getMessage()); nlog($e->getMessage());
SystemLogger::dispatch( SystemLogger::dispatch(
$e->getMessage(), $e->getMessage(),
@ -143,8 +143,6 @@ class WebhookHandler implements ShouldQueue
} }
} }
public function failed($exception) public function failed($exception)

View File

@ -19,6 +19,8 @@ use App\Models\Webhook;
class InvoiceObserver class InvoiceObserver
{ {
public $afterCommit = true;
/** /**
* Handle the client "created" event. * Handle the client "created" event.
* *
@ -27,6 +29,7 @@ class InvoiceObserver
*/ */
public function created(Invoice $invoice) public function created(Invoice $invoice)
{ {
$subscriptions = Webhook::where('company_id', $invoice->company->id) $subscriptions = Webhook::where('company_id', $invoice->company->id)
->where('event_id', Webhook::EVENT_CREATE_INVOICE) ->where('event_id', Webhook::EVENT_CREATE_INVOICE)
->exists(); ->exists();