New transferwise APIs no longer allow downloading statements
authorMagnus Hagander <magnus@hagander.net>
Wed, 4 Jun 2025 13:45:19 +0000 (15:45 +0200)
committerMagnus Hagander <magnus@hagander.net>
Wed, 11 Jun 2025 13:55:22 +0000 (15:55 +0200)
So remove the scheduled job that handles them, as well as the database
table that stores them.

postgresqleu/transferwise/management/commands/transferwise_fetch_statements.py [deleted file]
postgresqleu/transferwise/migrations/0006_delete_transferwisemonthlystatement.py [new file with mode: 0644]
postgresqleu/transferwise/models.py

diff --git a/postgresqleu/transferwise/management/commands/transferwise_fetch_statements.py b/postgresqleu/transferwise/management/commands/transferwise_fetch_statements.py
deleted file mode 100644 (file)
index e23d793..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-#
-# This script fetches monthly statements in PDF format from transferwise
-# and passes them on to the notification address.
-#
-# Copyright (C) 2019, PostgreSQL Europe
-#
-
-
-from django.core.management.base import BaseCommand
-from django.db import transaction
-from django.conf import settings
-
-import datetime
-
-from postgresqleu.invoices.models import InvoicePaymentMethod
-from postgresqleu.mailqueue.util import send_simple_mail
-from postgresqleu.transferwise.models import TransferwiseMonthlyStatement
-
-
-class Command(BaseCommand):
-    help = 'Fetch TransferWise monthly statements'
-
-    class ScheduledJob:
-        scheduled_times = [datetime.time(2, 2), ]
-
-        @classmethod
-        def should_run(self):
-            return InvoicePaymentMethod.objects.filter(active=True, classname='postgresqleu.util.payment.transferwise.Transferwise').exists()
-
-    def handle(self, *args, **options):
-        for method in InvoicePaymentMethod.objects.filter(active=True, classname='postgresqleu.util.payment.transferwise.Transferwise'):
-            self.fetch_one_statement(method)
-
-    @transaction.atomic
-    def fetch_one_statement(self, method):
-        pm = method.get_implementation()
-        if not pm.config('send_statements'):
-            return
-
-        # We fetch for the *previous* month. Take todays day, truncate it to the month,
-        # subtract one day to get the last day of the previous month, and then truncate
-        # again to the first of that month.
-        d = (datetime.date.today().replace(day=1) - datetime.timedelta(days=1)).replace(day=1)
-
-        if TransferwiseMonthlyStatement.objects.filter(paymentmethod=method, month=d).exists():
-            return
-
-        # Else we don't have it, so download it
-        api = pm.get_api()
-        r = api.get_binary(
-            'profiles/{}/borderless-accounts/{}/statement.pdf'.format(api.get_profile(), api.get_account()['id']), {
-                'currency': settings.CURRENCY_ABBREV,
-                'intervalStart': api.format_date(d),
-                'intervalEnd': api.format_date(datetime.date.today().replace(day=1)),
-            },
-            version='v3',
-        )
-        statement = TransferwiseMonthlyStatement(
-            paymentmethod=method,
-            month=d,
-            contents=r.read(),
-        )
-        statement.save()
-
-        send_simple_mail(settings.INVOICE_SENDER_EMAIL,
-                         pm.config('notification_receiver'),
-                         'TransferWise monthly statement for {}'.format(statement.month.strftime("%B %Y")),
-                         "The TransferWise monthly statement for {0} for the month of {1} is attached.".format(
-                             method.internaldescription,
-                             statement.month.strftime("%B %Y"),
-                         ),
-                         attachments=[
-                             ('TransferWise_{}.pdf'.format(statement.month.strftime("%b_%Y")), 'application/pdf', statement.contents),
-                         ]
-        )
diff --git a/postgresqleu/transferwise/migrations/0006_delete_transferwisemonthlystatement.py b/postgresqleu/transferwise/migrations/0006_delete_transferwisemonthlystatement.py
new file mode 100644 (file)
index 0000000..36a6ce4
--- /dev/null
@@ -0,0 +1,16 @@
+# Generated by Django 4.2.11 on 2025-06-04 13:46
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('transferwise', '0005_transferwise_monthly_statements'),
+    ]
+
+    operations = [
+        migrations.DeleteModel(
+            name='TransferwiseMonthlyStatement',
+        ),
+    ]
index 0659149bbdef0a157e8cb414fa81686f1b6f1a01..58bdab528f3fe8852b6bad0fa4849f5d1cd392e7 100644 (file)
@@ -52,15 +52,3 @@ class TransferwisePayout(models.Model):
     sentat = models.DateTimeField(null=True, blank=True)
     completedat = models.DateTimeField(null=True, blank=True)
     completedtrans = models.ForeignKey(TransferwiseTransaction, blank=True, null=True, on_delete=models.CASCADE)
-
-
-class TransferwiseMonthlyStatement(models.Model):
-    paymentmethod = models.ForeignKey(InvoicePaymentMethod, blank=False, null=False, on_delete=models.CASCADE)
-    month = models.DateField(null=False, blank=False)
-    downloaded = models.DateTimeField(null=False, blank=False, auto_now_add=True)
-    contents = models.BinaryField(null=False)
-
-    class Meta:
-        unique_together = (
-            ('month', 'paymentmethod'),
-        )