Browse Source

ref(piaf): retire la dépendance eopayment; corrige des bugs de formulaire tipi

master
François Poulain 1 year ago
parent
commit
7c34db98aa
4 changed files with 27 additions and 44 deletions
  1. +22
    -1
      piaf/base/models.py
  2. +4
    -41
      piaf/base/views.py
  3. +1
    -1
      piaf/templates/pages/prepare_invoice.html
  4. +0
    -1
      requirements/base.txt

+ 22
- 1
piaf/base/models.py View File

@@ -17,6 +17,7 @@
import uuid
from pytz import timezone
from datetime import datetime
from requests import Request

from django.db import models
from django.core.validators import MinLengthValidator
@@ -24,6 +25,7 @@ from django.contrib import messages
from django.conf import settings
from django.template.loader import render_to_string
from django.core.mail import EmailMessage
from django.urls import reverse
from constance import config

from piaf.base import resthys
@@ -82,11 +84,30 @@ class TipiPaiement(models.Model):
data={**dict([(f, getattr(self, f)) for f in fields])}
)

def get_pay_link(self, request):
url = 'http://www.jepaiemesserviceslocaux.dgfip.finances.gouv.fr' \
'/tpa/paiement.web'
params = {
'urlcl': request.build_absolute_uri(
reverse('paid_invoice')).replace('https://', 'http://'),
'refdet': self.refdet,
'saisie': self.saisie,
'exer': datetime.today().year,
'objet': self.objet,
'numcli': self.numcli,
'mel': self.email,
'montant': '{}'.format(int(self.amount*100)),
}
# FIXME: to be removed
params['urlcl'] = 'http://apps.villedeviolaines.fr/piaf/paid_invoice'
r = Request('GET', url, params=params)
return r.prepare().url

@classmethod
def set_from_post(cls, data):
paiement = cls.objects.get(
numcli=data['numcli'],
amount=data['montant'],
amount=data['montant']/100,
refdet=data['refdet'],
objet=data['objet'],
email=data['mel'],

+ 4
- 41
piaf/base/views.py View File

@@ -28,7 +28,6 @@ from django.views.decorators.csrf import csrf_exempt
from constance import config

from piaf.base import forms, utils, resthys, models, mixins
from eopayment import tipi


class RetrieveInvoice(mixins.AntiAbuse, generic.edit.FormView):
@@ -121,25 +120,7 @@ class PrepareInvoice(mixins.HackyMessagesMixin, generic.edit.FormView):
self.request.session['paiement'] = paiement.id

# create pay link
p = tipi.Payment(
{
'numcli': paiement.numcli,
# 'automatic_return_url':
# self.request.build_absolute_uri(reverse('paid_invoice')),
'automatic_return_url':
'http://apps.villedeviolaines.fr/piaf/paid_invoice',
'service_url':
'https://www.tipi.budget.gouv.fr/tpa/paiement.web',
'saisie': paiement.saisie,
}
)
context['tipi'] = p.request(
amount=paiement.amount,
exer=datetime.today().year,
refdet=paiement.refdet,
objet=paiement.objet,
email=paiement.email,
)
context['tipi'] = paiement.get_pay_link(self.request)
else:
context['emailform'] = forms.EmailForm

@@ -158,7 +139,7 @@ class PrepareInvoice(mixins.HackyMessagesMixin, generic.edit.FormView):
'exer': datetime.today().year,
'refdet': paiement.refdet,
'objet': paiement.objet,
'montant': paiement.amount,
'montant': paiement.amount*100,
'mel': paiement.email,
'saisie': paiement.saisie,
'numauto': '420042',
@@ -231,25 +212,7 @@ class PrepareMergedInvoices(PrepareInvoice):
paiement.save()

# create pay link
p = tipi.Payment(
{
'numcli': paiement.numcli,
# 'automatic_return_url':
# self.request.build_absolute_uri(reverse('paid_invoice')),
'automatic_return_url':
'http://apps.villedeviolaines.fr/piaf/paid_invoice',
'service_url':
'https://www.tipi.budget.gouv.fr/tpa/paiement.web',
'saisie': paiement.saisie,
}
)
context['tipi'] = p.request(
amount=paiement.amount,
exer=datetime.today().year,
refdet=paiement.refdet,
objet=paiement.objet,
email=paiement.email,
)
context['tipi'] = paiement.get_pay_link(self.request)

# prestations
context['prestations'] = utils.regroup_prestations(
@@ -265,7 +228,7 @@ class PrepareMergedInvoices(PrepareInvoice):
'exer': datetime.today().year,
'refdet': paiement.refdet,
'objet': paiement.objet,
'montant': paiement.amount,
'montant': paiement.amount*100,
'mel': paiement.email,
'saisie': paiement.saisie,
'numauto': '420042',

+ 1
- 1
piaf/templates/pages/prepare_invoice.html View File

@@ -111,7 +111,7 @@ Période du
<script>
var open_dialog = function() {
var win = window.open(
'{{ tipi.2|safe }}',
'{{ tipi|safe }}',
'_blank',
'height=700, width=900, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no'
);

+ 0
- 1
requirements/base.txt View File

@@ -1,5 +1,4 @@
django >=2.0,<2.1
django-environ
git+https://forge.cliss21.org/fpoulain/eopayment.git@wip/python3#egg=eopayment
django-constance[database]
django-ipware

Loading…
Cancel
Save