From: Gael Le Mignot Date: Tue, 19 Nov 2019 14:18:31 +0000 (+0100) Subject: Added post-payment mail, minor payment bug fixes X-Git-Tag: 1.4.1~5^2~12^2~5 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=5b628ade330bea5a75f86952d82c3114565bca3d;p=teleforma.git Added post-payment mail, minor payment bug fixes --- diff --git a/teleforma/templates/payment/email_payment_failed.txt b/teleforma/templates/payment/email_payment_failed.txt new file mode 100644 index 00000000..60180658 --- /dev/null +++ b/teleforma/templates/payment/email_payment_failed.txt @@ -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 index 00000000..fe0cf1c8 --- /dev/null +++ b/teleforma/templates/payment/email_payment_failed_subject.txt @@ -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 index 00000000..a51d23f5 --- /dev/null +++ b/teleforma/templates/payment/email_payment_ok.txt @@ -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 index 00000000..7127486b --- /dev/null +++ b/teleforma/templates/payment/email_payment_ok_subject.txt @@ -0,0 +1 @@ +Confirmation de paiement en ligne diff --git a/teleforma/templatetags/payment.py b/teleforma/templatetags/payment.py index 93852a68..c95e2ae6 100644 --- a/teleforma/templatetags/payment.py +++ b/teleforma/templatetags/payment.py @@ -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: diff --git a/teleforma/views/payment.py b/teleforma/views/payment.py index 38e86f45..19f50981 100644 --- a/teleforma/views/payment.py +++ b/teleforma/views/payment.py @@ -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):