Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/WalletObserver.php
Show All 32 Lines | class WalletObserver | ||||
* Ensures that a wallet with a non-zero balance can not be deleted. | * Ensures that a wallet with a non-zero balance can not be deleted. | ||||
* | * | ||||
* Ensures that the wallet being deleted is not the last wallet for the user. | * Ensures that the wallet being deleted is not the last wallet for the user. | ||||
* | * | ||||
* Ensures that no entitlements are being billed to the wallet currently. | * Ensures that no entitlements are being billed to the wallet currently. | ||||
* | * | ||||
* @param Wallet $wallet The wallet being deleted. | * @param Wallet $wallet The wallet being deleted. | ||||
* | * | ||||
* @return boolean|null | * @return bool | ||||
*/ | */ | ||||
public function deleting(Wallet $wallet) | public function deleting(Wallet $wallet): bool | ||||
{ | { | ||||
// can't delete a wallet that has any balance on it (positive and negative). | // can't delete a wallet that has any balance on it (positive and negative). | ||||
if ($wallet->balance != 0.00) { | if ($wallet->balance != 0.00) { | ||||
return false; | return false; | ||||
} | } | ||||
if (!$wallet->owner) { | if (!$wallet->owner) { | ||||
throw new \Exception("Wallet: " . var_export($wallet, true)); | throw new \Exception("Wallet: " . var_export($wallet, true)); | ||||
Show All 9 Lines | public function deleting(Wallet $wallet): bool | ||||
return false; | return false; | ||||
} | } | ||||
/* | /* | ||||
// 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; | |||||
} | } | ||||
} | } |