mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
Les factures validées par comnpay sont effectivement validées.
This commit is contained in:
parent
af3cc1cf69
commit
6957598afc
2 changed files with 48 additions and 50 deletions
|
@ -1,11 +1,13 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from cotisations.models import Paiement
|
from cotisations.models import Paiement
|
||||||
from cotisations.payment_methods.mixins import PaymentMethodMixin
|
from cotisations.payment_methods.mixins import PaymentMethodMixin
|
||||||
|
|
||||||
from .aes_field import AESEncryptedField
|
from .aes_field import AESEncryptedField
|
||||||
from .views import comnpay
|
from .comnpay import Transaction
|
||||||
|
|
||||||
|
|
||||||
class ComnpayPayment(PaymentMethodMixin, models.Model):
|
class ComnpayPayment(PaymentMethodMixin, models.Model):
|
||||||
|
@ -29,7 +31,34 @@ class ComnpayPayment(PaymentMethodMixin, models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
def end_payment(self, invoice, request):
|
def end_payment(self, invoice, request):
|
||||||
|
"""
|
||||||
|
Build a request to start the negociation with Comnpay by using
|
||||||
|
a facture id, the price and the secret transaction data stored in
|
||||||
|
the preferences.
|
||||||
|
"""
|
||||||
invoice.valid = False
|
invoice.valid = False
|
||||||
invoice.save()
|
invoice.save()
|
||||||
content = comnpay(invoice, request, self)
|
host = request.get_host()
|
||||||
return render(request, 'cotisations/payment.html', content)
|
p = Transaction(
|
||||||
|
str(self.payment_credential),
|
||||||
|
str(self.payment_pass),
|
||||||
|
'https://' + host + reverse(
|
||||||
|
'cotisations:comnpay:accept_payment',
|
||||||
|
kwargs={'factureid': invoice.id}
|
||||||
|
),
|
||||||
|
'https://' + host + reverse('cotisations:comnpay:refuse_payment'),
|
||||||
|
'https://' + host + reverse('cotisations:comnpay:ipn'),
|
||||||
|
"",
|
||||||
|
"D"
|
||||||
|
)
|
||||||
|
r = {
|
||||||
|
'action': 'https://secure.homologation.comnpay.com',
|
||||||
|
'method': 'POST',
|
||||||
|
'content': p.buildSecretHTML(
|
||||||
|
_("Pay invoice no : ")+str(invoice.id),
|
||||||
|
invoice.prix_total(),
|
||||||
|
idTransaction=str(invoice.id)
|
||||||
|
),
|
||||||
|
'amount': invoice.prix_total(),
|
||||||
|
}
|
||||||
|
return render(request, 'cotisations/payment.html', r)
|
||||||
|
|
|
@ -14,9 +14,9 @@ from django.utils.datastructures import MultiValueDictKeyError
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.http import HttpResponse, HttpResponseBadRequest
|
from django.http import HttpResponse, HttpResponseBadRequest
|
||||||
|
|
||||||
from preferences.models import AssoOption
|
|
||||||
from cotisations.models import Facture
|
from cotisations.models import Facture
|
||||||
from .comnpay import Transaction
|
from .comnpay import Transaction
|
||||||
|
from .models import ComnpayPayment
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
@ -35,7 +35,8 @@ def accept_payment(request, factureid):
|
||||||
)
|
)
|
||||||
# In case a cotisation was bought, inform the user, the
|
# In case a cotisation was bought, inform the user, the
|
||||||
# cotisation time has been extended too
|
# cotisation time has been extended too
|
||||||
if any(purchase.type_cotisation for purchase in invoice.vente_set.all()):
|
if any(purchase.type_cotisation
|
||||||
|
for purchase in invoice.vente_set.all()):
|
||||||
messages.success(
|
messages.success(
|
||||||
request,
|
request,
|
||||||
_("The cotisation of %(member_name)s has been \
|
_("The cotisation of %(member_name)s has been \
|
||||||
|
@ -80,28 +81,29 @@ def ipn(request):
|
||||||
except MultiValueDictKeyError:
|
except MultiValueDictKeyError:
|
||||||
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request")
|
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request")
|
||||||
|
|
||||||
if not p.validSec(data, AssoOption.get_cached_value('payment_pass')):
|
|
||||||
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request")
|
|
||||||
|
|
||||||
result = True if (request.POST['result'] == 'OK') else False
|
|
||||||
idTpe = request.POST['idTpe']
|
|
||||||
idTransaction = request.POST['idTransaction']
|
idTransaction = request.POST['idTransaction']
|
||||||
|
|
||||||
# Checking that the payment is actually for us.
|
|
||||||
if not idTpe == AssoOption.get_cached_value('payment_id'):
|
|
||||||
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
factureid = int(idTransaction)
|
factureid = int(idTransaction)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request")
|
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request")
|
||||||
|
|
||||||
facture = get_object_or_404(Facture, id=factureid)
|
facture = get_object_or_404(Facture, id=factureid)
|
||||||
|
payment_method = get_object_or_404(
|
||||||
|
ComnpayPayment, payment=facture.paiement)
|
||||||
|
|
||||||
# Checking that the payment is valid
|
if not p.validSec(data, payment_method.payment_pass):
|
||||||
|
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request")
|
||||||
|
|
||||||
|
result = True if (request.POST['result'] == 'OK') else False
|
||||||
|
idTpe = request.POST['idTpe']
|
||||||
|
|
||||||
|
# Checking that the payment is actually for us.
|
||||||
|
if not idTpe == payment_method.payment_credential:
|
||||||
|
return HttpResponseBadRequest("HTTP/1.1 400 Bad Request")
|
||||||
|
|
||||||
|
# Checking that the payment is valid
|
||||||
if not result:
|
if not result:
|
||||||
# Payment failed: Cancelling the invoice operation
|
# Payment failed: Cancelling the invoice operation
|
||||||
facture.delete()
|
|
||||||
# And send the response to Comnpay indicating we have well
|
# And send the response to Comnpay indicating we have well
|
||||||
# received the failure information.
|
# received the failure information.
|
||||||
return HttpResponse("HTTP/1.1 200 OK")
|
return HttpResponse("HTTP/1.1 200 OK")
|
||||||
|
@ -112,36 +114,3 @@ def ipn(request):
|
||||||
# Everything worked we send a reponse to Comnpay indicating that
|
# Everything worked we send a reponse to Comnpay indicating that
|
||||||
# it's ok for them to proceed
|
# it's ok for them to proceed
|
||||||
return HttpResponse("HTTP/1.0 200 OK")
|
return HttpResponse("HTTP/1.0 200 OK")
|
||||||
|
|
||||||
|
|
||||||
def comnpay(facture, request, payment):
|
|
||||||
"""
|
|
||||||
Build a request to start the negociation with Comnpay by using
|
|
||||||
a facture id, the price and the secret transaction data stored in
|
|
||||||
the preferences.
|
|
||||||
"""
|
|
||||||
host = request.get_host()
|
|
||||||
p = Transaction(
|
|
||||||
str(payment.payment_credential),
|
|
||||||
str(payment.payment_pass),
|
|
||||||
'https://' + host + reverse(
|
|
||||||
'cotisations:comnpay:accept_payment',
|
|
||||||
kwargs={'factureid': facture.id}
|
|
||||||
),
|
|
||||||
'https://' + host + reverse('cotisations:comnpay:refuse_payment'),
|
|
||||||
'https://' + host + reverse('cotisations:comnpay:ipn'),
|
|
||||||
"",
|
|
||||||
"D"
|
|
||||||
)
|
|
||||||
r = {
|
|
||||||
'action': 'https://secure.homologation.comnpay.com',
|
|
||||||
'method': 'POST',
|
|
||||||
'content': p.buildSecretHTML(
|
|
||||||
"Paiement de la facture "+str(facture.id),
|
|
||||||
facture.prix_total(),
|
|
||||||
idTransaction=str(facture.id)
|
|
||||||
),
|
|
||||||
'amount': facture.prix_total(),
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue