diff options
Diffstat (limited to 'jb/managers/thl.py')
| -rw-r--r-- | jb/managers/thl.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/jb/managers/thl.py b/jb/managers/thl.py index f88acad..59bd2ab 100644 --- a/jb/managers/thl.py +++ b/jb/managers/thl.py @@ -10,6 +10,8 @@ from generalresearch.models.thl.wallet.cashout_method import ( ) from jb.config import settings + + def get_task_status(tsid: str) -> TaskStatusResponse | None: url = f"{settings.fsb_host}{settings.product_id}/status/{tsid}/" d = requests.get(url).json() @@ -61,6 +63,41 @@ def manage_pending_cashout( return UserPayoutEvent.model_validate(d) +def get_paypal_cashout_method_if_exists(product_user_id: str) -> str | None: + """ + Todo: This does not work right now for new users, in that this endpoint expects the user + to have IP history or the request made from the client + (b/c it needs their country to know which tango card are available). + We don't care about that for paypal, but, it expects it anyways. + Once a user can change their paypal email, this needs to change to avoid overwriting it + every time they login. + """ + url = f"{settings.fsb_host}{settings.product_id}/cashout_methods/" + params = {"bpuid": product_user_id} + res = requests.get(url, params=params) + assert res.status_code == status.HTTP_200_OK, res.text + cms = res.json()["cashout_methods"] + res = next(filter(lambda x: x["type"] == "PAYPAL", cms), None) + if res: + return res["id"] + return None + + +def create_paypal_cashout_method(product_user_id: str, email: str) -> dict: + url = f"{settings.fsb_host}{settings.product_id}/cashout_methods/" + body = {"bpuid": product_user_id, "type": "PAYPAL", "email": email} + res = requests.post(url, json=body) + assert res.status_code == status.HTTP_200_OK, res.text + return res.json()["cashout_method"] + + +def create_paypal_cashout_method_if_not_exists( + product_user_id: str, email: str +) -> None: + if not get_paypal_cashout_method_if_exists(product_user_id): + create_paypal_cashout_method(product_user_id, email) + + def get_wallet_balance(amt_worker_id: str) -> USDCent: # This will raise an Exception if wallet balance is negative url = f"{settings.fsb_host}{settings.product_id}/wallet/" |
