Skip to content

Commit

Permalink
fix: not found receipt link
Browse files Browse the repository at this point in the history
  • Loading branch information
igobranco committed Apr 4, 2024
1 parent 4d1137e commit 0869cda
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
8 changes: 5 additions & 3 deletions nau_extensions/financial_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,18 @@ def get_receipt_link(order):
receipt_link_url += transaction_id + '/'
token = _get_financial_manager_setting(site, "token")
try:
logger.info("Get receipt link for transaction id [%s]", transaction_id)
response = requests.post(
receipt_link_url,
headers={"Authorization": token},
timeout=10,
)
except Exception as e: # pylint: disable=broad-except
logger.exception("Error can't get receipt link for transaction_id [%s] error: [%s]", transaction_id, e)
return None
finally:
content = response.content()
logger.info("Get receipt link status: [%d] response: [%s]", response.status_code, content)
logger.info("Received the receipt link status_code: [%d]")
if response.status_code == 200:
return content
logger.info("Received the receipt link content: [%s]", response.content)
return response.content
return None
1 change: 1 addition & 0 deletions nau_extensions/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def json(self):
"""
return self.json_data

@property
def content(self):
"""
The Json data
Expand Down
47 changes: 46 additions & 1 deletion nau_extensions/tests/test_financial_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def test_send_to_financial_manager_without_basket_billing_information(self):
json_data="https://example.com/somereceipt.pdf",
status_code=200,
))
def test_get_receipt_link(self, mock_fm_receipt_link):
def test_get_receipt_link_found(self, mock_fm_receipt_link):
"""
Test the `get_receipt_link` method.
"""
Expand Down Expand Up @@ -489,3 +489,48 @@ def test_get_receipt_link(self, mock_fm_receipt_link):
mock_fm_receipt_link.assert_called_once_with(f"https://finacial-manager.example.com/api/billing/receipt-link/{basket.order_number}/", headers={'Authorization': 'a-very-long-token'}, timeout=10)

self.assertEqual(link, "https://example.com/somereceipt.pdf")

@override_settings(
NAU_FINANCIAL_MANAGER={
"edx": {
"receipt-link-url": "https://finacial-manager.example.com/api/billing/receipt-link/",
"token": "a-very-long-token",
},
},
)
@mock.patch.object(requests, "post", return_value=MockResponse(
status_code=404,
))
def test_get_receipt_link_not_found(self, mock_fm_receipt_link):
"""
Test the `get_receipt_link` method.
"""
partner = PartnerFactory(short_code="edX")

site_configuration = SiteConfigurationFactory(partner=partner)
site_configuration.site = SiteFactory(name="openedx")
site = site_configuration.site

course = CourseFactory(
id="course-v1:edX+DemoX+Demo_Course",
name="edX Demonstration Course",
partner=partner,
)
honor_product = course.create_or_update_seat("honor", False, 0)
verified_product = course.create_or_update_seat("verified", True, 10)

owner = UserFactory(email="[email protected]")

# create an empty basket so we know what it's inside
basket = create_basket(owner=owner, empty=True, site=site)
basket.add_product(verified_product)
basket.add_product(honor_product)
basket.save()

# creating an order will mark the card submitted
order = create_order(basket=basket)

link = get_receipt_link(order)
mock_fm_receipt_link.assert_called_once_with(f"https://finacial-manager.example.com/api/billing/receipt-link/{basket.order_number}/", headers={'Authorization': 'a-very-long-token'}, timeout=10)

self.assertEqual(link, None)

0 comments on commit 0869cda

Please sign in to comment.