From 6ef34933bcaa6216c45c49a7c8eb080612b1ec7c Mon Sep 17 00:00:00 2001 From: ilestis Date: Thu, 24 Oct 2024 12:25:55 -0600 Subject: [PATCH] Fix paypal upgrade broken --- app/Http/Controllers/Settings/SubscriptionController.php | 2 +- app/Services/PayPalService.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Settings/SubscriptionController.php b/app/Http/Controllers/Settings/SubscriptionController.php index 1957a7c65..f3b6e3997 100644 --- a/app/Http/Controllers/Settings/SubscriptionController.php +++ b/app/Http/Controllers/Settings/SubscriptionController.php @@ -115,7 +115,7 @@ public function change(Request $request, Tier $tier) $period = $request->get('period') === 'yearly' ? PricingPeriod::Yearly : PricingPeriod::Monthly; // If the user has a cancelled sub still ending - if ($user->subscribed('kanka') && $user->subscription('kanka')->onGracePeriod()) { + if ($user->subscribed('kanka') && $user->subscription('kanka')->onGracePeriod() && !$user->hasPayPal()) { return view('settings.subscription.change_blocked') ->with('user', $user); } diff --git a/app/Services/PayPalService.php b/app/Services/PayPalService.php index 2c4a0d6a8..ea68d2063 100644 --- a/app/Services/PayPalService.php +++ b/app/Services/PayPalService.php @@ -47,9 +47,9 @@ public function process(): mixed $oldPrice = $tier->yearly; } // @phpstan-ignore-next-line - $price = (floatval($price) - ($oldPrice)) * ($this->user->subscriptions()->first()->ends_at->diffInDays(Carbon::now()) / 365); - $price = number_format($price, 2); + $price = round(($price - ($oldPrice)) * ($this->user->subscriptions()->first()->ends_at->diffInDays(Carbon::now(), true) / 365), 2); } + $price = max(0, $price); $provider = new PayPal(); $provider->setApiCredentials(config('paypal'));