aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstuppie2026-09-07 16:11:50 -0600
committerstuppie2026-09-07 16:11:50 -0600
commit075c8d762af7d7d97e50ffc06eebdc249891f151 (patch)
tree2bf14b0ecf17c7f8f3865158954156d4069bada7
parent63dde379996190f1827d76cbaa155b6c33702f7b (diff)
downloadgeneralresearch-075c8d762af7d7d97e50ffc06eebdc249891f151.tar.gz
generalresearch-075c8d762af7d7d97e50ffc06eebdc249891f151.zip
put amt stuff back for now
-rw-r--r--generalresearch/managers/thl/cashout_method.py10
-rw-r--r--generalresearch/managers/thl/ledger_manager/thl_ledger.py19
-rw-r--r--generalresearch/managers/thl/wallet/__init__.py29
-rw-r--r--generalresearch/managers/thl/wallet/approve.py26
4 files changed, 74 insertions, 10 deletions
diff --git a/generalresearch/managers/thl/cashout_method.py b/generalresearch/managers/thl/cashout_method.py
index 7d2366d..910d37b 100644
--- a/generalresearch/managers/thl/cashout_method.py
+++ b/generalresearch/managers/thl/cashout_method.py
@@ -248,6 +248,8 @@ class CashoutMethodManager(PostgresManager):
product = user.product
supported_payout_types = copy(product.user_wallet_config.supported_payout_types)
+ if product.user_wallet_config.amt:
+ supported_payout_types.add(PayoutType.AMT)
user_scoped_payout_types = [PayoutType.PAYPAL, PayoutType.CASH_IN_MAIL]
params = {
"user_scoped_payout_types": [x.value for x in user_scoped_payout_types],
@@ -270,6 +272,14 @@ class CashoutMethodManager(PostgresManager):
raise ValueError(f"Unexpectedly large number of cashout_methods: {user=}")
cms = [self.format_from_db(x, user=user) for x in res]
+ # Only allow AMT if the BP is marked as AMT (already should have been
+ # filtered in query)
+ cms = [
+ x
+ for x in cms
+ if (x.type == PayoutType.AMT and product.user_wallet_config.amt)
+ or (x.type != PayoutType.AMT)
+ ]
return cms
@staticmethod
diff --git a/generalresearch/managers/thl/ledger_manager/thl_ledger.py b/generalresearch/managers/thl/ledger_manager/thl_ledger.py
index eccc99f..2fef50f 100644
--- a/generalresearch/managers/thl/ledger_manager/thl_ledger.py
+++ b/generalresearch/managers/thl/ledger_manager/thl_ledger.py
@@ -1064,12 +1064,28 @@ class ThlLedgerManager(LedgerManager):
amt_str = f"${int(amount) / 100:,.2f}"
descriptions = {
+ PayoutType.AMT_HIT: f"User Payout AMT Assignment Request {amt_str}",
+ PayoutType.AMT_BONUS: f"User Payout AMT Bonus Request {amt_str}",
PayoutType.PAYPAL: f"User Payout Paypal Request {amt_str}",
PayoutType.CASH_IN_MAIL: f"User Payout Cash Request {amt_str}",
PayoutType.TANGO: f"User Payout Tango Request {amt_str}",
}
description = descriptions[payout_event.payout_type]
+ if payout_event.payout_type in {
+ PayoutType.AMT_HIT,
+ PayoutType.AMT_BONUS,
+ }:
+ """
+ This is for AMT accounts only (currently JB). This is the
+ payment of a either 1) 1c or 5c (typically) assignment or 2) a
+ bonus for task complete to the user. The 20% commission will
+ be taken from the BP's wallet once the tx is completed.
+ """
+ assert user.product.user_wallet_amt, (
+ "Can only call this on an AMT-enabled BPs"
+ )
+
f = lambda: self.create_tx_user_payout_request_(
user=user,
payout_event=payout_event,
@@ -1078,6 +1094,9 @@ class ThlLedgerManager(LedgerManager):
)
min_balance: int | None = int(amount)
+ if payout_event.payout_type == PayoutType.AMT_HIT:
+ # We allow the user's balance to reach up to -$1.00.
+ min_balance = -100 + amount
if skip_wallet_balance_check:
min_balance = None
diff --git a/generalresearch/managers/thl/wallet/__init__.py b/generalresearch/managers/thl/wallet/__init__.py
index 7a8b4c9..1f0c30b 100644
--- a/generalresearch/managers/thl/wallet/__init__.py
+++ b/generalresearch/managers/thl/wallet/__init__.py
@@ -2,6 +2,7 @@ from decimal import Decimal
from typing import TYPE_CHECKING, Any
from generalresearch.managers.thl.wallet.approve import (
+ approve_amt_cashout,
approve_paypal_order,
)
from generalresearch.models.thl.definitions import PayoutStatus
@@ -58,13 +59,13 @@ def manage_pending_cashout(
user = user_manager.get_user(user_uuid=pe.account_reference_uuid)
user.prefetch_product(user_manager.mysql_user_manager.pg_config)
- assert (
- user.product.user_wallet_enabled
- ), "manage_pending_cashout called on user without managed wallet"
+ assert user.product.user_wallet_enabled, (
+ "manage_pending_cashout called on user without managed wallet"
+ )
assert not user.blocked, "manage_pending_cashout: Blocked user"
- assert not user_ip_history_manager.is_user_anonymous(
- user
- ), "manage_pending_cashout: Anonymous user"
+ assert not user_ip_history_manager.is_user_anonymous(user), (
+ "manage_pending_cashout: Anonymous user"
+ )
# Just assign it with direct casting/type annotation
payout_event_manager: PayoutEventManager = user_payout_event_manager
@@ -90,6 +91,14 @@ def manage_pending_cashout(
payout_event=pe, payout_event_manager=payout_event_manager
)
+ elif pe.payout_type in {PayoutType.AMT_BONUS, PayoutType.AMT_HIT}:
+ approve_amt_cashout(
+ user=user,
+ payout_event=pe,
+ payout_event_manager=payout_event_manager,
+ ledger_manager=ledger_manager,
+ )
+
elif pe.payout_type == PayoutType.CASH_IN_MAIL:
assert order_data, "must pass order_data"
payout_event_manager.update(
@@ -107,8 +116,14 @@ def manage_pending_cashout(
return pe
elif new_status == PayoutStatus.COMPLETE:
+ # Used only for AMT/dummy cashouts that are actually paid out not
+ # by us. They are informing us that the cashout was successfully
+ # sent to the user
+ if pe.payout_type in {PayoutType.AMT_BONUS, PayoutType.AMT_HIT}:
+ # We already do this under approve_amt_cashout()
+ pass
- if pe.payout_type == PayoutType.PAYPAL:
+ elif pe.payout_type == PayoutType.PAYPAL:
# This is an issue here in that we actually don't know what the
# fee is until it is sent and we read it back from paypal's csv
# result. We have to just run this with a custom script, which
diff --git a/generalresearch/managers/thl/wallet/approve.py b/generalresearch/managers/thl/wallet/approve.py
index 7cae025..a1c01d2 100644
--- a/generalresearch/managers/thl/wallet/approve.py
+++ b/generalresearch/managers/thl/wallet/approve.py
@@ -13,6 +13,26 @@ if TYPE_CHECKING:
from generalresearch.models.thl.user import User
+def approve_amt_cashout(
+ user: User,
+ payout_event: UserPayoutEvent,
+ ledger_manager: ThlLedgerManager,
+ payout_event_manager: PayoutEventManager,
+) -> None:
+ """
+ This is going to be paid out by the requester (the jb-lambdas) as an AMT bonus.
+ """
+ assert payout_event.status in {
+ PayoutStatus.PENDING,
+ PayoutStatus.FAILED,
+ }, (
+ "attempting to manage payout that is not pending (or you can retry a failed order)"
+ )
+
+ payout_event_manager.update(payout_event, status=PayoutStatus.APPROVED)
+ ledger_manager.create_tx_user_payout_complete(user, payout_event=payout_event)
+
+
def approve_paypal_order(
payout_event: UserPayoutEvent, payout_event_manager: PayoutEventManager
):
@@ -22,7 +42,9 @@ def approve_paypal_order(
assert payout_event.status in {
PayoutStatus.PENDING,
PayoutStatus.FAILED,
- }, "attempting to manage payout that is not pending (or you can retry a failed order)"
+ }, (
+ "attempting to manage payout that is not pending (or you can retry a failed order)"
+ )
payout_event_manager.update(payout_event, status=PayoutStatus.APPROVED)
@@ -38,5 +60,3 @@ def approve_paypal_order(
pass
return payout_event
-
-