I am doing some investigation in how to connect Databricks and Stripe. Stirpe has really good documentation and I have decided to set up a webhook in Django as per their recommendation. This function handles events as they occur in stripe:
----------------
import json
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
# Using Django
@csrf_exempt
def my_webhook_view(request):
payload = request.body
event = None
try:
event = stripe.Event.construct_from(
json.loads(payload), stripe.api_key
)
except ValueError as e:
# Invalid payload
return HttpResponse(status=400)
# Handle the event
if event['type'] == 'customer.created':
customer = event['data']['object']
elif event['type'] == 'customer.deleted':
customer = event['data']['object']
elif event['type'] == 'customer.source.created':
source = event['data']['object']
elif event['type'] == 'customer.subscription.created':
subscription = event['data']['object']
elif event['type'] == 'customer.subscription.updated':
subscription = event['data']['object']
# ... handle other event types
else:
print('Unhandled event type {}'.format(event['type']))
return HttpResponse(status=200)
-------------------------
I now need to integrate some logic to make this work. I wanted to ask:
- Is there an established approach for connecting stripe to databricks?
- How can I set up my endpoint in databricks?
Thanks