-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ivan
committed
Mar 28, 2023
1 parent
f91333d
commit 1033eb3
Showing
6 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.urls import path, include | ||
|
||
urlpatterns = [ | ||
path('v1/', include('api.v1.urls'), name='v1'), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.urls import path | ||
|
||
from api.v1.views import StripeWebhook | ||
|
||
urlpatterns = [ | ||
path('webhooks/stripe/', StripeWebhook.as_view(), name='stripe_webhook'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from http import HTTPStatus | ||
import json | ||
|
||
from django.conf import settings | ||
from django.core.exceptions import PermissionDenied | ||
from django.http import HttpResponse | ||
from django.utils.decorators import method_decorator | ||
from django.views import View | ||
from django.views.decorators.csrf import csrf_exempt | ||
|
||
import stripe | ||
|
||
|
||
@method_decorator(csrf_exempt, name='dispatch') | ||
class StripeWebhook(View): | ||
def post(self, request, *args, **kwargs): | ||
try: | ||
sig_header = request.headers['Stripe-Signature'] | ||
except KeyError: | ||
return HttpResponse(status=HTTPStatus.FORBIDDEN) | ||
|
||
try: | ||
event = stripe.Webhook.construct_event( | ||
request.body, sig_header, settings.STRIPE_ENDPOINT_SECRET | ||
) | ||
except ValueError as e: | ||
raise PermissionDenied() | ||
except stripe.error.SignatureVerificationError as verification_err: | ||
return HttpResponse(status=HTTPStatus.FORBIDDEN) | ||
|
||
return HttpResponse(status=HTTPStatus.OK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters