35 |
35 |
from django.utils.translation import ugettext_lazy as _
|
36 |
36 |
from django.db.transaction import atomic
|
37 |
37 |
from django.utils.encoding import smart_text
|
|
38 |
from django.shortcuts import render
|
38 |
39 |
|
39 |
40 |
import eopayment
|
40 |
41 |
|
|
42 |
from combo.public.views import publish_page
|
41 |
43 |
from combo.data.models import Page
|
42 |
44 |
from combo.utils import check_request_signature, aes_hex_decrypt, DecryptionError
|
43 |
45 |
from combo.profile.utils import get_user_from_name_id
|
|
46 |
from combo.utils.urls import same_origin
|
44 |
47 |
|
45 |
48 |
from .models import (Regie, BasketItem, Transaction, TransactionOperation,
|
46 |
49 |
LingoBasketCell, SelfDeclaredInvoicePayment)
|
... | ... | |
67 |
70 |
return check_request_signature(request, keys=keys)
|
68 |
71 |
|
69 |
72 |
|
|
73 |
def payment_error(request, location, *args, **kwargs):
|
|
74 |
try:
|
|
75 |
page = Page.objects.get(slug='payment-error')
|
|
76 |
template_name = None
|
|
77 |
except Page.DoesNotExist:
|
|
78 |
page = Page()
|
|
79 |
page.template_name = 'standard'
|
|
80 |
template_name = 'lingo/payment-error.html'
|
|
81 |
request.extra_context_data = {'location': location}
|
|
82 |
return publish_page(request, page, template_name=template_name)
|
|
83 |
|
|
84 |
|
|
85 |
class ShowMessageOnExternalRedirectMixin(object):
|
|
86 |
def dispatch(self, request, *args, **kwargs):
|
|
87 |
response = super(ShowMessageOnExternalRedirectMixin, self).dispatch(request, *args, **kwargs)
|
|
88 |
if self.is_external_redirect(request, response) and self.has_messages(request):
|
|
89 |
return payment_error(request, response['Location'], *args, **kwargs)
|
|
90 |
return response
|
|
91 |
|
|
92 |
def has_messages(self, request):
|
|
93 |
storage = messages.get_messages(request)
|
|
94 |
if not storage:
|
|
95 |
return False
|
|
96 |
return bool(len(storage))
|
|
97 |
|
|
98 |
def is_external_redirect(self, request, response):
|
|
99 |
if not isinstance(response, HttpResponseRedirect):
|
|
100 |
return False
|
|
101 |
return not self.is_same_origin(request, response)
|
|
102 |
|
|
103 |
def is_same_origin(self, request, response):
|
|
104 |
local_url = request.build_absolute_uri()
|
|
105 |
redirect_url = response['Location']
|
|
106 |
if (not redirect_url
|
|
107 |
or (redirect_url[0] == '/'
|
|
108 |
and (len(redirect_url) == 1 or redirect_url[1] != '/'))):
|
|
109 |
return True
|
|
110 |
return same_origin(local_url, redirect_url)
|
|
111 |
|
|
112 |
|
70 |
113 |
class RegiesApiView(ListView):
|
71 |
114 |
model = Regie
|
72 |
115 |
|
... | ... | |
403 |
446 |
return self.handle_payment(request, regie, items, remote_items, next_url, email)
|
404 |
447 |
|
405 |
448 |
|
406 |
|
class BasketItemPayView(PayMixin, View):
|
|
449 |
class BasketItemPayView(ShowMessageOnExternalRedirectMixin, PayMixin, View):
|
407 |
450 |
def get(self, request, *args, **kwargs):
|
408 |
451 |
next_url = request.GET.get('next_url') or '/'
|
409 |
452 |
if not (request.user and request.user.is_authenticated()):
|
... | ... | |
545 |
588 |
return super(CallbackView, self).dispatch(*args, **kwargs)
|
546 |
589 |
|
547 |
590 |
|
548 |
|
class ReturnView(PaymentView):
|
|
591 |
class ReturnView(ShowMessageOnExternalRedirectMixin, PaymentView):
|
549 |
592 |
@csrf_exempt
|
550 |
593 |
def dispatch(self, *args, **kwargs):
|
551 |
594 |
return super(ReturnView, self).dispatch(*args, **kwargs)
|