transaction: Make fee_amount() Optional.
Outgoing payments don't have a fee (PayPal takes their fee out on the receiver's end).
This commit is contained in:
parent
63497d18d4
commit
23608de591
3 changed files with 15 additions and 2 deletions
|
@ -140,6 +140,7 @@ def summarize_transaction(txn: Transaction, stream: TextIO) -> None:
|
|||
txn_amt = txn.amount()
|
||||
cart.append(CartItem(None, txn_name, None, 1, txn_amt, txn_amt))
|
||||
fee_amt = txn.fee_amount()
|
||||
if fee_amt is not None:
|
||||
cart.append(CartItem(None, "PayPal Fee", None, 1, fee_amt, fee_amt))
|
||||
names = [
|
||||
item.name or item.description or item.code or "Unknown Item"
|
||||
|
|
|
@ -129,13 +129,21 @@ class Transaction(APIResponse):
|
|||
except KeyError:
|
||||
pass
|
||||
|
||||
def _fee_amount(txn_info: APIResponse) -> Optional[Amount]: # type:ignore[misc]
|
||||
try:
|
||||
raw_fee = txn_info['fee_amount']
|
||||
except KeyError:
|
||||
return None
|
||||
else:
|
||||
return Amount.from_api(raw_fee)
|
||||
|
||||
amount = _from_response(
|
||||
Amount.from_api,
|
||||
'transaction_info',
|
||||
'transaction_amount',
|
||||
)
|
||||
cart_items = _from_response(_cart_items, 'cart_info')
|
||||
fee_amount = _from_response(Amount.from_api, 'transaction_info', 'fee_amount')
|
||||
fee_amount = _from_response(_fee_amount, 'transaction_info')
|
||||
initiation_date = _from_response(
|
||||
parse_datetime,
|
||||
'transaction_info',
|
||||
|
|
|
@ -166,6 +166,10 @@ def test_fee_amount_whole(number):
|
|||
txn = txn_mod.Transaction({'transaction_info': source})
|
||||
assert txn.fee_amount() == (int(number), 'JPY')
|
||||
|
||||
def test_fee_amount_none():
|
||||
txn = txn_mod.Transaction({'transaction_info': {}})
|
||||
assert txn.fee_amount() is None
|
||||
|
||||
def test_payer_email():
|
||||
email = 'test@example.net'
|
||||
source = payer_info(email_address=email)
|
||||
|
|
Loading…
Reference in a new issue