Note: After changing the package, refund is not possible.
@php
// On a subreseller POP $packages holds SubPackage rows, which
// name their columns `name`/`rate`; everywhere else they are
// Packages rows with `package_name`/`package_rate`. Normalise
// once here so the two loops below can't read the wrong column.
$isSubresellerPop = $details['userinfo']->pop->subreseller == 'yes';
$currentRate = $details['package']->package_rate;
$packageOptions = collect($packages)
->map(function ($package) use ($isSubresellerPop, $currentRate, $days_left_to_expire) {
$rate = $isSubresellerPop ? $package->rate : $package->package_rate;
$name = $isSubresellerPop ? $package->name : $package->package_name;
// Only an upgrade is charged, and only for the days left.
$cost = 0;
if ($days_left_to_expire > 0 && $currentRate < $rate) {
$cost = ($rate / 30) * $days_left_to_expire;
}
return [
'id' => $package->id,
'name' => $name,
'rate' => $rate,
'cost' => $cost,
];
});
@endphp