Skip to content

Commit

Permalink
Merge pull request openedx#34818 from openedx/gmartin/cc-logging
Browse files Browse the repository at this point in the history
fix: adding additional logging to commerce handle_refund_order
  • Loading branch information
grmartin committed May 17, 2024
2 parents 4c0623b + 20c8fc1 commit 73231ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions common/djangoapps/student/views/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ def change_enrollment(request, check_access=True):
except UnenrollmentNotAllowed as exc:
return HttpResponseBadRequest(str(exc))

log.info("User %s unenrolled from %s; sending REFUND_ORDER", user.username, course_id)
REFUND_ORDER.send(sender=None, course_enrollment=enrollment)
return HttpResponse()
else:
Expand Down
18 changes: 16 additions & 2 deletions lms/djangoapps/commerce/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Signal handling functions for use with external commerce service.
"""


import logging

from crum import get_current_request
Expand All @@ -21,13 +20,15 @@
@receiver(REFUND_ORDER)
def handle_refund_order(sender, course_enrollment=None, **kwargs):
"""
Signal receiver for unenrollments, used to automatically initiate refunds
Signal receiver for un-enrollments, used to automatically initiate refunds
when applicable.
"""
if not is_commerce_service_configured():
log.info("Commerce service not configured, skipping refund")
return

if course_enrollment and course_enrollment.refundable():
log.info("Handling refund for course enrollment %s", course_enrollment.course_id)
try:
request_user = get_request_user() or course_enrollment.user
if isinstance(request_user, AnonymousUser):
Expand All @@ -36,7 +37,13 @@ def handle_refund_order(sender, course_enrollment=None, **kwargs):
# construct a client to call Otto back anyway, because
# the client does not work anonymously, and furthermore,
# there's certainly no need to inform Otto about this request.
log.info(
"Anonymous user attempting to initiate refund for course [%s]",
course_enrollment.course_id,
)
return
log.info("Initiating refund_seat for user [%s] for course enrollment %s",
course_enrollment.user.id, course_enrollment.course_id)
refund_seat(course_enrollment, change_mode=True)
except Exception: # pylint: disable=broad-except
# don't assume the signal was fired with `send_robust`.
Expand All @@ -47,6 +54,13 @@ def handle_refund_order(sender, course_enrollment=None, **kwargs):
course_enrollment.user.id,
course_enrollment.course_id,
)
elif course_enrollment:
log.info(
"Not refunding seat for course enrollment %s, as its not refundable",
course_enrollment.course_id
)
else:
log.info("Not refunding seat for course due to missing course enrollment")


def get_request_user():
Expand Down

0 comments on commit 73231ed

Please sign in to comment.