aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jb/flow/assignment_tasks.py8
-rw-r--r--jb/managers/thl.py12
2 files changed, 17 insertions, 3 deletions
diff --git a/jb/flow/assignment_tasks.py b/jb/flow/assignment_tasks.py
index a41d7cf..b678f44 100644
--- a/jb/flow/assignment_tasks.py
+++ b/jb/flow/assignment_tasks.py
@@ -23,7 +23,7 @@ from jb.managers.thl import (
user_cashout_request,
manage_pending_cashout,
get_user_blocked_or_not_exists,
- get_wallet_balance,
+ get_wallet_balance_if_non_negative,
)
from jb.models.assignment import Assignment
from jb.models.definitions import AssignmentStatus
@@ -458,7 +458,11 @@ def issue_worker_payment(
# then approve it, send the amt bonus, then complete it
amt_assignment_id = assignment.amt_assignment_id
hit = hm.get_from_amt_id(amt_hit_id=assignment.amt_hit_id)
- wallet_balance = get_wallet_balance(amt_worker_id=assignment.amt_worker_id)
+ wallet_balance = get_wallet_balance_if_non_negative(
+ amt_worker_id=assignment.amt_worker_id
+ )
+ if not wallet_balance:
+ return None
amount = round_payment(amount=wallet_balance)
if not amount:
return None
diff --git a/jb/managers/thl.py b/jb/managers/thl.py
index c1cd672..6e8effc 100644
--- a/jb/managers/thl.py
+++ b/jb/managers/thl.py
@@ -35,7 +35,7 @@ def get_user_profile(amt_worker_id: str) -> UserProfile:
# todo: this contains computed fields inside each streak object
user_profile.pop("streaks", None)
# todo: this shouldn't be in here anyways ---v
- user_profile['user'].pop("id", None)
+ user_profile["user"].pop("id", None)
return UserProfile.model_validate(user_profile)
@@ -104,6 +104,16 @@ def manage_pending_cashout(
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/"
params = {"bpuid": amt_worker_id}
return USDCent(requests.get(url, params=params).json()["wallet"]["amount"])
+
+
+def get_wallet_balance_if_non_negative(amt_worker_id: str) -> Optional[USDCent]:
+ url = f"{settings.fsb_host}{settings.product_id}/wallet/"
+ params = {"bpuid": amt_worker_id}
+ amt = requests.get(url, params=params).json()["wallet"]["amount"]
+ if amt >= 0:
+ return USDCent(amt)
+ return None