From 666d58ff7eb975b8af5f72c1659c8cfa0cb3ea9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Voron?= Date: Wed, 30 Oct 2024 09:05:18 +0100 Subject: [PATCH] server/transaction: handle Stripe radar fee --- server/polar/models/transaction.py | 5 ++++ .../transaction/service/processor_fee.py | 2 ++ .../transaction/service/test_processor_fee.py | 23 +++++++++++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/server/polar/models/transaction.py b/server/polar/models/transaction.py index acdda2f6f6..f8024043be 100644 --- a/server/polar/models/transaction.py +++ b/server/polar/models/transaction.py @@ -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): """ diff --git a/server/polar/transaction/service/processor_fee.py b/server/polar/transaction/service/processor_fee.py index d51de1b93d..1413ed67d8 100644 --- a/server/polar/transaction/service/processor_fee.py +++ b/server/polar/transaction/service/processor_fee.py @@ -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) diff --git a/server/tests/transaction/service/test_processor_fee.py b/server/tests/transaction/service/test_processor_fee.py index a9cf24ef20..b9b133c4f5 100644 --- a/server/tests/transaction/service/test_processor_fee.py +++ b/server/tests/transaction/service/test_processor_fee.py @@ -456,7 +456,7 @@ 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, ), @@ -464,6 +464,16 @@ async def test_sync_stripe_fees( { "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", @@ -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, @@ -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) @@ -508,7 +518,7 @@ async def test_sync_stripe_fees( session ) - assert len(fee_transactions) == 10 + assert len(fee_transactions) == 11 ( fee_transaction_1, @@ -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 @@ -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