-
Notifications
You must be signed in to change notification settings - Fork 3
feat: adding new canceled field to stripe event summary view #35
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7fb3ac0
feat: adding new canceled field to stripe event summary view
kiram15 c8f7102
fix: copilot review
kiram15 d6b6688
Merge branch 'main' into kiram15/ENT-11295
kiram15 bd3110a
fix: PR requests
kiram15 b8188cc
Merge branch 'main' into kiram15/ENT-11295
kiram15 964a5c0
fix: more stuff I forgot the first time
kiram15 5e05d91
Merge branch 'kiram15/ENT-11295' of github.com:edx/enterprise-access …
kiram15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -604,17 +604,54 @@ def list(self, request, *args, **kwargs): | |
| ) | ||
| def first_upcoming_invoice_amount_due(self, request, *args, **kwargs): | ||
| """ | ||
| Given a license-manager SubscriptionPlan uuid, returns an upcoming | ||
| invoice amount due, dervied from Stripe's preview invoice API. | ||
| Deprecated first-invoice-upcoming-amount-due endpoint. | ||
|
|
||
| Temporary passthrough to aid with transitioning to get-stripe-subscription-plan-info. | ||
| """ | ||
| return self.get_stripe_subscription_plan_info(request, *args, **kwargs) | ||
|
|
||
| @action( | ||
| detail=False, | ||
| methods=['get'], | ||
| url_path='get-stripe-subscription-plan-info', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, to mitigate deployment risk I think we could introduce a simple passthrough: @action(
detail=False,
methods=['get'],
url_path='first-invoice-upcoming-amount-due',
)
def first_upcoming_invoice_amount_due(self, request, *args, **kwargs):
"""
Deprecated first-invoice-upcoming-amount-due endpoint.
Temporary passthrough to aid with transitioning to get-stripe-subscription-plan-info.
"""
return self.get_stripe_subscription_plan_info(request, *args, **kwargs) |
||
| ) | ||
| def get_stripe_subscription_plan_info(self, request, *args, **kwargs): | ||
|
kiram15 marked this conversation as resolved.
|
||
| """ | ||
| Given a license-manager SubscriptionPlan uuid, returns information needed for the | ||
| Subscription management page on admin portal, like the upcoming subscription price | ||
| and if the subscription has been cancelled | ||
|
kiram15 marked this conversation as resolved.
|
||
| """ | ||
| subscription_plan_uuid = self.request.query_params.get('subscription_plan_uuid') | ||
|
kiram15 marked this conversation as resolved.
|
||
| summary = StripeEventSummary.objects.filter( | ||
| if not subscription_plan_uuid: | ||
| raise exceptions.ValidationError(detail='subscription_plan_uuid query param is required') | ||
| subscription_plan_uuid = self.request.query_params.get('subscription_plan_uuid') | ||
| created_event_summary = StripeEventSummary.objects.filter( | ||
| event_type='customer.subscription.created', | ||
| subscription_plan_uuid=subscription_plan_uuid, | ||
| ).first() | ||
| if not (subscription_plan_uuid and summary): | ||
| ).order_by('-stripe_event_created_at').first() | ||
| updated_event_summary = StripeEventSummary.objects.filter( | ||
| event_type='customer.subscription.updated', | ||
| subscription_plan_uuid=subscription_plan_uuid, | ||
| ).order_by('-stripe_event_created_at').first() | ||
|
|
||
| canceled_date, currency, upcoming_invoice_amount_due = None, None, None | ||
|
|
||
| if updated_event_summary: | ||
| canceled_date = updated_event_summary.subscription_cancel_at | ||
|
|
||
| if created_event_summary: | ||
| currency = created_event_summary.currency | ||
| upcoming_invoice_amount_due = created_event_summary.upcoming_invoice_amount_due | ||
|
|
||
| response_serializer = serializers.StripeSubscriptionPlanInfoResponseSerializer( | ||
| data={ | ||
| 'upcoming_invoice_amount_due': upcoming_invoice_amount_due, | ||
| 'currency': currency, | ||
| 'canceled_date': canceled_date, | ||
| }, | ||
| ) | ||
| if not (subscription_plan_uuid and (updated_event_summary or created_event_summary)): | ||
| return Response({}) | ||
| return Response({ | ||
| 'upcoming_invoice_amount_due': summary.upcoming_invoice_amount_due, | ||
| 'currency': summary.currency, | ||
| }) | ||
| if not response_serializer.is_valid(): | ||
| return HttpResponseServerError() | ||
| return Response(response_serializer.data, status=status.HTTP_200_OK) | ||
|
kiram15 marked this conversation as resolved.
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field type has been changed from IntegerField to CharField. In the model (StripeEventSummary), upcoming_invoice_amount_due is defined as an IntegerField storing amounts in cents. Converting this to a CharField in the response serializer will change the API response format from an integer to a string, which is a breaking change for API consumers.
Unless there's a specific requirement for string representation (e.g., to support very large numbers or decimal precision), this should remain as an IntegerField to maintain API compatibility. If the change is intentional, it should be documented as a breaking change.