Allow for non-existing paypal transaction details key
authorMagnus Hagander <magnus@hagander.net>
Mon, 22 Sep 2025 09:35:57 +0000 (11:35 +0200)
committerMagnus Hagander <magnus@hagander.net>
Mon, 22 Sep 2025 09:37:56 +0000 (11:37 +0200)
Contrary to their own documentation, Paypal now returns a json object
with no 'transaction_details' key when there are no matching
transactions (previously and per documentation they should return an
empty array). To work around this, treat the case of missing key the
same as an empty array.

postgresqleu/paypal/util.py

index 097d812cf7d4105fadd59c7780b87071018a5fba..2a11379c52d2c56602f6843a796814dc7c6d263d 100644 (file)
@@ -71,7 +71,7 @@ class PaypalAPI(object):
         if r.status_code != 200:
             raise Exception("Failed to get transactions: %s" % r.json()['message'])
 
-        for t in r.json()['transaction_details']:
+        for t in r.json().get('transaction_details', []):
             if t['transaction_info']['transaction_status'] != 'S':
                 continue