Commit c099f1c5 authored by Skia's avatar Skia

Make eboutic working

parent 60e606b3
......@@ -119,6 +119,10 @@ td {
padding: 4px;
border: solid 1px black;
border-collapse: collapse;
vertical-align: top;
}
td>ul {
margin-top: 0px;
}
thead {
font-weight: bold;
......
......@@ -7,8 +7,73 @@
{% block infos %}
<h3>{% trans %}User account{% endtrans %}</h3>
<p>{% trans %}Amount: {% endtrans %}{{ customer.amount }}</p>
<p>{{ customer.refillings.all() }}</p>
<p>{{ customer.buyings.all() }}</p>
<h4>{% trans %}Refillings{% endtrans %}</h4>
<table>
<thead>
<tr>
<td>{% trans %}Date{% endtrans %}</td>
<td>{% trans %}Barman{% endtrans %}</td>
<td>{% trans %}Amount{% endtrans %}</td>
</tr>
</thead>
<tbody>
{% for i in customer.refillings.all() %}
<tr>
<td>{{ i.date|localtime|date(DATETIME_FORMAT) }} - {{ i.date|localtime|time(DATETIME_FORMAT) }}</td>
<td>{{ i.operator }}</td>
<td>{{ i.amount }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<h4>{% trans %}Buyings{% endtrans %}</h4>
<table>
<thead>
<tr>
<td>{% trans %}Date{% endtrans %}</td>
<td>{% trans %}Barman{% endtrans %}</td>
<td>{% trans %}Product{% endtrans %}</td>
<td>{% trans %}Quantity{% endtrans %}</td>
<td>{% trans %}Total{% endtrans %}</td>
</tr>
</thead>
<tbody>
{% for i in customer.buyings.all() %}
<tr>
<td>{{ i.date|localtime|date(DATETIME_FORMAT) }} - {{ i.date|localtime|time(DATETIME_FORMAT) }}</td>
<td>{{ i.seller }}</td>
<td>{{ i.product }}</td>
<td>{{ i.quantity }}</td>
<td>{{ i.quantity * i.unit_price }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<h4>{% trans %}Invoices{% endtrans %}</h4>
<table>
<thead>
<tr>
<td>{% trans %}Date{% endtrans %}</td>
<td>{% trans %}Items{% endtrans %}</td>
<td>{% trans %}Amount{% endtrans %}</td>
</tr>
</thead>
<tbody>
{% for i in customer.user.invoices.all() %}
<tr>
<td>{{ i.date|localtime|date(DATETIME_FORMAT) }} - {{ i.date|localtime|time(DATETIME_FORMAT) }}</td>
<td>
<ul>
{% for it in i.items.all() %}
<li>{{ it.product_name }} - {{ it.product_unit_price }}</li>
{% endfor %}
</ul>
</td>
<td>{{ i.get_total() }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('eboutic', '0002_auto_20160722_0100'),
]
operations = [
migrations.DeleteModel(
name='Eboutic',
),
migrations.AddField(
model_name='basketitem',
name='type',
field=models.CharField(default='GUY', verbose_name='product type', max_length=255),
preserve_default=False,
),
migrations.AddField(
model_name='invoiceitem',
name='type',
field=models.CharField(default='GUY', verbose_name='product type', max_length=255),
preserve_default=False,
),
]
......@@ -28,7 +28,6 @@ class Invoice(models.Model):
max_length=20, verbose_name=_('payment method'))
validated = models.BooleanField(_("validated"), default=False)
def get_total(self):
total = 0
for i in self.items.all():
......@@ -41,13 +40,17 @@ class Invoice(models.Model):
if self.payment_method == "SITH_ACCOUNT":
self.user.customer.amount -= self.get_total()
self.user.customer.save()
else:
for i in self.items.filter(type="REFILLING").all():
self.user.customer.amount += i.product_unit_price * i.quantity
self.user.customer.save()
self.validated = True
self.save()
class AbstractBaseItem(models.Model):
product_name = models.CharField(_('product name'), max_length=255)
type = models.CharField(_('product type'), max_length=255)
product_unit_price = CurrencyField(_('unit price'))
quantity = models.IntegerField(_('quantity'))
......
from collections import OrderedDict
from datetime import datetime
import pytz
import hmac
import base64
from OpenSSL import crypto
......@@ -84,6 +85,8 @@ class EbouticCommand(TemplateView):
return HttpResponseRedirect(reverse_lazy('eboutic:main', args=self.args, kwargs=kwargs))
def post(self, request, *args, **kwargs):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse_lazy('core:login', args=self.args, kwargs=kwargs))
if 'basket' not in request.session.keys():
return HttpResponseRedirect(reverse_lazy('eboutic:main', args=self.args, kwargs=kwargs))
if self.make_basket(request):
......@@ -102,7 +105,8 @@ class EbouticCommand(TemplateView):
request.session.modified = True
b.items.all().delete()
for pid,infos in request.session['basket'].items():
BasketItem(basket=b, product_name=Product.objects.filter(id=int(pid)).first().name,
p = Product.objects.filter(id=int(pid)).first()
BasketItem(basket=b, product_name=p.name, type=p.product_type.name,
quantity=infos['qty'], product_unit_price=infos['price']/100).save()
self.basket = b
return True
......@@ -115,10 +119,12 @@ class EbouticCommand(TemplateView):
kwargs['et_request']['PBX_IDENTIFIANT'] = settings.SITH_EBOUTIC_PBX_IDENTIFIANT
kwargs['et_request']['PBX_TOTAL'] = int(self.basket.get_total()*100)
kwargs['et_request']['PBX_DEVISE'] = 978 # This is Euro. ET support only this value anyway
kwargs['et_request']['PBX_CMD'] = "CMD_"+str(self.basket.id)
kwargs['et_request']['PBX_CMD'] = self.basket.id
kwargs['et_request']['PBX_PORTEUR'] = self.basket.user.email
kwargs['et_request']['PBX_RETOUR'] = "Amount:M;BasketID:R;Auto:A;Error:E;Sig:K"
kwargs['et_request']['PBX_HASH'] = "SHA512"
kwargs['et_request']['PBX_TYPEPAIEMENT'] = "CARTE"
kwargs['et_request']['PBX_TYPECARTE'] = "CB"
kwargs['et_request']['PBX_TIME'] = str(datetime.now().replace(microsecond=0).isoformat('T'))
kwargs['et_request']['PBX_HMAC'] = hmac.new(settings.SITH_EBOUTIC_HMAC_KEY,
bytes("&".join(["%s=%s"%(k,v) for k,v in kwargs['et_request'].items()]), 'utf-8'),
......@@ -148,7 +154,7 @@ class EbouticPayWithSith(TemplateView):
i.payment_method = "SITH_ACCOUNT"
i.save()
for it in b.items.all():
InvoiceItem(invoice=i, product_name=it.product_name,
InvoiceItem(invoice=i, product_name=it.product_name, type=it.type,
product_unit_price=it.product_unit_price, quantity=it.quantity).save()
i.validate()
kwargs['not_enough'] = False
......@@ -184,9 +190,10 @@ class EtransactionAutoAnswer(View):
i.payment_method = "CREDIT_CARD"
i.save()
for it in b.items.all():
InvoiceItem(invoice=i, product_name=it.product_name,
InvoiceItem(invoice=i, product_name=it.product_name, type=it.type,
product_unit_price=it.product_unit_price, quantity=it.quantity).save()
i.validate()
b.delete()
return HttpResponse("Payment validated")
else:
return HttpResponse("Payment failed with error: "+request.GET['Error'])
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDe+hkicNP7ROHUssGNtHwiT2Ew
HFrSk/qwrcq8v5metRtTTFPE/nmzSkRnTs3GMpi57rBdxBBJW5W9cpNyGUh0jNXc
VrOSClpD5Ri2hER/GcNrxVRP7RlWOqB1C03q4QYmwjHZ+zlM4OUhCCAtSWflB4wC
Ka1g88CjFwRw/PB9kwIDAQAB
-----END PUBLIC KEY-----
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