aboutsummaryrefslogtreecommitdiff
path: root/jb/managers
diff options
context:
space:
mode:
Diffstat (limited to 'jb/managers')
-rw-r--r--jb/managers/email_manager.py29
-rw-r--r--jb/managers/thl.py7
2 files changed, 33 insertions, 3 deletions
diff --git a/jb/managers/email_manager.py b/jb/managers/email_manager.py
index 8006844..08ac0cf 100644
--- a/jb/managers/email_manager.py
+++ b/jb/managers/email_manager.py
@@ -1,14 +1,19 @@
import requests
from generalresearch.config import is_debug
from generalresearch.currency import USDCent
-from generalresearch.models.thl.wallet.cashout_method import CashoutMethodOut
+from generalresearch.models.thl.wallet.cashout_method import (
+ CashoutMethodOut,
+ CashoutRequestInfo,
+)
from jb.config import settings
MAUTIC_BASE_URL = "https://mail.jamesbillings67.com"
LOGIN_EMAIL_TEMPLATE_ID = 1
# Todo: We need a new template for the cashout confirmation
-CASHOUT_EMAIL_TEMPLATE_ID = 3
+CASHOUT_REQUEST_EMAIL_TEMPLATE_ID = 3
+# Todo: We need a new template for the cashout status / sent
+CASHOUT_STATUS_EMAIL_TEMPLATE_ID = 4
assert settings.mautic_api_key
auth_headers = {"Authorization": f"Basic {settings.mautic_api_key.get_secret_value()}"}
@@ -72,7 +77,7 @@ def send_cashout_confirmation_email(
email: str, token: str, cashout_method: CashoutMethodOut, amount: USDCent
) -> None:
contact_id = get_or_create_contact(email=email)
- mautic_url = f"{MAUTIC_BASE_URL}/api/emails/{CASHOUT_EMAIL_TEMPLATE_ID}/contact/{contact_id}/send"
+ mautic_url = f"{MAUTIC_BASE_URL}/api/emails/{CASHOUT_REQUEST_EMAIL_TEMPLATE_ID}/contact/{contact_id}/send"
magic_link = f"{settings.base_url}wallet/cashout/confirm/?token={token}"
if is_debug():
print("MAGIC_LINK: ", magic_link)
@@ -87,3 +92,21 @@ def send_cashout_confirmation_email(
if cashout_method.image_url:
email_tokens["image_url"] = cashout_method.image_url
send_email_with_tokens(email_tokens, mautic_url)
+
+
+def send_cashout_status_email(email: str, cashout: CashoutRequestInfo) -> None:
+ assert cashout.status is not None
+ email_tokens = {
+ "cashout_id": str(cashout.id),
+ "cashout_status": cashout.status.value,
+ }
+ # todo: (if tango) format credentials and redemption instructions
+ # "credentials": "",
+ # "redemption_instructions": "",
+
+ if is_debug():
+ print("CASHOUT_STATUS_EMAIL: ", email_tokens)
+ return
+ contact_id = get_or_create_contact(email=email)
+ mautic_url = f"{MAUTIC_BASE_URL}/api/emails/{CASHOUT_STATUS_EMAIL_TEMPLATE_ID}/contact/{contact_id}/send"
+ send_email_with_tokens(email_tokens, mautic_url)
diff --git a/jb/managers/thl.py b/jb/managers/thl.py
index 4d6b23a..191a56b 100644
--- a/jb/managers/thl.py
+++ b/jb/managers/thl.py
@@ -121,3 +121,10 @@ def get_wallet_balance_if_non_negative(amt_worker_id: str) -> USDCent | None:
if amt >= 0:
return USDCent(amt)
return None
+
+
+def get_cashout_detail(cashout_id: str) -> CashoutRequestInfo:
+ url = f"{settings.fsb_host}{settings.product_id}/cashout/{cashout_id}/"
+ res = requests.get(url)
+ assert res.status_code == status.HTTP_200_OK, res.text
+ return CashoutRequestInfo.model_validate(res.json()["cashout"])