+ {!! __('settings.subscription.cancel.grace.text', ['date' => '' . $endDate . ''])!!} +
++ {!! __('subscriptions/renew.helper')!!} +
+diff --git a/app/Enums/Permission.php b/app/Enums/Permission.php index 4179019958..28daef3e34 100644 --- a/app/Enums/Permission.php +++ b/app/Enums/Permission.php @@ -24,4 +24,3 @@ enum Permission: int case PostTemplates = 18; case Bookmarks = 19; } - diff --git a/app/Http/Controllers/CrudController.php b/app/Http/Controllers/CrudController.php index 78daeea2c2..28b8152922 100644 --- a/app/Http/Controllers/CrudController.php +++ b/app/Http/Controllers/CrudController.php @@ -696,7 +696,6 @@ protected function hasLimitCheck(bool $value = true): self /** * Load a list of templates the user can create new entities from - * @param MiscModel $model */ protected function loadTemplates(EntityType $entityType): Collection { diff --git a/app/Http/Controllers/Settings/SubscriptionController.php b/app/Http/Controllers/Settings/SubscriptionController.php index 79037db3e7..ab6ebf1cc0 100644 --- a/app/Http/Controllers/Settings/SubscriptionController.php +++ b/app/Http/Controllers/Settings/SubscriptionController.php @@ -15,6 +15,7 @@ use App\Services\Users\CurrencyService; use App\Services\Users\EmailValidationService; use App\Models\User; +use App\Models\UserLog; use Exception; use Illuminate\Http\Request; use Illuminate\Support\Arr; @@ -115,6 +116,10 @@ public function change(Request $request, Tier $tier) // If the user has a cancelled sub still ending if ($user->subscribed('kanka') && $user->subscription('kanka')->onGracePeriod() && !$user->hasPayPal()) { + if ($tier->isCurrent($user)) { + return view('settings.subscription.renew') + ->with('user', $user); + } return view('settings.subscription.change_blocked') ->with('user', $user); } @@ -169,6 +174,44 @@ public function change(Request $request, Tier $tier) )); } + public function renew(Request $request) + { + if ($request->ajax()) { + return response()->json([]); + } + try { + $this->subscription + ->user($request->user()) + ->renew(); + $request->user()->log(UserLog::TYPE_SUB_RENEW); + + $routeOptions = []; + + return redirect() + ->route('settings.subscription', $routeOptions) + ->withSuccess(__('subscriptions.renew.success')) + ; + } catch (IncompletePayment $exception) { + session()->put('subscription_callback', $request->get('payment_id')); + return redirect()->route( + 'cashier.payment', + // @phpstan-ignore-next-line + [$exception->payment->id, 'redirect' => route('settings.subscription.callback')] + ); + } catch (TranslatableException $e) { + return redirect() + ->route('settings.subscription') + ->with('error_raw', $e->getTranslatedMessage()) + ; + } catch (Exception $e) { + // Error? json + return response()->json([ + 'error' => true, + 'message' => $e->getMessage(), + ]); + } + } + /** * Subscribe */ diff --git a/app/Jobs/SubscriptionEndJob.php b/app/Jobs/SubscriptionEndJob.php index 2ad75bd4a1..8ec11374ea 100644 --- a/app/Jobs/SubscriptionEndJob.php +++ b/app/Jobs/SubscriptionEndJob.php @@ -47,8 +47,8 @@ public function handle() { /** @var ?User $user */ $user = User::find($this->userId); - if (empty($user) || $this->userId == 27078) { - // User deleted their account already. + if (empty($user) || $this->userId == 27078 || $user->subscribed('kanka')) { + // User deleted their account already or renewed their subscription. return; } diff --git a/app/Models/Scopes/AclScope.php b/app/Models/Scopes/AclScope.php index ed2d645b1c..1b32f62c8d 100644 --- a/app/Models/Scopes/AclScope.php +++ b/app/Models/Scopes/AclScope.php @@ -5,7 +5,6 @@ use App\Enums\Permission; use App\Facades\CampaignLocalization; use App\Facades\Permissions; -use App\Models\CampaignPermission; use App\Models\Entity; use App\Models\Post; use App\Models\MiscModel; diff --git a/app/Models/UserLog.php b/app/Models/UserLog.php index b92082c01e..2149cdab71 100644 --- a/app/Models/UserLog.php +++ b/app/Models/UserLog.php @@ -33,6 +33,7 @@ class UserLog extends Model public const TYPE_SUB_DOWNGRADE = 13; public const TYPE_SUB_FAIL = 15; public const TYPE_SUB_PAYPAL = 16; + public const TYPE_SUB_RENEW = 17; public const TYPE_CAMPAIGN_NEW = 20; public const TYPE_CAMPAIGN_JOIN = 21; diff --git a/app/Policies/MiscPolicy.php b/app/Policies/MiscPolicy.php index 98b3c75cbf..6c188ce9ff 100644 --- a/app/Policies/MiscPolicy.php +++ b/app/Policies/MiscPolicy.php @@ -2,17 +2,12 @@ namespace App\Policies; -use App\Facades\CampaignLocalization; -use App\Facades\UserCache; use App\Models\Campaign; use App\Facades\EntityPermission; -use App\Models\CampaignPermission; use App\Models\Entity; use App\Models\MiscModel; -use App\Models\Post; use App\Models\User; use Illuminate\Auth\Access\HandlesAuthorization; -use Illuminate\Support\Facades\Auth; class MiscPolicy { diff --git a/app/Services/Entity/PrivacyService.php b/app/Services/Entity/PrivacyService.php index 03360a73f3..56664fb29a 100644 --- a/app/Services/Entity/PrivacyService.php +++ b/app/Services/Entity/PrivacyService.php @@ -3,7 +3,6 @@ namespace App\Services\Entity; use App\Enums\Permission; -use App\Models\CampaignPermission; use App\Models\CampaignRole; use App\Models\Entity; use App\Models\User; diff --git a/app/Services/Permissions/EntityPermission.php b/app/Services/Permissions/EntityPermission.php index fcb0168c92..a7074e12fe 100644 --- a/app/Services/Permissions/EntityPermission.php +++ b/app/Services/Permissions/EntityPermission.php @@ -18,10 +18,10 @@ class EntityPermission { - use UserAware; + use CampaignAware; use EntityAware; use EntityTypeAware; - use CampaignAware; + use UserAware; protected array $cached = []; @@ -64,18 +64,18 @@ public function can(Permission $permission): bool $perm = $this->cached[$key]; } -// dump('module permission'); -// dump($key); -// dump($this->cached); + // dump('module permission'); + // dump($key); + // dump($this->cached); if (!isset($this->entity)) { -// dd('no entity'); + // dd('no entity'); return $perm; } // Search for entity $entityKey = '_' . $permission->value . '_' . $this->entity->id; -// dump('check entity'); -// dd($entityKey); + // dump('check entity'); + // dd($entityKey); if (isset($this->cached[$entityKey])) { return $this->cached[$entityKey]; } @@ -106,6 +106,7 @@ public function hasPermission( } $key = $entityType . '_' . $action; + // if ($action === Permission::Bookmarks->value) { // dump($key = $entityType . '_' . $action); // dump($this->cached); @@ -118,8 +119,8 @@ public function hasPermission( // Check if we have permission to do this action for exactly this entity if (!empty($entity)) { -// dump('i have an entity?'); -// dump($entity); + // dump('i have an entity?'); + // dump($entity); //Check if $entity is an entity type. if (isset($entity->type_id)) { @@ -128,7 +129,7 @@ public function hasPermission( //dump('misc object'); $entityKey = '_' . $action . '_' . $entity->id; } -// dump('entity key ' . $entityKey); + // dump('entity key ' . $entityKey); if (isset($this->cached[$entityKey])) { $perm = $this->cached[$entityKey]; } diff --git a/app/Services/SearchService.php b/app/Services/SearchService.php index 7f603d568e..1a40bb551f 100644 --- a/app/Services/SearchService.php +++ b/app/Services/SearchService.php @@ -4,7 +4,6 @@ use App\Facades\Avatar; use App\Facades\Mentions; -use App\Facades\Module; use App\Models\Calendar; use App\Models\Entity; use App\Models\EntityAsset; @@ -12,7 +11,6 @@ use App\Models\MiscModel; use App\Services\Entity\NewService; use App\Traits\CampaignAware; -use App\Traits\EntityTypeAware; use App\Traits\UserAware; use Illuminate\Support\Collection; use Illuminate\Support\Str; diff --git a/app/Services/SubscriptionService.php b/app/Services/SubscriptionService.php index 532fb04a45..e4537f3382 100644 --- a/app/Services/SubscriptionService.php +++ b/app/Services/SubscriptionService.php @@ -195,6 +195,12 @@ public function subscribe(string $paymentID): self return $this; } + public function renew(): void + { + $this->user->subscription('kanka')->resume(); + } + + /** * Setup the user's pledge, role, discord * @return $this diff --git a/app/Traits/GuestAuthTrait.php b/app/Traits/GuestAuthTrait.php index a0cbec4b96..cfacdff61a 100644 --- a/app/Traits/GuestAuthTrait.php +++ b/app/Traits/GuestAuthTrait.php @@ -5,7 +5,6 @@ use App\Enums\Permission; use App\Facades\CampaignLocalization; use App\Facades\EntityPermission; -use App\Models\CampaignPermission; use App\Models\Entity; trait GuestAuthTrait diff --git a/lang/en/subscriptions/renew.php b/lang/en/subscriptions/renew.php new file mode 100644 index 0000000000..c4699caea2 --- /dev/null +++ b/lang/en/subscriptions/renew.php @@ -0,0 +1,10 @@ + 'Subscription renewal', + 'helper' => 'However, you can choose to renew your subscription to enjoy the benefits without interruptions.', + 'success' => '', + 'actions' => [ + 'renew' => 'Renew subscription', + ], +]; diff --git a/resources/views/settings/subscription/index.blade.php b/resources/views/settings/subscription/index.blade.php index e908afd51c..4834c1fe35 100644 --- a/resources/views/settings/subscription/index.blade.php +++ b/resources/views/settings/subscription/index.blade.php @@ -115,9 +115,15 @@ @if (!$tier->isFree() && $tier->isCurrent($user) && $user->subscribed('kanka') && !$hasManual)
+ {!! __('settings.subscription.cancel.grace.text', ['date' => '' . $endDate . ''])!!} +
++ {!! __('subscriptions/renew.helper')!!} +
+