diff --git a/app/dashboard/management/commands/grant_txn_failed_email.py b/app/dashboard/management/commands/grant_txn_failed_email.py new file mode 100644 index 00000000000..cea356c3898 --- /dev/null +++ b/app/dashboard/management/commands/grant_txn_failed_email.py @@ -0,0 +1,32 @@ +''' + Copyright (C) 2019 Gitcoin Core + 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 . +''' +from django.conf import settings +from django.core.management.base import BaseCommand + +from grants.models import Contribution +from marketing.mails import grant_txn_failed + + +class Command(BaseCommand): + help = 'sends emails for grant contributors whose contribution txns have failed' + + def handle(self, *args, **options): + if settings.DEBUG: + print("not active in non prod environments") + return + + failed_contribs = Contribution.objects.exclude(validator_passed=True) + + for failed_contrib in failed_contribs: + grant_txn_failed(failed_contrib.subscription.contributor_profile, failed_contrib.subscription.grant, failed_contrib.tx_id) diff --git a/app/marketing/mails.py b/app/marketing/mails.py index 60fc0c3dd22..37154c99132 100644 --- a/app/marketing/mails.py +++ b/app/marketing/mails.py @@ -36,7 +36,7 @@ render_bounty_expire_warning, render_bounty_feedback, render_bounty_request, render_bounty_startwork_expire_warning, render_bounty_unintersted, render_comment, render_faucet_rejected, render_faucet_request, render_featured_funded_bounty, render_funder_payout_reminder, render_funder_stale, render_gdpr_reconsent, - render_gdpr_update, render_grant_cancellation_email, render_grant_update, render_kudos_email, + render_gdpr_update, render_grant_cancellation_email, render_grant_txn_failed, render_grant_update, render_kudos_email, render_match_distribution, render_match_email, render_mention, render_new_bounty, render_new_bounty_acceptance, render_new_bounty_rejection, render_new_bounty_roundup, render_new_grant_email, render_new_supporter_email, render_new_work_submission, render_no_applicant_reminder, render_nth_day_email_campaign, render_quarterly_stats, @@ -288,6 +288,25 @@ def grant_cancellation(grant, subscription): finally: translation.activate(cur_language) +def grant_txn_failed(profile, grant, tx_id): + from_email = settings.CONTACT_EMAIL + to_email = profile.email + if not to_email: + if profile and profile.user: + to_email = profile.user.email + if not to_email: + return + + cur_language = translation.get_language() + + subject = f"Your Grant transaction failed. Wanna try again?" + + try: + setup_lang(to_email) + html, text = render_grant_txn_failed(to_email, grant, tx_id) + send_mail(from_email, to_email, subject, text, html, categories=['transactional', func_name()]) + finally: + translation.activate(cur_language) def subscription_terminated(grant, subscription): if subscription and subscription.negative: