summaryrefslogtreecommitdiffstats
path: root/combo/apps/lingo/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'combo/apps/lingo/views.py')
-rw-r--r--combo/apps/lingo/views.py34
1 files changed, 23 insertions, 11 deletions
diff --git a/combo/apps/lingo/views.py b/combo/apps/lingo/views.py
index dde0690..cb4f089 100644
--- a/combo/apps/lingo/views.py
+++ b/combo/apps/lingo/views.py
@@ -43,17 +43,22 @@ from combo.utils import check_request_signature, aes_hex_decrypt, DecryptionErro
from combo.profile.utils import get_user_from_name_id
from .models import (Regie, BasketItem, Transaction, TransactionOperation,
- LingoBasketCell, SelfDeclaredInvoicePayment)
+ LingoBasketCell, SelfDeclaredInvoicePayment, PaymentBackend)
-def get_eopayment_object(request, regie):
- options = regie.service_options
+def get_eopayment_object(request, regie_or_payment_backend):
+ payment_backend = regie_or_payment_backend
+ if isinstance(regie_or_payment_backend, Regie):
+ payment_backend = regie_or_payment_backend.payment_backend
+ options = payment_backend.service_options
options.update({
'automatic_return_url': request.build_absolute_uri(
- reverse('lingo-callback', kwargs={'regie_pk': regie.id})),
+ reverse('lingo-callback-payment-backend',
+ kwargs={'payment_backend_pk': payment_backend.id})),
'normal_return_url': request.build_absolute_uri(
- reverse('lingo-return', kwargs={'regie_pk': regie.id})),
+ reverse('lingo-return-payment-backend',
+ kwargs={'payment_backend_pk': payment_backend.id})),
})
- return eopayment.Payment(regie.service, options)
+ return eopayment.Payment(payment_backend.service, options)
def get_basket_url():
@@ -434,8 +439,14 @@ class UnknownPaymentException(PaymentException):
class PaymentView(View):
def handle_response(self, request, backend_response, **kwargs):
- regie = Regie.objects.get(id=kwargs.get('regie_pk'))
- payment = get_eopayment_object(request, regie)
+ if 'regie_pk' in kwargs:
+ payment_backend = Regie.objects.get(id=kwargs['regie_pk']).payment_backend
+ elif 'payment_backend_pk' in kwargs:
+ payment_backend = PaymentBackend.objects.get(id=kwargs['payment_backend_pk'])
+ else:
+ raise Exception("A payment backend or regie primary key must be specified")
+
+ payment = get_eopayment_object(request, payment_backend)
logger = logging.getLogger(__name__)
logger.info(u'received payment response: %r', backend_response)
try:
@@ -484,9 +495,10 @@ class PaymentView(View):
transaction.status, payment_response.result))
# check if transaction belongs to right regie
- if not transaction.regie == regie:
- logger.warning(u'received payment for inappropriate regie '
- '(expecteds: %s, received: %s)' % (transaction.regie, regie))
+ if not transaction.regie.payment_backend == payment_backend:
+ logger.warning(u'received payment for inappropriate payment backend '
+ '(expecteds: %s, received: %s)' % (
+ transaction.regie.payment_backend, payment_backend))
raise PaymentException('Invalid payment regie')
transaction.status = payment_response.result