Commit 893cb9c2 by Adam

Merge pull request #5873 from edx/release

Release
parents fd587b97 8fee0318
...@@ -25,6 +25,7 @@ import binascii ...@@ -25,6 +25,7 @@ import binascii
import re import re
import json import json
import uuid import uuid
import logging
from textwrap import dedent from textwrap import dedent
from datetime import datetime from datetime import datetime
from collections import OrderedDict, defaultdict from collections import OrderedDict, defaultdict
...@@ -38,6 +39,8 @@ from shoppingcart.processors.exceptions import * ...@@ -38,6 +39,8 @@ from shoppingcart.processors.exceptions import *
from shoppingcart.processors.helpers import get_processor_config from shoppingcart.processors.helpers import get_processor_config
from microsite_configuration import microsite from microsite_configuration import microsite
log = logging.getLogger(__name__)
def process_postpay_callback(params): def process_postpay_callback(params):
""" """
...@@ -82,6 +85,7 @@ def process_postpay_callback(params): ...@@ -82,6 +85,7 @@ def process_postpay_callback(params):
'error_html': _get_processor_decline_html(params) 'error_html': _get_processor_decline_html(params)
} }
except CCProcessorException as error: except CCProcessorException as error:
log.exception('error processing CyberSource postpay callback')
return { return {
'success': False, 'success': False,
'order': None, # due to exception we may not have the order 'order': None, # due to exception we may not have the order
...@@ -449,9 +453,9 @@ def _get_processor_exception_html(exception): ...@@ -449,9 +453,9 @@ def _get_processor_exception_html(exception):
if isinstance(exception, CCProcessorDataException): if isinstance(exception, CCProcessorDataException):
return _format_error_html( return _format_error_html(
_( _(
u"Sorry! Our payment processor sent us back a payment confirmation that had inconsistent data! " u"Sorry! Our payment processor sent us back a payment confirmation that had inconsistent data! "
u"We apologize that we cannot verify whether the charge went through and take further action on your order. " u"We apologize that we cannot verify whether the charge went through and take further action on your order. "
u"The specific error message is: {msg} " u"The specific error message is: {msg} "
u"Your credit card may possibly have been charged. Contact us with payment-specific questions at {email}." u"Your credit card may possibly have been charged. Contact us with payment-specific questions at {email}."
).format( ).format(
msg=u'<span class="exception_msg">{msg}</span>'.format(msg=exception.message), msg=u'<span class="exception_msg">{msg}</span>'.format(msg=exception.message),
...@@ -461,8 +465,8 @@ def _get_processor_exception_html(exception): ...@@ -461,8 +465,8 @@ def _get_processor_exception_html(exception):
elif isinstance(exception, CCProcessorWrongAmountException): elif isinstance(exception, CCProcessorWrongAmountException):
return _format_error_html( return _format_error_html(
_( _(
u"Sorry! Due to an error your purchase was charged for a different amount than the order total! " u"Sorry! Due to an error your purchase was charged for a different amount than the order total! "
u"The specific error message is: {msg}. " u"The specific error message is: {msg}. "
u"Your credit card has probably been charged. Contact us with payment-specific questions at {email}." u"Your credit card has probably been charged. Contact us with payment-specific questions at {email}."
).format( ).format(
msg=u'<span class="exception_msg">{msg}</span>'.format(msg=exception.message), msg=u'<span class="exception_msg">{msg}</span>'.format(msg=exception.message),
...@@ -476,7 +480,7 @@ def _get_processor_exception_html(exception): ...@@ -476,7 +480,7 @@ def _get_processor_exception_html(exception):
u"unable to validate that the message actually came from the payment processor. " u"unable to validate that the message actually came from the payment processor. "
u"The specific error message is: {msg}. " u"The specific error message is: {msg}. "
u"We apologize that we cannot verify whether the charge went through and take further action on your order. " u"We apologize that we cannot verify whether the charge went through and take further action on your order. "
u"Your credit card may possibly have been charged. Contact us with payment-specific questions at {email}." u"Your credit card may possibly have been charged. Contact us with payment-specific questions at {email}."
).format( ).format(
msg=u'<span class="exception_msg">{msg}</span>'.format(msg=exception.message), msg=u'<span class="exception_msg">{msg}</span>'.format(msg=exception.message),
email=payment_support_email email=payment_support_email
...@@ -495,7 +499,7 @@ def _get_processor_exception_html(exception): ...@@ -495,7 +499,7 @@ def _get_processor_exception_html(exception):
else: else:
return _format_error_html( return _format_error_html(
_( _(
u"Sorry! Your payment could not be processed because an unexpected exception occurred. " u"Sorry! Your payment could not be processed because an unexpected exception occurred. "
u"Please contact us at {email} for assistance." u"Please contact us at {email} for assistance."
).format(email=payment_support_email) ).format(email=payment_support_email)
) )
...@@ -503,7 +507,7 @@ def _get_processor_exception_html(exception): ...@@ -503,7 +507,7 @@ def _get_processor_exception_html(exception):
def _format_error_html(msg): def _format_error_html(msg):
""" Format an HTML error message """ """ Format an HTML error message """
return '<p class="error_msg">{msg}</p>'.format(msg=msg) return u'<p class="error_msg">{msg}</p>'.format(msg=msg)
CARDTYPE_MAP = defaultdict(lambda: "UNKNOWN") CARDTYPE_MAP = defaultdict(lambda: "UNKNOWN")
......
...@@ -4,6 +4,7 @@ Tests for the newer CyberSource API implementation. ...@@ -4,6 +4,7 @@ Tests for the newer CyberSource API implementation.
""" """
from mock import patch from mock import patch
from django.test import TestCase from django.test import TestCase
from django.conf import settings
import ddt import ddt
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
...@@ -12,7 +13,13 @@ from shoppingcart.processors.CyberSource2 import ( ...@@ -12,7 +13,13 @@ from shoppingcart.processors.CyberSource2 import (
processor_hash, processor_hash,
process_postpay_callback, process_postpay_callback,
render_purchase_form_html, render_purchase_form_html,
get_signed_purchase_params get_signed_purchase_params,
_get_processor_exception_html
)
from shoppingcart.processors.exceptions import (
CCProcessorSignatureException,
CCProcessorDataException,
CCProcessorWrongAmountException
) )
...@@ -227,6 +234,19 @@ class CyberSource2Test(TestCase): ...@@ -227,6 +234,19 @@ class CyberSource2Test(TestCase):
result = process_postpay_callback(params) result = process_postpay_callback(params)
self.assertTrue(result['success']) self.assertTrue(result['success'])
@ddt.data('string', u'üñîçø∂é')
def test_get_processor_exception_html(self, error_string):
"""
Tests the processor exception html message
"""
for exception_type in [CCProcessorSignatureException, CCProcessorWrongAmountException, CCProcessorDataException]:
error_msg = error_string
exception = exception_type(error_msg)
html = _get_processor_exception_html(exception)
self.assertIn(settings.PAYMENT_SUPPORT_EMAIL, html)
self.assertIn('Sorry!', html)
self.assertIn(error_msg, html)
def _signed_callback_params( def _signed_callback_params(
self, order_id, order_amount, paid_amount, self, order_id, order_amount, paid_amount,
accepted=True, signature=None, card_number='xxxxxxxxxxxx1111', accepted=True, signature=None, card_number='xxxxxxxxxxxx1111',
......
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