diff --git a/subscribie/blueprints/admin/subscriber.py b/subscribie/blueprints/admin/subscriber.py
index 8e212782..0ca84b10 100644
--- a/subscribie/blueprints/admin/subscriber.py
+++ b/subscribie/blueprints/admin/subscriber.py
@@ -1,9 +1,11 @@
from . import admin
from subscribie.auth import login_required
from subscribie.models import Person
-from flask import render_template
+from flask import render_template, url_for, request
from subscribie.utils import get_stripe_secret_key, get_stripe_connect_account_id
+from subscribie.database import database
import stripe
+import json
import logging
log = logging.getLogger(__name__)
@@ -54,6 +56,73 @@ def show_subscriber(subscriber_id):
)
+def show_subscriber_email(subscriber_id):
+ person = Person.query.execution_options(include_archived=True).get(subscriber_id)
+
+ return f"""
+
+ 📧 {person.email}
+
+
+
+ """
+
+
+@admin.route("/subscriber//email", methods=["GET"])
+@login_required
+def get_subscriber_email_address(subscriber_id):
+ return show_subscriber_email(subscriber_id)
+
+
+@admin.route("/subscriber//edit", methods=["GET", "PUT"])
+@login_required
+def edit_subscriber(subscriber_id):
+ person = Person.query.execution_options(include_archived=True).get(subscriber_id)
+
+ if request.method == "PUT":
+ old_email = person.email
+ new_email = request.form.get("email")
+ person.email = new_email
+ database.session.commit()
+
+ # Also update Stripe customer email record
+ try:
+ if len(person.subscriptions) > 0:
+ stripe_customer_id = json.loads(
+ person.subscriptions[0].stripe_invoices[0].stripe_invoice_raw_json
+ )["customer"]
+ stripe.api_key = get_stripe_secret_key()
+ stripe_connect_account_id = get_stripe_connect_account_id()
+ stripe.Customer.modify(
+ id=stripe_customer_id,
+ stripe_account=stripe_connect_account_id,
+ email=new_email,
+ )
+ except Exception as e:
+ log.error(
+ f"Failure updating person '{person.id}' email to {new_email}. {e}"
+ )
+ log.debug("Switching person email address back to old email")
+ person.email = old_email
+ database.session.commit()
+
+ return show_subscriber_email(subscriber_id)
+
+ return f"""
+
+ """
+
+
@admin.route("/charge/subscriber/", methods=["GET"])
@login_required
def charge_subscriber(person_id):
diff --git a/subscribie/blueprints/admin/templates/admin/subscriber/show_subscriber.html b/subscribie/blueprints/admin/templates/admin/subscriber/show_subscriber.html
index 91135071..580f2936 100644
--- a/subscribie/blueprints/admin/templates/admin/subscriber/show_subscriber.html
+++ b/subscribie/blueprints/admin/templates/admin/subscriber/show_subscriber.html
@@ -25,7 +25,13 @@ Subscriber: {{ person.full_name | title }
👤 {{ person.full_name | title }}
- - 📧 {{ person.email }}
+
+ - 📧 {{ person.email }}
+
+
+
- 📱 {{ person.mobile }}
- 🏠 Address