Initial commit
This commit is contained in:
33
app/Observers/TransactionObserver.php
Normal file
33
app/Observers/TransactionObserver.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\Transaction;
|
||||
use App\Services\CallCreditService;
|
||||
|
||||
class TransactionObserver
|
||||
{
|
||||
/**
|
||||
* After a transaction is created, check if the spending profile
|
||||
* still has sufficient credits. If not, pause all their active calls.
|
||||
*/
|
||||
public function created(Transaction $transaction): void
|
||||
{
|
||||
$fromAccount = $transaction->accountFrom;
|
||||
if (!$fromAccount) {
|
||||
return;
|
||||
}
|
||||
|
||||
$accountable = $fromAccount->accountable;
|
||||
if (!$accountable) {
|
||||
return;
|
||||
}
|
||||
|
||||
$profileType = get_class($accountable);
|
||||
$profileId = $accountable->id;
|
||||
|
||||
if (!CallCreditService::profileHasCredits($profileType, $profileId)) {
|
||||
CallCreditService::pauseAllActiveCalls($profileType, $profileId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user