summaryrefslogtreecommitdiff
path: root/postgresqleu/trustlypayment/views.py
diff options
context:
space:
mode:
authorMagnus Hagander2018-12-14 11:43:50 +0000
committerMagnus Hagander2018-12-14 11:43:50 +0000
commit5e8a4a7ab78a9939b21d11094234231bda59567a (patch)
tree9d32974ce783aeecbae020d6391baef4fa376a95 /postgresqleu/trustlypayment/views.py
parent5e500d7d55ef048adc1dcf009db42d10c7ad53fc (diff)
Replace tabs with spaces
In an effort to close up with PEP8, we should use spaces for indent rather than tabs... Time to update your editor config!
Diffstat (limited to 'postgresqleu/trustlypayment/views.py')
-rw-r--r--postgresqleu/trustlypayment/views.py170
1 files changed, 85 insertions, 85 deletions
diff --git a/postgresqleu/trustlypayment/views.py b/postgresqleu/trustlypayment/views.py
index 8cc5d351..4c3d2877 100644
--- a/postgresqleu/trustlypayment/views.py
+++ b/postgresqleu/trustlypayment/views.py
@@ -14,98 +14,98 @@ from models import ReturnAuthorizationStatus
@transaction.atomic
def invoicepayment_secret(request, invoiceid, secret):
- invoice = get_object_or_404(Invoice, pk=invoiceid, deleted=False, finalized=True, recipient_secret=secret)
-
- # If this payment has already been initiated, redirect back to existing URL
- try:
- t = TrustlyTransaction.objects.get(invoiceid=invoice.id, amount=invoice.total_amount)
- if t.pendingat:
- # This transaction is already started, so we need to redirect back to our own return URL
- return HttpResponseRedirect('{0}/trustly_success/{1}/{2}/'.format(settings.SITEBASE, invoice.id, invoice.recipient_secret))
- # Else it's not started, so we're going to abandon this one and create a new one
- TrustlyLog(message='Abandoning order {0} and starting over.'.format(t.orderid)).save()
- t.delete()
- except TrustlyTransaction.DoesNotExist:
- # Not processed, so get a new one
- pass
-
- # Make a call to the Trustly API to set up a payment.
- # XXX: should we have a verify step here? As in "hey, we're about to send you to Trustly"
- # XXX: should we use an iframe? For now just send everything there because it's easier..
-
- t = Trustly()
-
- try:
- if request.user and not request.user.is_anonymous():
- enduserid = request.user.username
- first = request.user.first_name
- last = request.user.last_name
- email = request.user.email
- else:
- first = last = email = None
- # For secret payments, use the invoice secret as the identifier
- enduserid = secret
-
- r = t.deposit(enduserid,
- "{0}".format(invoice.id),
- invoice.total_amount,
- '{0}#{1}'.format(settings.ORG_SHORTNAME, invoice.id),
- '{0}/trustly_success/{1}/{2}/'.format(settings.SITEBASE, invoice.id, invoice.recipient_secret),
- '{0}/trustly_failure/{1}/{2}/'.format(settings.SITEBASE, invoice.id, invoice.recipient_secret),
- first,
- last,
- email,
- request.META['REMOTE_ADDR'])
-
- # Trustly request was successful, so we have an url to send the user to. Let's set up
- # the transaction on our end.
-
- TrustlyTransaction(createdat=datetime.now(),
- invoiceid=invoice.id,
- amount=invoice.total_amount,
- orderid=r['data']['orderid'],
- redirecturl=r['data']['url'],
- ).save()
-
- # With the transaction saved, redirect the user to Trustly
- return HttpResponseRedirect(r['data']['url'])
- except TrustlyException, e:
- return HttpResponse("Error communicating with Trustly: {0}".format(e))
+ invoice = get_object_or_404(Invoice, pk=invoiceid, deleted=False, finalized=True, recipient_secret=secret)
+
+ # If this payment has already been initiated, redirect back to existing URL
+ try:
+ t = TrustlyTransaction.objects.get(invoiceid=invoice.id, amount=invoice.total_amount)
+ if t.pendingat:
+ # This transaction is already started, so we need to redirect back to our own return URL
+ return HttpResponseRedirect('{0}/trustly_success/{1}/{2}/'.format(settings.SITEBASE, invoice.id, invoice.recipient_secret))
+ # Else it's not started, so we're going to abandon this one and create a new one
+ TrustlyLog(message='Abandoning order {0} and starting over.'.format(t.orderid)).save()
+ t.delete()
+ except TrustlyTransaction.DoesNotExist:
+ # Not processed, so get a new one
+ pass
+
+ # Make a call to the Trustly API to set up a payment.
+ # XXX: should we have a verify step here? As in "hey, we're about to send you to Trustly"
+ # XXX: should we use an iframe? For now just send everything there because it's easier..
+
+ t = Trustly()
+
+ try:
+ if request.user and not request.user.is_anonymous():
+ enduserid = request.user.username
+ first = request.user.first_name
+ last = request.user.last_name
+ email = request.user.email
+ else:
+ first = last = email = None
+ # For secret payments, use the invoice secret as the identifier
+ enduserid = secret
+
+ r = t.deposit(enduserid,
+ "{0}".format(invoice.id),
+ invoice.total_amount,
+ '{0}#{1}'.format(settings.ORG_SHORTNAME, invoice.id),
+ '{0}/trustly_success/{1}/{2}/'.format(settings.SITEBASE, invoice.id, invoice.recipient_secret),
+ '{0}/trustly_failure/{1}/{2}/'.format(settings.SITEBASE, invoice.id, invoice.recipient_secret),
+ first,
+ last,
+ email,
+ request.META['REMOTE_ADDR'])
+
+ # Trustly request was successful, so we have an url to send the user to. Let's set up
+ # the transaction on our end.
+
+ TrustlyTransaction(createdat=datetime.now(),
+ invoiceid=invoice.id,
+ amount=invoice.total_amount,
+ orderid=r['data']['orderid'],
+ redirecturl=r['data']['url'],
+ ).save()
+
+ # With the transaction saved, redirect the user to Trustly
+ return HttpResponseRedirect(r['data']['url'])
+ except TrustlyException, e:
+ return HttpResponse("Error communicating with Trustly: {0}".format(e))
def success(request, invoiceid, secret):
- # Get the invoice so we can be sure that we have the secret
- get_object_or_404(Invoice, id=invoiceid, recipient_secret=secret)
- trans = get_object_or_404(TrustlyTransaction, invoiceid=invoiceid)
-
- if trans.completedat:
- # Payment is completed, to redirect the user back to the invoice
- return HttpResponseRedirect("/invoices/{0}/{1}/".format(invoiceid, secret))
-
- # Else we need to loop on this page. To handle this we create
- # a temporary object so we can increase the waiting time
- status, created = ReturnAuthorizationStatus.objects.get_or_create(orderid=trans.orderid)
- status.seencount += 1
- status.save()
- return render(request, 'trustlypayment/pending.html', {
- 'refresh': 3*status.seencount,
- 'url': '/invoices/{0}/{1}/'.format(invoiceid, secret),
- 'createdat': trans.createdat,
- 'pendingat': trans.pendingat,
- })
+ # Get the invoice so we can be sure that we have the secret
+ get_object_or_404(Invoice, id=invoiceid, recipient_secret=secret)
+ trans = get_object_or_404(TrustlyTransaction, invoiceid=invoiceid)
+
+ if trans.completedat:
+ # Payment is completed, to redirect the user back to the invoice
+ return HttpResponseRedirect("/invoices/{0}/{1}/".format(invoiceid, secret))
+
+ # Else we need to loop on this page. To handle this we create
+ # a temporary object so we can increase the waiting time
+ status, created = ReturnAuthorizationStatus.objects.get_or_create(orderid=trans.orderid)
+ status.seencount += 1
+ status.save()
+ return render(request, 'trustlypayment/pending.html', {
+ 'refresh': 3*status.seencount,
+ 'url': '/invoices/{0}/{1}/'.format(invoiceid, secret),
+ 'createdat': trans.createdat,
+ 'pendingat': trans.pendingat,
+ })
def failure(request, invoiceid, secret):
- return render(request, 'trustlypayment/error.html', {
- 'url': '/invoices/{0}/{1}/'.format(invoiceid, secret),
- })
+ return render(request, 'trustlypayment/error.html', {
+ 'url': '/invoices/{0}/{1}/'.format(invoiceid, secret),
+ })
@csrf_exempt
def notification(request):
- raw = TrustlyRawNotification(contents=request.body)
- raw.save()
+ raw = TrustlyRawNotification(contents=request.body)
+ raw.save()
- t = Trustly()
+ t = Trustly()
- (ok, uuid, method) = t.process_raw_trustly_notification(raw)
- return HttpResponse(t.create_notification_response(uuid, method, ok and "OK" or "FAILED"),
- content_type='application/json')
+ (ok, uuid, method) = t.process_raw_trustly_notification(raw)
+ return HttpResponse(t.create_notification_response(uuid, method, ok and "OK" or "FAILED"),
+ content_type='application/json')