def select_account(self, request):
        ctx = self.get_context_data()

        # Check for blocked users
        if security.is_blocked(request):
            messages.error(request,
                           "You are currently blocked from using accounts")
            return http.HttpResponseRedirect(
                reverse('checkout:payment-deatils'))

        # If account form has been submitted, validate it and show the
        # allocation form if the account has non-zero balance
        form = forms.ValidAccountForm(self.request.user,
                                      self.request.POST)
        ctx['account_form'] = form
        if not form.is_valid():
            security.record_failed_request(self.request)
            return self.render_to_response(ctx)

        security.record_successful_request(self.request)
        ctx['allocation_form'] = forms.AllocationForm(
            form.account, self.request.basket,
            ctx['shipping_total_incl_tax'],
            ctx['order_total_incl_tax'],
            self.get_account_allocations())
        return self.render_to_response(ctx)
Esempio n. 2
0
    def select_account(self, request):
        ctx = self.get_context_data()

        # Check for blocked users
        if security.is_blocked(request):
            messages.error(request,
                           "You are currently blocked from using accounts")
            return http.HttpResponseRedirect(
                reverse('checkout:payment-deatils'))

        # If account form has been submitted, validate it and show the
        # allocation form if the account has non-zero balance
        form = forms.ValidAccountForm(self.request.user, self.request.POST)
        ctx['account_form'] = form
        if not form.is_valid():
            security.record_failed_request(self.request)
            return self.render_to_response(ctx)

        security.record_successful_request(self.request)
        ctx['allocation_form'] = forms.AllocationForm(
            form.account, self.request.basket, ctx['shipping_charge'].incl_tax
            if ctx['shipping_charge'].is_tax_known else
            ctx['shipping_charge'].excl_tax, ctx['order_total'].incl_tax if
            ctx['order_total'].is_tax_known else ctx['order_total'].excl_tax,
            self.get_account_allocations())
        return self.render_to_response(ctx)
    def get_context_data(self, **kwargs):
        ctx = super(PaymentDetailsView, self).get_context_data(**kwargs)

        # Add variable to indicate if the user is blocked from paying with
        # accounts.
        ctx['is_blocked'] = security.is_blocked(self.request)

        form = forms.ValidAccountForm(self.request.user)
        ctx['account_form'] = form

        # Add accounts that are linked to this user
        if self.request.user.is_authenticated():
            ctx['user_accounts'] = gateway.user_accounts(self.request.user)

        # Add existing allocations to context
        allocations = self.get_account_allocations()
        ctx['account_allocations'] = allocations
        ctx['to_allocate'] = ctx['order_total_incl_tax'] - allocations.total

        return ctx
Esempio n. 4
0
    def get_context_data(self, **kwargs):
        ctx = super(PaymentDetailsView, self).get_context_data(**kwargs)

        # Add variable to indicate if the user is blocked from paying with
        # accounts.
        ctx['is_blocked'] = security.is_blocked(self.request)

        form = forms.ValidAccountForm(self.request.user)
        ctx['account_form'] = form

        # Add accounts that are linked to this user
        if self.request.user.is_authenticated():
            ctx['user_accounts'] = gateway.user_accounts(self.request.user)

        # Add existing allocations to context
        allocations = self.get_account_allocations()
        ctx['account_allocations'] = allocations
        ctx['to_allocate'] = ctx['order_total_incl_tax'] - allocations.total

        return ctx
Esempio n. 5
0
    def get_context_data(self, **kwargs):
        ctx = super().get_context_data(**kwargs)

        # Add variable to indicate if the user is blocked from paying with
        # accounts.
        ctx['is_blocked'] = security.is_blocked(self.request)

        form = forms.ValidAccountForm(self.request.user)
        ctx['account_form'] = form

        # Add accounts that are linked to this user
        if self.request.user.is_authenticated:
            ctx['user_accounts'] = gateway.user_accounts(self.request.user)

        # Add existing allocations to context
        allocations = self.get_account_allocations()
        ctx['account_allocations'] = allocations
        order_total = ctx['order_total']
        total_for_allocation = order_total.incl_tax if order_total.is_tax_known else order_total.excl_tax
        ctx['to_allocate'] = total_for_allocation - allocations.total

        return ctx
Esempio n. 6
0
    def get_context_data(self, **kwargs):
        ctx = super(PaymentDetailsView, self).get_context_data(**kwargs)
        ctx['paysource'] = self.get_paymethod()
        ctx['paymethod'] = self.paymentsource_name[self.get_paymethod()]
        if self.get_paymethod() == 'oscar_account':
            # Add variable to indicate if the user is blocked from paying with
            # accounts.
            ctx['is_blocked'] = security.is_blocked(self.request)

            form = forms.ValidAccountForm(self.request.user)
            ctx['account_form'] = form

            # Add accounts that are linked to this user
            if self.request.user.is_authenticated():
                ctx['user_accounts'] = gateway.user_accounts(
                    self.request.user)[0]
                code = ctx['user_accounts'].code
                balance = ctx['user_accounts'].balance
                order_total = ctx['order_total'].incl_tax if ctx[
                    'order_total'].is_tax_known else ctx['order_total'].excl_tax
                if balance < order_total:
                    self.store_allocation_in_session({
                        'code': code,
                        'amount': balance
                    })
                else:
                    self.store_allocation_in_session({
                        'code': code,
                        'amount': order_total
                    })
                ctx['allocation_form'] = forms.AllocationForm(
                    ctx['user_accounts'], self.request.basket,
                    ctx['shipping_charge'].incl_tax
                    if ctx['shipping_charge'].is_tax_known else
                    ctx['shipping_charge'].excl_tax, order_total,
                    self.get_account_allocations())

        return ctx
 def test_resets_after_success(self):
     for __ in range(2):
         security.record_failed_request(self.request)
     security.record_successful_request(self.request)
     security.record_failed_request(self.request)
     self.assertFalse(security.is_blocked(self.request))
 def test_blocks_after_freeze_threshold(self):
     for __ in range(3):
         security.record_failed_request(self.request)
     self.assertTrue(security.is_blocked(self.request))
 def test_does_not_block_by_default(self):
     self.assertFalse(security.is_blocked(self.request))
Esempio n. 10
0
 def post(self, request, *args, **kwargs):
     # Check for blocked users before trying to validate form
     if security.is_blocked(request):
         return self.get(request, *args, **kwargs)
     return super(AccountBalanceView, self).post(request, *args, **kwargs)
Esempio n. 11
0
 def get_context_data(self, **kwargs):
     ctx = super(AccountBalanceView, self).get_context_data(**kwargs)
     ctx['is_blocked'] = security.is_blocked(self.request)
     return ctx
Esempio n. 12
0
 def test_resets_after_success(self):
     for __ in range(2):
         security.record_failed_request(self.request)
     security.record_successful_request(self.request)
     security.record_failed_request(self.request)
     self.assertFalse(security.is_blocked(self.request))
Esempio n. 13
0
 def test_blocks_after_freeze_threshold(self):
     for __ in range(3):
         security.record_failed_request(self.request)
     self.assertTrue(security.is_blocked(self.request))
Esempio n. 14
0
 def test_does_not_block_by_default(self):
     self.assertFalse(security.is_blocked(self.request))