Skip to content

Commit da9ebe8

Browse files
committed
Add USD value in transaction description when available
1 parent 042828e commit da9ebe8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

thebook/webhooks/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,13 @@ def process(self, bank_account=None, user=None):
247247
full_name = " ".join([given_name, surname]).strip()
248248
payer_id = jmespath.search("subscriber.payer_id", subscription) or ""
249249

250-
description = " - ".join([part for part in (full_name, payer_id) if part])
250+
description_parts = (full_name, payer_id)
251+
currency = jmespath.search("resource.amount.currency", payload)
252+
if currency == "USD":
253+
usd_amount = jmespath.search("resource.amount.total", payload)
254+
description_parts = (full_name, f"USD {usd_amount}", payer_id)
255+
256+
description = " - ".join([part for part in description_parts if part])
251257

252258
reference = jmespath.search("resource.id", payload)
253259

thebook/webhooks/tests/paypal/test_paypal_process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_payment_sale_completed__usd_transaction(
7575

7676
transaction = Transaction.objects.get(reference="0PAAAAAAAAAAAAAAA")
7777
assert transaction.date == datetime.date(2026, 2, 12)
78-
assert transaction.description == "Elvis Presley - Q64J6VDR3DBHN"
78+
assert transaction.description == "Elvis Presley - USD 50.00 - Q64J6VDR3DBHN"
7979
assert transaction.amount == Decimal("231.93")
8080

8181
# Do not create transaction with bank fees. Total received amount already in transaction above

0 commit comments

Comments
 (0)