Commit 017afc70 by Peter Fogg

Merge pull request #466 from edx/peter-fogg/credit-checkout-processor-switches

Make the credit checkout page respect payment processor switches.
parents d6929657 fba7eed3
...@@ -4,9 +4,11 @@ Tests for the checkout page. ...@@ -4,9 +4,11 @@ Tests for the checkout page.
from __future__ import unicode_literals from __future__ import unicode_literals
import json import json
import ddt
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
import httpretty import httpretty
from waffle.models import Switch
from ecommerce.core.tests import toggle_switch from ecommerce.core.tests import toggle_switch
from ecommerce.courses.models import Course from ecommerce.courses.models import Course
...@@ -19,6 +21,7 @@ from ecommerce.tests.testcases import TestCase ...@@ -19,6 +21,7 @@ from ecommerce.tests.testcases import TestCase
JSON = 'application/json' JSON = 'application/json'
@ddt.ddt
class CheckoutPageTest(CourseCatalogTestMixin, TestCase, JwtMixin): class CheckoutPageTest(CourseCatalogTestMixin, TestCase, JwtMixin):
"""Test for Checkout page""" """Test for Checkout page"""
...@@ -235,3 +238,45 @@ class CheckoutPageTest(CourseCatalogTestMixin, TestCase, JwtMixin): ...@@ -235,3 +238,45 @@ class CheckoutPageTest(CourseCatalogTestMixin, TestCase, JwtMixin):
response = self.client.get(self.path) response = self.client.get(self.path)
self.assertEqual(response.context['error'], 'No credit seat is available for this course.') self.assertEqual(response.context['error'], 'No credit seat is available for this course.')
@ddt.data(
(settings.PAYMENT_PROCESSORS, {
'payment_processors': {},
'error': u'All payment options are currently unavailable. Try the transaction again in a few minutes.'
}),
(('ecommerce.extensions.payment.processors.paypal.Paypal',), {
'payment_processors': {
'cybersource': 'Checkout'
}
}),
((), {
'payment_processors': {
'cybersource': 'Checkout',
'paypal': 'Checkout with PayPal'
}
})
)
@ddt.unpack
@httpretty.activate
def test_disabled_providers(self, disabled_processors, expected_context):
""" Verify that payment processors can be disabled with their Waffle
switches, and that an error is shown if none are available.
"""
for path in disabled_processors:
processor_class = get_processor_class(path)
switch, __ = Switch.objects.get_or_create(
name=settings.PAYMENT_PROCESSOR_SWITCH_PREFIX + processor_class.NAME
)
switch.active = False
switch.save()
self.course.create_or_update_seat(
'credit', True, self.price, self.partner, self.provider, credit_hours=self.credit_hours
)
self._mock_eligibility_api(body=self.eligibilities)
self._mock_providers_api(body=self.provider_data)
response = self.client.get(self.path)
self.assertEqual(response.status_code, 200)
self.assertDictContainsSubset(expected_context, response.context)
...@@ -66,13 +66,22 @@ class Checkout(TemplateView): ...@@ -66,13 +66,22 @@ class Checkout(TemplateView):
# Make button text for each processor which will be shown to user. # Make button text for each processor which will be shown to user.
processors_dict = OrderedDict() processors_dict = OrderedDict()
for path in settings.PAYMENT_PROCESSORS: for path in settings.PAYMENT_PROCESSORS:
processor = get_processor_class(path).NAME.lower() processor_class = get_processor_class(path)
if not processor_class.is_enabled():
continue
processor = processor_class.NAME.lower()
if processor == 'cybersource': if processor == 'cybersource':
processors_dict[processor] = 'Checkout' processors_dict[processor] = 'Checkout'
elif processor == 'paypal': elif processor == 'paypal':
processors_dict[processor] = 'Checkout with PayPal' processors_dict[processor] = 'Checkout with PayPal'
else: else:
processors_dict[processor] = 'Checkout with {}'.format(processor) processors_dict[processor] = 'Checkout with {}'.format(processor)
if len(processors_dict) == 0:
context.update({
'error': _(
u'All payment options are currently unavailable. Try the transaction again in a few minutes.'
)
})
context.update({ context.update({
'course': course, 'course': course,
......
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