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
b475ac36
Commit
b475ac36
authored
Aug 21, 2013
by
Diana Huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some pep8/pylint cleanup
parent
055ad535
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
12 deletions
+26
-12
lms/djangoapps/shoppingcart/exceptions.py
+2
-0
lms/djangoapps/shoppingcart/processors/CyberSource.py
+0
-0
lms/djangoapps/shoppingcart/processors/__init__.py
+2
-1
lms/djangoapps/shoppingcart/processors/exceptions.py
+4
-0
lms/djangoapps/shoppingcart/processors/tests/test_CyberSource.py
+11
-10
lms/djangoapps/shoppingcart/views.py
+7
-1
No files found.
lms/djangoapps/shoppingcart/exceptions.py
View file @
b475ac36
class
PaymentException
(
Exception
):
pass
class
PurchasedCallbackException
(
PaymentException
):
pass
class
InvalidCartItem
(
PaymentException
):
pass
lms/djangoapps/shoppingcart/processors/CyberSource.py
View file @
b475ac36
This diff is collapsed.
Click to expand it.
lms/djangoapps/shoppingcart/processors/__init__.py
View file @
b475ac36
...
...
@@ -7,6 +7,7 @@ module = __import__('shoppingcart.processors.' + processor_name,
'process_postpay_callback'
,
])
def
render_purchase_form_html
(
*
args
,
**
kwargs
):
"""
The top level call to this module to begin the purchase.
...
...
@@ -16,6 +17,7 @@ def render_purchase_form_html(*args, **kwargs):
"""
return
module
.
render_purchase_form_html
(
*
args
,
**
kwargs
)
def
process_postpay_callback
(
*
args
,
**
kwargs
):
"""
The top level call to this module after the purchase.
...
...
@@ -29,4 +31,3 @@ def process_postpay_callback(*args, **kwargs):
return a helpful-enough error message in error_html.
"""
return
module
.
process_postpay_callback
(
*
args
,
**
kwargs
)
lms/djangoapps/shoppingcart/processors/exceptions.py
View file @
b475ac36
from
shoppingcart.exceptions
import
PaymentException
class
CCProcessorException
(
PaymentException
):
pass
class
CCProcessorSignatureException
(
CCProcessorException
):
pass
class
CCProcessorDataException
(
CCProcessorException
):
pass
class
CCProcessorWrongAmountException
(
CCProcessorException
):
pass
lms/djangoapps/shoppingcart/processors/tests/test_CyberSource.py
View file @
b475ac36
...
...
@@ -13,15 +13,16 @@ from mock import patch, Mock
TEST_CC_PROCESSOR
=
{
'CyberSource'
:
{
'CyberSource'
:
{
'SHARED_SECRET'
:
'secret'
,
'MERCHANT_ID'
:
'edx_test'
,
'SERIAL_NUMBER'
:
'12345'
,
'MERCHANT_ID'
:
'edx_test'
,
'SERIAL_NUMBER'
:
'12345'
,
'ORDERPAGE_VERSION'
:
'7'
,
'PURCHASE_ENDPOINT'
:
''
,
}
}
@override_settings
(
CC_PROCESSOR
=
TEST_CC_PROCESSOR
)
class
CyberSourceTests
(
TestCase
):
...
...
@@ -36,8 +37,8 @@ class CyberSourceTests(TestCase):
"""
Tests the hash function. Basically just hardcodes the answer.
"""
self
.
assertEqual
(
hash
(
'test'
),
'GqNJWF7X7L07nEhqMAZ+OVyks1Y='
)
self
.
assertEqual
(
hash
(
'edx '
),
'/KowheysqM2PFYuxVKg0P8Flfk4='
)
self
.
assertEqual
(
processor_
hash
(
'test'
),
'GqNJWF7X7L07nEhqMAZ+OVyks1Y='
)
self
.
assertEqual
(
processor_
hash
(
'edx '
),
'/KowheysqM2PFYuxVKg0P8Flfk4='
)
def
test_sign_then_verify
(
self
):
"""
...
...
@@ -76,7 +77,7 @@ class CyberSourceTests(TestCase):
"""
DECISION
=
'REJECT'
for
code
,
reason
in
REASONCODE_MAP
.
iteritems
():
params
=
{
params
=
{
'decision'
:
DECISION
,
'reasonCode'
:
code
,
}
...
...
@@ -109,8 +110,8 @@ class CyberSourceTests(TestCase):
student1
.
save
()
student2
=
UserFactory
()
student2
.
save
()
params_cc
=
{
'card_accountNumber'
:
'1234'
,
'card_cardType'
:
'001'
,
'billTo_firstName'
:
student1
.
first_name
}
params_nocc
=
{
'card_accountNumber'
:
''
,
'card_cardType'
:
'002'
,
'billTo_firstName'
:
student2
.
first_name
}
params_cc
=
{
'card_accountNumber'
:
'1234'
,
'card_cardType'
:
'001'
,
'billTo_firstName'
:
student1
.
first_name
}
params_nocc
=
{
'card_accountNumber'
:
''
,
'card_cardType'
:
'002'
,
'billTo_firstName'
:
student2
.
first_name
}
order1
=
Order
.
get_cart_for_user
(
student1
)
order2
=
Order
.
get_cart_for_user
(
student2
)
record_purchase
(
params_cc
,
order1
)
...
...
@@ -173,7 +174,7 @@ class CyberSourceTests(TestCase):
# tests for an order number that doesn't match up
params_bad_ordernum
=
params
.
copy
()
params_bad_ordernum
[
'orderNumber'
]
=
str
(
order1
.
id
+
10
)
params_bad_ordernum
[
'orderNumber'
]
=
str
(
order1
.
id
+
10
)
with
self
.
assertRaises
(
CCProcessorDataException
):
payment_accepted
(
params_bad_ordernum
)
...
...
@@ -215,7 +216,7 @@ class CyberSourceTests(TestCase):
self
.
assertDictContainsSubset
({
'amount'
:
'1.00'
,
'currency'
:
'usd'
,
'orderPage_transactionType'
:
'sale'
,
'orderNumber'
:
str
(
order1
.
id
)},
'orderNumber'
:
str
(
order1
.
id
)},
context
[
'params'
])
def
test_process_postpay_exception
(
self
):
...
...
lms/djangoapps/shoppingcart/views.py
View file @
b475ac36
...
...
@@ -12,6 +12,7 @@ from .processors import process_postpay_callback, render_purchase_form_html
log
=
logging
.
getLogger
(
"shoppingcart"
)
def
test
(
request
,
course_id
):
item1
=
PaidCourseRegistration
(
course_id
,
200
)
item1
.
purchased_callback
(
request
.
user
.
id
)
...
...
@@ -41,6 +42,7 @@ def register_for_verified_cert(request, course_id):
CertificateItem
.
add_to_order
(
cart
,
course_id
,
30
,
'verified'
)
return
HttpResponse
(
"Added"
)
@login_required
def
show_cart
(
request
):
cart
=
Order
.
get_cart_for_user
(
request
.
user
)
...
...
@@ -54,12 +56,14 @@ def show_cart(request):
'form_html'
:
form_html
,
})
@login_required
def
clear_cart
(
request
):
cart
=
Order
.
get_cart_for_user
(
request
.
user
)
cart
.
clear
()
return
HttpResponse
(
'Cleared'
)
@login_required
def
remove_item
(
request
):
item_id
=
request
.
REQUEST
.
get
(
'id'
,
'-1'
)
...
...
@@ -71,6 +75,7 @@ def remove_item(request):
log
.
exception
(
'Cannot remove cart OrderItem id={0}. DoesNotExist or item is already purchased'
.
format
(
item_id
))
return
HttpResponse
(
'OK'
)
@csrf_exempt
def
postpay_callback
(
request
):
"""
...
...
@@ -87,9 +92,10 @@ def postpay_callback(request):
if
result
[
'success'
]:
return
HttpResponseRedirect
(
reverse
(
'shoppingcart.views.show_receipt'
,
args
=
[
result
[
'order'
]
.
id
]))
else
:
return
render_to_response
(
'shoppingcart/error.html'
,
{
'order'
:
result
[
'order'
],
return
render_to_response
(
'shoppingcart/error.html'
,
{
'order'
:
result
[
'order'
],
'error_html'
:
result
[
'error_html'
]})
@login_required
def
show_receipt
(
request
,
ordernum
):
"""
...
...
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