mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
Format eboutic
This commit is contained in:
parent
d722efc40f
commit
4395d62cd8
@ -27,9 +27,9 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from accounting.models import CurrencyField
|
from accounting.models import CurrencyField
|
||||||
from counter.models import Counter, Product, Customer, Selling, Refilling
|
from counter.models import Counter, Product, Selling, Refilling
|
||||||
from core.models import User
|
from core.models import User
|
||||||
from subscription.models import Subscription
|
|
||||||
|
|
||||||
class Basket(models.Model):
|
class Basket(models.Model):
|
||||||
"""
|
"""
|
||||||
@ -38,16 +38,16 @@ class Basket(models.Model):
|
|||||||
user = models.ForeignKey(User, related_name='baskets', verbose_name=_('user'), blank=False)
|
user = models.ForeignKey(User, related_name='baskets', verbose_name=_('user'), blank=False)
|
||||||
date = models.DateTimeField(_('date'), auto_now=True)
|
date = models.DateTimeField(_('date'), auto_now=True)
|
||||||
|
|
||||||
def add_product(self, p, q = 1):
|
def add_product(self, p, q=1):
|
||||||
item = self.items.filter(product_id=p.id).first()
|
item = self.items.filter(product_id=p.id).first()
|
||||||
if item is None:
|
if item is None:
|
||||||
BasketItem(basket=self, product_id=p.id, product_name=p.name, type_id=p.product_type.id,
|
BasketItem(basket=self, product_id=p.id, product_name=p.name, type_id=p.product_type.id,
|
||||||
quantity=q, product_unit_price=p.selling_price).save()
|
quantity=q, product_unit_price=p.selling_price).save()
|
||||||
else:
|
else:
|
||||||
item.quantity += q
|
item.quantity += q
|
||||||
item.save()
|
item.save()
|
||||||
|
|
||||||
def del_product(self, p, q = 1):
|
def del_product(self, p, q=1):
|
||||||
item = self.items.filter(product_id=p.id).first()
|
item = self.items.filter(product_id=p.id).first()
|
||||||
if item is not None:
|
if item is not None:
|
||||||
item.quantity -= q
|
item.quantity -= q
|
||||||
@ -64,6 +64,7 @@ class Basket(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s's basket (%d items)" % (self.user, self.items.all().count())
|
return "%s's basket (%d items)" % (self.user, self.items.all().count())
|
||||||
|
|
||||||
|
|
||||||
class Invoice(models.Model):
|
class Invoice(models.Model):
|
||||||
"""
|
"""
|
||||||
Invoices are generated once the payment has been validated
|
Invoices are generated once the payment has been validated
|
||||||
@ -92,34 +93,35 @@ class Invoice(models.Model):
|
|||||||
for i in self.items.all():
|
for i in self.items.all():
|
||||||
if i.type_id == settings.SITH_COUNTER_PRODUCTTYPE_REFILLING:
|
if i.type_id == settings.SITH_COUNTER_PRODUCTTYPE_REFILLING:
|
||||||
new = Refilling(
|
new = Refilling(
|
||||||
counter=eboutic,
|
counter=eboutic,
|
||||||
customer=self.user.customer,
|
customer=self.user.customer,
|
||||||
operator=self.user,
|
operator=self.user,
|
||||||
amount=i.product_unit_price * i.quantity,
|
amount=i.product_unit_price * i.quantity,
|
||||||
payment_method="CARD",
|
payment_method="CARD",
|
||||||
bank="OTHER",
|
bank="OTHER",
|
||||||
date=self.date,
|
date=self.date,
|
||||||
)
|
)
|
||||||
new.save()
|
new.save()
|
||||||
else:
|
else:
|
||||||
product = Product.objects.filter(id=i.product_id).first()
|
product = Product.objects.filter(id=i.product_id).first()
|
||||||
new = Selling(
|
new = Selling(
|
||||||
label=i.product_name,
|
label=i.product_name,
|
||||||
counter=eboutic,
|
counter=eboutic,
|
||||||
club=product.club,
|
club=product.club,
|
||||||
product=product,
|
product=product,
|
||||||
seller=self.user,
|
seller=self.user,
|
||||||
customer=self.user.customer,
|
customer=self.user.customer,
|
||||||
unit_price=i.product_unit_price,
|
unit_price=i.product_unit_price,
|
||||||
quantity=i.quantity,
|
quantity=i.quantity,
|
||||||
payment_method="CARD",
|
payment_method="CARD",
|
||||||
is_validated=True,
|
is_validated=True,
|
||||||
date=self.date,
|
date=self.date,
|
||||||
)
|
)
|
||||||
new.save()
|
new.save()
|
||||||
self.validated = True
|
self.validated = True
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
|
||||||
class AbstractBaseItem(models.Model):
|
class AbstractBaseItem(models.Model):
|
||||||
product_id = models.IntegerField(_('product id'))
|
product_id = models.IntegerField(_('product id'))
|
||||||
product_name = models.CharField(_('product name'), max_length=255)
|
product_name = models.CharField(_('product name'), max_length=255)
|
||||||
@ -133,8 +135,10 @@ class AbstractBaseItem(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Item: %s (%s) x%d" % (self.product_name, self.product_unit_price, self.quantity)
|
return "Item: %s (%s) x%d" % (self.product_name, self.product_unit_price, self.quantity)
|
||||||
|
|
||||||
|
|
||||||
class BasketItem(AbstractBaseItem):
|
class BasketItem(AbstractBaseItem):
|
||||||
basket = models.ForeignKey(Basket, related_name='items', verbose_name=_('basket'))
|
basket = models.ForeignKey(Basket, related_name='items', verbose_name=_('basket'))
|
||||||
|
|
||||||
|
|
||||||
class InvoiceItem(AbstractBaseItem):
|
class InvoiceItem(AbstractBaseItem):
|
||||||
invoice = models.ForeignKey(Invoice, related_name='items', verbose_name=_('invoice'))
|
invoice = models.ForeignKey(Invoice, related_name='items', verbose_name=_('invoice'))
|
||||||
|
@ -34,7 +34,8 @@ from django.core.management import call_command
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from core.models import User
|
from core.models import User
|
||||||
from counter.models import Customer, ProductType, Product, Counter, Refilling
|
from counter.models import Product, Counter, Refilling
|
||||||
|
|
||||||
|
|
||||||
class EbouticTest(TestCase):
|
class EbouticTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -74,25 +75,24 @@ class EbouticTest(TestCase):
|
|||||||
"action": "add_product",
|
"action": "add_product",
|
||||||
"product_id": self.barbar.id})
|
"product_id": self.barbar.id})
|
||||||
self.assertTrue("<input type=\"hidden\" name=\"action\" value=\"add_product\">\\n"
|
self.assertTrue("<input type=\"hidden\" name=\"action\" value=\"add_product\">\\n"
|
||||||
" <button type=\"submit\" name=\"product_id\" value=\"4\"> + </button>\\n"
|
" <button type=\"submit\" name=\"product_id\" value=\"4\"> + </button>\\n"
|
||||||
"</form>\\n Barbar: 1.70 \\xe2\\x82\\xac</li>" in str(response.content))
|
"</form>\\n Barbar: 1.70 \\xe2\\x82\\xac</li>" in str(response.content))
|
||||||
response = self.client.post(reverse("eboutic:command"))
|
response = self.client.post(reverse("eboutic:command"))
|
||||||
self.assertTrue("<tr>\\n <td>Barbar</td>\\n <td>1</td>\\n"
|
self.assertTrue("<tr>\\n <td>Barbar</td>\\n <td>1</td>\\n"
|
||||||
" <td>1.70 \\xe2\\x82\\xac</td>\\n </tr>" in str(response.content))
|
" <td>1.70 \\xe2\\x82\\xac</td>\\n </tr>" in str(response.content))
|
||||||
response = self.client.post(reverse("eboutic:pay_with_sith"), {
|
response = self.client.post(reverse("eboutic:pay_with_sith"), {
|
||||||
"action": "pay_with_sith_account"
|
"action": "pay_with_sith_account"
|
||||||
})
|
})
|
||||||
self.assertTrue("Le paiement a \\xc3\\xa9t\\xc3\\xa9 effectu\\xc3\\xa9\\n" in str(response.content))
|
self.assertTrue("Le paiement a \\xc3\\xa9t\\xc3\\xa9 effectu\\xc3\\xa9\\n" in str(response.content))
|
||||||
response = self.client.get(reverse("core:user_account_detail", kwargs={
|
response = self.client.get(reverse("core:user_account_detail", kwargs={
|
||||||
"user_id": self.subscriber.id,
|
"user_id": self.subscriber.id,
|
||||||
"year": datetime.now().year,
|
"year": datetime.now().year,
|
||||||
"month": datetime.now().month,
|
"month": datetime.now().month,
|
||||||
}))
|
}))
|
||||||
self.assertTrue("class=\"selected_tab\">Compte (8.30 \\xe2\\x82\\xac)</a>" in str(response.content))
|
self.assertTrue("class=\"selected_tab\">Compte (8.30 \\xe2\\x82\\xac)</a>" in str(response.content))
|
||||||
self.assertTrue("<td>Eboutic</td>\\n <td><a href=\"/user/3/\">Subscribed User</a></td>\\n"
|
self.assertTrue("<td>Eboutic</td>\\n <td><a href=\"/user/3/\">Subscribed User</a></td>\\n"
|
||||||
" <td>Barbar</td>\\n <td>1</td>\\n <td>1.70 \\xe2\\x82\\xac</td>\\n"
|
" <td>Barbar</td>\\n <td>1</td>\\n <td>1.70 \\xe2\\x82\\xac</td>\\n"
|
||||||
" <td>Compte utilisateur</td>" in str(response.content))
|
" <td>Compte utilisateur</td>" in str(response.content))
|
||||||
|
|
||||||
|
|
||||||
def test_buy_simple_product_with_credit_card(self):
|
def test_buy_simple_product_with_credit_card(self):
|
||||||
self.client.login(username='subscriber', password='plop')
|
self.client.login(username='subscriber', password='plop')
|
||||||
@ -100,11 +100,11 @@ class EbouticTest(TestCase):
|
|||||||
"action": "add_product",
|
"action": "add_product",
|
||||||
"product_id": self.barbar.id})
|
"product_id": self.barbar.id})
|
||||||
self.assertTrue("<input type=\"hidden\" name=\"action\" value=\"add_product\">\\n"
|
self.assertTrue("<input type=\"hidden\" name=\"action\" value=\"add_product\">\\n"
|
||||||
" <button type=\"submit\" name=\"product_id\" value=\"4\"> + </button>\\n"
|
" <button type=\"submit\" name=\"product_id\" value=\"4\"> + </button>\\n"
|
||||||
"</form>\\n Barbar: 1.70 \\xe2\\x82\\xac</li>" in str(response.content))
|
"</form>\\n Barbar: 1.70 \\xe2\\x82\\xac</li>" in str(response.content))
|
||||||
response = self.client.post(reverse("eboutic:command"))
|
response = self.client.post(reverse("eboutic:command"))
|
||||||
self.assertTrue("<tr>\\n <td>Barbar</td>\\n <td>1</td>\\n"
|
self.assertTrue("<tr>\\n <td>Barbar</td>\\n <td>1</td>\\n"
|
||||||
" <td>1.70 \\xe2\\x82\\xac</td>\\n </tr>" in str(response.content))
|
" <td>1.70 \\xe2\\x82\\xac</td>\\n </tr>" in str(response.content))
|
||||||
|
|
||||||
response = self.generate_bank_valid_answer_from_page_content(response.content)
|
response = self.generate_bank_valid_answer_from_page_content(response.content)
|
||||||
|
|
||||||
@ -112,11 +112,11 @@ class EbouticTest(TestCase):
|
|||||||
"user_id": self.subscriber.id,
|
"user_id": self.subscriber.id,
|
||||||
"year": datetime.now().year,
|
"year": datetime.now().year,
|
||||||
"month": datetime.now().month,
|
"month": datetime.now().month,
|
||||||
}))
|
}))
|
||||||
self.assertTrue("class=\"selected_tab\">Compte (0.00 \\xe2\\x82\\xac)</a>" in str(response.content))
|
self.assertTrue("class=\"selected_tab\">Compte (0.00 \\xe2\\x82\\xac)</a>" in str(response.content))
|
||||||
self.assertTrue("<td>Eboutic</td>\\n <td><a href=\"/user/3/\">Subscribed User</a></td>\\n"
|
self.assertTrue("<td>Eboutic</td>\\n <td><a href=\"/user/3/\">Subscribed User</a></td>\\n"
|
||||||
" <td>Barbar</td>\\n <td>1</td>\\n <td>1.70 \\xe2\\x82\\xac</td>\\n"
|
" <td>Barbar</td>\\n <td>1</td>\\n <td>1.70 \\xe2\\x82\\xac</td>\\n"
|
||||||
" <td>Carte bancaire</td>" in str(response.content))
|
" <td>Carte bancaire</td>" in str(response.content))
|
||||||
|
|
||||||
def test_buy_refill_product_with_credit_card(self):
|
def test_buy_refill_product_with_credit_card(self):
|
||||||
self.client.login(username='subscriber', password='plop')
|
self.client.login(username='subscriber', password='plop')
|
||||||
@ -124,11 +124,11 @@ class EbouticTest(TestCase):
|
|||||||
"action": "add_product",
|
"action": "add_product",
|
||||||
"product_id": self.refill.id})
|
"product_id": self.refill.id})
|
||||||
self.assertTrue("<input type=\"hidden\" name=\"action\" value=\"add_product\">\\n"
|
self.assertTrue("<input type=\"hidden\" name=\"action\" value=\"add_product\">\\n"
|
||||||
" <button type=\"submit\" name=\"product_id\" value=\"3\"> + </button>\\n"
|
" <button type=\"submit\" name=\"product_id\" value=\"3\"> + </button>\\n"
|
||||||
"</form>\\n Rechargement 15 \\xe2\\x82\\xac: 15.00 \\xe2\\x82\\xac</li>" in str(response.content))
|
"</form>\\n Rechargement 15 \\xe2\\x82\\xac: 15.00 \\xe2\\x82\\xac</li>" in str(response.content))
|
||||||
response = self.client.post(reverse("eboutic:command"))
|
response = self.client.post(reverse("eboutic:command"))
|
||||||
self.assertTrue("<tr>\\n <td>Rechargement 15 \\xe2\\x82\\xac</td>\\n <td>1</td>\\n"
|
self.assertTrue("<tr>\\n <td>Rechargement 15 \\xe2\\x82\\xac</td>\\n <td>1</td>\\n"
|
||||||
" <td>15.00 \\xe2\\x82\\xac</td>\\n </tr>" in str(response.content))
|
" <td>15.00 \\xe2\\x82\\xac</td>\\n </tr>" in str(response.content))
|
||||||
|
|
||||||
response = self.generate_bank_valid_answer_from_page_content(response.content)
|
response = self.generate_bank_valid_answer_from_page_content(response.content)
|
||||||
|
|
||||||
@ -136,12 +136,12 @@ class EbouticTest(TestCase):
|
|||||||
"user_id": self.subscriber.id,
|
"user_id": self.subscriber.id,
|
||||||
"year": datetime.now().year,
|
"year": datetime.now().year,
|
||||||
"month": datetime.now().month,
|
"month": datetime.now().month,
|
||||||
}))
|
}))
|
||||||
self.assertTrue("class=\"selected_tab\">Compte (15.00 \\xe2\\x82\\xac)</a>" in str(response.content))
|
self.assertTrue("class=\"selected_tab\">Compte (15.00 \\xe2\\x82\\xac)</a>" in str(response.content))
|
||||||
self.assertTrue("<td>\\n <ul>\\n \\n "
|
self.assertTrue("<td>\\n <ul>\\n \\n "
|
||||||
"<li>1 x Rechargement 15 \\xe2\\x82\\xac - 15.00 \\xe2\\x82\\xac</li>\\n"
|
"<li>1 x Rechargement 15 \\xe2\\x82\\xac - 15.00 \\xe2\\x82\\xac</li>\\n"
|
||||||
" \\n </ul>\\n </td>\\n"
|
" \\n </ul>\\n </td>\\n"
|
||||||
" <td>15.00 \\xe2\\x82\\xac</td>" in str(response.content))
|
" <td>15.00 \\xe2\\x82\\xac</td>" in str(response.content))
|
||||||
|
|
||||||
def test_buy_subscribe_product_with_credit_card(self):
|
def test_buy_subscribe_product_with_credit_card(self):
|
||||||
self.client.login(username='old_subscriber', password='plop')
|
self.client.login(username='old_subscriber', password='plop')
|
||||||
@ -151,11 +151,11 @@ class EbouticTest(TestCase):
|
|||||||
"action": "add_product",
|
"action": "add_product",
|
||||||
"product_id": self.cotis.id})
|
"product_id": self.cotis.id})
|
||||||
self.assertTrue("<input type=\"hidden\" name=\"action\" value=\"add_product\">\\n"
|
self.assertTrue("<input type=\"hidden\" name=\"action\" value=\"add_product\">\\n"
|
||||||
" <button type=\"submit\" name=\"product_id\" value=\"1\"> + </button>\\n"
|
" <button type=\"submit\" name=\"product_id\" value=\"1\"> + </button>\\n"
|
||||||
"</form>\\n Cotis 1 semestre: 15.00 \\xe2\\x82\\xac</li>" in str(response.content))
|
"</form>\\n Cotis 1 semestre: 15.00 \\xe2\\x82\\xac</li>" in str(response.content))
|
||||||
response = self.client.post(reverse("eboutic:command"))
|
response = self.client.post(reverse("eboutic:command"))
|
||||||
self.assertTrue("<tr>\\n <td>Cotis 1 semestre</td>\\n <td>1</td>\\n"
|
self.assertTrue("<tr>\\n <td>Cotis 1 semestre</td>\\n <td>1</td>\\n"
|
||||||
" <td>15.00 \\xe2\\x82\\xac</td>\\n </tr>" in str(response.content))
|
" <td>15.00 \\xe2\\x82\\xac</td>\\n </tr>" in str(response.content))
|
||||||
|
|
||||||
response = self.generate_bank_valid_answer_from_page_content(response.content)
|
response = self.generate_bank_valid_answer_from_page_content(response.content)
|
||||||
|
|
||||||
@ -163,14 +163,11 @@ class EbouticTest(TestCase):
|
|||||||
"user_id": self.old_subscriber.id,
|
"user_id": self.old_subscriber.id,
|
||||||
"year": datetime.now().year,
|
"year": datetime.now().year,
|
||||||
"month": datetime.now().month,
|
"month": datetime.now().month,
|
||||||
}))
|
}))
|
||||||
self.assertTrue("class=\"selected_tab\">Compte (0.00 \\xe2\\x82\\xac)</a>" in str(response.content))
|
self.assertTrue("class=\"selected_tab\">Compte (0.00 \\xe2\\x82\\xac)</a>" in str(response.content))
|
||||||
self.assertTrue("<td>\\n <ul>\\n \\n "
|
self.assertTrue("<td>\\n <ul>\\n \\n "
|
||||||
"<li>1 x Cotis 1 semestre - 15.00 \\xe2\\x82\\xac</li>\\n"
|
"<li>1 x Cotis 1 semestre - 15.00 \\xe2\\x82\\xac</li>\\n"
|
||||||
" \\n </ul>\\n </td>\\n"
|
" \\n </ul>\\n </td>\\n"
|
||||||
" <td>15.00 \\xe2\\x82\\xac</td>" in str(response.content))
|
" <td>15.00 \\xe2\\x82\\xac</td>" in str(response.content))
|
||||||
response = self.client.get(reverse("core:user_profile", kwargs={"user_id": self.old_subscriber.id}))
|
response = self.client.get(reverse("core:user_profile", kwargs={"user_id": self.old_subscriber.id}))
|
||||||
self.assertTrue("Cotisant jusqu\\'au" in str(response.content))
|
self.assertTrue("Cotisant jusqu\\'au" in str(response.content))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
from django.conf.urls import url, include
|
from django.conf.urls import url
|
||||||
|
|
||||||
from eboutic.views import *
|
from eboutic.views import *
|
||||||
|
|
||||||
@ -33,6 +33,3 @@ urlpatterns = [
|
|||||||
url(r'^pay$', EbouticPayWithSith.as_view(), name='pay_with_sith'),
|
url(r'^pay$', EbouticPayWithSith.as_view(), name='pay_with_sith'),
|
||||||
url(r'^et_autoanswer$', EtransactionAutoAnswer.as_view(), name='etransation_autoanswer'),
|
url(r'^et_autoanswer$', EtransactionAutoAnswer.as_view(), name='etransation_autoanswer'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,29 +24,27 @@
|
|||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import pytz
|
|
||||||
import hmac
|
import hmac
|
||||||
import base64
|
import base64
|
||||||
from OpenSSL import crypto
|
from OpenSSL import crypto
|
||||||
|
|
||||||
from django.shortcuts import render
|
|
||||||
from django.core.urlresolvers import reverse_lazy
|
from django.core.urlresolvers import reverse_lazy
|
||||||
from django.views.generic import TemplateView, View
|
from django.views.generic import TemplateView, View
|
||||||
from django.http import HttpResponse, HttpResponseRedirect
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from django.core.exceptions import SuspiciousOperation
|
from django.core.exceptions import SuspiciousOperation
|
||||||
from django.shortcuts import render
|
|
||||||
from django.db import transaction, DataError
|
from django.db import transaction, DataError
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from counter.models import Customer, Counter, ProductType, Selling
|
from counter.models import Customer, Counter, ProductType, Selling
|
||||||
from eboutic.models import Basket, Invoice, BasketItem, InvoiceItem
|
from eboutic.models import Basket, Invoice, InvoiceItem
|
||||||
|
|
||||||
|
|
||||||
class EbouticMain(TemplateView):
|
class EbouticMain(TemplateView):
|
||||||
template_name = 'eboutic/eboutic_main.jinja'
|
template_name = 'eboutic/eboutic_main.jinja'
|
||||||
|
|
||||||
def make_basket(self, request):
|
def make_basket(self, request):
|
||||||
if 'basket_id' not in request.session.keys(): # Init the basket session entry
|
if 'basket_id' not in request.session.keys(): # Init the basket session entry
|
||||||
self.basket = Basket(user=request.user)
|
self.basket = Basket(user=request.user)
|
||||||
self.basket.save()
|
self.basket.save()
|
||||||
else:
|
else:
|
||||||
@ -60,7 +58,7 @@ class EbouticMain(TemplateView):
|
|||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
if not request.user.is_authenticated():
|
if not request.user.is_authenticated():
|
||||||
return HttpResponseRedirect(reverse_lazy('core:login', args=self.args, kwargs=kwargs) + "?next=" +
|
return HttpResponseRedirect(reverse_lazy('core:login', args=self.args, kwargs=kwargs) + "?next=" +
|
||||||
request.path)
|
request.path)
|
||||||
self.object = Counter.objects.filter(type="EBOUTIC").first()
|
self.object = Counter.objects.filter(type="EBOUTIC").first()
|
||||||
self.make_basket(request)
|
self.make_basket(request)
|
||||||
return super(EbouticMain, self).get(request, *args, **kwargs)
|
return super(EbouticMain, self).get(request, *args, **kwargs)
|
||||||
@ -68,7 +66,7 @@ class EbouticMain(TemplateView):
|
|||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
if not request.user.is_authenticated():
|
if not request.user.is_authenticated():
|
||||||
return HttpResponseRedirect(reverse_lazy('core:login', args=self.args, kwargs=kwargs) + "?next=" +
|
return HttpResponseRedirect(reverse_lazy('core:login', args=self.args, kwargs=kwargs) + "?next=" +
|
||||||
request.path)
|
request.path)
|
||||||
self.object = Counter.objects.filter(type="EBOUTIC").first()
|
self.object = Counter.objects.filter(type="EBOUTIC").first()
|
||||||
self.make_basket(request)
|
self.make_basket(request)
|
||||||
if 'add_product' in request.POST['action']:
|
if 'add_product' in request.POST['action']:
|
||||||
@ -77,7 +75,6 @@ class EbouticMain(TemplateView):
|
|||||||
self.del_product(request)
|
self.del_product(request)
|
||||||
return self.render_to_response(self.get_context_data(**kwargs))
|
return self.render_to_response(self.get_context_data(**kwargs))
|
||||||
|
|
||||||
|
|
||||||
def add_product(self, request):
|
def add_product(self, request):
|
||||||
""" Add a product to the basket """
|
""" Add a product to the basket """
|
||||||
try:
|
try:
|
||||||
@ -108,19 +105,20 @@ class EbouticMain(TemplateView):
|
|||||||
kwargs['categories'] = kwargs['categories'].exclude(id=settings.SITH_PRODUCTTYPE_SUBSCRIPTION)
|
kwargs['categories'] = kwargs['categories'].exclude(id=settings.SITH_PRODUCTTYPE_SUBSCRIPTION)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class EbouticCommand(TemplateView):
|
class EbouticCommand(TemplateView):
|
||||||
template_name = 'eboutic/eboutic_makecommand.jinja'
|
template_name = 'eboutic/eboutic_makecommand.jinja'
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
if not request.user.is_authenticated():
|
if not request.user.is_authenticated():
|
||||||
return HttpResponseRedirect(reverse_lazy('core:login', args=self.args, kwargs=kwargs) + "?next=" +
|
return HttpResponseRedirect(reverse_lazy('core:login', args=self.args, kwargs=kwargs) + "?next=" +
|
||||||
request.path)
|
request.path)
|
||||||
return HttpResponseRedirect(reverse_lazy('eboutic:main', args=self.args, kwargs=kwargs))
|
return HttpResponseRedirect(reverse_lazy('eboutic:main', args=self.args, kwargs=kwargs))
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
if not request.user.is_authenticated():
|
if not request.user.is_authenticated():
|
||||||
return HttpResponseRedirect(reverse_lazy('core:login', args=self.args, kwargs=kwargs) + "?next=" +
|
return HttpResponseRedirect(reverse_lazy('core:login', args=self.args, kwargs=kwargs) + "?next=" +
|
||||||
request.path)
|
request.path)
|
||||||
if 'basket_id' not in request.session.keys():
|
if 'basket_id' not in request.session.keys():
|
||||||
return HttpResponseRedirect(reverse_lazy('eboutic:main', args=self.args, kwargs=kwargs))
|
return HttpResponseRedirect(reverse_lazy('eboutic:main', args=self.args, kwargs=kwargs))
|
||||||
self.basket = Basket.objects.filter(id=request.session['basket_id']).first()
|
self.basket = Basket.objects.filter(id=request.session['basket_id']).first()
|
||||||
@ -136,8 +134,8 @@ class EbouticCommand(TemplateView):
|
|||||||
kwargs['et_request']['PBX_SITE'] = settings.SITH_EBOUTIC_PBX_SITE
|
kwargs['et_request']['PBX_SITE'] = settings.SITH_EBOUTIC_PBX_SITE
|
||||||
kwargs['et_request']['PBX_RANG'] = settings.SITH_EBOUTIC_PBX_RANG
|
kwargs['et_request']['PBX_RANG'] = settings.SITH_EBOUTIC_PBX_RANG
|
||||||
kwargs['et_request']['PBX_IDENTIFIANT'] = settings.SITH_EBOUTIC_PBX_IDENTIFIANT
|
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_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_DEVISE'] = 978 # This is Euro. ET support only this value anyway
|
||||||
kwargs['et_request']['PBX_CMD'] = self.basket.id
|
kwargs['et_request']['PBX_CMD'] = self.basket.id
|
||||||
kwargs['et_request']['PBX_PORTEUR'] = self.basket.user.email
|
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_RETOUR'] = "Amount:M;BasketID:R;Auto:A;Error:E;Sig:K"
|
||||||
@ -146,10 +144,11 @@ class EbouticCommand(TemplateView):
|
|||||||
kwargs['et_request']['PBX_TYPECARTE'] = "CB"
|
kwargs['et_request']['PBX_TYPECARTE'] = "CB"
|
||||||
kwargs['et_request']['PBX_TIME'] = str(datetime.now().replace(microsecond=0).isoformat('T'))
|
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,
|
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'),
|
bytes("&".join(["%s=%s" % (k, v) for k, v in kwargs['et_request'].items()]), 'utf-8'),
|
||||||
"sha512").hexdigest().upper()
|
"sha512").hexdigest().upper()
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class EbouticPayWithSith(TemplateView):
|
class EbouticPayWithSith(TemplateView):
|
||||||
template_name = 'eboutic/eboutic_payment_result.jinja'
|
template_name = 'eboutic/eboutic_payment_result.jinja'
|
||||||
|
|
||||||
@ -172,30 +171,31 @@ class EbouticPayWithSith(TemplateView):
|
|||||||
for it in b.items.all():
|
for it in b.items.all():
|
||||||
product = eboutic.products.filter(id=it.product_id).first()
|
product = eboutic.products.filter(id=it.product_id).first()
|
||||||
Selling(
|
Selling(
|
||||||
label=it.product_name,
|
label=it.product_name,
|
||||||
counter=eboutic,
|
counter=eboutic,
|
||||||
club=product.club,
|
club=product.club,
|
||||||
product=product,
|
product=product,
|
||||||
seller=c.user,
|
seller=c.user,
|
||||||
customer=c,
|
customer=c,
|
||||||
unit_price=it.product_unit_price,
|
unit_price=it.product_unit_price,
|
||||||
quantity=it.quantity,
|
quantity=it.quantity,
|
||||||
payment_method="SITH_ACCOUNT",
|
payment_method="SITH_ACCOUNT",
|
||||||
).save()
|
).save()
|
||||||
b.delete()
|
b.delete()
|
||||||
kwargs['not_enough'] = False
|
kwargs['not_enough'] = False
|
||||||
request.session.pop('basket_id', None)
|
request.session.pop('basket_id', None)
|
||||||
except DataError as e:
|
except DataError as e:
|
||||||
kwargs['not_enough'] = True
|
kwargs['not_enough'] = True
|
||||||
return self.render_to_response(self.get_context_data(**kwargs))
|
return self.render_to_response(self.get_context_data(**kwargs))
|
||||||
|
|
||||||
|
|
||||||
class EtransactionAutoAnswer(View):
|
class EtransactionAutoAnswer(View):
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
if (not 'Amount' in request.GET.keys() or
|
if (not 'Amount' in request.GET.keys() or
|
||||||
not 'BasketID' in request.GET.keys() or
|
not 'BasketID' in request.GET.keys() or
|
||||||
not 'Auto' in request.GET.keys() or
|
not 'Auto' in request.GET.keys() or
|
||||||
not 'Error' in request.GET.keys() or
|
not 'Error' in request.GET.keys() or
|
||||||
not 'Sig' in request.GET.keys()):
|
not 'Sig' in request.GET.keys()):
|
||||||
return HttpResponse("Bad arguments", status=400)
|
return HttpResponse("Bad arguments", status=400)
|
||||||
key = crypto.load_publickey(crypto.FILETYPE_PEM, settings.SITH_EBOUTIC_PUB_KEY)
|
key = crypto.load_publickey(crypto.FILETYPE_PEM, settings.SITH_EBOUTIC_PUB_KEY)
|
||||||
cert = crypto.X509()
|
cert = crypto.X509()
|
||||||
@ -217,12 +217,11 @@ class EtransactionAutoAnswer(View):
|
|||||||
i.save()
|
i.save()
|
||||||
for it in b.items.all():
|
for it in b.items.all():
|
||||||
InvoiceItem(invoice=i, product_id=it.product_id, product_name=it.product_name, type_id=it.type_id,
|
InvoiceItem(invoice=i, product_id=it.product_id, product_name=it.product_name, type_id=it.type_id,
|
||||||
product_unit_price=it.product_unit_price, quantity=it.quantity).save()
|
product_unit_price=it.product_unit_price, quantity=it.quantity).save()
|
||||||
i.validate()
|
i.validate()
|
||||||
b.delete()
|
b.delete()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return HttpResponse("Payment failed with error: "+repr(e), status=400)
|
return HttpResponse("Payment failed with error: " + repr(e), status=400)
|
||||||
return HttpResponse()
|
return HttpResponse()
|
||||||
else:
|
else:
|
||||||
return HttpResponse("Payment failed with error: "+request.GET['Error'], status=400)
|
return HttpResponse("Payment failed with error: " + request.GET['Error'], status=400)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user