def _get_payment_processors_data(self, payment_processors): """Retrieve information about payment processors for the client side checkout basket. Args: payment_processors (list): List of all available payment processors. Returns: A dictionary containing information about the payment processor(s) with which the 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() if payment_processor_class: payment_processor = payment_processor_class(self.request.site) current_year = datetime.today().year return { 'client_side_payment_processor': payment_processor, 'enable_client_side_checkout': True, 'months': range(1, 13), 'payment_form': PaymentForm( user=self.request.user, initial={'basket': self.request.basket}, label_suffix='' ), 'paypal_enabled': 'paypal' in (p.NAME for p in payment_processors), # Assumption is that the credit card duration is 15 years 'years': range(current_year, current_year + 16), } else: msg = 'Unable to load client-side payment processor [{processor}] for ' \ 'site configuration [{sc}]'.format(processor=site_configuration.client_side_payment_processor, sc=site_configuration.id) raise SiteConfigurationError(msg)
def get_context_data(self, **kwargs): context = super(BasketSummaryView, self).get_context_data(**kwargs) formset = context.get('formset', []) lines = context.get('line_list', []) lines_data = [] is_verification_required = is_bulk_purchase = False switch_link_text = partner_sku = '' basket = self.request.basket site = self.request.site site_configuration = site.siteconfiguration for line in lines: course_key = CourseKey.from_string(line.product.attr.course_key) course_name = None image_url = None short_description = None try: course = get_course_info_from_catalog(self.request.site, course_key) try: image_url = course['image']['src'] except (KeyError, TypeError): image_url = '' short_description = course.get('short_description', '') course_name = course.get('title', '') except (ConnectionError, SlumberBaseException, Timeout): logger.exception('Failed to retrieve data from Catalog Service for course [%s].', course_key) if self.request.site.siteconfiguration.enable_enrollment_codes: # Get variables for the switch link that toggles from enrollment codes and seat. switch_link_text, partner_sku = get_basket_switch_data(line.product) if line.product.get_product_class().name == ENROLLMENT_CODE_PRODUCT_CLASS_NAME: is_bulk_purchase = True # Iterate on message storage so all messages are marked as read. # This will hide the success messages when a user updates the quantity # for an item in the basket. list(messages.get_messages(self.request)) if line.has_discount: benefit = basket.applied_offers().values()[0].benefit benefit_value = format_benefit_value(benefit) else: benefit_value = None lines_data.append({ 'seat_type': self._determine_seat_type(line.product), 'course_name': course_name, 'course_key': course_key, 'image_url': image_url, 'course_short_description': short_description, 'benefit_value': benefit_value, 'enrollment_code': line.product.get_product_class().name == ENROLLMENT_CODE_PRODUCT_CLASS_NAME, 'line': line, }) user = self.request.user context.update({ 'analytics_data': prepare_analytics_data( user, self.request.site.siteconfiguration.segment_key, unicode(course_key) ), 'enable_client_side_checkout': False, }) if site_configuration.client_side_payment_processor \ and waffle.flag_is_active(self.request, CLIENT_SIDE_CHECKOUT_FLAG_NAME): payment_processor_class = site_configuration.get_client_side_payment_processor_class() if payment_processor_class: payment_processor = payment_processor_class(site) context.update({ 'enable_client_side_checkout': True, 'payment_form': PaymentForm(user=user, initial={'basket': basket}, label_suffix=''), 'payment_url': payment_processor.client_side_payment_url, }) else: msg = 'Unable to load client-side payment processor [{processor}] for ' \ 'site configuration [{sc}]'.format(processor=site_configuration.client_side_payment_processor, sc=site_configuration.id) raise SiteConfigurationError(msg) # Check product attributes to determine if ID verification is required for this basket try: is_verification_required = line.product.attr.id_verification_required \ and line.product.attr.certificate_type != 'credit' except AttributeError: pass context.update({ 'free_basket': context['order_total'].incl_tax == 0, 'payment_processors': site_configuration.get_payment_processors(), 'homepage_url': get_lms_url(''), 'formset_lines_data': zip(formset, lines_data), 'is_verification_required': is_verification_required, 'min_seat_quantity': 1, 'is_bulk_purchase': is_bulk_purchase, 'switch_link_text': switch_link_text, 'partner_sku': partner_sku, }) return context