From ab438e7d829b29a3a6643f233478ff58dd4bf39f Mon Sep 17 00:00:00 2001 From: Jeremy Kun Date: Wed, 1 Jun 2016 15:38:22 -0700 Subject: [PATCH] dynamic pricing for redeem --- hello/views.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hello/views.py b/hello/views.py index 510d8b0..3bb71b7 100644 --- a/hello/views.py +++ b/hello/views.py @@ -46,7 +46,24 @@ def _redeem(token): return JsonResponse({'success': True, "message": "Thanks!"}, status=200) +def get_redeem_price(request): + try: + token = request.data['token'] + except: + return JsonResponse({'error': 'POST data must include "token"'}, status=400) + + try: + requested_token = Token.objects.get(value=token) + if requested_token.redeemed: + raise ValueError() + except: + return 100 + + return 0 + + @api_view(['POST']) +@payment.required(get_redeem_price) def redeem(request): try: token = request.data['token']