Commit 0fe430d7 authored by Hugo LEVY-FALK's avatar Hugo LEVY-FALK

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

parent cc4815c8
......@@ -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
......
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
......@@ -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)
......@@ -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"
)
......
......@@ -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))
......
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')),
]
......@@ -144,5 +144,5 @@ urlpatterns = [
name='recharge'
),
url(r'^$', views.index, name='index'),
] + payment_methods.urlpatterns
] + payment_methods.urls.urlpatterns
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment