Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/EntitlementObserver.php
Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | public function deleting(Entitlement $entitlement) | ||||
} | } | ||||
$owner = $entitlement->wallet->owner; | $owner = $entitlement->wallet->owner; | ||||
if ($owner->isDegraded()) { | if ($owner->isDegraded()) { | ||||
return; | return; | ||||
} | } | ||||
// Determine if we're still within the free first month | $now = Carbon::now(); | ||||
$freeMonthEnds = $owner->created_at->copy()->addMonthsWithoutOverflow(1); | |||||
if ($freeMonthEnds >= Carbon::now()) { | // Determine if we're still within the trial period | ||||
$trial = $entitlement->wallet->trialInfo(); | |||||
if ( | |||||
!empty($trial) | |||||
&& $entitlement->updated_at < $trial['end'] | |||||
&& in_array($entitlement->sku_id, $trial['skus']) | |||||
) { | |||||
if ($trial['end'] >= $now) { | |||||
return; | return; | ||||
} | } | ||||
$now = Carbon::now(); | $entitlement->updated_at = $trial['end']; | ||||
mollekopf: Why are we doing this? A comment would be helpful. | |||||
Done Inline ActionsBelow we calculate the price using updated_at timestamp. machniak: Below we calculate the price using updated_at timestamp. | |||||
} | |||||
// get the discount rate applied to the wallet. | // get the discount rate applied to the wallet. | ||||
$discount = $entitlement->wallet->getDiscountRate(); | $discount = $entitlement->wallet->getDiscountRate(); | ||||
// just in case this had not been billed yet, ever | // just in case this had not been billed yet, ever | ||||
$diffInMonths = $entitlement->updated_at->diffInMonths($now); | $diffInMonths = $entitlement->updated_at->diffInMonths($now); | ||||
$cost = (int) ($entitlement->cost * $discount * $diffInMonths); | $cost = (int) ($entitlement->cost * $discount * $diffInMonths); | ||||
$fee = (int) ($entitlement->fee * $diffInMonths); | $fee = (int) ($entitlement->fee * $diffInMonths); | ||||
Show All 30 Lines | public function deleting(Entitlement $entitlement) | ||||
$method = $profit > 0 ? 'credit' : 'debit'; | $method = $profit > 0 ? 'credit' : 'debit'; | ||||
$wallet->{$method}(abs($profit), $desc); | $wallet->{$method}(abs($profit), $desc); | ||||
} | } | ||||
if ($cost == 0) { | if ($cost == 0) { | ||||
return; | return; | ||||
} | } | ||||
// FIXME: Shouldn't we create per-entitlement transaction record? | |||||
$entitlement->wallet->debit($cost); | $entitlement->wallet->debit($cost); | ||||
} | } | ||||
} | } |
Why are we doing this? A comment would be helpful.