diff options
Diffstat (limited to 'jb/managers/email_manager.py')
| -rw-r--r-- | jb/managers/email_manager.py | 65 |
1 files changed, 56 insertions, 9 deletions
diff --git a/jb/managers/email_manager.py b/jb/managers/email_manager.py index 7298c60..08ac0cf 100644 --- a/jb/managers/email_manager.py +++ b/jb/managers/email_manager.py @@ -1,10 +1,19 @@ import requests from generalresearch.config import is_debug +from generalresearch.currency import USDCent +from generalresearch.models.thl.wallet.cashout_method import ( + CashoutMethodOut, + CashoutRequestInfo, +) from jb.config import settings MAUTIC_BASE_URL = "https://mail.jamesbillings67.com" -EMAIL_TEMPLATE_ID = 1 +LOGIN_EMAIL_TEMPLATE_ID = 1 +# Todo: We need a new template for the cashout confirmation +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()}"} @@ -26,11 +35,14 @@ def send_login_email_from_url(mautic_url: str, magic_link: str) -> None: if is_debug(): print("MAGIC_LINK: ", magic_link) return - email_tokens = { "magic_link": magic_link, } - body = {"tokens": email_tokens} + send_email_with_tokens(email_tokens, mautic_url) + + +def send_email_with_tokens(tokens: dict[str, str], mautic_url: str) -> None: + body = {"tokens": tokens} response = requests.post(url=mautic_url, json=body, headers=auth_headers) try: @@ -47,9 +59,7 @@ def send_login_email_from_url(mautic_url: str, magic_link: str) -> None: def send_login_email(email: str, magic_token: str) -> None: contact_id = get_or_create_contact(email=email) - mautic_url = ( - f"{MAUTIC_BASE_URL}/api/emails/{EMAIL_TEMPLATE_ID}/contact/{contact_id}/send" - ) + mautic_url = f"{MAUTIC_BASE_URL}/api/emails/{LOGIN_EMAIL_TEMPLATE_ID}/contact/{contact_id}/send" magic_link = f"{settings.base_url}auth/magic-link/?token={magic_token}" send_login_email_from_url(mautic_url, magic_link) @@ -58,8 +68,45 @@ def send_amt_link_email(email: str, magic_token: str) -> None: # Don't actually associate the email with the worker ID # until they click the link contact_id = get_or_create_contact(email=email) - mautic_url = ( - f"{MAUTIC_BASE_URL}/api/emails/{EMAIL_TEMPLATE_ID}/contact/{contact_id}/send" - ) + mautic_url = f"{MAUTIC_BASE_URL}/api/emails/{LOGIN_EMAIL_TEMPLATE_ID}/contact/{contact_id}/send" magic_link = f"{settings.base_url}auth/link-amt/?token={magic_token}" send_login_email_from_url(mautic_url, magic_link) + + +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_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) + return + email_tokens = { + "magic_link": magic_link, + "cashout_method_name": cashout_method.name, + "cashout_method_description": cashout_method.description, + "cashout_method_type": cashout_method.type.value, + "amount": amount.to_usd_str(), + } + 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) |
