List both the 'paypal_reference_id' and 'transaction_id' for likely one-off donations

This commit is contained in:
Ben Sturmfels 2025-07-16 10:43:10 +10:00
parent 8fd968c6f9
commit 621e130f7f
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0

View file

@ -231,13 +231,26 @@ def report_on_unique_profiles(transactions, verbose=False):
records = {} records = {}
for t in transactions: for t in transactions:
transaction_info = t['transaction_info'] transaction_info = t['transaction_info']
if 'paypal_reference_id' in transaction_info: try:
records[ item_details = t['cart_info']['item_details'][0]
( except KeyError:
transaction_info['paypal_reference_id'], item_details = None
transaction_info.get('transaction_subject', 'NO TRANSACTION SUBJECT'),
) if 'paypal_reference_id' in transaction_info and 'transaction_subject' in transaction_info:
] = t # 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: else:
print( print(
f'Skipping transaction {transaction_info["transaction_id"]} with no PayPal Reference ID.', f'Skipping transaction {transaction_info["transaction_id"]} with no PayPal Reference ID.',