From f9e775ac35b904600f2a82ed319d4944b7cd7d08 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 3 Mar 2021 09:09:17 +0100 Subject: [PATCH] [bug] do not send notifications each hour for payment schedules deadlines --- CHANGELOG.md | 1 + app/workers/payment_schedule_item_worker.rb | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eb00bf71..e29ad89eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Improved the setup script - Fix a bug: unable to install a new instance with an external reverse proxy - Fix a bug: do not display "powered by disqus" if Disqus is disabled +- Fix a bug: do not send notifications each hour for payment schedules deadlines ## v4.7.2 2021 March 1st - Updated yq to v4 diff --git a/app/workers/payment_schedule_item_worker.rb b/app/workers/payment_schedule_item_worker.rb index 56348aa6b..0120dbb78 100644 --- a/app/workers/payment_schedule_item_worker.rb +++ b/app/workers/payment_schedule_item_worker.rb @@ -29,12 +29,15 @@ class PaymentScheduleItemWorker psi.update_attributes(state: 'paid', payment_method: 'stripe', stp_invoice_id: stp_invoice.id) elsif stp_subscription.status == 'past_due' || stp_invoice.status == 'open' ##### Stripe / Payment error - NotificationCenter.call type: 'notify_admin_payment_schedule_failed', - receiver: User.admins_and_managers, - attached_object: psi - NotificationCenter.call type: 'notify_member_payment_schedule_failed', - receiver: psi.payment_schedule.user, - attached_object: psi + if psi.state == 'new' + # notify only for new deadlines, to prevent spamming + NotificationCenter.call type: 'notify_admin_payment_schedule_failed', + receiver: User.admins_and_managers, + attached_object: psi + NotificationCenter.call type: 'notify_member_payment_schedule_failed', + receiver: psi.payment_schedule.user, + attached_object: psi + end stp_payment_intent = Stripe::PaymentIntent.retrieve(stp_invoice.payment_intent, api_key: stripe_key) psi.update_attributes(state: stp_payment_intent.status, stp_invoice_id: stp_invoice.id, @@ -42,8 +45,8 @@ class PaymentScheduleItemWorker else psi.update_attributes(state: 'error') end - else - ### Check + elsif psi.state == 'new' + ### Check (only new deadlines, to prevent spamming) NotificationCenter.call type: 'notify_admin_payment_schedule_check_deadline', receiver: User.admins_and_managers, attached_object: psi