Commit 9fdf60ff by Jason Bau Committed by Diana Huang

change method sig of process_postpay_callback

parent ca3651fa
......@@ -158,8 +158,7 @@ class PaidCourseRegistration(OrderItem):
Is the course defined by course_id in the order?
"""
return course_id in [item.paidcourseregistration.course_id
for item in order.orderitem_set.all()
if item.is_of_subtype(PaidCourseRegistration)]
for item in order.orderitem_set.all().select_subclasses("paidcourseregistration")]
@classmethod
def add_to_order(cls, order, course_id, mode_slug=CourseMode.DEFAULT_MODE_SLUG, cost=None, currency=None):
......@@ -169,15 +168,11 @@ class PaidCourseRegistration(OrderItem):
Returns the order item
"""
super(PaidCourseRegistration, cls).add_to_order(order, course_id, cost, currency=currency)
# TODO: Possibly add checking for whether student is already enrolled in course
course = course_from_id(course_id) # actually fetch the course to make sure it exists, use this to
# throw errors if it doesn't
item, created = cls.objects.get_or_create(order=order, user=order.user, course_id=course_id)
item.status = order.status
### Get this course_mode
### handle default arguments for mode_slug, cost, currency
course_mode = CourseMode.mode_for_course(course_id, mode_slug)
if not course_mode:
# user could have specified a mode that's not set, in that case return the DEFAULT_MODE
......@@ -187,6 +182,11 @@ class PaidCourseRegistration(OrderItem):
if not currency:
currency = course_mode.currency
super(PaidCourseRegistration, cls).add_to_order(order, course_id, cost, currency=currency)
item, created = cls.objects.get_or_create(order=order, user=order.user, course_id=course_id)
item.status = order.status
item.mode = course_mode.slug
item.qty = 1
item.unit_cost = cost
......
......@@ -24,7 +24,7 @@ orderPage_version = settings.CC_PROCESSOR['CyberSource'].get('ORDERPAGE_VERSION'
purchase_endpoint = settings.CC_PROCESSOR['CyberSource'].get('PURCHASE_ENDPOINT','')
payment_support_email = settings.PAYMENT_SUPPORT_EMAIL
def process_postpay_callback(request):
def process_postpay_callback(params):
"""
The top level call to this module, basically
This function is handed the callback request after the customer has entered the CC info and clicked "buy"
......@@ -36,7 +36,6 @@ def process_postpay_callback(request):
If unsuccessful this function should not have those side effects but should try to figure out why and
return a helpful-enough error message in error_html.
"""
params = request.POST.dict()
try:
verify_signatures(params)
result = payment_accepted(params)
......@@ -164,17 +163,18 @@ def payment_accepted(params):
if valid_params['decision'] == 'ACCEPT':
try:
# Moved reading of charged_amount from the valid_params loop above because
# Moved reading of charged_amount here from the valid_params loop above because
# only 'ACCEPT' messages have a 'ccAuthReply_amount' parameter
charged_amt = Decimal(params['ccAuthReply_amount'])
except InvalidOperation:
raise CCProcessorDataException(
_("The payment processor returned a badly-typed value {0} for param {1}.".format(params[key], key))
_("The payment processor returned a badly-typed value {0} for param {1}.".format(
params['ccAuthReply_amount'], 'ccAuthReply_amount'))
)
if charged_amt == order.total_cost and valid_params['orderCurrency'] == order.currency:
return {'accepted': True,
'amt_charged': valid_params['ccAuthReply_amount'],
'amt_charged': charged_amt,
'currency': valid_params['orderCurrency'],
'order': order}
else:
......@@ -275,7 +275,8 @@ def get_processor_exception_html(params, exception):
return '<p class="error_msg">EXCEPTION!</p>'
CARDTYPE_MAP = defaultdict(lambda:"UNKNOWN").update(
CARDTYPE_MAP = defaultdict(lambda:"UNKNOWN")
CARDTYPE_MAP.update(
{
'001': 'Visa',
'002': 'MasterCard',
......
......@@ -82,7 +82,8 @@ def postpay_callback(request):
If unsuccessful the order will be left untouched and HTML messages giving more detailed error info will be
returned.
"""
result = process_postpay_callback(request)
params = request.POST.dict()
result = process_postpay_callback(params)
if result['success']:
return HttpResponseRedirect(reverse('shoppingcart.views.show_receipt', args=[result['order'].id]))
else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment