summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander2025-11-10 10:19:36 +0000
committerMagnus Hagander2025-11-10 10:19:36 +0000
commitbfef39f2091534a8f3e4c59dab179f5082f04c2c (patch)
tree0bca1388589dce5f25da7012fe392c1dd27ec2e5
parenta931d840991161eb6f7d027f74d089a0c72dc167 (diff)
Try to fix handling of transferwise returned payments
This also changed when they killed the old API, but we hadn't seen one yet..
-rw-r--r--postgresqleu/transferwise/api.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/postgresqleu/transferwise/api.py b/postgresqleu/transferwise/api.py
index 54a29a78..886f0b80 100644
--- a/postgresqleu/transferwise/api.py
+++ b/postgresqleu/transferwise/api.py
@@ -138,21 +138,31 @@ class TransferwiseApi(object):
reference = details['reference']
fulldescription = details['details']['reference']
except requests.exceptions.HTTPError as e:
- if e.response.status_code == 403:
+ if e.response.status_code == 403 or (e.response.status_code == 404 and activity['resource']['type'] == 'BANK_DETAILS_PAYMENT_RETURN'):
# No permissions can mean (1) it's a wise-to-wise transaction, for which we are not allowed to
# see details, or (2) a direct debit transaction.
- print("No permissions to access transaction {} from {}, adding placeholder without details".format(
- activity['resource']['id'],
- activity['updatedOn'],
- ))
+ # 404 on a returned payment means, it's a returned payment.
+ if e.response.status_code == 403:
+ print("No permissions to access transaction {} from {}, adding placeholder without details".format(
+ activity['resource']['id'],
+ activity['updatedOn'],
+ ))
+ else:
+ print("Bank details payment returned transaction {} from {}, no details available, adding placeholder without details".format(
+ activity['resource']['id'],
+ activity['updatedOn'],
+ ))
amount, currency = self.parse_transferwise_amount(activity['primaryAmount'])
if currency != settings.CURRENCY_ABBREV:
# This is transaction is in a different currency, so ignore it
continue
+ if activity['resource']['type'] == 'BANK_DETAILS_PAYMENT_RETURN':
+ # Yes, it's returned with the wrong sign
+ amount = -amount
created = activity['createdOn']
reference = ''
- fulldescription = 'Transaction with no permissions on details: {}'.format(self.strip_tw_tags(activity['title']))
+ fulldescription = 'Transaction with no details: {}'.format(self.strip_tw_tags(activity['title']))
else:
raise