summaryrefslogtreecommitdiff
path: root/postgresqleu/trustlypayment/models.py
diff options
context:
space:
mode:
authorMagnus Hagander2025-10-10 11:33:52 +0000
committerMagnus Hagander2025-10-10 11:36:09 +0000
commita03baf562438718146d9e4a492185f17856a749f (patch)
treedd90d1e9c64eb77886a80622fa57c1861c7febaf /postgresqleu/trustlypayment/models.py
parent4f87c2cc310ee9de32b474de3fe222874e85af0b (diff)
Re-implement Trustly refund tracker on top of the ledger
Previously we explicitly called the API about the withdrawal entry, but that API is now restricted. And we don't *really* need it -- refunds show up on the ledger, so just use that. The only case this doesn't work is refunds in a different currency, and in that case we just estimate the fees and send a notice to hope for the best :) It's not a common scenario, and not worth spending too much on (in production it has never happened outside of testing). To do this, we now track refund transactions int he TrustlyWithdrawals table, and also store the orderid on them if we have them. This removes the separate job to match trustly refunds, and handles it all from the fetch withdrawals job. Not fully tested since it needs production data, so expect some follow-up commits..
Diffstat (limited to 'postgresqleu/trustlypayment/models.py')
-rw-r--r--postgresqleu/trustlypayment/models.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/postgresqleu/trustlypayment/models.py b/postgresqleu/trustlypayment/models.py
index 89e93c9c..7f8c0624 100644
--- a/postgresqleu/trustlypayment/models.py
+++ b/postgresqleu/trustlypayment/models.py
@@ -1,7 +1,7 @@
from django.db import models
-from postgresqleu.invoices.models import InvoicePaymentMethod
+from postgresqleu.invoices.models import InvoicePaymentMethod, InvoiceRefund
class TrustlyTransaction(models.Model):
@@ -11,7 +11,7 @@ class TrustlyTransaction(models.Model):
amount = models.DecimalField(decimal_places=2, max_digits=20, null=False)
invoiceid = models.IntegerField(null=False, blank=False)
redirecturl = models.CharField(max_length=2000, null=False, blank=False)
- orderid = models.BigIntegerField(null=False, blank=False)
+ orderid = models.BigIntegerField(null=False, blank=False, unique=True)
paymentmethod = models.ForeignKey(InvoicePaymentMethod, blank=False, null=False, on_delete=models.CASCADE)
def __str__(self):
@@ -59,5 +59,7 @@ class ReturnAuthorizationStatus(models.Model):
class TrustlyWithdrawal(models.Model):
paymentmethod = models.ForeignKey(InvoicePaymentMethod, blank=False, null=False, on_delete=models.CASCADE)
gluepayid = models.BigIntegerField(null=False, blank=False)
+ orderid = models.BigIntegerField(null=True, blank=True)
amount = models.DecimalField(decimal_places=2, max_digits=20, null=False, blank=False)
message = models.CharField(max_length=200, null=False, blank=True)
+ matched_refund = models.ForeignKey(InvoiceRefund, null=True, blank=True, on_delete=models.SET_NULL)