From 785adc51b2cc2b4d3e845a454f38b2a5197cc7f0 Mon Sep 17 00:00:00 2001 From: stuppie Date: Wed, 23 Sep 2026 15:07:47 -0600 Subject: working on cashout postback, to be hit by thl upon cashout status change, which will send the user an email with the info --- jb/managers/email_manager.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'jb/managers/email_manager.py') 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) -- cgit v1.2.3