]> git.parisson.com Git - teleforma.git/commitdiff
Added post-payment mail, minor payment bug fixes
authorGael Le Mignot <gael@pilotsystems.net>
Tue, 19 Nov 2019 14:18:31 +0000 (15:18 +0100)
committerGael Le Mignot <gael@pilotsystems.net>
Tue, 19 Nov 2019 14:18:31 +0000 (15:18 +0100)
teleforma/templates/payment/email_payment_failed.txt [new file with mode: 0644]
teleforma/templates/payment/email_payment_failed_subject.txt [new file with mode: 0644]
teleforma/templates/payment/email_payment_ok.txt [new file with mode: 0644]
teleforma/templates/payment/email_payment_ok_subject.txt [new file with mode: 0644]
teleforma/templatetags/payment.py
teleforma/views/payment.py

diff --git a/teleforma/templates/payment/email_payment_failed.txt b/teleforma/templates/payment/email_payment_failed.txt
new file mode 100644 (file)
index 0000000..6018065
--- /dev/null
@@ -0,0 +1,9 @@
+Bonjour {{ student.first_name }},
+
+Vous avez essayé de payer en ligne une échéance de {{ amount }} €.
+
+La transaction n'a pas pu aboutir. Nous vous conseillons de ré-essayer
+ultérieurement ou de nous contacter.
+
+Cordialement,
+L'équipe Pré-Barreau
diff --git a/teleforma/templates/payment/email_payment_failed_subject.txt b/teleforma/templates/payment/email_payment_failed_subject.txt
new file mode 100644 (file)
index 0000000..fe0cf1c
--- /dev/null
@@ -0,0 +1 @@
+Échec de paiement en ligne
diff --git a/teleforma/templates/payment/email_payment_ok.txt b/teleforma/templates/payment/email_payment_ok.txt
new file mode 100644 (file)
index 0000000..a51d23f
--- /dev/null
@@ -0,0 +1,7 @@
+Bonjour {{ student.first_name }},
+
+Vous venez de payer en ligne une échéance de {{ amount }} € et nous
+vous en remercions.
+
+Cordialement,
+L'équipe Pré-Barreau
diff --git a/teleforma/templates/payment/email_payment_ok_subject.txt b/teleforma/templates/payment/email_payment_ok_subject.txt
new file mode 100644 (file)
index 0000000..7127486
--- /dev/null
@@ -0,0 +1 @@
+Confirmation de paiement en ligne
index 93852a68e7bfb75ec7ec479117a2abd46692c328..c95e2ae634d388bae7dcba87852dc4576b160782 100644 (file)
@@ -13,13 +13,13 @@ def payment_summary(context, payment):
     today = date.today()
     for obj in objs:
         if obj.type == 'online':
-            if obj.id == payment.id:
-                status = 'en cours'
-                sclass = "pending"
-            elif obj.online_paid:
+            if obj.online_paid:
                 status = 'payé'
                 sclass = "paid" 
-            elif obj.scheduled >= today:
+            elif obj.id == payment.id:
+                status = 'en cours'
+                sclass = "pending"
+            elif obj.scheduled > today:
                 status = 'à payer ultérieurement'
                 sclass = "topay_later"
             else:
index 38e86f4501d95dd265590d4c514097eb8c258a33..19f50981af6bd3b902adc875b0862a0ce06a5783 100644 (file)
@@ -10,6 +10,8 @@ from django.http import HttpResponseForbidden
 from django.core.exceptions import ValidationError, PermissionDenied
 from django.conf import settings
 from django.contrib.sites.models import get_current_site
+from django.core.mail import send_mail
+from django.template.loader import render_to_string
 
 import commands
 
@@ -99,7 +101,7 @@ class PaymentStartView(DetailView):
 def bank_auto(request, merchant_id):
     """
     Bank automatic callback
-    """
+    """    
     res = call_scherlocks('response', { 'message': request.POST['DATA'] },
                           merchant_id = merchant_id)
     order_id = res[24];
@@ -107,9 +109,27 @@ def bank_auto(request, merchant_id):
     if check_payment_info(res) and payment.type == 'online' and not payment.online_paid:
         payment.online_paid = True
         payment.save()
-        return HttpResponse('OK - Validated')
+        tmpl_name = 'payment_ok'
+        res = 'OK - Validated'
     else:
-        return HttpResponse('OK - Cancelled')
+        tmpl_name = 'payment_failed'
+        res = 'OK - Cancelled'
+
+    user = payment.student.user
+    data = { 'mfrom': settings.DEFAULT_FROM_EMAIL,
+             'mto': user.email,
+             'student': user,
+             'amount': payment.value, }
+        
+    subject_template = 'payment/email_%s_subject.txt' % tmpl_name
+    message_template = 'payment/email_%s.txt' % tmpl_name
+    subject = render_to_string(subject_template, data)
+    subject = ''.join(subject.splitlines())
+    message = render_to_string(message_template, data)
+    send_mail(subject, message, data['mfrom'], [ data['mto'] ],
+              fail_silently=True)
+    
+    return HttpResponse(res)
 
 @csrf_exempt
 def bank_success(request, merchant_id):