Skip to content

Commit 9e074af

Browse files
author
Umar Asghar
authored
fix Cybersource cancellation or success redirect failures (#5116)
fix Cybersource cancellation or success redirect failures
1 parent 164e2b4 commit 9e074af

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

Diff for: ecommerce/urls.py

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
CouponsView,
66
OrderFulfillmentView,
77
UserCouponsView,
8+
PaymentCallBackView
89
)
910

1011
urlpatterns = [
@@ -16,4 +17,5 @@
1617
name='coupon-user-create',
1718
),
1819
url(r'^api/v0/order_fulfillment/$', OrderFulfillmentView.as_view(), name='order-fulfillment'),
20+
url(r'^payment-callback/$', PaymentCallBackView.as_view(), name='payment-callback'),
1921
]

Diff for: ecommerce/views.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django.db import transaction
88
from django.http.response import Http404
99
from django.shortcuts import get_object_or_404
10+
from django.views.generic.base import RedirectView
1011
from ipware import get_client_ip
1112
from rest_framework.authentication import SessionAuthentication, TokenAuthentication
1213
from rest_framework.exceptions import ValidationError
@@ -44,6 +45,7 @@
4445
)
4546
from ecommerce.serializers import CouponSerializer
4647
from mail.api import MailgunClient
48+
from ui.url_utils import DASHBOARD_URL, PAYMENT_CALL_BACK_URL
4749

4850
log = logging.getLogger(__name__)
4951

@@ -80,7 +82,7 @@ def post(self, request, *args, **kwargs): # pylint: disable=unused-argument
8082
)
8183
if course_run.course.program.financial_aid_availability:
8284
order = create_unfulfilled_order(course_id, request.user)
83-
dashboard_url = request.build_absolute_uri('/dashboard/')
85+
payment_callback_url = request.build_absolute_uri(PAYMENT_CALL_BACK_URL)
8486
if order.total_price_paid == 0:
8587
# If price is $0, don't bother going to CyberSource, just mark as fulfilled
8688
order.status = Order.FULFILLED
@@ -112,11 +114,11 @@ def post(self, request, *args, **kwargs): # pylint: disable=unused-argument
112114

113115
# This redirects the user to our order success page
114116
payload = {}
115-
url = make_dashboard_receipt_url(dashboard_url, course_id, 'receipt')
117+
url = make_dashboard_receipt_url(payment_callback_url, course_id, 'receipt')
116118
method = 'GET'
117119
else:
118120
# This generates a signed payload which is submitted as an HTML form to CyberSource
119-
payload = generate_cybersource_sa_payload(order, dashboard_url, user_ip)
121+
payload = generate_cybersource_sa_payload(order, payment_callback_url, user_ip)
120122
url = settings.CYBERSOURCE_SECURE_ACCEPTANCE_URL
121123
method = 'POST'
122124
else:
@@ -275,3 +277,11 @@ def post(self, request, code, *args, **kwargs): # pylint: disable=unused-argume
275277
'coupon': CouponSerializer(coupon).data,
276278
}
277279
)
280+
281+
282+
class PaymentCallBackView(RedirectView):
283+
"""
284+
payment callback view that will redirect to dashboard url
285+
"""
286+
url = DASHBOARD_URL
287+
query_string = True

Diff for: ecommerce/views_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_creates_order(self):
131131
assert create_mock.call_count == 1
132132
assert create_mock.call_args[0] == (course_run.edx_course_key, user)
133133
assert generate_mock.call_count == 1
134-
assert generate_mock.call_args[0] == (order, 'http://testserver/dashboard/', fake_ip)
134+
assert generate_mock.call_args[0] == (order, 'http://testserver/payment-callback/', fake_ip)
135135

136136
@override_settings(EDXORG_BASE_URL='http://edx_base')
137137
def test_provides_edx_link(self):
@@ -180,7 +180,7 @@ def test_zero_price_checkout(self):
180180
assert resp.status_code == status.HTTP_200_OK
181181
assert resp.json() == {
182182
'payload': {},
183-
'url': 'http://testserver/dashboard/?status=receipt&course_key={}'.format(
183+
'url': 'http://testserver/payment-callback/?status=receipt&course_key={}'.format(
184184
quote_plus(course_run.edx_course_key)
185185
),
186186
'method': 'GET',
@@ -223,7 +223,7 @@ def test_zero_price_checkout_failed_enroll(self):
223223
assert resp.status_code == status.HTTP_200_OK
224224
assert resp.json() == {
225225
'payload': {},
226-
'url': 'http://testserver/dashboard/?status=receipt&course_key={}'.format(
226+
'url': 'http://testserver/payment-callback/?status=receipt&course_key={}'.format(
227227
quote_plus(course_run.edx_course_key)
228228
),
229229
'method': 'GET',

Diff for: ui/url_utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
SEARCH_URL = "/learners/"
1212
ORDER_SUMMARY = "/order_summary/"
1313
EMAIL_URL = "/automaticemails/"
14+
PAYMENT_CALL_BACK_URL = "/payment-callback/"
1415

1516
DASHBOARD_URLS = [
1617
DASHBOARD_URL,

0 commit comments

Comments
 (0)