Пример #1
0
 def _verify_enterprise_needs(self, voucher, code, stock_record):
     if get_enterprise_customer_from_voucher(self.request.site, voucher) is not None:
         # The below lines only apply if the voucher that was entered is attached
         # to an EnterpriseCustomer. If that's the case, then rather than following
         # the standard redemption flow, we kick the user out to the `redeem` flow.
         # This flow will handle any additional information that needs to be gathered
         # due to the fact that the voucher is attached to an Enterprise Customer.
         params = urllib.parse.urlencode(
             OrderedDict([
                 ('code', code),
                 ('sku', stock_record.partner_sku),
                 ('failure_url', self.request.build_absolute_uri(
                     '{path}?{params}'.format(
                         path=reverse('basket:summary'),
                         params=urllib.parse.urlencode(
                             {
                                 CONSENT_FAILED_PARAM: code
                             }
                         )
                     )
                 ))
             ])
         )
         redirect_response = HttpResponseRedirect(
             self.request.build_absolute_uri(
                 '{path}?{params}'.format(
                     path=reverse('coupons:redeem'),
                     params=params
                 )
             )
         )
         raise RedirectException(response=redirect_response)
Пример #2
0
 def _redirect_for_enterprise_entitlement_if_needed(self, request, voucher,
                                                    products, skus):
     """
     If there is an Enterprise entitlement available for this basket,
     we redirect to the CouponRedeemView to apply the discount to the
     basket and handle the data sharing consent requirement.
     """
     if voucher is None:
         code_redemption_redirect = get_enterprise_code_redemption_redirect(
             request, products, skus, 'basket:basket-add')
         if code_redemption_redirect:
             raise RedirectException(response=code_redemption_redirect)
Пример #3
0
    def verify_enterprise_needs(self, basket):
        failed_enterprise_consent_code = self.request.GET.get(
            CONSENT_FAILED_PARAM)
        if failed_enterprise_consent_code:
            messages.error(
                self.request,
                _("Could not apply the code '{code}'; it requires data sharing consent."
                  ).format(code=failed_enterprise_consent_code))

        if has_enterprise_offer(basket) and basket.total_incl_tax == Decimal(
                0):
            raise RedirectException(response=absolute_redirect(
                self.request, 'checkout:free-checkout'), )
Пример #4
0
 def _redirect_to_payment_microfrontend_if_configured(self, request):
     microfrontend_url = get_payment_microfrontend_url_if_configured(request)
     if microfrontend_url:
         # For now, the enterprise consent form validation is communicated via
         # a URL parameter, which must be forwarded via this redirect.
         consent_failed_param_to_forward = request.GET.get(CONSENT_FAILED_PARAM)
         if consent_failed_param_to_forward:
             microfrontend_url = '{}?{}={}'.format(
                 microfrontend_url,
                 CONSENT_FAILED_PARAM,
                 consent_failed_param_to_forward,
             )
         redirect_response = HttpResponseRedirect(microfrontend_url)
         raise RedirectException(response=redirect_response)
Пример #5
0
 def _redirect_for_enterprise_data_sharing_consent(self, basket):
     """
     Redirect to LMS to get data sharing consent from learner.
     """
     # check if basket contains only a single product of type seat
     if basket.lines.count() == 1 and basket.lines.first(
     ).product.is_seat_product:
         enterprise_custmer_uuid = get_enterprise_customer_from_enterprise_offer(
             basket)
         product = basket.lines.first().product
         course = product.course
         if enterprise_custmer_uuid is not None and enterprise_customer_user_needs_consent(
                 self.request.site,
                 enterprise_custmer_uuid,
                 course.id,
                 self.request.user.username,
         ):
             redirect_url = construct_enterprise_course_consent_url(
                 self.request, product.course.id, enterprise_custmer_uuid)
             raise RedirectException(
                 response=HttpResponseRedirect(redirect_url))
Пример #6
0
 def _verify_email_confirmation(self, voucher, product):
     offer = voucher.best_offer
     redirect_response = get_redirect_to_email_confirmation_if_required(
         self.request, offer, product)
     if redirect_response:
         raise RedirectException(response=redirect_response)