From: Magnus Hagander Date: Mon, 10 Nov 2025 10:19:36 +0000 (+0100) Subject: Try to fix handling of transferwise returned payments X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/static/users.php?a=commitdiff_plain;p=pgeu-system.git Try to fix handling of transferwise returned payments This also changed when they killed the old API, but we hadn't seen one yet.. --- 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