From 31895688849eabf3124c075293045f692e518400 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 27 Dec 2017 20:04:20 +0100 Subject: [PATCH] Send emails to admin when Stripe transaction error --- digitalglarus/views.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/digitalglarus/views.py b/digitalglarus/views.py index 3b12934f..32d8e1f5 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -24,6 +24,7 @@ from utils.forms import ( ) from utils.stripe_utils import StripeUtils from utils.models import UserBillingAddress +from utils.tasks import send_plain_email_task from .forms import ( LoginForm, SignupForm, MembershipBillingForm, BookingDateForm, @@ -387,6 +388,18 @@ class MembershipPaymentView(LoginRequiredMixin, IsNotMemberMixin, FormView): 'paymentError': charge_response.get('error'), 'form': form }) + email_to_admin_data = { + 'subject': "Could not create charge for Digital Glarus " + "user: {user}".format( + user=self.request.user.email + ), + 'from_email': 'info@digitalglarus.ch', + 'to': ['info@ungleich.ch'], + 'body': "\n".join( + ["%s=%s" % (k, v) for (k, v) in + charge_response.items()]), + } + send_plain_email_task.delay(email_to_admin_data) return render(request, self.template_name, context) # Subscribe the customer to dg plan from the next month onwards @@ -415,6 +428,18 @@ class MembershipPaymentView(LoginRequiredMixin, IsNotMemberMixin, FormView): 'paymentError': subscription_result.get('error'), 'form': form }) + email_to_admin_data = { + 'subject': "Could not create Stripe subscription for " + "Digital Glarus user: {user}".format( + user=self.request.user.email + ), + 'from_email': 'info@digitalglarus.ch', + 'to': ['info@ungleich.ch'], + 'body': "\n".join( + ["%s=%s" % (k, v) for (k, v) in + subscription_result.items()]), + } + send_plain_email_task.delay(email_to_admin_data) return render(request, self.template_name, context) charge = charge_response.get('response_object')