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
363a0c8d
Commit
363a0c8d
authored
Sep 28, 2016
by
Marko Jevtic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[SOL-2082] Add a value to SiteConfiguration to enable ecommerce Receipt Page usage
parent
024e2e4b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
13 deletions
+80
-13
lms/djangoapps/commerce/models.py
+2
-1
lms/djangoapps/commerce/tests/test_utils.py
+40
-4
lms/djangoapps/commerce/utils.py
+35
-6
lms/djangoapps/student_account/views.py
+3
-2
No files found.
lms/djangoapps/commerce/models.py
View file @
363a0c8d
...
@@ -15,6 +15,7 @@ class CommerceConfiguration(ConfigurationModel):
...
@@ -15,6 +15,7 @@ class CommerceConfiguration(ConfigurationModel):
API_NAME
=
'commerce'
API_NAME
=
'commerce'
CACHE_KEY
=
'commerce.api.data'
CACHE_KEY
=
'commerce.api.data'
DEFAULT_RECEIPT_PAGE_URL
=
'/commerce/checkout/receipt/?orderNum='
checkout_on_ecommerce_service
=
models
.
BooleanField
(
checkout_on_ecommerce_service
=
models
.
BooleanField
(
default
=
False
,
default
=
False
,
...
@@ -35,7 +36,7 @@ class CommerceConfiguration(ConfigurationModel):
...
@@ -35,7 +36,7 @@ class CommerceConfiguration(ConfigurationModel):
)
)
receipt_page
=
models
.
CharField
(
receipt_page
=
models
.
CharField
(
max_length
=
255
,
max_length
=
255
,
default
=
'/commerce/checkout/receipt/?orderNum='
,
default
=
DEFAULT_RECEIPT_PAGE_URL
,
help_text
=
_
(
'Path to order receipt page.'
)
help_text
=
_
(
'Path to order receipt page.'
)
)
)
...
...
lms/djangoapps/commerce/tests/test_utils.py
View file @
363a0c8d
"""Tests of commerce utilities."""
"""Tests of commerce utilities."""
from
django.conf
import
settings
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.test.client
import
RequestFactory
from
django.test.client
import
RequestFactory
from
django.test.utils
import
override_settings
from
django.test.utils
import
override_settings
...
@@ -7,14 +8,20 @@ from mock import patch
...
@@ -7,14 +8,20 @@ from mock import patch
from
commerce.models
import
CommerceConfiguration
from
commerce.models
import
CommerceConfiguration
from
commerce.utils
import
EcommerceService
from
commerce.utils
import
EcommerceService
from
openedx.core.lib.log_utils
import
audit_log
from
openedx.core.lib.log_utils
import
audit_log
from
openedx.core.djangoapps.site_configuration.tests.test_util
import
with_site_configuration
from
student.tests.factories
import
UserFactory
from
student.tests.factories
import
UserFactory
TEST_SITE_CONFIGURATION
=
{
'ECOMMERCE_RECEIPT_PAGE_URL'
:
'/checkout/receipt/?order_number='
}
def
update_commerce_config
(
enabled
=
False
,
checkout_page
=
'/test_basket/'
):
def
update_commerce_config
(
enabled
=
False
,
checkout_page
=
'/test_basket/'
,
receipt_page
=
'/checkout/receipt/'
):
""" Enable / Disable CommerceConfiguration model """
""" Enable / Disable CommerceConfiguration model """
CommerceConfiguration
.
objects
.
create
(
CommerceConfiguration
.
objects
.
create
(
checkout_on_ecommerce_service
=
enabled
,
checkout_on_ecommerce_service
=
enabled
,
single_course_checkout_page
=
checkout_page
receipt_page
=
receipt_page
,
single_course_checkout_page
=
checkout_page
,
)
)
...
@@ -61,14 +68,43 @@ class EcommerceServiceTests(TestCase):
...
@@ -61,14 +68,43 @@ class EcommerceServiceTests(TestCase):
self
.
assertTrue
(
is_enabled
)
self
.
assertTrue
(
is_enabled
)
@override_settings
(
ECOMMERCE_PUBLIC_URL_ROOT
=
'http://ecommerce_url'
)
@override_settings
(
ECOMMERCE_PUBLIC_URL_ROOT
=
'http://ecommerce_url'
)
def
test_payment_page_url
(
self
):
def
test_ecommerce_url_root
(
self
):
"""Verify that the proper root URL is returned."""
self
.
assertEqual
(
EcommerceService
()
.
ecommerce_url_root
,
'http://ecommerce_url'
)
@override_settings
(
ECOMMERCE_PUBLIC_URL_ROOT
=
'http://ecommerce_url'
)
def
test_get_absolute_ecommerce_url
(
self
):
"""Verify that the proper URL is returned."""
"""Verify that the proper URL is returned."""
url
=
EcommerceService
()
.
payment_page_url
(
)
url
=
EcommerceService
()
.
get_absolute_ecommerce_url
(
'/test_basket/'
)
self
.
assertEqual
(
url
,
'http://ecommerce_url/test_basket/'
)
self
.
assertEqual
(
url
,
'http://ecommerce_url/test_basket/'
)
@override_settings
(
ECOMMERCE_PUBLIC_URL_ROOT
=
'http://ecommerce_url'
)
@override_settings
(
ECOMMERCE_PUBLIC_URL_ROOT
=
'http://ecommerce_url'
)
def
test_get_receipt_page_url
(
self
):
"""Verify that the proper Receipt page URL is returned."""
order_number
=
'ORDER1'
url
=
EcommerceService
()
.
get_receipt_page_url
(
order_number
)
expected_url
=
'/checkout/receipt/{}'
.
format
(
order_number
)
self
.
assertEqual
(
url
,
expected_url
)
@override_settings
(
ECOMMERCE_PUBLIC_URL_ROOT
=
'http://ecommerce_url'
)
def
test_checkout_page_url
(
self
):
def
test_checkout_page_url
(
self
):
""" Verify the checkout page URL is properly constructed and returned. """
""" Verify the checkout page URL is properly constructed and returned. """
url
=
EcommerceService
()
.
checkout_page_url
(
self
.
SKU
)
url
=
EcommerceService
()
.
checkout_page_url
(
self
.
SKU
)
expected_url
=
'http://ecommerce_url/test_basket/?sku={}'
.
format
(
self
.
SKU
)
expected_url
=
'http://ecommerce_url/test_basket/?sku={}'
.
format
(
self
.
SKU
)
self
.
assertEqual
(
url
,
expected_url
)
self
.
assertEqual
(
url
,
expected_url
)
@override_settings
(
ECOMMERCE_PUBLIC_URL_ROOT
=
'http://ecommerce_url'
)
@with_site_configuration
(
configuration
=
TEST_SITE_CONFIGURATION
)
def
test_get_receipt_page_url_with_site_configuration
(
self
):
order_number
=
'ORDER1'
config
=
CommerceConfiguration
.
current
()
config
.
use_ecommerce_receipt_page
=
True
config
.
save
()
receipt_page_url
=
EcommerceService
()
.
get_receipt_page_url
(
order_number
)
expected_url
=
'{ecommerce_root}{receipt_page_url}{order_number}'
.
format
(
ecommerce_root
=
settings
.
ECOMMERCE_PUBLIC_URL_ROOT
,
order_number
=
order_number
,
receipt_page_url
=
TEST_SITE_CONFIGURATION
[
'ECOMMERCE_RECEIPT_PAGE_URL'
]
)
self
.
assertEqual
(
receipt_page_url
,
expected_url
)
lms/djangoapps/commerce/utils.py
View file @
363a0c8d
...
@@ -12,6 +12,39 @@ class EcommerceService(object):
...
@@ -12,6 +12,39 @@ class EcommerceService(object):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
config
=
CommerceConfiguration
.
current
()
self
.
config
=
CommerceConfiguration
.
current
()
@property
def
ecommerce_url_root
(
self
):
""" Retrieve Ecommerce service public url root. """
return
configuration_helpers
.
get_value
(
'ECOMMERCE_PUBLIC_URL_ROOT'
,
settings
.
ECOMMERCE_PUBLIC_URL_ROOT
)
def
get_absolute_ecommerce_url
(
self
,
ecommerce_page_url
):
""" Return the absolute URL to the ecommerce page.
Args:
ecommerce_page_url (str): Relative path to the ecommerce page.
Returns:
Absolute path to the ecommerce page.
"""
return
urljoin
(
self
.
ecommerce_url_root
,
ecommerce_page_url
)
def
get_receipt_page_url
(
self
,
order_number
):
"""
Gets the URL for the Order Receipt page hosted by the ecommerce service.
Args:
order_number (str): Order number.
Returns:
Receipt page for the specified Order.
"""
ecommerce_receipt_page_url
=
configuration_helpers
.
get_value
(
'ECOMMERCE_RECEIPT_PAGE_URL'
)
if
ecommerce_receipt_page_url
:
receipt_page_url
=
self
.
get_absolute_ecommerce_url
(
ecommerce_receipt_page_url
)
else
:
receipt_page_url
=
self
.
config
.
receipt_page
return
receipt_page_url
+
order_number
def
is_enabled
(
self
,
user
):
def
is_enabled
(
self
,
user
):
"""
"""
Determines the availability of the EcommerceService based on user activation and service configuration.
Determines the availability of the EcommerceService based on user activation and service configuration.
...
@@ -29,11 +62,7 @@ class EcommerceService(object):
...
@@ -29,11 +62,7 @@ class EcommerceService(object):
Example:
Example:
http://localhost:8002/basket/single_item/
http://localhost:8002/basket/single_item/
"""
"""
ecommerce_url_root
=
configuration_helpers
.
get_value
(
return
self
.
get_absolute_ecommerce_url
(
self
.
config
.
single_course_checkout_page
)
'ECOMMERCE_PUBLIC_URL_ROOT'
,
settings
.
ECOMMERCE_PUBLIC_URL_ROOT
,
)
return
urljoin
(
ecommerce_url_root
,
self
.
config
.
single_course_checkout_page
)
def
checkout_page_url
(
self
,
sku
):
def
checkout_page_url
(
self
,
sku
):
""" Construct the URL to the ecommerce checkout page and include a product.
""" Construct the URL to the ecommerce checkout page and include a product.
...
@@ -41,4 +70,4 @@ class EcommerceService(object):
...
@@ -41,4 +70,4 @@ class EcommerceService(object):
Example:
Example:
http://localhost:8002/basket/single_item/?sku=5H3HG5
http://localhost:8002/basket/single_item/?sku=5H3HG5
"""
"""
return
"{}?sku={}"
.
format
(
self
.
payment_page_url
(
),
sku
)
return
"{}?sku={}"
.
format
(
self
.
get_absolute_ecommerce_url
(
self
.
config
.
single_course_checkout_page
),
sku
)
lms/djangoapps/student_account/views.py
View file @
363a0c8d
...
@@ -22,6 +22,7 @@ from edxmako.shortcuts import render_to_response
...
@@ -22,6 +22,7 @@ from edxmako.shortcuts import render_to_response
import
pytz
import
pytz
from
commerce.models
import
CommerceConfiguration
from
commerce.models
import
CommerceConfiguration
from
lms.djangoapps.commerce.utils
import
EcommerceService
from
openedx.core.djangoapps.external_auth.login_and_register
import
(
from
openedx.core.djangoapps.external_auth.login_and_register
import
(
login
as
external_auth_login
,
login
as
external_auth_login
,
register
as
external_auth_register
register
as
external_auth_register
...
@@ -316,7 +317,7 @@ def _external_auth_intercept(request, mode):
...
@@ -316,7 +317,7 @@ def _external_auth_intercept(request, mode):
def
get_user_orders
(
user
):
def
get_user_orders
(
user
):
"""Given a user, get the detail of all the orders from the Ecommerce service.
"""Given a user, get the detail of all the orders from the Ecommerce service.
Arg
ument
s:
Args:
user (User): The user to authenticate as when requesting ecommerce.
user (User): The user to authenticate as when requesting ecommerce.
Returns:
Returns:
...
@@ -351,7 +352,7 @@ def get_user_orders(user):
...
@@ -351,7 +352,7 @@ def get_user_orders(user):
'order_date'
:
strftime_localized
(
'order_date'
:
strftime_localized
(
date_placed
.
replace
(
tzinfo
=
pytz
.
UTC
),
'SHORT_DATE'
date_placed
.
replace
(
tzinfo
=
pytz
.
UTC
),
'SHORT_DATE'
),
),
'receipt_url'
:
commerce_configuration
.
receipt_page
+
order
[
'number'
]
'receipt_url'
:
EcommerceService
()
.
get_receipt_page_url
(
order
[
'number'
])
}
}
user_orders
.
append
(
order_data
)
user_orders
.
append
(
order_data
)
except
KeyError
:
except
KeyError
:
...
...
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