Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/EntitlementObserver.php
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | class EntitlementObserver | ||||
{ | { | ||||
// Remove all configured 2FA methods from Roundcube database | // Remove all configured 2FA methods from Roundcube database | ||||
if ($entitlement->sku->title == '2fa') { | if ($entitlement->sku->title == '2fa') { | ||||
// FIXME: Should that be an async job? | // FIXME: Should that be an async job? | ||||
$sf = new \App\Auth\SecondFactor($entitlement->entitleable); | $sf = new \App\Auth\SecondFactor($entitlement->entitleable); | ||||
$sf->removeFactors(); | $sf->removeFactors(); | ||||
} | } | ||||
if ($entitlement->entitleable && !$entitlement->entitleable->trashed()) { | if (!$entitlement->entitleable->trashed()) { | ||||
$entitlement->entitleable->updated_at = Carbon::now(); | $entitlement->entitleable->updated_at = Carbon::now(); | ||||
$entitlement->entitleable->save(); | $entitlement->entitleable->save(); | ||||
$entitlement->createTransaction(\App\Transaction::ENTITLEMENT_DELETED); | $entitlement->createTransaction(\App\Transaction::ENTITLEMENT_DELETED); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
Show All 14 Lines | public function deleting(Entitlement $entitlement) | ||||
// | // | ||||
// Effect is that anything's free for the first 14 days | // Effect is that anything's free for the first 14 days | ||||
if ($entitlement->created_at >= Carbon::now()->subDays(14)) { | if ($entitlement->created_at >= Carbon::now()->subDays(14)) { | ||||
return; | return; | ||||
} | } | ||||
$owner = $entitlement->wallet->owner; | $owner = $entitlement->wallet->owner; | ||||
if ($owner->isDegraded()) { | |||||
return; | |||||
} | |||||
// Determine if we're still within the free first month | // Determine if we're still within the free first month | ||||
$freeMonthEnds = $owner->created_at->copy()->addMonthsWithoutOverflow(1); | $freeMonthEnds = $owner->created_at->copy()->addMonthsWithoutOverflow(1); | ||||
if ($freeMonthEnds >= Carbon::now()) { | if ($freeMonthEnds >= Carbon::now()) { | ||||
return; | return; | ||||
} | } | ||||
$now = Carbon::now(); | $now = Carbon::now(); | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |