Skip to content

Commit

Permalink
server/transaction: handle Stripe radar fee
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 committed Oct 30, 2024
1 parent 240e090 commit 666d58f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions server/polar/models/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ class ProcessorFeeType(StrEnum):
It considers an account active if a payout has been made in the month.
"""

security = "security"
"""
Fee applied for safety and fraud prevention tools.
"""


class PlatformFeeType(StrEnum):
"""
Expand Down
2 changes: 2 additions & 0 deletions server/polar/transaction/service/processor_fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def _get_stripe_processor_fee_type(description: str) -> ProcessorFeeType:
# Instant Bank Account Validation for ACH payments
if "connections verification" in description:
return ProcessorFeeType.payment
if "radar" in description:
return ProcessorFeeType.security
raise UnsupportedStripeFeeType(description)


Expand Down
23 changes: 19 additions & 4 deletions server/tests/transaction/service/test_processor_fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,24 @@ async def test_sync_stripe_fees(
"id": "STRIPE_BALANCE_TRANSACTION_ID_11",
"net": -100,
"currency": "usd",
"description": "Connect (2024-01-01 - 2024-01-31): Payout Fee",
"description": "Radar (2024-10-28): Radar for Fraud Teams",
},
None,
),
stripe_lib.BalanceTransaction.construct_from(
{
"created": now_timestamp,
"id": "STRIPE_BALANCE_TRANSACTION_ID_12",
"net": -100,
"currency": "usd",
"description": "Connect (2024-01-01 - 2024-01-31): Payout Fee",
},
None,
),
stripe_lib.BalanceTransaction.construct_from(
{
"created": now_timestamp,
"id": "STRIPE_BALANCE_TRANSACTION_ID_13",
"net": -200,
"currency": "usd",
"description": "Connect (2024-01-01 - 2024-01-31): Account Volume Billing",
Expand All @@ -485,7 +495,7 @@ async def test_sync_stripe_fees(
account_currency="usd",
account_amount=-200,
tax_amount=0,
fee_balance_transaction_id="STRIPE_BALANCE_TRANSACTION_ID_12",
fee_balance_transaction_id="STRIPE_BALANCE_TRANSACTION_ID_13",
)
fee_transaction_13 = Transaction(
type=TransactionType.processor_fee,
Expand All @@ -496,7 +506,7 @@ async def test_sync_stripe_fees(
account_currency="usd",
account_amount=-100,
tax_amount=0,
fee_balance_transaction_id="STRIPE_BALANCE_TRANSACTION_ID_11",
fee_balance_transaction_id="STRIPE_BALANCE_TRANSACTION_ID_12",
)
await save_fixture(fee_transaction_12)
await save_fixture(fee_transaction_13)
Expand All @@ -508,7 +518,7 @@ async def test_sync_stripe_fees(
session
)

assert len(fee_transactions) == 10
assert len(fee_transactions) == 11

(
fee_transaction_1,
Expand All @@ -521,6 +531,7 @@ async def test_sync_stripe_fees(
fee_transaction_8,
fee_transaction_9,
fee_transaction_10,
fee_transaction_11,
) = fee_transactions

assert fee_transaction_1.type == TransactionType.processor_fee
Expand Down Expand Up @@ -565,3 +576,7 @@ async def test_sync_stripe_fees(
assert fee_transaction_10.type == TransactionType.processor_fee
assert fee_transaction_10.processor_fee_type == ProcessorFeeType.payment
assert fee_transaction_10.amount == -150

assert fee_transaction_11.type == TransactionType.processor_fee
assert fee_transaction_11.processor_fee_type == ProcessorFeeType.security
assert fee_transaction_11.amount == -100

0 comments on commit 666d58f

Please sign in to comment.