0002-lingo-add-callback-through-payment-backend-s-slug-49.patch
combo/apps/lingo/views.py | ||
---|---|---|
25 | 25 |
from django.contrib.auth.models import User |
26 | 26 |
from django.core import signing |
27 | 27 |
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied |
28 |
from django.db.models.query import Q |
|
28 | 29 |
from django.db.transaction import atomic |
29 | 30 |
from django.http import ( |
30 | 31 |
Http404, |
... | ... | |
611 | 612 |
class PaymentView(View): |
612 | 613 |
def handle_response(self, request, backend_response, *, callback=True, transaction=None, **kwargs): |
613 | 614 |
if 'regie_pk' in kwargs: |
614 |
payment_backend = get_object_or_404(Regie, pk=kwargs['regie_pk']).payment_backend |
|
615 |
try: |
|
616 |
regie_pk = int(kwargs['regie_pk']) |
|
617 |
except ValueError: |
|
618 |
regie_pk = None |
|
619 |
payment_backend = PaymentBackend.objects.filter(regie__pk=regie_pk).first() |
|
615 | 620 |
elif 'payment_backend_pk' in kwargs: |
616 |
payment_backend = get_object_or_404(PaymentBackend, pk=kwargs['payment_backend_pk']) |
|
621 |
payment_backend_slug = kwargs['payment_backend_pk'] |
|
622 |
try: |
|
623 |
payment_backend_pk = int(kwargs['payment_backend_pk']) |
|
624 |
except ValueError: |
|
625 |
payment_backend_pk = None |
|
626 |
payment_backend = PaymentBackend.objects.filter( |
|
627 |
Q(pk=payment_backend_pk) | Q(slug=payment_backend_slug) |
|
628 |
).first() |
|
617 | 629 |
else: |
618 |
return HttpResponseBadRequest("A payment backend or regie primary key must be specified") |
|
630 |
payment_backend = None |
|
631 | ||
632 |
if not payment_backend: |
|
633 |
logger.warning('lingo: payment backend not found on callback kwargs=%r', kwargs) |
|
634 |
raise Http404("A payment backend or regie primary key or slug must be specified") |
|
619 | 635 | |
620 | 636 |
payment = payment_backend.make_eopayment(request=request) |
621 | 637 |
logger.info(u'received payment response: %r', backend_response) |
622 |
- |