| @@ -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 | { |
| @@ -152,9 +153,13 @@ | ||
| 152 | 153 | $prorateCredit = self::calculateUpgradeToDiscount($order, $originalItem); |
| 153 | 154 | } |
| 154 | 155 | |
| 155 | 156 | $signupFee = Arr::get($variant->other_info, 'signup_fee', 0); |
| 156 | - $cost = floatval($variant->item_price + Arr::get($variant->other_info, 'signup_fee', 0) - $prorateCredit - $discountAmount); | |
| 157 | + if (empty($signupFee)) { | |
| 158 | + $signupFee = 0; | |
| 159 | + } | |
| 160 | + | |
| 161 | + $cost = floatval($variant->item_price + $signupFee - $prorateCredit - $discountAmount); | |
| 157 | 162 | |
| 158 | 163 | if ($cost < 0) { |
| 159 | 164 | $cost = 0; |
| 160 | 165 | } |
| @@ -243,20 +248,15 @@ | ||
| 243 | 248 | } |
| 244 | 249 | |
| 245 | 250 | $daysRemaining = ceil((strtotime($subscription->next_billing_date) - time()) / 86400); // convert seconds to days |
| 246 | 251 | |
| 247 | - $maps = [ | |
| 248 | - 'monthly' => (int) gmdate('t'), // Get exact days in current month (handles leap year) to avoid false remaining days calculation | |
| 249 | - 'yearly' => 365, | |
| 250 | - 'weekly' => 7, | |
| 251 | - 'daily' => 1, | |
| 252 | - ]; | |
| 252 | + $divider = PaymentHelper::getIntervalDays($subscription->billing_interval); | |
| 253 | 253 | |
| 254 | - if (!isset($maps[$subscription->billing_interval])) { | |
| 255 | - 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; | |
| 256 | 258 | } |
| 257 | - | |
| 258 | - $divider = $maps[$subscription->billing_interval]; | |
| 259 | 259 | |
| 260 | 260 | if ($daysRemaining > $divider) { // making sure we are not giving discount more than the actual amount |
| 261 | 261 | $daysRemaining = $divider; |
| 262 | 262 | } |