8
0
Fork 0
mirror of https://gitlab.federez.net/re2o/re2o synced 2024-06-13 22:28:11 +00:00

Ajout de comnpay + fix de l'utilisation des paiements personnalisés

This commit is contained in:
Hugo LEVY-FALK 2018-07-02 22:14:51 +02:00
parent cc4815c82c
commit 0fe430d72e
8 changed files with 32 additions and 32 deletions

View file

@ -51,6 +51,8 @@ from re2o.field_permissions import FieldPermissionModelMixin
from re2o.mixins import AclMixin, RevMixin
from preferences.models import OptionalUser
from cotisations.utils import find_payment_method
# TODO : change facture to invoice
class Facture(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
@ -643,8 +645,9 @@ class Paiement(RevMixin, AclMixin, models.Model):
:returns: An `HttpResponse`-like object.
"""
if hasattr(self, 'payment_method') and use_payment_method:
return self.payment_method.end_payment(invoice, request)
payment_method = find_payment_method(self)
if payment_method is not None and use_payment_method:
return payment_method.end_payment(invoice, request)
# In case a cotisation was bought, inform the user, the
# cotisation time has been extended too

View file

@ -1,25 +1,6 @@
from django.conf.urls import include, url
from django.utils.translation import ugettext_lazy as _l
from . import comnpay, cheque
urlpatterns = [
url(r'^comnpay/', include(comnpay.urls, namespace='comnpay')),
url(r'^cheque/', include(cheque.urls, namespace='cheque')),
]
from . import comnpay, cheque, urls
PAYMENT_METHODS = [
comnpay,
cheque,
]
def find_payment_method(payment):
for method in PAYMENT_METHODS:
try:
o = method.PaymentMethod.objects.get(payment=payment)
return o
except method.PaymentMethod.DoesNotExist:
pass
return None

View file

@ -31,5 +31,5 @@ class ComnpayPayment(PaymentMethodMixin, models.Model):
def end_payment(self, invoice, request):
invoice.valid = False
invoice.save()
content = comnpay(invoice, request)
content = comnpay(invoice, request, self)
return render(request, 'cotisations/payment.html', content)

View file

@ -114,7 +114,7 @@ def ipn(request):
return HttpResponse("HTTP/1.0 200 OK")
def comnpay(facture, request):
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
@ -122,14 +122,14 @@ def comnpay(facture, request):
"""
host = request.get_host()
p = Transaction(
str(AssoOption.get_cached_value('payment_id')),
str(AssoOption.get_cached_value('payment_pass')),
str(payment.payment_credential),
str(payment.payment_pass),
'https://' + host + reverse(
'cotisations:comnpay_accept_payment',
'cotisations:comnpay:accept_payment',
kwargs={'factureid': facture.id}
),
'https://' + host + reverse('cotisations:comnpay_refuse_payment'),
'https://' + host + reverse('cotisations:comnpay_ipn'),
'https://' + host + reverse('cotisations:comnpay:refuse_payment'),
'https://' + host + reverse('cotisations:comnpay:ipn'),
"",
"D"
)

View file

@ -2,8 +2,8 @@ from django import forms
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy as _l
from . import PAYMENT_METHODS, find_payment_method
from . import PAYMENT_METHODS
from cotisations.utils import find_payment_method
def payment_method_factory(payment, *args, **kwargs):
payment_method = kwargs.pop('instance', find_payment_method(payment))

View file

@ -0,0 +1,7 @@
from django.conf.urls import include, url
from . import comnpay, cheque
urlpatterns = [
url(r'^comnpay/', include(comnpay.urls, namespace='comnpay')),
url(r'^cheque/', include(cheque.urls, namespace='cheque')),
]

View file

@ -144,5 +144,5 @@ urlpatterns = [
name='recharge'
),
url(r'^$', views.index, name='index'),
] + payment_methods.urlpatterns
] + payment_methods.urls.urlpatterns

9
cotisations/utils.py Normal file
View file

@ -0,0 +1,9 @@
def find_payment_method(payment):
from cotisations.payment_methods import PAYMENT_METHODS
for method in PAYMENT_METHODS:
try:
o = method.PaymentMethod.objects.get(payment=payment)
return o
except method.PaymentMethod.DoesNotExist:
pass
return None