From 621e130f7ffd6bacc0fa2d99741a0c4a16c17173 Mon Sep 17 00:00:00 2001 From: Ben Sturmfels Date: Wed, 16 Jul 2025 10:43:10 +1000 Subject: [PATCH] List both the 'paypal_reference_id' and 'transaction_id' for likely one-off donations --- paypal_report.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/paypal_report.py b/paypal_report.py index 9ee5508..7082483 100755 --- a/paypal_report.py +++ b/paypal_report.py @@ -231,13 +231,26 @@ def report_on_unique_profiles(transactions, verbose=False): records = {} for t in transactions: transaction_info = t['transaction_info'] - if 'paypal_reference_id' in transaction_info: - records[ - ( - transaction_info['paypal_reference_id'], - transaction_info.get('transaction_subject', 'NO TRANSACTION SUBJECT'), - ) - ] = t + try: + item_details = t['cart_info']['item_details'][0] + except KeyError: + item_details = None + + if 'paypal_reference_id' in transaction_info and 'transaction_subject' in transaction_info: + # A typical recurring payment + records[(transaction_info['paypal_reference_id'], transaction_info['transaction_subject'])] = t + elif 'paypal_reference_id' in transaction_info and item_details: + # A typical one-off payment + # + # List separate entries for the paypal_reference_id and + # transaction_id since they no longer match. + label = f'LIKELY NOT RECURRING: {item_details["item_description"]} - {item_details["item_name"]}' + records[(transaction_info['paypal_reference_id'], label)] = t + records[(transaction_info['transaction_id'], label)] = t + elif 'paypal_reference_id' in transaction_info: + # Something else, possibly a payout. + label = 'NO TRANSACTION SUBJECT' + records[(transaction_info['paypal_reference_id'], label)] = t else: print( f'Skipping transaction {transaction_info["transaction_id"]} with no PayPal Reference ID.',