Skip to content
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
2 changes: 1 addition & 1 deletion ecommerce/views/legacy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ def post_checkout_redirect(self, order_state, order, request):
reverse("user-dashboard"),
{
"type": USER_MSG_TYPE_PAYMENT_ACCEPTED,
"run": order.lines.first().purchased_object.course.title,
"run": order.lines.first().courseware,
},
)
else:
Expand Down
50 changes: 50 additions & 0 deletions ecommerce/views/legacy/views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
USER_MSG_COOKIE_NAME,
USER_MSG_TYPE_COURSE_NON_UPGRADABLE,
USER_MSG_TYPE_ENROLL_DUPLICATED,
USER_MSG_TYPE_PAYMENT_ACCEPTED,
USER_MSG_TYPE_PAYMENT_ACCEPTED_NOVALUE,
)
from main.settings import TIME_ZONE
Expand Down Expand Up @@ -1114,6 +1115,55 @@ def test_checkout_api_result_verification_failure(
assert resp.status_code == 403


@pytest.mark.skip_nplusone_check
def test_checkout_api_result_program_accept(
settings,
user,
user_client,
mocker,
):
"""
Tests that an ACCEPT response from CyberSource works for a program product,
i.e., does not raise AttributeError accessing .course on a Program object.
"""
settings.OPENEDX_SERVICE_WORKER_API_TOKEN = "mock_api_token" # noqa: S105
mocker.patch(
"mitol.payment_gateway.api.PaymentGateway.validate_processor_response",
return_value=True,
)

program = ProgramFactory.create()
with reversion.create_revision():
product = ProductFactory.create(purchasable_object=program)

basket = create_basket_with_product(user, product)

resp = user_client.post(reverse("checkout_api-start_checkout"))
assert resp.status_code == 200

payload = resp.json()["payload"]
payload = {
**{f"req_{key}": value for key, value in payload.items()},
"decision": "ACCEPT",
"message": "payment processor message",
"transaction_id": "12345",
}

resp = user_client.post(reverse("checkout-result-callback"), payload)

assert resp.status_code == 302

order = Order.objects.get(state=OrderStatus.FULFILLED, purchaser=user)
assert USER_MSG_COOKIE_NAME in resp.cookies
assert resp.cookies[USER_MSG_COOKIE_NAME].value == encode_json_cookie_value(
{
"type": USER_MSG_TYPE_PAYMENT_ACCEPTED,
"run": order.lines.first().courseware,
}
)
assert not Basket.objects.filter(id=basket.id).exists()


@pytest.mark.skip_nplusone_check
@pytest.mark.parametrize(
"upgrade_deadline, status_code", # noqa: PT006
Expand Down