Respond to subscription change events so I can stop polling the stripe event list.

This commit is contained in:
jakedt 2014-04-15 17:00:32 -04:00
parent 27072d4a2d
commit d95c321e28
2 changed files with 23 additions and 1 deletions

View file

@ -8,7 +8,7 @@ from data import model
from auth.auth import process_auth
from auth.permissions import ModifyRepositoryPermission
from util.invoice import renderInvoiceToHtml
from util.email import send_invoice_email
from util.email import send_invoice_email, send_subscription_change
from util.names import parse_repository_name
from util.http import abort
from endpoints.trigger import BuildTrigger, ValidationRequestException
@ -41,6 +41,12 @@ def stripe_webhook():
if invoice:
invoice_html = renderInvoiceToHtml(invoice, user)
send_invoice_email(user.email, invoice_html)
elif event_type.startswith('customer.subscription.'):
customer_id = request_data['data']['object']['customer']
cust = model.get_user_or_org_by_customer_id(customer_id)
cust_email = cust.email if cust is not None else 'unknown@domain.com'
quay_username = cust.username if cust is not None else 'unknown'
send_subscription_change(event_type, customer_id, cust_email, quay_username)
return make_response('Okay')

View file

@ -34,6 +34,14 @@ not given access. Please disregard this email.<br>
"""
SUBSCRIPTION_CHANGE = """
Event name: {0}<br>
Customer id: <a href="https://manage.stripe.com/customers/{1}">{1}</a><br>
Customer email: <a href="mailto:{2}">{2}</a><br>
Quay user or org name: {3}<br>
"""
def send_change_email(username, email, token):
msg = Message('Quay.io email change. Please confirm your email.',
sender='support@quay.io', # Why do I need this?
@ -64,3 +72,11 @@ def send_invoice_email(email, contents):
recipients=[email])
msg.html = contents
mail.send(msg)
def send_subscription_change(event_name, customer_id, customer_email, quay_username):
msg = Message('Quay.io Customer Subscription Change',
sender='support@quay.io', # Why do I need this?
recipients=['stripe@quay.io'])
msg.html = SUBSCRIPTION_CHANGE.format(event_name, customer_id, customer_email, quay_username)
mail.send(msg)