Skip to content

Commit

Permalink
do not crash if the order id is not well formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
gcmalloc committed Jan 13, 2014
1 parent 6253e4f commit 999b02e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions server/paiements/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
from django.utils.timezone import now


def build_error(status, error_code=400):
"""Build an error response"""
return HttpResponse(json.dumps({'status': status, 'url': ''}), status=error_code)


@csrf_exempt
def start(request):
"""Start a new request"""

def build_error(status, error_code=400):
"""Build an error response"""
return HttpResponse(json.dumps({'status': status, 'url': ''}), status=error_code)
if request.method != 'POST':
build_error('BAD_REQUEST_TYPE', error_code=405)

Expand Down Expand Up @@ -121,9 +123,13 @@ def ipn(request):
"""Call by Postfinance website about status"""

# Get transaction pk
orderId = request.POST.get('orderID')
orderId = request.POST.get('orderID', '')

(who, pk) = orderId.split('-', 2)
if '-' in orderId:
(who, pk) = orderId.split('-', 2)
else:
#should also raise an error
build_error('UNVALID_ ID')

if who != 'polybanking':
raise Http404
Expand Down

0 comments on commit 999b02e

Please sign in to comment.