diff options
| author | stuppie | 2026-11-02 13:19:02 -0600 |
|---|---|---|
| committer | stuppie | 2026-11-02 13:19:02 -0600 |
| commit | bc2852423b064dcd639423f0a14e5ce93e973731 (patch) | |
| tree | 2f6a89cfcd4fc463a5c3db90ad8f70a57e89f0d5 | |
| parent | 98e2ae983d4ae23dba3209fa7eaaccce59ddb4df (diff) | |
| download | generalresearch-bc2852423b064dcd639423f0a14e5ce93e973731.tar.gz generalresearch-bc2852423b064dcd639423f0a14e5ce93e973731.zip | |
get_user_cashout_methods: provider-specific country filtering logic
| -rw-r--r-- | generalresearch/managers/thl/cashout_method.py | 30 | ||||
| -rw-r--r-- | generalresearch/models/thl/wallet/cashout_method.py | 2 |
2 files changed, 22 insertions, 10 deletions
diff --git a/generalresearch/managers/thl/cashout_method.py b/generalresearch/managers/thl/cashout_method.py index 32bda88..2b9bb96 100644 --- a/generalresearch/managers/thl/cashout_method.py +++ b/generalresearch/managers/thl/cashout_method.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections.abc import Collection from copy import copy from datetime import UTC, datetime -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, cast from uuid import UUID, uuid4 from pydantic import NonNegativeInt @@ -25,7 +25,9 @@ if TYPE_CHECKING: from generalresearch.models.thl.wallet.cashout_method import ( CashMailCashoutMethodData, CashoutMethod, + GiftbitCashoutMethodData, PaypalCashoutMethodData, + TangoCashoutMethodData, ) @@ -418,14 +420,24 @@ class CashoutMethodManager(PostgresManager): cms = self.get_cashout_methods(user=user) # Filter out by country before bothering w exchange rates - cms = [ - cm - for cm in cms - if ( - cm.type == PayoutType.TANGO and country_iso.lower() in cm.data.countries - ) - or cm.type != PayoutType.TANGO - ] + country_iso = country_iso.lower() + country_cms = [] + for cm in cms: + if cm.type == PayoutType.TANGO: + data = cast("TangoCashoutMethodData", cm.data) + if country_iso in data.countries: + country_cms.append(cm) + continue + + if cm.type == PayoutType.GIFTBIT: + data = cast("GiftbitCashoutMethodData", cm.data) + if data.countries is None or country_iso in data.countries: + country_cms.append(cm) + continue + + country_cms.append(cm) + + cms = country_cms cms = [ self.apply_currency_adjustments(x, product, usd_exchange_rate) for x in cms diff --git a/generalresearch/models/thl/wallet/cashout_method.py b/generalresearch/models/thl/wallet/cashout_method.py index 8ad02f5..b957d9c 100644 --- a/generalresearch/models/thl/wallet/cashout_method.py +++ b/generalresearch/models/thl/wallet/cashout_method.py @@ -350,7 +350,7 @@ class GiftbitCashoutMethodData(BaseModel): min_price_in_cents: int | None = Field(default=None) max_price_in_cents: int | None = Field(default=None) allowed_prices_in_cents: list[int] | None = Field(default=None) - countries: list[str] | None= Field(description="None means global") + countries: list[str] | None = Field(description="None means global") disclaimer: str = Field(default="") |
