diff options
Diffstat (limited to 'jb/managers/thl.py')
| -rw-r--r-- | jb/managers/thl.py | 20 |
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 |
