diff options
author | Magnus Hagander | 2025-07-31 12:40:49 +0000 |
---|---|---|
committer | Magnus Hagander | 2025-07-31 12:40:49 +0000 |
commit | 7e64f2bc8edfec1123227b39820851377d9cf959 (patch) | |
tree | c5c5af1787ec4d8109b0f91f0612a708bfc5e628 /postgresqleu/transferwise/api.py | |
parent | 763a0e7bbf5fce1175def5927c2ac14d1d2d435b (diff) |
Attempt best-effort on transferwise transactions with no permissions
If a transferwise transaction is sent from another user of their bank,
the id of the transaction belongs to the *other user*, and the recipient
has no permissions to get to the details. So when this happens, do a
best-effort set of details based on what we can find in the activity
(which generally does not contain payment references for example), and
leave it to the user - rather than just ignoring it.
The same seems to happen for direct debit transactions, so process them
the same.
Diffstat (limited to 'postgresqleu/transferwise/api.py')
-rw-r--r-- | postgresqleu/transferwise/api.py | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/postgresqleu/transferwise/api.py b/postgresqleu/transferwise/api.py index 621e97a4..86661953 100644 --- a/postgresqleu/transferwise/api.py +++ b/postgresqleu/transferwise/api.py @@ -129,19 +129,32 @@ class TransferwiseApi(object): (activity['type'] == 'BALANCE_DEPOSIT' and activity['resource']['type'] == 'TRANSFER'): try: details = self.get('transfers/{}'.format(activity['resource']['id'])) + + if details['sourceCurrency'] != settings.CURRENCY_ABBREV: + continue + + amount = Decimal(details['targetValue']).quantize(Decimal('0.01')) + created = details['created'] + reference = details['reference'] + fulldescription = details['details']['reference'] except requests.exceptions.HTTPError as e: if e.response.status_code == 403: - print("No permissions to access transaction {} from {}, ignoring".format( + # 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'], )) - continue - raise - - if details['sourceCurrency'] != settings.CURRENCY_ABBREV: - continue - amount = Decimal(details['targetValue']).quantize(Decimal('0.01')) + 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 + created = activity['createdOn'] + reference = '' + fulldescription = 'Transaction with no permissions on details: {}'.format(self.strip_tw_tags(activity['title'])) + else: + raise # Yes, the transfer will actually have a positive amount even if it's a withdrawal. # No, this is not indicated anywhere, since the "target account id" that would @@ -173,12 +186,12 @@ class TransferwiseApi(object): yield { 'id': 'TRANSFER-{}'.format(activity['resource']['id']), - 'datetime': details['created'], + 'datetime': created, 'amount': amount * negatizer, 'feeamount': 0, # XXX! 'transtype': 'TRANSFER', - 'paymentref': details['reference'], - 'fulldescription': details['details']['reference'], + 'paymentref': reference, + 'fulldescription': fulldescription, } elif activity['type'] == 'BALANCE_CASHBACK': # No API endpoint to get this so we have to parse it out of |