Update the subscription change webhook to be more friendly and not send emails for payments.

This commit is contained in:
jakedt 2014-04-17 16:18:37 -04:00
parent 05b3851a54
commit a0cbead5aa
2 changed files with 25 additions and 7 deletions

View file

@ -46,7 +46,23 @@ def stripe_webhook():
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)
change_type = ''
if event_type.endswith('.deleted'):
plan_id = request_data['data']['object']['plan']['id']
change_type = 'canceled %s' % plan_id
send_subscription_change(change_type, customer_id, cust_email, quay_username)
elif event_type.endswith('.created'):
plan_id = request_data['data']['object']['plan']['id']
change_type = 'subscribed %s' % plan_id
send_subscription_change(change_type, customer_id, cust_email, quay_username)
elif event_type.endswith('.updated'):
if 'previous_attributes' in request_data['data']:
if 'plan' in request_data['data']['previous_attributes']:
old_plan = request_data['data']['previous_attributes']['plan']['id']
new_plan = request_data['data']['object']['plan']['id']
change_type = 'switched %s -> %s' % (old_plan, new_plan)
send_subscription_change(change_type, customer_id, cust_email, quay_username)
return make_response('Okay')