Skip to content

Firefly III: a personal finances manager

Subscription reminder for extension or ending. https://github.com/firefly-iii/firefly-iii/issues/11544

James Coleaeac59e851cc
diff --git a/app/Events/Model/Account/Updated.php b/app/Events/Model/Subscription/SubscriptionNeedsExtensionOrRenewal.php
similarity index 64%
rename from app/Events/Model/Account/Updated.php
rename to app/Events/Model/Subscription/SubscriptionNeedsExtensionOrRenewal.php
index fe765e1d08..7c6bfb2ac7 100644
--- a/app/Events/Model/Account/Updated.php
+++ b/app/Events/Model/Subscription/SubscriptionNeedsExtensionOrRenewal.php
@@ -1,8 +1,7 @@
<?php
-
/*
- * Updated.php
- * Copyright (c) 2024 [email protected].
+ * SubscriptionNeedsExtensionOrRenewal.php
+ * Copyright (c) 2026 [email protected]
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
@@ -17,19 +16,20 @@
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see https://www.gnu.org/licenses/.
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
-namespace FireflyIII\Events\Model\Account;
+namespace FireflyIII\Events\Model\Subscription;
-use FireflyIII\Models\Account;
+use FireflyIII\Events\Event;
+use FireflyIII\Models\Bill;
use Illuminate\Queue\SerializesModels;
-class Updated
+class SubscriptionNeedsExtensionOrRenewal extends Event
{
use SerializesModels;
- public function __construct(public Account $account) {}
+ public function __construct(public Bill $subscription, public string $field, public int $diff) {}
}
diff --git a/app/Handlers/Events/BillEventHandler.php b/app/Handlers/Events/BillEventHandler.php
index 9969bfbf1c..10d4f0901c 100644
--- a/app/Handlers/Events/BillEventHandler.php
+++ b/app/Handlers/Events/BillEventHandler.php
@@ -27,6 +27,7 @@ namespace FireflyIII\Handlers\Events;
use Exception;
use FireflyIII\Events\Model\Bill\WarnUserAboutBill;
use FireflyIII\Events\Model\Bill\WarnUserAboutOverdueSubscriptions;
+use FireflyIII\Events\Model\Subscription\SubscriptionNeedsExtensionOrRenewal;
use FireflyIII\Models\Bill;
use FireflyIII\Notifications\User\BillReminder;
use FireflyIII\Notifications\User\SubscriptionsOverdueReminder;
@@ -105,39 +106,4 @@ class BillEventHandler
}
-
- public function warnAboutBill(WarnUserAboutBill $event): void
- {
- Log::debug(sprintf('Now in %s', __METHOD__));
-
- $bill = $event->bill;
-
- /** @var bool $preference */
- $preference = Preferences::getForUser($bill->user, 'notification_bill_reminder', true)->data;
-
- if (true === $preference) {
- Log::debug('Bill reminder is true!');
-
- try {
- Notification::send($bill->user, new BillReminder($bill, $event->field, $event->diff));
- } catch (Exception $e) {
- $message = $e->getMessage();
- if (str_contains($message, 'Bcc')) {
- Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');
-
- return;
- }
- if (str_contains($message, 'RFC 2822')) {
- Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');
-
- return;
- }
- Log::error($e->getMessage());
- Log::error($e->getTraceAsString());
- }
-
- return;
- }
- Log::debug('User has disabled bill reminders.');
- }
}
diff --git a/app/Jobs/WarnAboutBills.php b/app/Jobs/WarnAboutBills.php
index 8a6d2f9631..9e9e7c5210 100644
--- a/app/Jobs/WarnAboutBills.php
+++ b/app/Jobs/WarnAboutBills.php
@@ -27,6 +27,7 @@ namespace FireflyIII\Jobs;
use Carbon\Carbon;
use FireflyIII\Events\Model\Bill\WarnUserAboutBill;
use FireflyIII\Events\Model\Bill\WarnUserAboutOverdueSubscriptions;
+use FireflyIII\Events\Model\Subscription\SubscriptionNeedsExtensionOrRenewal;
use FireflyIII\Models\Bill;
use FireflyIII\Support\Facades\Navigation;
use FireflyIII\Support\JsonApi\Enrichments\SubscriptionEnrichment;
@@ -143,7 +144,7 @@ class WarnAboutBills implements ShouldQueue
{
$diff = $this->getDiff($bill, $field);
Log::debug('Will now send warning!');
- event(new WarnUserAboutBill($bill, $field, $diff));
+ event(new SubscriptionNeedsExtensionOrRenewal($bill, $field, $diff));
}
public function setDate(Carbon $date): void
diff --git a/app/Listeners/Model/Subscription/NotifiesAboutExtensionOrRenewal.php b/app/Listeners/Model/Subscription/NotifiesAboutExtensionOrRenewal.php
new file mode 100644
index 0000000000..362bafa516
--- /dev/null
+++ b/app/Listeners/Model/Subscription/NotifiesAboutExtensionOrRenewal.php
@@ -0,0 +1,67 @@
+<?php
+/*
+ * NotifiesAboutExtensionOrRenewal.php
+ * Copyright (c) 2026 [email protected]
+ *
+ * This file is part of Firefly III (https://github.com/firefly-iii).
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+namespace FireflyIII\Listeners\Model\Subscription;
+
+use Exception;
+use FireflyIII\Events\Model\Subscription\SubscriptionNeedsExtensionOrRenewal;
+use FireflyIII\Notifications\User\BillReminder;
+use FireflyIII\Support\Facades\Preferences;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Notification;
+
+class NotifiesAboutExtensionOrRenewal implements ShouldQueue
+{
+ public function handle(SubscriptionNeedsExtensionOrRenewal $event): void
+ {
+ Log::debug(sprintf('Now in %s', __METHOD__));
+ $subscription = $event->subscription;
+ /** @var bool $preference */
+ $preference = Preferences::getForUser($subscription->user, 'notification_bill_reminder', true)->data;
+
+ if (true === $preference) {
+ Log::debug('Subscription reminder is true!');
+
+ try {
+ Notification::send($subscription->user, new BillReminder($subscription, $event->field, $event->diff));
+ } catch (Exception $e) {
+ $message = $e->getMessage();
+ if (str_contains($message, 'Bcc')) {
+ Log::warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');
+
+ return;
+ }
+ if (str_contains($message, 'RFC 2822')) {
+ Log::warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');
+
+ return;
+ }
+ Log::error($e->getMessage());
+ Log::error($e->getTraceAsString());
+ }
+
+ return;
+ }
+ Log::debug('User has disabled subscription reminders.');
+ }
+
+}
diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php
index 4ced9fe70b..cfb4ac1344 100644
--- a/app/Providers/EventServiceProvider.php
+++ b/app/Providers/EventServiceProvider.php
@@ -27,7 +27,6 @@ use FireflyIII\Events\ActuallyLoggedIn;
use FireflyIII\Events\Admin\InvitationCreated;
use FireflyIII\Events\DestroyedTransactionGroup;
use FireflyIII\Events\DetectedNewIPAddress;
-use FireflyIII\Events\Model\Bill\WarnUserAboutBill;
use FireflyIII\Events\Model\Bill\WarnUserAboutOverdueSubscriptions;
use FireflyIII\Events\Model\PiggyBank\ChangedAmount;
use FireflyIII\Events\Model\PiggyBank\ChangedName;
@@ -160,10 +159,10 @@ class EventServiceProvider extends ServiceProvider
'FireflyIII\Handlers\Events\UpdatedAccountEventHandler@recalculateCredit',
],
- // bill related events:
- WarnUserAboutBill::class => [
- 'FireflyIII\Handlers\Events\BillEventHandler@warnAboutBill',
- ],
+ // subscription related events:
+ // SubscriptionNeedsExtensionOrRenewal::class => [
+ // 'FireflyIII\Handlers\Events\BillEventHandler@warnAboutBill',
+ // ],
WarnUserAboutOverdueSubscriptions::class => [
'FireflyIII\Handlers\Events\BillEventHandler@warnAboutOverdueSubscriptions',
],