-
Notifications
You must be signed in to change notification settings - Fork 5
/
events.py
27 lines (19 loc) · 842 Bytes
/
events.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
import stripe
from .models import Customer
stripe.api_key = os.environ.get('STRIPE_SECRET')
def get_customer_from_event(stripe_event):
customer_events = ['customer.created', 'customer.updated',
'customer.deleted']
customer = None
if stripe_event.type in customer_events:
stripe_customer_id = stripe_event.data['object']['id']
customer, flag = Customer.get_or_construct(stripe_id=stripe_customer_id)
assert not (flag and stripe_event.livemode)
elif 'customer' in stripe_event.data['object']:
stripe_customer_id = stripe_event.data['object']['customer']
customer, flag = Customer.get_or_construct(stripe_id=stripe_customer_id)
assert not (flag and stripe_event.livemode)
return customer
def get_invoice_from_event(stripe_event):
pass