Skip to content

Commit

Permalink
Return 200 code on unknown subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan committed Apr 6, 2023
1 parent ab0259e commit 9f57f74
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.36] - 2023-04-06

### Fixed

- Minor bugs [@AivGitHub](https://github.com/AivGitHub/).

## [0.0.35] - 2023-04-06

### Improved
Expand Down
8 changes: 8 additions & 0 deletions api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ def __init__(self, detail=None):
if detail is None:
detail = 'Not authenticated'
super().__init__(detail=detail, code=status.HTTP_401_UNAUTHORIZED)


class FeatureNotReady(BaseCustomException):
def __init__(self, detail=None):
if detail is None:
detail = 'Not implemented'
# Should be ``status.HTTP_501_NOT_IMPLEMENTED``, but webhook requires 200-299 response code.
super().__init__(detail=detail, code=status.HTTP_200_OK)
12 changes: 11 additions & 1 deletion api/v1/services.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from api.exceptions import FeatureNotReady
from payments.core import stripe
from payments.models import get_payment_instance, Subscription

Expand All @@ -15,7 +16,16 @@ def process_post_request(self):
self.customer_subscription_updated()

def customer_subscription_updated(self):
payment_instance = Subscription.objects.get(psp_id=self.event.data.object.id)
try:
payment_instance = Subscription.objects.get(psp_id=self.event.data.object.id)
except Subscription.DoesNotExist:
# It can be in case payment was declined or something similar.
# For now, it's not important, subscription not created locally, because payment is no successful.
# I have no time to implement proper webhook handler.
# TODO: https://github.com/AivGitHub/brosfiles/issues/4 task for webhook handler.
# I would appreciate any help in this.
raise FeatureNotReady()

payment_instance.update_from_event(self.event)

def checkout_session_completed(self):
Expand Down

0 comments on commit 9f57f74

Please sign in to comment.