mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-11 04:19:25 +00:00
Format eboutic
This commit is contained in:
@ -24,29 +24,27 @@
|
||||
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
import pytz
|
||||
import hmac
|
||||
import base64
|
||||
from OpenSSL import crypto
|
||||
|
||||
from django.shortcuts import render
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.views.generic import TemplateView, View
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.core.exceptions import SuspiciousOperation
|
||||
from django.shortcuts import render
|
||||
from django.db import transaction, DataError
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.conf import settings
|
||||
|
||||
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):
|
||||
template_name = 'eboutic/eboutic_main.jinja'
|
||||
|
||||
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.save()
|
||||
else:
|
||||
@ -60,7 +58,7 @@ class EbouticMain(TemplateView):
|
||||
def get(self, request, *args, **kwargs):
|
||||
if not request.user.is_authenticated():
|
||||
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.make_basket(request)
|
||||
return super(EbouticMain, self).get(request, *args, **kwargs)
|
||||
@ -68,7 +66,7 @@ class EbouticMain(TemplateView):
|
||||
def post(self, request, *args, **kwargs):
|
||||
if not request.user.is_authenticated():
|
||||
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.make_basket(request)
|
||||
if 'add_product' in request.POST['action']:
|
||||
@ -77,7 +75,6 @@ class EbouticMain(TemplateView):
|
||||
self.del_product(request)
|
||||
return self.render_to_response(self.get_context_data(**kwargs))
|
||||
|
||||
|
||||
def add_product(self, request):
|
||||
""" Add a product to the basket """
|
||||
try:
|
||||
@ -108,19 +105,20 @@ class EbouticMain(TemplateView):
|
||||
kwargs['categories'] = kwargs['categories'].exclude(id=settings.SITH_PRODUCTTYPE_SUBSCRIPTION)
|
||||
return kwargs
|
||||
|
||||
|
||||
class EbouticCommand(TemplateView):
|
||||
template_name = 'eboutic/eboutic_makecommand.jinja'
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
if not request.user.is_authenticated():
|
||||
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))
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
if not request.user.is_authenticated():
|
||||
return HttpResponseRedirect(reverse_lazy('core:login', args=self.args, kwargs=kwargs) + "?next=" +
|
||||
request.path)
|
||||
request.path)
|
||||
if 'basket_id' not in request.session.keys():
|
||||
return HttpResponseRedirect(reverse_lazy('eboutic:main', args=self.args, kwargs=kwargs))
|
||||
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_RANG'] = settings.SITH_EBOUTIC_PBX_RANG
|
||||
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_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'] = 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"
|
||||
@ -146,10 +144,11 @@ class EbouticCommand(TemplateView):
|
||||
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'),
|
||||
"sha512").hexdigest().upper()
|
||||
bytes("&".join(["%s=%s" % (k, v) for k, v in kwargs['et_request'].items()]), 'utf-8'),
|
||||
"sha512").hexdigest().upper()
|
||||
return kwargs
|
||||
|
||||
|
||||
class EbouticPayWithSith(TemplateView):
|
||||
template_name = 'eboutic/eboutic_payment_result.jinja'
|
||||
|
||||
@ -172,30 +171,31 @@ class EbouticPayWithSith(TemplateView):
|
||||
for it in b.items.all():
|
||||
product = eboutic.products.filter(id=it.product_id).first()
|
||||
Selling(
|
||||
label=it.product_name,
|
||||
counter=eboutic,
|
||||
club=product.club,
|
||||
product=product,
|
||||
seller=c.user,
|
||||
customer=c,
|
||||
unit_price=it.product_unit_price,
|
||||
quantity=it.quantity,
|
||||
payment_method="SITH_ACCOUNT",
|
||||
).save()
|
||||
label=it.product_name,
|
||||
counter=eboutic,
|
||||
club=product.club,
|
||||
product=product,
|
||||
seller=c.user,
|
||||
customer=c,
|
||||
unit_price=it.product_unit_price,
|
||||
quantity=it.quantity,
|
||||
payment_method="SITH_ACCOUNT",
|
||||
).save()
|
||||
b.delete()
|
||||
kwargs['not_enough'] = False
|
||||
request.session.pop('basket_id', None)
|
||||
except DataError as e:
|
||||
kwargs['not_enough'] = True
|
||||
kwargs['not_enough'] = True
|
||||
return self.render_to_response(self.get_context_data(**kwargs))
|
||||
|
||||
|
||||
class EtransactionAutoAnswer(View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
if (not 'Amount' in request.GET.keys() or
|
||||
not 'BasketID' in request.GET.keys() or
|
||||
not 'Auto' 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)
|
||||
key = crypto.load_publickey(crypto.FILETYPE_PEM, settings.SITH_EBOUTIC_PUB_KEY)
|
||||
cert = crypto.X509()
|
||||
@ -217,12 +217,11 @@ class EtransactionAutoAnswer(View):
|
||||
i.save()
|
||||
for it in b.items.all():
|
||||
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()
|
||||
b.delete()
|
||||
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()
|
||||
else:
|
||||
return HttpResponse("Payment failed with error: "+request.GET['Error'], status=400)
|
||||
|
||||
return HttpResponse("Payment failed with error: " + request.GET['Error'], status=400)
|
||||
|
Reference in New Issue
Block a user