Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/WalletObserver.php
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | /* | ||||
// can't remove a wallet that has payments attached. | // can't remove a wallet that has payments attached. | ||||
if ($wallet->payments()->count() > 0) { | if ($wallet->payments()->count() > 0) { | ||||
return false; | return false; | ||||
} | } | ||||
*/ | */ | ||||
return true; | return true; | ||||
} | } | ||||
/** | |||||
* Handle the wallet "updated" event. | |||||
* | |||||
* @param \App\Wallet $wallet The wallet. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function updated(Wallet $wallet) | |||||
{ | |||||
$negative_since = $wallet->getSetting('balance_negative_since'); | |||||
if ($wallet->balance < 0) { | |||||
if (!$negative_since) { | |||||
$now = \Carbon\Carbon::now()->toDateTimeString(); | |||||
$wallet->setSetting('balance_negative_since', $now); | |||||
} | |||||
} elseif ($negative_since) { | |||||
$wallet->setSettings([ | |||||
'balance_negative_since' => null, | |||||
'balance_warning_initial' => null, | |||||
'balance_warning_reminder' => null, | |||||
'balance_warning_suspended' => null, | |||||
'balance_warning_before_delete' => null, | |||||
]); | |||||
// Unsuspend the account/domains/users | |||||
if ($wallet->owner) { | |||||
$wallet->owner->unsuspend(); | |||||
} | |||||
foreach ($wallet->entitlements as $entitlement) { | |||||
if ( | |||||
$entitlement->entitleable_type == \App\Domain::class | |||||
|| $entitlement->entitleable_type == \App\User::class | |||||
) { | |||||
$entitlement->entitleable->unsuspend(); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | } |