0001-contrib.teamnet_axel-invoice-payment-notify-endpoint.patch
passerelle/contrib/teamnet_axel/models.py | ||
---|---|---|
16 | 16 | |
17 | 17 |
import logging |
18 | 18 |
import xml.etree.ElementTree as ET |
19 |
from datetime import datetime |
|
19 | 20 | |
20 | 21 |
from django.core.urlresolvers import reverse |
21 | 22 |
from django.db import models |
... | ... | |
157 | 158 |
pdf = data.find('PORTAIL/PDF') |
158 | 159 |
return pdf.get('FILE') |
159 | 160 | |
161 |
def pay_invoice(self, family_id, invoice, regie, email=None): |
|
162 |
payment_xml = ET.Element('PAIEMENT') |
|
163 |
ET.SubElement(payment_xml, 'IDDEMANDE') |
|
164 |
ET.SubElement(payment_xml, 'IDFAMILLE').text = family_id |
|
165 |
ET.SubElement(payment_xml, 'IDREGIEENC').text = utils.get_billing_regie(regie) |
|
166 |
ET.SubElement(payment_xml, 'MODEREGLEMENT').text = 'PAY' |
|
167 |
ET.SubElement(payment_xml, 'MONTANT').text = str(invoice['amount']) |
|
168 |
ET.SubElement(payment_xml, 'URL') |
|
169 |
if email: |
|
170 |
ET.SubElement(payment_xml, 'COURRIEL').text = email |
|
171 |
else: |
|
172 |
ET.SubElement(payment_xml, 'COURRIEL') |
|
173 |
ET.SubElement(payment_xml, 'REFPAIEMENT') |
|
174 |
ET.SubElement(payment_xml, 'DATEENVOI').text = datetime.now().strftime('%d/%m/%Y %H:%M:%S') |
|
175 |
ET.SubElement(payment_xml, 'DATERETOUR').text = datetime.now().strftime('%d/%m/%Y %H:%M:%S') |
|
176 |
ET.SubElement(payment_xml, 'CODERETOUR') |
|
177 |
ET.SubElement(ET.SubElement(payment_xml, 'FACTURE'), 'NOFACTURE').text = invoice['id'] |
|
178 |
data = self.get_data('PaiementFactures', payment_xml) |
|
179 |
return data.text |
|
180 | ||
181 | ||
160 | 182 |
class Link(models.Model): |
161 | 183 |
resource = models.ForeignKey(Management) |
162 | 184 |
nameid = models.CharField(blank=False, max_length=256) |
passerelle/contrib/teamnet_axel/templates/passerelle/contrib/teamnet_axel/detail.html | ||
---|---|---|
59 | 59 |
{{ site_base_uri }}{% url 'teamnet-axel-invoice-download' slug=object.slug regie_id='42' invoice_id='20150916' %}?NameID=... |
60 | 60 |
</a> |
61 | 61 |
</li> |
62 |
<li>{% trans 'Pay invoice:' %} |
|
63 |
<a href="{% url 'teamnet-axel-invoice-payment' slug=object.slug regie_id='42' family_id='999' invoice_id='20150808' %}"> |
|
64 |
{{ site_base_uri }}{% url 'teamnet-axel-invoice-payment' slug=object.slug regie_id='42' family_id='999' invoice_id='20150808' %}?NameID=... |
|
65 |
</a> |
|
66 |
</li> |
|
62 | 67 |
</ul> |
63 | 68 |
</div> |
64 | 69 |
passerelle/contrib/teamnet_axel/urls.py | ||
---|---|---|
43 | 43 |
name='teamnet-axel-invoice'), |
44 | 44 |
url(r'^(?P<slug>[\w,-]+)/regie/(?P<regie_id>[\w,-]+)/invoice/(?P<invoice_id>[\w,-]+)/download$', InvoicePDFView.as_view(), |
45 | 45 |
name='teamnet-axel-invoice-download'), |
46 |
#url(r'^(?P<slug>[\w,-]+)/invoice-pdf/(?P<id>[\w,-]+)/$', InvoicePDFView.as_view(), |
|
47 |
# name='teamnet-axel-unlink'), |
|
48 |
#url(r'^(?P<slug>[\w,-]+)/invoice-paid/(?P<id>[\w,-]+)/$', InvoicePayView.as_view(), |
|
49 |
# name='teamnet-axel-unlink'), |
|
46 |
url(r'^(?P<slug>[\w,-]+)/regie/(?P<regie_id>[\w,-]+)/family/(?P<family_id>[\w,-]+)/invoice/(?P<invoice_id>[\w,-]+)/pay$', |
|
47 |
InvoicePayView.as_view(), |
|
48 |
name='teamnet-axel-invoice-payment'), |
|
50 | 49 |
) |
51 | 50 | |
52 | 51 |
management_urlpatterns = patterns('', |
passerelle/contrib/teamnet_axel/utils.py | ||
---|---|---|
1 | 1 |
from datetime import datetime |
2 | 2 |
from decimal import Decimal |
3 | 3 | |
4 |
def get_billing_regie(slug): |
|
5 |
billing_ids = {'42': 'EN29-RESTC', |
|
6 |
'31': 'EN31-C.V.'} |
|
7 |
return billing_ids.get(slug) |
|
8 | ||
9 | ||
4 | 10 |
def normalize_invoice(invoice): |
5 | 11 |
invoice['total_amount'] = Decimal(invoice['FMONTANT']) |
6 | 12 |
invoice['amount'] = Decimal(invoice['RESTEAPAYER']) |
passerelle/contrib/teamnet_axel/views.py | ||
---|---|---|
165 | 165 |
family_id = self.get_family_id(request) |
166 | 166 |
return self.object.download_invoice(family_id, |
167 | 167 |
kwargs.get('invoice_id')) |
168 | ||
169 | ||
170 |
class InvoicePayView(ActiveInvoicesView): |
|
171 | ||
172 |
def get_data(self, request, *args, **kwargs): |
|
173 |
invoice_id = kwargs['invoice_id'] |
|
174 |
regie = kwargs['regie_id'] |
|
175 |
family = kwargs['family_id'] |
|
176 |
email = self.request.GET.get('email') |
|
177 | ||
178 |
invoices = super(InvoicePayView, self).get_data(request, regie) |
|
179 |
for invoice in invoices: |
|
180 |
if invoice['id'] == invoice_id and invoice['to_pay']: |
|
181 |
return self.object.pay_invoice(family, invoice, regie, email) |
|
168 |
- |