Skip to content

Commit

Permalink
Make name and email acquisition more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
kvdveer committed Sep 17, 2024
1 parent d3e51db commit bf8ae26
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,17 @@ def _paypal_transaction_to_lines(self, data):
transaction_note = transaction.get("transaction_note")
invoice = transaction.get("invoice_id")
payer_name = payer.get("payer_name", {})
payer_email = payer_name.get("email_address")
payer_email = payer_name.get("email_address") or payer.get("email_address")
payer_full_name = payer_name.get("full_name") or payer_name.get(
"alternate_full_name"
)
if invoice:
invoice = _("Invoice %s") % invoice
note = transaction_id
if transaction_subject or transaction_note:
note = f"{note}: {transaction_subject or transaction_note}"
if payer_email:
note += " (%s)" % payer_email
if payer_email or payer_full_name:
note += f" ({payer_email or payer_full_name})"
unique_import_id = f"{transaction_id}-{int(date.timestamp())}"
name = (
invoice
Expand All @@ -315,9 +318,6 @@ def _paypal_transaction_to_lines(self, data):
"unique_import_id": unique_import_id,
"raw_data": transaction,
}
payer_full_name = payer_name.get("full_name") or payer_name.get(
"alternate_full_name"
)
if payer_full_name:
line.update({"partner_name": payer_full_name})
lines = [line]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,9 @@ def test_pull(self):
"date": self.yesterday,
"amount": "1000.00",
"ref": "Invoice 1",
"payment_ref": "1234567890: Payment for Invoice(s) 1",
"payment_ref": (
"1234567890: Payment for Invoice(s) 1 ([email protected])"
),
"partner_name": "Acme, Inc.",
"unique_import_id": f"1234567890-{self.yesterday_timestamp}",
},
Expand All @@ -572,7 +574,8 @@ def test_pull(self):
"amount": "-100.00",
"ref": "Fee for Invoice 1",
"payment_ref": (
"Transaction fee for 1234567890: Payment for Invoice(s) 1"
"Transaction fee for 1234567890: Payment for Invoice(s) 1 "
"([email protected])"
),
"partner_name": "PayPal",
"unique_import_id": f"1234567890-{self.yesterday_timestamp}-FEE",
Expand Down Expand Up @@ -634,7 +637,9 @@ def test_transaction_parse_1(self):
"date": self.today,
"amount": "1000.00",
"ref": "Invoice 1",
"payment_ref": "1234567890: Payment for Invoice(s) 1",
"payment_ref": (
"1234567890: Payment for Invoice(s) 1 ([email protected])"
),
"partner_name": "Acme, Inc.",
"unique_import_id": f"1234567890-{self.today_timestamp}",
},
Expand Down Expand Up @@ -694,7 +699,9 @@ def test_transaction_parse_2(self):
"date": self.today,
"amount": "1000.00",
"ref": "Invoice 1",
"payment_ref": "1234567890: Payment for Invoice(s) 1",
"payment_ref": (
"1234567890: Payment for Invoice(s) 1 ([email protected])"
),
"partner_name": "Acme, Inc.",
"unique_import_id": f"1234567890-{self.today_timestamp}",
},
Expand Down Expand Up @@ -754,7 +761,9 @@ def test_transaction_parse_3(self):
"date": self.today,
"amount": "1000.00",
"ref": "Invoice 1",
"payment_ref": "1234567890: Payment for Invoice(s) 1",
"payment_ref": (
"1234567890: Payment for Invoice(s) 1 ([email protected])"
),
"partner_name": "Acme, Inc.",
"unique_import_id": f"1234567890-{self.today_timestamp}",
},
Expand All @@ -766,7 +775,8 @@ def test_transaction_parse_3(self):
"amount": "-100.00",
"ref": "Fee for Invoice 1",
"payment_ref": (
"Transaction fee for 1234567890: Payment for Invoice(s) 1"
"Transaction fee for 1234567890: Payment for Invoice(s) 1 "
"([email protected])"
),
"partner_name": "PayPal",
"unique_import_id": f"1234567890-{self.today_timestamp}-FEE",
Expand Down Expand Up @@ -823,7 +833,9 @@ def test_transaction_parse_4(self):
"date": self.today,
"amount": "1000.00",
"ref": "Invoice 1",
"payment_ref": "1234567890: Payment for Invoice(s) 1",
"payment_ref": (
"1234567890: Payment for Invoice(s) 1 ([email protected])"
),
"partner_name": "Acme, Inc.",
"unique_import_id": f"1234567890-{self.today_timestamp}",
},
Expand Down

0 comments on commit bf8ae26

Please sign in to comment.