summaryrefslogtreecommitdiff
path: root/postgresqleu/trustlypayment
diff options
context:
space:
mode:
Diffstat (limited to 'postgresqleu/trustlypayment')
-rw-r--r--postgresqleu/trustlypayment/admin.py5
-rw-r--r--postgresqleu/trustlypayment/api.py3
-rwxr-xr-xpostgresqleu/trustlypayment/management/commands/send_trustly_logreport.py2
-rw-r--r--postgresqleu/trustlypayment/management/commands/trustly_match_refunds.py1
-rw-r--r--postgresqleu/trustlypayment/management/commands/verify_trustly_balance.py1
-rw-r--r--postgresqleu/trustlypayment/models.py5
-rw-r--r--postgresqleu/trustlypayment/util.py2
-rw-r--r--postgresqleu/trustlypayment/views.py3
8 files changed, 19 insertions, 3 deletions
diff --git a/postgresqleu/trustlypayment/admin.py b/postgresqleu/trustlypayment/admin.py
index 1d00085d..afda9167 100644
--- a/postgresqleu/trustlypayment/admin.py
+++ b/postgresqleu/trustlypayment/admin.py
@@ -4,9 +4,11 @@ from django.urls import reverse
from models import TrustlyTransaction, TrustlyRawNotification, TrustlyNotification, TrustlyLog
+
class TrustlyTransactionAdmin(admin.ModelAdmin):
list_display = ('orderid', 'invoiceid', 'amount', 'createdat', 'pendingat', 'completedat',)
+
class TrustlyRawNotificationAdmin(admin.ModelAdmin):
list_display = ('dat', 'confirmed')
readonly_fields = ('notification_link',)
@@ -18,6 +20,7 @@ class TrustlyRawNotificationAdmin(admin.ModelAdmin):
return mark_safe('<a href="{0}">{1}</a>'.format(url, n))
notification_link.short_description = 'Notification'
+
class TrustlyNotificationAdmin(admin.ModelAdmin):
list_display = ('receivedat', 'notificationid', 'orderid', 'method', 'amount', 'confirmed')
readonly_fields = ('rawnotification_link',)
@@ -28,6 +31,7 @@ class TrustlyNotificationAdmin(admin.ModelAdmin):
return mark_safe('<a href="{0}">{1}</a>'.format(url, obj))
rawnotification_link.short_description = 'Rawnotification'
+
class TrustlyLogAdmin(admin.ModelAdmin):
list_display = ('timestamp', 'success', 'sentstr', 'message', )
@@ -39,6 +43,7 @@ class TrustlyLogAdmin(admin.ModelAdmin):
return obj.sent and 'Yes' or 'No'
sentstr.short_description = 'Log sent'
+
admin.site.register(TrustlyTransaction, TrustlyTransactionAdmin)
admin.site.register(TrustlyRawNotification, TrustlyRawNotificationAdmin)
admin.site.register(TrustlyNotification, TrustlyNotificationAdmin)
diff --git a/postgresqleu/trustlypayment/api.py b/postgresqleu/trustlypayment/api.py
index 3f248132..a4fca9fd 100644
--- a/postgresqleu/trustlypayment/api.py
+++ b/postgresqleu/trustlypayment/api.py
@@ -8,9 +8,11 @@ from Crypto.PublicKey import RSA
import base64
import urllib2
+
class TrustlyException(Exception):
pass
+
class TrustlyWrapper(object):
def __init__(self, apibase, username, password, privatekey, publickey, notificationurl, currency='EUR', hold_notifications=False):
self.apibase = apibase
@@ -61,7 +63,6 @@ class TrustlyWrapper(object):
else:
raise TrustlyException('Failed to refund orderid {0}'.format(orderid))
-
def get_balance(self):
r = self.apicall('Balance', {})
balance = None
diff --git a/postgresqleu/trustlypayment/management/commands/send_trustly_logreport.py b/postgresqleu/trustlypayment/management/commands/send_trustly_logreport.py
index 07db06a2..c51dc551 100755
--- a/postgresqleu/trustlypayment/management/commands/send_trustly_logreport.py
+++ b/postgresqleu/trustlypayment/management/commands/send_trustly_logreport.py
@@ -14,6 +14,7 @@ from StringIO import StringIO
from postgresqleu.trustlypayment.models import TrustlyLog, TrustlyNotification, TrustlyTransaction
from postgresqleu.mailqueue.util import send_simple_mail
+
class Command(BaseCommand):
help = 'Send log information about Trustly events'
@@ -70,4 +71,3 @@ class Command(BaseCommand):
settings.TRUSTLY_NOTIFICATION_RECEIVER,
'Trustly integration unconfirmed notifications',
sio.getvalue())
-
diff --git a/postgresqleu/trustlypayment/management/commands/trustly_match_refunds.py b/postgresqleu/trustlypayment/management/commands/trustly_match_refunds.py
index 04acc66c..61aed7ae 100644
--- a/postgresqleu/trustlypayment/management/commands/trustly_match_refunds.py
+++ b/postgresqleu/trustlypayment/management/commands/trustly_match_refunds.py
@@ -18,6 +18,7 @@ from postgresqleu.invoices.util import InvoiceManager
from decimal import Decimal
+
class Command(BaseCommand):
help = 'Verify that a Trustly refund has completed, and flag it as such'
diff --git a/postgresqleu/trustlypayment/management/commands/verify_trustly_balance.py b/postgresqleu/trustlypayment/management/commands/verify_trustly_balance.py
index 2c273484..6b43f5b3 100644
--- a/postgresqleu/trustlypayment/management/commands/verify_trustly_balance.py
+++ b/postgresqleu/trustlypayment/management/commands/verify_trustly_balance.py
@@ -15,6 +15,7 @@ from postgresqleu.trustlypayment.util import Trustly
from postgresqleu.accounting.util import get_latest_account_balance
from postgresqleu.mailqueue.util import send_simple_mail
+
class Command(BaseCommand):
help = 'Compare trustly balance to the accounting system'
diff --git a/postgresqleu/trustlypayment/models.py b/postgresqleu/trustlypayment/models.py
index 6473d809..9a84a1f7 100644
--- a/postgresqleu/trustlypayment/models.py
+++ b/postgresqleu/trustlypayment/models.py
@@ -1,5 +1,6 @@
from django.db import models
+
class TrustlyTransaction(models.Model):
createdat = models.DateTimeField(null=False, blank=False)
pendingat = models.DateTimeField(null=True, blank=True)
@@ -12,6 +13,7 @@ class TrustlyTransaction(models.Model):
def __unicode__(self):
return "%s" % self.orderid
+
class TrustlyRawNotification(models.Model):
dat = models.DateTimeField(null=False, blank=False, auto_now_add=True, unique=True)
contents = models.TextField(null=False, blank=False)
@@ -20,6 +22,7 @@ class TrustlyRawNotification(models.Model):
def __unicode__(self):
return "%s" % self.dat
+
class TrustlyNotification(models.Model):
receivedat = models.DateTimeField(null=False, blank=False, auto_now_add=True, unique=True)
rawnotification = models.ForeignKey(TrustlyRawNotification, null=True, blank=True, on_delete=models.CASCADE)
@@ -34,12 +37,14 @@ class TrustlyNotification(models.Model):
def __unicode__(self):
return "%s" % self.receivedat
+
class TrustlyLog(models.Model):
timestamp = models.DateTimeField(null=False, blank=False, auto_now_add=True)
message = models.TextField(null=False, blank=False)
error = models.BooleanField(null=False, blank=False, default=False)
sent = models.BooleanField(null=False, blank=False, default=False)
+
class ReturnAuthorizationStatus(models.Model):
orderid = models.BigIntegerField(null=False, blank=False, primary_key=True)
seencount = models.IntegerField(null=False, default=0)
diff --git a/postgresqleu/trustlypayment/util.py b/postgresqleu/trustlypayment/util.py
index 474b689e..1165d93b 100644
--- a/postgresqleu/trustlypayment/util.py
+++ b/postgresqleu/trustlypayment/util.py
@@ -12,8 +12,8 @@ from api import TrustlyWrapper, TrustlyException
from models import TrustlyTransaction, TrustlyLog
from models import TrustlyNotification
-# Django intgrated wrapper for the trustly API
+# Django intgrated wrapper for the trustly API
class Trustly(TrustlyWrapper):
def __init__(self):
super(Trustly, self).__init__(settings.TRUSTLY_APIBASE,
diff --git a/postgresqleu/trustlypayment/views.py b/postgresqleu/trustlypayment/views.py
index 5716c432..f2368d6d 100644
--- a/postgresqleu/trustlypayment/views.py
+++ b/postgresqleu/trustlypayment/views.py
@@ -12,6 +12,7 @@ from util import Trustly, TrustlyException
from models import TrustlyTransaction, TrustlyRawNotification, TrustlyLog
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)
@@ -94,11 +95,13 @@ def success(request, invoiceid, secret):
'pendingat': trans.pendingat,
})
+
def failure(request, 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)