8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-25 00:13:45 +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 bfefca6832
commit 05bc31709a
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 re2o.mixins import AclMixin, RevMixin
from preferences.models import OptionalUser from preferences.models import OptionalUser
from cotisations.utils import find_payment_method
# TODO : change facture to invoice # TODO : change facture to invoice
class Facture(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model): class Facture(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
@ -643,8 +645,9 @@ class Paiement(RevMixin, AclMixin, models.Model):
:returns: An `HttpResponse`-like object. :returns: An `HttpResponse`-like object.
""" """
if hasattr(self, 'payment_method') and use_payment_method: payment_method = find_payment_method(self)
return self.payment_method.end_payment(invoice, request) 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 # In case a cotisation was bought, inform the user, the
# cotisation time has been extended too # cotisation time has been extended too

View file

@ -1,25 +1,6 @@
from django.conf.urls import include, url from . import comnpay, cheque, urls
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')),
]
PAYMENT_METHODS = [ PAYMENT_METHODS = [
comnpay, comnpay,
cheque, 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): def end_payment(self, invoice, request):
invoice.valid = False invoice.valid = False
invoice.save() invoice.save()
content = comnpay(invoice, request) content = comnpay(invoice, request, self)
return render(request, 'cotisations/payment.html', content) return render(request, 'cotisations/payment.html', content)

View file

@ -114,7 +114,7 @@ def ipn(request):
return HttpResponse("HTTP/1.0 200 OK") 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 Build a request to start the negociation with Comnpay by using
a facture id, the price and the secret transaction data stored in a facture id, the price and the secret transaction data stored in
@ -122,14 +122,14 @@ def comnpay(facture, request):
""" """
host = request.get_host() host = request.get_host()
p = Transaction( p = Transaction(
str(AssoOption.get_cached_value('payment_id')), str(payment.payment_credential),
str(AssoOption.get_cached_value('payment_pass')), str(payment.payment_pass),
'https://' + host + reverse( 'https://' + host + reverse(
'cotisations:comnpay_accept_payment', 'cotisations:comnpay:accept_payment',
kwargs={'factureid': facture.id} kwargs={'factureid': facture.id}
), ),
'https://' + host + reverse('cotisations:comnpay_refuse_payment'), 'https://' + host + reverse('cotisations:comnpay:refuse_payment'),
'https://' + host + reverse('cotisations:comnpay_ipn'), 'https://' + host + reverse('cotisations:comnpay:ipn'),
"", "",
"D" "D"
) )

View file

@ -2,8 +2,8 @@ from django import forms
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy as _l 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): def payment_method_factory(payment, *args, **kwargs):
payment_method = kwargs.pop('instance', find_payment_method(payment)) 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' name='recharge'
), ),
url(r'^$', views.index, name='index'), 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