Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

build(deps): bump minimist and karma #3848

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [master]
branches: [master, project-zebra]
pull_request:
branches: [master]
branches: [master, project-zebra]

jobs:
build:
Expand Down
12 changes: 10 additions & 2 deletions ecommerce/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ecommerce.core.constants import ALL_ACCESS_CONTEXT, ALLOW_MISSING_LMS_USER_ID
from ecommerce.core.exceptions import MissingLmsUserIdException
from ecommerce.core.utils import log_message_and_raise_validation_error
from ecommerce.extensions.basket.constants import ENABLE_STRIPE_PAYMENT_PROCESSOR
from ecommerce.extensions.payment.exceptions import ProcessorNotFoundError
from ecommerce.extensions.payment.helpers import get_processor_class, get_processor_class_by_name

Expand Down Expand Up @@ -274,17 +275,24 @@ def get_payment_processors(self):
if processor.NAME in self.payment_processors_set and processor.is_enabled()
]

def get_client_side_payment_processor_class(self):
def get_client_side_payment_processor_class(self, request):
""" Returns the payment processor class to be used for client-side payments.

If no processor is set, returns None.

Returns:
BasePaymentProcessor
"""
desired_processor = self.client_side_payment_processor

# Force client_side_payment_processor to be Stripe when waffle flag is set.
# This allows slowly increasing the percentage of users redirected to Stripe.
if waffle.flag_is_active(request, ENABLE_STRIPE_PAYMENT_PROCESSOR):
desired_processor = 'stripe'

if self.client_side_payment_processor:
for processor in self._all_payment_processors():
if processor.NAME == self.client_side_payment_processor:
if processor.NAME == desired_processor:
return processor

return None
Expand Down
18 changes: 16 additions & 2 deletions ecommerce/core/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from requests.exceptions import ConnectionError as ReqConnectionError
from social_django.models import UserSocialAuth
from testfixtures import LogCapture
from waffle.testutils import override_flag

from ecommerce.core.models import (
BusinessClient,
Expand All @@ -22,6 +23,7 @@
User
)
from ecommerce.core.tests import toggle_switch
from ecommerce.extensions.basket.constants import ENABLE_STRIPE_PAYMENT_PROCESSOR
from ecommerce.extensions.catalogue.tests.mixins import DiscoveryTestMixin
from ecommerce.extensions.payment.tests.processors import AnotherDummyProcessor, DummyProcessor
from ecommerce.tests.factories import SiteConfigurationFactory
Expand Down Expand Up @@ -334,10 +336,22 @@ def test_get_client_side_payment_processor(self):
site_config = _make_site_config(processor_name)

site_config.client_side_payment_processor = None
self.assertIsNone(site_config.get_client_side_payment_processor_class())
self.assertIsNone(site_config.get_client_side_payment_processor_class(request=None))

site_config.client_side_payment_processor = processor_name
self.assertEqual(site_config.get_client_side_payment_processor_class().NAME, processor_name)
self.assertEqual(site_config.get_client_side_payment_processor_class(request=None).NAME, processor_name)

@override_flag(ENABLE_STRIPE_PAYMENT_PROCESSOR, active=True)
def test_get_client_side_payment_processor_waffle_enabled(self):
""" Verify that Stripe is always returned when waffle flag is on. """
processor_name = 'cybersource,stripe'
site_config = _make_site_config(processor_name)

site_config.client_side_payment_processor = None
self.assertIsNone(site_config.get_client_side_payment_processor_class(request=None))

site_config.client_side_payment_processor = 'cybersource'
self.assertEqual(site_config.get_client_side_payment_processor_class(request=None).NAME, 'stripe')

def test_get_from_email(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions ecommerce/extensions/api/v2/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# .. toggle_name: enable_hoist_order_history
# .. toggle_type: waffle_flag
# .. toggle_default: False
# .. toggle_description: Allows order fetching from Commerce Coordinator API for display in Order History MFE.
# .. toggle_description: Allows order fetching from Commerce Coordinator API for display in Order History MFE
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2022-04-05
# .. toggle_tickets: REV-2576
Expand All @@ -19,7 +19,7 @@
# .. toggle_name: enable_receipts_via_ecommerce_mfe
# .. toggle_type: waffle_flag
# .. toggle_default: False
# .. toggle_description: Determines whether to send user to new receipt page (vs old) .
# .. toggle_description: Determines whether to send user to new receipt page (vs old)
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2022-06-02
# .. toggle_tickets: REV-2687
Expand Down
10 changes: 10 additions & 0 deletions ecommerce/extensions/basket/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
EMAIL_OPT_IN_ATTRIBUTE = "email_opt_in"
PURCHASER_BEHALF_ATTRIBUTE = "purchased_for_organization"
PAYMENT_INTENT_ID_ATTRIBUTE = "payment_intent_id"

# .. toggle_name: enable_stripe_payment_processor
# .. toggle_type: waffle_flag
# .. toggle_default: False
# .. toggle_description: Allows payments to be processed through Stripe instead of CyberSource
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2022-09-19
# .. toggle_tickets: REV-3004
# .. toggle_status: supported
ENABLE_STRIPE_PAYMENT_PROCESSOR = 'enable_stripe_payment_processor'
16 changes: 15 additions & 1 deletion ecommerce/extensions/basket/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from ecommerce.enterprise.utils import construct_enterprise_course_consent_url
from ecommerce.entitlements.utils import create_or_update_course_entitlement
from ecommerce.extensions.analytics.utils import translate_basket_line_for_segment
from ecommerce.extensions.basket.constants import EMAIL_OPT_IN_ATTRIBUTE
from ecommerce.extensions.basket.constants import EMAIL_OPT_IN_ATTRIBUTE, ENABLE_STRIPE_PAYMENT_PROCESSOR
from ecommerce.extensions.basket.tests.mixins import BasketMixin
from ecommerce.extensions.basket.tests.test_utils import TEST_BUNDLE_ID
from ecommerce.extensions.basket.utils import _set_basket_bundle_status, apply_voucher_on_basket_and_check_discount
Expand Down Expand Up @@ -403,6 +403,7 @@ def assert_empty_basket_response(
def assert_expected_response(
self,
basket,
enable_stripe_payment_processor=False,
url=None,
response=None,
status_code=200,
Expand Down Expand Up @@ -456,6 +457,7 @@ def assert_expected_response(
expected_response = {
'basket_id': basket.id,
'currency': currency,
'enable_stripe_payment_processor': enable_stripe_payment_processor,
'offers': offers,
'coupons': coupons,
'messages': messages if messages else [],
Expand Down Expand Up @@ -698,6 +700,18 @@ def test_discounted_seat_type(self, discount_value):
voucher=voucher,
)

@ddt.data(True, False)
def test_enable_stripe_payment_processor_flag(self, enable_stripe_payment_processor):
with override_flag(ENABLE_STRIPE_PAYMENT_PROCESSOR, active=enable_stripe_payment_processor):
seat = self.create_seat(self.course)
basket = self.create_basket_and_add_product(seat)
response = self.client.get(self.path)
self.assert_expected_response(
basket,
response=response,
enable_stripe_payment_processor=enable_stripe_payment_processor,
)

@responses.activate
def test_enterprise_free_basket_redirect(self):
"""
Expand Down
43 changes: 42 additions & 1 deletion ecommerce/extensions/basket/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from ecommerce.core.url_utils import absolute_url
from ecommerce.courses.utils import mode_for_product
from ecommerce.extensions.analytics.utils import track_segment_event
from ecommerce.extensions.basket.constants import PURCHASER_BEHALF_ATTRIBUTE
from ecommerce.extensions.basket.constants import PAYMENT_INTENT_ID_ATTRIBUTE, PURCHASER_BEHALF_ATTRIBUTE
from ecommerce.extensions.order.exceptions import AlreadyPlacedOrderException
from ecommerce.extensions.order.utils import UserAlreadyPlacedOrder
from ecommerce.extensions.payment.constants import DISABLE_MICROFRONTEND_FOR_BASKET_PAGE_FLAG_NAME
Expand All @@ -30,6 +30,8 @@
Basket = get_model('basket', 'Basket')
BasketAttribute = get_model('basket', 'BasketAttribute')
BasketAttributeType = get_model('basket', 'BasketAttributeType')
BillingAddress = get_model('order', 'BillingAddress')
Country = get_model('address', 'Country')
BUNDLE = 'bundle_identifier'
ORGANIZATION_ATTRIBUTE_TYPE = 'organization'
ENTERPRISE_CATALOG_ATTRIBUTE_TYPE = 'enterprise_catalog_uuid'
Expand Down Expand Up @@ -384,6 +386,25 @@ def basket_add_organization_attribute(basket, request_data):
)


@newrelic.agent.function_trace()
def basket_add_payment_intent_id_attribute(basket, payment_intent_id):
"""
Adds the Stripe payment_intent_id attribute on basket.

Arguments:
basket(Basket): order basket
payment_intent_id (string): Payment Intent Identifier

"""

payment_intent_id_attribute, __ = BasketAttributeType.objects.get_or_create(name=PAYMENT_INTENT_ID_ATTRIBUTE)
BasketAttribute.objects.update_or_create(
basket=basket,
attribute_type=payment_intent_id_attribute,
defaults={'value_text': payment_intent_id.strip()}
)


@newrelic.agent.function_trace()
def basket_add_enterprise_catalog_attribute(basket, request_data):
"""
Expand Down Expand Up @@ -569,3 +590,23 @@ def is_duplicate_seat_attempt(basket, product):
found_product_quantity = basket.product_quantity(product)

return bool(product_type == 'Seat' and found_product_quantity)


def get_billing_address_from_payment_intent_data(payment_intent):
"""
Take stripes response_data dict, instantiates a BillingAddress object
and return it.
"""
billing_details = payment_intent['payment_method']['billing_details']
customer_address = billing_details['address']
address = BillingAddress(
first_name=billing_details['name'], # Stripe only has a single name field
last_name='',
line1=customer_address['line1'],
line2='' if not customer_address['line2'] else customer_address['line2'], # line2 is optional
line4=customer_address['city'], # Oscar uses line4 for city
postcode='' if not customer_address['postal_code'] else customer_address['postal_code'], # postcode is optional
state='' if not customer_address['state'] else customer_address['state'], # state is optional
country=Country.objects.get(iso_3166_1_a2__iexact=customer_address['country'])
)
return address
15 changes: 11 additions & 4 deletions ecommerce/extensions/basket/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
translate_basket_line_for_segment
)
from ecommerce.extensions.basket import message_utils
from ecommerce.extensions.basket.constants import EMAIL_OPT_IN_ATTRIBUTE
from ecommerce.extensions.basket.constants import EMAIL_OPT_IN_ATTRIBUTE, ENABLE_STRIPE_PAYMENT_PROCESSOR
from ecommerce.extensions.basket.exceptions import BadRequestException, RedirectException, VoucherException
from ecommerce.extensions.basket.utils import (
add_invalid_code_message_to_url,
Expand Down Expand Up @@ -583,7 +583,7 @@ def _get_payment_processors_data(self, payment_processors):
basket view context needs to be updated with.
"""
site_configuration = self.request.site.siteconfiguration
payment_processor_class = site_configuration.get_client_side_payment_processor_class()
payment_processor_class = site_configuration.get_client_side_payment_processor_class(self.request)

if payment_processor_class:
payment_processor = payment_processor_class(self.request.site)
Expand Down Expand Up @@ -615,15 +615,16 @@ class CaptureContextApiLogicMixin: # pragma: no cover
Business logic for the capture context API.
"""
def _add_capture_context(self, response):
payment_processor_class = self.request.site.siteconfiguration.get_client_side_payment_processor_class()
site_configuration = self.request.site.siteconfiguration
payment_processor_class = site_configuration.get_client_side_payment_processor_class(self.request)
if not payment_processor_class:
return
payment_processor = payment_processor_class(self.request.site)
if not hasattr(payment_processor, 'get_capture_context'):
return

try:
response['capture_context'] = payment_processor.get_capture_context(self.request.session)
response['capture_context'] = payment_processor.get_capture_context(self.request)
except: # pylint: disable=bare-except
logger.exception("Error generating capture_context")
return
Expand Down Expand Up @@ -681,6 +682,7 @@ def _serialize_context(self, context, lines_data):
self._add_total_summary(response, context)
self._add_offers(response)
self._add_coupons(response, context)
self._add_enable_stripe_payment_processor(response)
return response

def _add_products(self, response, lines_data):
Expand Down Expand Up @@ -738,6 +740,11 @@ def _add_coupons(self, response, context):
def _add_messages(self, response):
response['messages'] = message_utils.serialize(self.request)

def _add_enable_stripe_payment_processor(self, response):
response['enable_stripe_payment_processor'] = waffle.flag_is_active(
self.request, ENABLE_STRIPE_PAYMENT_PROCESSOR
)

def _get_response_status(self, response):
return message_utils.get_response_status(response['messages'])

Expand Down
24 changes: 20 additions & 4 deletions ecommerce/extensions/payment/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,41 @@
'display_name': _('American Express'),
'cybersource_code': '003',
'apple_pay_network': 'amex',
'stripe_brand': 'American Express',
'stripe_brand': 'amex',
},
'diners': {
'display_name': _('Diners'),
'stripe_brand': 'diners',
},
'discover': {
'display_name': _('Discover'),
'cybersource_code': '004',
'apple_pay_network': 'discover',
'stripe_brand': 'Discover',
'stripe_brand': 'discover',
},
'jcb': {
'display_name': _('JCB'),
'stripe_brand': 'jcb',
},
'mastercard': {
'display_name': _('MasterCard'),
'cybersource_code': '002',
'apple_pay_network': 'mastercard',
'stripe_brand': 'MasterCard',
'stripe_brand': 'mastercard',
},
'unionpay': {
'display_name': _('UnionPay'),
'stripe_brand': 'unionpay',
},
'unknown': {
'display_name': _('Unknown'),
'stripe_brand': 'unknown',
},
'visa': {
'display_name': _('Visa'),
'cybersource_code': '001',
'apple_pay_network': 'visa',
'stripe_brand': 'Visa',
'stripe_brand': 'visa',
},
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.15 on 2022-10-11 16:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('payment', '0031_sdnfallbackdata'),
]

operations = [
migrations.AlterField(
model_name='source',
name='card_type',
field=models.CharField(blank=True, choices=[('american_express', 'American Express'), ('diners', 'Diners'), ('discover', 'Discover'), ('jcb', 'JCB'), ('mastercard', 'MasterCard'), ('unionpay', 'UnionPay'), ('unknown', 'Unknown'), ('visa', 'Visa')], max_length=255, null=True),
),
]
3 changes: 3 additions & 0 deletions ecommerce/extensions/payment/processors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@


import abc
import logging
from collections import namedtuple

import waffle
Expand All @@ -13,6 +14,8 @@
HandledProcessorResponse = namedtuple('HandledProcessorResponse',
['transaction_id', 'total', 'currency', 'card_number', 'card_type'])

logger = logging.getLogger(__name__)


class BasePaymentProcessor(metaclass=abc.ABCMeta): # pragma: no cover
"""Base payment processor class."""
Expand Down
3 changes: 2 additions & 1 deletion ecommerce/extensions/payment/processors/cybersource.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ def __init__(self, site):
def client_side_payment_url(self):
return None

def get_capture_context(self, session): # pragma: no cover
def get_capture_context(self, request): # pragma: no cover
# To delete None values in Input Request Json body
session = request.session

requestObj = GeneratePublicKeyRequest(
encryption_type='RsaOaep256',
Expand Down
Loading