1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Observers/CreditObserver.php

95 lines
2.4 KiB
PHP
Raw Normal View History

2021-02-15 11:52:50 +01:00
<?php
/**
* Credit Ninja (https://creditninja.com).
*
* @link https://github.com/creditninja/creditninja source repository
*
2022-04-27 05:20:41 +02:00
* @copyright Copyright (c) 2022. Credit Ninja LLC (https://creditninja.com)
2021-02-15 11:52:50 +01:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2021-02-15 11:52:50 +01:00
*/
namespace App\Observers;
use App\Jobs\Util\UnlinkFile;
use App\Jobs\Util\WebhookHandler;
use App\Models\Client;
use App\Models\Credit;
use App\Models\Webhook;
class CreditObserver
{
/**
* Handle the client "created" event.
*
* @param Credit $credit
* @return void
*/
public function created(Credit $credit)
{
2022-09-15 09:43:33 +02:00
$subscriptions = Webhook::where('company_id', $credit->company->id)
->where('event_id', Webhook::EVENT_CREATE_CREDIT)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_CREATE_CREDIT, $credit, $credit->company)->delay(now()->addSeconds(2));
}
2021-02-15 11:52:50 +01:00
}
/**
* Handle the client "updated" event.
*
* @param Credit $credit
* @return void
*/
public function updated(Credit $credit)
{
2022-09-15 09:43:33 +02:00
$subscriptions = Webhook::where('company_id', $credit->company->id)
->where('event_id', Webhook::EVENT_UPDATE_CREDIT)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_CREDIT, $credit, $credit->company)->delay(now()->addSeconds(2));
}
2021-02-15 11:52:50 +01:00
}
/**
* Handle the client "deleted" event.
*
* @param Credit $credit
* @return void
*/
public function deleted(Credit $credit)
{
2022-09-15 09:43:33 +02:00
$subscriptions = Webhook::where('company_id', $credit->company->id)
->where('event_id', Webhook::EVENT_DELETE_CREDIT)
->exists();
if ($subscriptions) {
WebhookHandler::dispatch(Webhook::EVENT_DELETE_CREDIT, $credit, $credit->company)->delay(now()->addSeconds(2));
}
2021-02-15 11:52:50 +01:00
}
/**
* Handle the client "restored" event.
*
* @param Credit $credit
* @return void
*/
public function restored(Credit $credit)
{
//
}
/**
* Handle the client "force deleted" event.
*
* @param Credit $credit
* @return void
*/
public function forceDeleted(Credit $credit)
{
//
}
}