Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117748486
WalletObserver.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
WalletObserver.php
View Options
<?php
namespace
App\Observers
;
use
App\Wallet
;
/**
* This is an observer for the Wallet model definition.
*/
class
WalletObserver
{
/**
* Ensure the wallet ID is a custom ID (uuid).
*
* @param Wallet $wallet
*
* @return void
*/
public
function
creating
(
Wallet
$wallet
)
{
while
(
true
)
{
$allegedly_unique
=
\App\Utils
::
uuidStr
();
if
(!
Wallet
::
find
(
$allegedly_unique
))
{
$wallet
->{
$wallet
->
getKeyName
()}
=
$allegedly_unique
;
break
;
}
}
}
/**
* Handle the wallet "deleting" event.
*
* 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 no entitlements are being billed to the wallet currently.
*
* @param Wallet $wallet The wallet being deleted.
*
* @return boolean|null
*/
public
function
deleting
(
Wallet
$wallet
)
{
// can't delete a wallet that has any balance on it (positive and negative).
if
(
$wallet
->
balance
!=
0.00
)
{
return
false
;
}
if
(!
$wallet
->
owner
)
{
throw
new
\Exception
(
"Wallet: "
.
var_export
(
$wallet
,
true
));
}
// can't remove the last wallet for the owner.
if
(
$wallet
->
owner
->
wallets
()->
count
()
<=
1
)
{
return
false
;
}
// can't remove a wallet that has billable entitlements attached.
if
(
$wallet
->
entitlements
()->
count
()
>
0
)
{
return
false
;
}
/*
// can't remove a wallet that has payments attached.
if ($wallet->payments()->count() > 0) {
return false;
}
*/
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Apr 4, 1:02 AM (3 w, 2 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
48/1d/8f759468b21267ee7980889008a7
Default Alt Text
WalletObserver.php (1 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline