Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
7ec89829
Commit
7ec89829
authored
Sep 06, 2016
by
PaulWattenberger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass Sailthru campaign id cookie to ecommerce
parent
33ae93ec
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
3 deletions
+23
-3
lms/djangoapps/commerce/api/v0/tests/test_views.py
+7
-0
lms/djangoapps/commerce/api/v0/views.py
+13
-1
openedx/core/djangoapps/commerce/utils.py
+3
-2
No files found.
lms/djangoapps/commerce/api/v0/tests/test_views.py
View file @
7ec89829
...
...
@@ -3,6 +3,7 @@ from datetime import datetime, timedelta
import
json
import
itertools
from
uuid
import
uuid4
import
httpretty
import
ddt
from
django.conf
import
settings
...
...
@@ -28,6 +29,7 @@ from student.models import CourseEnrollment
from
student.tests.factories
import
CourseModeFactory
from
student.tests.tests
import
EnrollmentEventTestMixin
from
xmodule.modulestore.django
import
modulestore
from
commerce.api.v0.views
import
SAILTHRU_CAMPAIGN_COOKIE
@attr
(
shard
=
1
)
...
...
@@ -51,6 +53,8 @@ class BasketsViewTests(EnrollmentEventTestMixin, UserMixin, ModuleStoreTestCase)
}
if
marketing_email_opt_in
:
payload
[
"email_opt_in"
]
=
True
self
.
client
.
cookies
[
SAILTHRU_CAMPAIGN_COOKIE
]
=
'sailthru id'
return
self
.
client
.
post
(
self
.
url
,
payload
)
def
assertResponseMessage
(
self
,
response
,
expected_msg
):
...
...
@@ -173,6 +177,9 @@ class BasketsViewTests(EnrollmentEventTestMixin, UserMixin, ModuleStoreTestCase)
else
:
self
.
assertResponsePaymentData
(
response
)
# make sure ecommerce API call forwards Sailthru cookie
self
.
assertIn
(
'{}=sailthru id'
.
format
(
SAILTHRU_CAMPAIGN_COOKIE
),
httpretty
.
last_request
()
.
headers
[
'cookie'
])
@ddt.data
(
True
,
False
)
def
test_course_with_honor_seat_sku
(
self
,
user_is_active
):
"""
...
...
lms/djangoapps/commerce/api/v0/views.py
View file @
7ec89829
""" API v0 views. """
import
logging
import
requests
from
edx_rest_api_client
import
exceptions
from
opaque_keys
import
InvalidKeyError
...
...
@@ -26,6 +27,7 @@ from util.json_request import JsonResponse
log
=
logging
.
getLogger
(
__name__
)
SAILTHRU_CAMPAIGN_COOKIE
=
'sailthru_bid'
class
BasketsView
(
APIView
):
...
...
@@ -135,7 +137,8 @@ class BasketsView(APIView):
# Setup the API
try
:
api
=
ecommerce_api_client
(
user
)
api_session
=
requests
.
Session
()
api
=
ecommerce_api_client
(
user
,
session
=
api_session
)
except
ValueError
:
self
.
_enroll
(
course_key
,
user
)
msg
=
Messages
.
NO_ECOM_API
.
format
(
username
=
user
.
username
,
course_id
=
unicode
(
course_key
))
...
...
@@ -146,6 +149,15 @@ class BasketsView(APIView):
# Make the API call
try
:
# Pass along Sailthru campaign id
campaign_cookie
=
request
.
COOKIES
.
get
(
SAILTHRU_CAMPAIGN_COOKIE
)
if
campaign_cookie
:
cookie
=
{
SAILTHRU_CAMPAIGN_COOKIE
:
campaign_cookie
}
if
api_session
.
cookies
:
requests
.
utils
.
add_dict_to_cookiejar
(
api_session
.
cookies
,
cookie
)
else
:
api_session
.
cookies
=
requests
.
utils
.
cookiejar_from_dict
(
cookie
)
response_data
=
api
.
baskets
.
post
({
'products'
:
[{
'sku'
:
default_enrollment_mode
.
sku
}],
'checkout'
:
True
,
...
...
openedx/core/djangoapps/commerce/utils.py
View file @
7ec89829
...
...
@@ -32,7 +32,7 @@ def is_commerce_service_configured():
return
bool
(
ecommerce_api_url
and
ecommerce_api_signing_key
)
def
ecommerce_api_client
(
user
):
def
ecommerce_api_client
(
user
,
session
=
None
):
""" Returns an E-Commerce API client setup with authentication for the specified user. """
jwt_auth
=
configuration_helpers
.
get_value
(
"JWT_AUTH"
,
settings
.
JWT_AUTH
)
return
EdxRestApiClient
(
...
...
@@ -43,5 +43,6 @@ def ecommerce_api_client(user):
user
.
email
,
tracking_context
=
create_tracking_context
(
user
),
issuer
=
jwt_auth
[
'JWT_ISSUER'
],
expires_in
=
jwt_auth
[
'JWT_EXPIRATION'
]
expires_in
=
jwt_auth
[
'JWT_EXPIRATION'
],
session
=
session
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment