aboutsummaryrefslogtreecommitdiff
path: root/jb/managers/thl.py
diff options
context:
space:
mode:
authorstuppie2026-09-21 18:03:20 -0600
committerstuppie2026-09-21 18:03:20 -0600
commitb63021c4492a1742b8fa65c39ec648f140e0748b (patch)
tree5fa7877c0686b6be2df0b10cc871420f910bf5f7 /jb/managers/thl.py
parent6249139ee928b954e74ac42df81211f1a8094b53 (diff)
downloadamt-jb-b63021c4492a1742b8fa65c39ec648f140e0748b.tar.gz
amt-jb-b63021c4492a1742b8fa65c39ec648f140e0748b.zip
cashout request email flow and views
Diffstat (limited to 'jb/managers/thl.py')
-rw-r--r--jb/managers/thl.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/jb/managers/thl.py b/jb/managers/thl.py
index 85e0697..f88acad 100644
--- a/jb/managers/thl.py
+++ b/jb/managers/thl.py
@@ -1,4 +1,5 @@
import requests
+from fastapi import HTTPException, status
from generalresearch.currency import USDCent
from generalresearch.models.thl.definitions import PayoutStatus
from generalresearch.models.thl.payout import UserPayoutEvent
@@ -9,9 +10,6 @@ from generalresearch.models.thl.wallet.cashout_method import (
)
from jb.config import settings
-from jb.models.auth import User
-
-
def get_task_status(tsid: str) -> TaskStatusResponse | None:
url = f"{settings.fsb_host}{settings.product_id}/status/{tsid}/"
d = requests.get(url).json()
@@ -22,20 +20,30 @@ def get_task_status(tsid: str) -> TaskStatusResponse | None:
def user_cashout_request(
- user: User, amount: USDCent, cashout_method_id: str
+ product_user_id: str, amount: USDCent, cashout_method_id: str
) -> CashoutRequestInfo:
assert isinstance(amount, USDCent)
assert USDCent(0) < amount < USDCent(10_00)
url = f"{settings.fsb_host}{settings.product_id}/cashout/"
body: dict[str, str | int] = {
- "bpuid": user.product_user_id,
+ "bpuid": product_user_id,
"amount": int(amount),
"cashout_method_id": cashout_method_id,
}
res = requests.post(url, json=body)
- d = res.json()
+ if res.status_code == status.HTTP_400_BAD_REQUEST:
+ try:
+ message = res.json().get("msg")
+ except (ValueError, AttributeError):
+ message = None
+ raise HTTPException(
+ status_code=status.HTTP_400_BAD_REQUEST,
+ detail=message or "Cashout request failed",
+ )
+ res.raise_for_status()
+ d = res.json()
return CashoutRequestResponse.model_validate(d).cashout