| @@ -8,8 +8,9 @@ | ||
| 8 | 8 | use FluentCart\App\Models\Order; |
| 9 | 9 | use FluentCart\App\Models\OrderItem; |
| 10 | 10 | use FluentCart\App\Models\ProductVariation; |
| 11 | 11 | use FluentCart\App\Models\Subscription; |
| 12 | +use FluentCart\App\Services\Payments\PaymentHelper; | |
| 12 | 13 | use FluentCart\Framework\Support\Arr; |
| 13 | 14 | |
| 14 | 15 | class PlanUpgradeService |
| 15 | 16 | { |
| @@ -247,20 +248,15 @@ | ||
| 247 | 248 | } |
| 248 | 249 | |
| 249 | 250 | $daysRemaining = ceil((strtotime($subscription->next_billing_date) - time()) / 86400); // convert seconds to days |
| 250 | 251 | |
| 251 | - $maps = [ | |
| 252 | - 'monthly' => (int) gmdate('t'), // Get exact days in current month (handles leap year) to avoid false remaining days calculation | |
| 253 | - 'yearly' => 365, | |
| 254 | - 'weekly' => 7, | |
| 255 | - 'daily' => 1, | |
| 256 | - ]; | |
| 252 | + $divider = PaymentHelper::getIntervalDays($subscription->billing_interval); | |
| 257 | 253 | |
| 258 | - if (!isset($maps[$subscription->billing_interval])) { | |
| 259 | - return 0; // Invalid repeat interval | |
| 254 | + // 0 = interval neither core nor filter-resolved; no credit rather than the | |
| 255 | + // full paid amount the days-remaining cap would otherwise allow. | |
| 256 | + if ($divider < 1) { | |
| 257 | + return 0; | |
| 260 | 258 | } |
| 261 | - | |
| 262 | - $divider = $maps[$subscription->billing_interval]; | |
| 263 | 259 | |
| 264 | 260 | if ($daysRemaining > $divider) { // making sure we are not giving discount more than the actual amount |
| 265 | 261 | $daysRemaining = $divider; |
| 266 | 262 | } |