Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to test a stripe webhook. #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions zebra/management/commands/test_stripe_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sys

from zebra.signals import WEBHOOK_MAP

try:
import json
except ImportError:
from django.utils import simplejson as json

from django.core.management.base import BaseCommand, CommandError

class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('webhook', metavar='webhook',
help="Webhook to test")
parser.add_argument('filenames', nargs='+', metavar='filename',
help="Filenames to read data from")

def handle(self, *args, **options):
for filename in options['filenames']:
if filename == '-':
data = sys.stdin.read()
else:
with open(filename) as f:
data = f.read()

full_json = json.loads(data)

signal_name = full_json['type'].replace('.', '_')

try:
signal = WEBHOOK_MAP[signal_name]
except KeyError:
raise CommandError(
"'%s' is not a valid signal name" % signal_name,
)

signal.send(sender=None, full_json=full_json)