Skip to content

Commit 31b200c

Browse files
committed
add logging for cybersource errors; fix minor unicode bug
1 parent f938a5d commit 31b200c

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

lms/djangoapps/shoppingcart/processors/CyberSource2.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import re
2626
import json
2727
import uuid
28+
import logging
2829
from textwrap import dedent
2930
from datetime import datetime
3031
from collections import OrderedDict, defaultdict
@@ -38,6 +39,8 @@
3839
from shoppingcart.processors.helpers import get_processor_config
3940
from microsite_configuration import microsite
4041

42+
log = logging.getLogger(__name__)
43+
4144

4245
def process_postpay_callback(params):
4346
"""
@@ -82,6 +85,7 @@ def process_postpay_callback(params):
8285
'error_html': _get_processor_decline_html(params)
8386
}
8487
except CCProcessorException as error:
88+
log.exception('error processing CyberSource postpay callback')
8589
return {
8690
'success': False,
8791
'order': None, # due to exception we may not have the order
@@ -449,9 +453,9 @@ def _get_processor_exception_html(exception):
449453
if isinstance(exception, CCProcessorDataException):
450454
return _format_error_html(
451455
_(
452-
u"Sorry! Our payment processor sent us back a payment confirmation that had inconsistent data! "
453-
u"We apologize that we cannot verify whether the charge went through and take further action on your order. "
454-
u"The specific error message is: {msg} "
456+
u"Sorry! Our payment processor sent us back a payment confirmation that had inconsistent data! "
457+
u"We apologize that we cannot verify whether the charge went through and take further action on your order. "
458+
u"The specific error message is: {msg} "
455459
u"Your credit card may possibly have been charged. Contact us with payment-specific questions at {email}."
456460
).format(
457461
msg=u'<span class="exception_msg">{msg}</span>'.format(msg=exception.message),
@@ -461,8 +465,8 @@ def _get_processor_exception_html(exception):
461465
elif isinstance(exception, CCProcessorWrongAmountException):
462466
return _format_error_html(
463467
_(
464-
u"Sorry! Due to an error your purchase was charged for a different amount than the order total! "
465-
u"The specific error message is: {msg}. "
468+
u"Sorry! Due to an error your purchase was charged for a different amount than the order total! "
469+
u"The specific error message is: {msg}. "
466470
u"Your credit card has probably been charged. Contact us with payment-specific questions at {email}."
467471
).format(
468472
msg=u'<span class="exception_msg">{msg}</span>'.format(msg=exception.message),
@@ -476,7 +480,7 @@ def _get_processor_exception_html(exception):
476480
u"unable to validate that the message actually came from the payment processor. "
477481
u"The specific error message is: {msg}. "
478482
u"We apologize that we cannot verify whether the charge went through and take further action on your order. "
479-
u"Your credit card may possibly have been charged. Contact us with payment-specific questions at {email}."
483+
u"Your credit card may possibly have been charged. Contact us with payment-specific questions at {email}."
480484
).format(
481485
msg=u'<span class="exception_msg">{msg}</span>'.format(msg=exception.message),
482486
email=payment_support_email
@@ -495,15 +499,15 @@ def _get_processor_exception_html(exception):
495499
else:
496500
return _format_error_html(
497501
_(
498-
u"Sorry! Your payment could not be processed because an unexpected exception occurred. "
502+
u"Sorry! Your payment could not be processed because an unexpected exception occurred. "
499503
u"Please contact us at {email} for assistance."
500504
).format(email=payment_support_email)
501505
)
502506

503507

504508
def _format_error_html(msg):
505509
""" Format an HTML error message """
506-
return '<p class="error_msg">{msg}</p>'.format(msg=msg)
510+
return u'<p class="error_msg">{msg}</p>'.format(msg=msg)
507511

508512

509513
CARDTYPE_MAP = defaultdict(lambda: "UNKNOWN")

lms/djangoapps/shoppingcart/processors/tests/test_CyberSource2.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
from mock import patch
66
from django.test import TestCase
7+
from django.conf import settings
78
import ddt
89

910
from student.tests.factories import UserFactory
@@ -12,7 +13,13 @@
1213
processor_hash,
1314
process_postpay_callback,
1415
render_purchase_form_html,
15-
get_signed_purchase_params
16+
get_signed_purchase_params,
17+
_get_processor_exception_html
18+
)
19+
from shoppingcart.processors.exceptions import (
20+
CCProcessorSignatureException,
21+
CCProcessorDataException,
22+
CCProcessorWrongAmountException
1623
)
1724

1825

@@ -227,6 +234,19 @@ def test_sign_then_verify_unicode(self, purchased_callback):
227234
result = process_postpay_callback(params)
228235
self.assertTrue(result['success'])
229236

237+
@ddt.data('string', u'üñîçø∂é')
238+
def test_get_processor_exception_html(self, error_string):
239+
"""
240+
Tests the processor exception html message
241+
"""
242+
for exception_type in [CCProcessorSignatureException, CCProcessorWrongAmountException, CCProcessorDataException]:
243+
error_msg = error_string
244+
exception = exception_type(error_msg)
245+
html = _get_processor_exception_html(exception)
246+
self.assertIn(settings.PAYMENT_SUPPORT_EMAIL, html)
247+
self.assertIn('Sorry!', html)
248+
self.assertIn(error_msg, html)
249+
230250
def _signed_callback_params(
231251
self, order_id, order_amount, paid_amount,
232252
accepted=True, signature=None, card_number='xxxxxxxxxxxx1111',

0 commit comments

Comments
 (0)