PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
← All changes | app/Services/PlanUpgradeService.php +6 -10 1.6.0 → 1.6.5 View file →
@@ -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 }