From 05d0843caa070d89def0d203236fc6482b6f45a2 Mon Sep 17 00:00:00 2001
From: Ali-Arbisoft <ali.salman@edly.io>
Date: Tue, 2 Nov 2021 10:53:28 +0500
Subject: [PATCH 1/2] Updated files to integrate authorizenet notifications

---
 common/djangoapps/student/views/dashboard.py | 24 ++++++++++++++++++--
 lms/static/sass/multicourse/_dashboard.scss  |  1 +
 lms/templates/dashboard.html                 |  8 +++++++
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/common/djangoapps/student/views/dashboard.py b/common/djangoapps/student/views/dashboard.py
index a0ba7af57823..ab3b363d2c59 100644
--- a/common/djangoapps/student/views/dashboard.py
+++ b/common/djangoapps/student/views/dashboard.py
@@ -5,6 +5,7 @@
 
 import datetime
 import logging
+import base64
 from collections import defaultdict
 
 from django.conf import settings
@@ -34,6 +35,7 @@
     get_pseudo_session_for_entitlement,
     get_visible_sessions_for_entitlement
 )
+from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
 from openedx.core.djangoapps.credit.email_utils import get_credit_provider_attribute_values, make_providers_strings
 from openedx.core.djangoapps.plugins.constants import ProjectType
 from openedx.core.djangoapps.programs.models import ProgramsApiConfig
@@ -490,6 +492,7 @@ def student_dashboard(request):  # lint-amnesty, pylint: disable=too-many-statem
         The dashboard response.
 
     """
+    ECOMMERCE_TRANSACTION_COOKIE_NAME = "pendingTransactionCourse"
     user = request.user
     if not UserProfile.objects.filter(user=user).exists():
         return redirect(reverse('account_settings'))
@@ -740,7 +743,7 @@ def student_dashboard(request):  # lint-amnesty, pylint: disable=too-many-statem
         course_enrollments = [
             enr for enr in course_enrollments if entitlement.enrollment_course_run.course_id != enr.course_id
         ]
-
+    
     context = {
         'urls': urls,
         'programs_data': programs_data,
@@ -810,6 +813,18 @@ def student_dashboard(request):  # lint-amnesty, pylint: disable=too-many-statem
             user,
         )
     )
+
+    # Retrieve pendingTransactionCourse cookie to show waiting alert to the learner. It conatain encrypted
+    # course_id for which AuthorizeNet transaction has been perfromed but notification is yet to be received.
+    transaction_hash = request.COOKIES.get(ECOMMERCE_TRANSACTION_COOKIE_NAME)
+    if transaction_hash:
+        decoded_course_id = base64.b64decode(transaction_hash[2:-1]).decode("utf-8")
+        transaction_course_id = CourseKey.from_string(decoded_course_id)
+        pending_transaction_course_name = CourseOverview.get_from_id(transaction_course_id).display_name
+        context.update({
+            'pending_upgrade_course_name': pending_transaction_course_name,
+        })
+
     if ecommerce_service.is_enabled(request.user):
         context.update({
             'use_ecommerce_payment_flow': True,
@@ -826,4 +841,9 @@ def student_dashboard(request):  # lint-amnesty, pylint: disable=too-many-statem
         'resume_button_urls': resume_button_urls
     })
 
-    return render_to_response('dashboard.html', context)
+    response = render_to_response('dashboard.html', context)
+    if transaction_hash:
+        response.delete_cookie(
+            ECOMMERCE_TRANSACTION_COOKIE_NAME, domain='localhost')
+
+    return response
diff --git a/lms/static/sass/multicourse/_dashboard.scss b/lms/static/sass/multicourse/_dashboard.scss
index 7d2161d196a3..5314fb4e6499 100644
--- a/lms/static/sass/multicourse/_dashboard.scss
+++ b/lms/static/sass/multicourse/_dashboard.scss
@@ -1506,6 +1506,7 @@ a.fade-cover {
   width: flex-grid(12);
 }
 
+.course-upgrade,
 .account-activation {
   .message-copy {
     position: relative;
diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html
index 5369df1551a5..2216233b0e30 100644
--- a/lms/templates/dashboard.html
+++ b/lms/templates/dashboard.html
@@ -140,6 +140,14 @@
       </div>
     %endif
 
+    %if pending_upgrade_course_name:
+    <div class="course-upgrade aa-icon info" role="alert">
+      <div class="message-copy" >
+        Please wait for the confirmation email as your request is being processed. Course: ${ pending_upgrade_course_name } will be upgraded soon.
+      </div>
+    </div>
+    %endif
+
 </div>
 
 <main id="main" aria-label="Content" tabindex="-1">

From ee5ffab313bcb5b60da711071b728593ac2873a4 Mon Sep 17 00:00:00 2001
From: Ali-Arbisoft <ali.salman@edly.io>
Date: Fri, 5 Nov 2021 16:48:35 +0500
Subject: [PATCH 2/2] Updated files based on suggestions

---
 common/djangoapps/student/views/dashboard.py | 7 +++----
 lms/envs/common.py                           | 2 ++
 lms/envs/production.py                       | 2 ++
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/common/djangoapps/student/views/dashboard.py b/common/djangoapps/student/views/dashboard.py
index ab3b363d2c59..2dfc45810bda 100644
--- a/common/djangoapps/student/views/dashboard.py
+++ b/common/djangoapps/student/views/dashboard.py
@@ -492,7 +492,6 @@ def student_dashboard(request):  # lint-amnesty, pylint: disable=too-many-statem
         The dashboard response.
 
     """
-    ECOMMERCE_TRANSACTION_COOKIE_NAME = "pendingTransactionCourse"
     user = request.user
     if not UserProfile.objects.filter(user=user).exists():
         return redirect(reverse('account_settings'))
@@ -743,7 +742,7 @@ def student_dashboard(request):  # lint-amnesty, pylint: disable=too-many-statem
         course_enrollments = [
             enr for enr in course_enrollments if entitlement.enrollment_course_run.course_id != enr.course_id
         ]
-    
+
     context = {
         'urls': urls,
         'programs_data': programs_data,
@@ -816,7 +815,7 @@ def student_dashboard(request):  # lint-amnesty, pylint: disable=too-many-statem
 
     # Retrieve pendingTransactionCourse cookie to show waiting alert to the learner. It conatain encrypted
     # course_id for which AuthorizeNet transaction has been perfromed but notification is yet to be received.
-    transaction_hash = request.COOKIES.get(ECOMMERCE_TRANSACTION_COOKIE_NAME)
+    transaction_hash = request.COOKIES.get(settings.ECOMMERCE_TRANSACTION_COOKIE_NAME)
     if transaction_hash:
         decoded_course_id = base64.b64decode(transaction_hash[2:-1]).decode("utf-8")
         transaction_course_id = CourseKey.from_string(decoded_course_id)
@@ -844,6 +843,6 @@ def student_dashboard(request):  # lint-amnesty, pylint: disable=too-many-statem
     response = render_to_response('dashboard.html', context)
     if transaction_hash:
         response.delete_cookie(
-            ECOMMERCE_TRANSACTION_COOKIE_NAME, domain='localhost')
+            settings.ECOMMERCE_TRANSACTION_COOKIE_NAME, domain=settings.SESSION_COOKIE_DOMAIN)
 
     return response
diff --git a/lms/envs/common.py b/lms/envs/common.py
index e96abbd0f585..6b082c6a06f7 100644
--- a/lms/envs/common.py
+++ b/lms/envs/common.py
@@ -4708,3 +4708,5 @@ def _make_locale_paths(settings):  # pylint: disable=missing-function-docstring
 ################# Settings for Chrome-specific origin trials ########
 # Token for " Disable Different Origin Subframe Dialog Suppression" for http://localhost:18000
 CHROME_DISABLE_SUBFRAME_DIALOG_SUPPRESSION_TOKEN = 'ArNBN7d1AkvMhJTGWXlJ8td/AN4lOokzOnqKRNkTnLqaqx0HpfYvmx8JePPs/emKh6O5fckx14LeZIGJ1AQYjgAAAABzeyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjE4MDAwIiwiZmVhdHVyZSI6IkRpc2FibGVEaWZmZXJlbnRPcmlnaW5TdWJmcmFtZURpYWxvZ1N1cHByZXNzaW9uIiwiZXhwaXJ5IjoxNjM5NTI2Mzk5fQ=='  # pylint: disable=line-too-long
+
+ECOMMERCE_TRANSACTION_COOKIE_NAME = 'pendingTransactionCourse'
diff --git a/lms/envs/production.py b/lms/envs/production.py
index 135ff904759a..cd36993ef3f0 100644
--- a/lms/envs/production.py
+++ b/lms/envs/production.py
@@ -1031,3 +1031,5 @@ def get_env_setting(setting):
 CHROME_DISABLE_SUBFRAME_DIALOG_SUPPRESSION_TOKEN = ENV_TOKENS.get(
     'CHROME_DISABLE_SUBFRAME_DIALOG_SUPPRESSION_TOKEN', CHROME_DISABLE_SUBFRAME_DIALOG_SUPPRESSION_TOKEN
 )
+
+ECOMMERCE_TRANSACTION_COOKIE_NAME = 'pendingTransactionCourse'