Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

fix: Added logs for ios refund exception #4040

Merged
merged 5 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions ecommerce/extensions/iap/api/v1/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ERROR_ALREADY_PURCHASED = "You have already purchased these products"
ERROR_BASKET_NOT_FOUND = "Basket [{}] not found."
ERROR_BASKET_ID_NOT_PROVIDED = "Basket id is not provided"
ERROR_DURING_IOS_REFUND_EXECUTION = "Could not execute IOS refund."
ERROR_DURING_ORDER_CREATION = "An error occurred during order creation."
ERROR_DURING_PAYMENT_HANDLING = "An error occurred during payment handling."
ERROR_ORDER_NOT_FOUND_FOR_REFUND = "Could not find any order to refund for [%s] by processor [%s]"
Expand Down
30 changes: 28 additions & 2 deletions ecommerce/extensions/iap/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
ERROR_ALREADY_PURCHASED,
ERROR_BASKET_ID_NOT_PROVIDED,
ERROR_BASKET_NOT_FOUND,
ERROR_DURING_IOS_REFUND_EXECUTION,
ERROR_DURING_ORDER_CREATION,
ERROR_DURING_PAYMENT_HANDLING,
ERROR_DURING_POST_ORDER_OP,
Expand Down Expand Up @@ -923,7 +924,7 @@ class IOSRefundTests(BaseRefundTests):
processor_name = IOSIAP.NAME

def assert_error_response(self, response):
""" Assert the response has HTTP status 200 and no data. """
""" Assert the response has HTTP status 500 and no data. """
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)

def check_record_not_found_log(self, logger, msg_t):
Expand Down Expand Up @@ -992,7 +993,7 @@ def test_valid_orders(self):

def test_non_refund_notification(self):
"""
View should create a refund if an order/line are found eligible for refund.
View should ignore non refund notifications
"""

with mock.patch.object(asn2, 'parse') as mock_ios_response_parse,\
Expand All @@ -1015,3 +1016,28 @@ def test_non_refund_notification(self):
IGNORE_NON_REFUND_NOTIFICATION_FROM_APPLE
)
)

def test_unknown_error_in_parsing_or_refund(self):
"""
If there is any other error in parsing or executing refund, View should log it and return 500.
"""

with mock.patch.object(asn2, 'parse') as mock_ios_response_parse, \
LogCapture(self.logger_name) as logger:

mock_ios_response_parse.side_effect = Exception("Test Exception")

response = self.client.post(self.path)
self.assert_error_response(response)
logger.check(
(
self.logger_name,
'ERROR',
ERROR_DURING_IOS_REFUND_EXECUTION
),
(
self.logger_name,
'ERROR',
"Test Exception"
),
)
6 changes: 4 additions & 2 deletions ecommerce/extensions/iap/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
ERROR_ALREADY_PURCHASED,
ERROR_BASKET_ID_NOT_PROVIDED,
ERROR_BASKET_NOT_FOUND,
ERROR_DURING_IOS_REFUND_EXECUTION,
ERROR_DURING_ORDER_CREATION,
ERROR_DURING_PAYMENT_HANDLING,
ERROR_DURING_POST_ORDER_OP,
Expand Down Expand Up @@ -359,8 +360,9 @@ def post(self, request):
logger.info(IGNORE_NON_REFUND_NOTIFICATION_FROM_APPLE)
return Response(status=status.HTTP_200_OK)

except Exception: # pylint: disable=broad-except
pass
except Exception as e: # pylint: disable=broad-except
logger.error(ERROR_DURING_IOS_REFUND_EXECUTION)
logger.error(e)

status_code = status.HTTP_200_OK if is_refunded else status.HTTP_500_INTERNAL_SERVER_ERROR
return Response(status=status_code)
Loading