Example #1
0
    def get_context_data(self, **kwargs):
        """
        Add data for Bpoint.
        """
        # Override method so the bankcard and billing address forms can be
        # added to the context.
        ctx = super(PaymentDetailsView, self).get_context_data(**kwargs)
        method = self.checkout_session.payment_method()
        custom_template = self.checkout_session.custom_template()

        ctx['store_card'] = True
        user = None
        # only load stored cards if the user is an admin or has legitimately logged in
        if self.checkout_session.basket_owner() and is_payment_admin(
                self.request.user):
            user = EmailUser.objects.get(
                id=int(self.checkout_session.basket_owner()))
        elif self.request.user.is_authenticated():
            user = self.request.user

        if user:
            cards = user.stored_cards.all()
            if cards:
                ctx['cards'] = cards

        ctx['custom_template'] = custom_template
        ctx['bpay_allowed'] = settings.BPAY_ALLOWED
        ctx['payment_method'] = method
        ctx['bankcard_form'] = kwargs.get('bankcard_form',
                                          forms.BankcardForm())
        ctx['billing_address_form'] = kwargs.get('billing_address_form',
                                                 forms.BillingAddressForm())
        return ctx
Example #2
0
    def post(self, request, *args, **kwargs):
        # Override so we can validate the bankcard/billingaddress submission.
        # If it is valid, we render the preview screen with the forms hidden
        # within it.  When the preview is submitted, we pick up the 'action'
        # parameters and actually place the order.
        if request.POST.get('action', '') == 'place_order':
            if self.checkout_session.payment_method() == 'card':
                return self.do_place_order(request)
            else:
                return self.handle_place_order_submission(request)
        else:
            # Get the payment method either card or other
            payment_method = request.POST.get('payment_method', '')
            self.checkout_session.pay_by(payment_method)
            # Get if user wants to store the card
            store_card = request.POST.get('store_card', False)
            self.checkout_session.permit_store_card(bool(store_card))
        bankcard_form = forms.BankcardForm(request.POST)
        if payment_method == 'card':
            if not bankcard_form.is_valid():
                # Form validation failed, render page again with errors
                self.preview = False
                ctx = self.get_context_data(bankcard_form=bankcard_form)
                return self.render_to_response(ctx)

        # Render preview with bankcard hidden
        if payment_method == 'card':
            return self.render_preview(request, bankcard_form=bankcard_form)
        else:
            return self.render_preview(request)
Example #3
0
    def get_context_data(self, **kwargs):
        """
        Add data for Bpoint.
        """
        # Override method so the bankcard and billing address forms can be
        # added to the context.
        ctx = super(PaymentDetailsView, self).get_context_data(**kwargs)
        method = self.checkout_session.payment_method()
        custom_template = self.checkout_session.custom_template()

        ctx['store_card'] = True
        if self.checkout_session.basket_owner():
            user = EmailUser.objects.get(
                id=int(self.checkout_session.basket_owner()))
        else:
            user = self.request.user
        cards = user.stored_cards.all()
        if cards:
            ctx['cards'] = cards

        ctx['custom_template'] = custom_template
        ctx['payment_method'] = method
        ctx['bankcard_form'] = kwargs.get('bankcard_form',
                                          forms.BankcardForm())
        ctx['billing_address_form'] = kwargs.get('billing_address_form',
                                                 forms.BillingAddressForm())
        return ctx
Example #4
0
    def do_place_order(self, request):
        # Helper method to check that the hidden forms wasn't tinkered
        # with.
        bankcard_form = forms.BankcardForm(request.POST)
        if not bankcard_form.is_valid():
            messages.error(request, "Invalid submission")
            return HttpResponseRedirect(reverse('checkout:payment-details'))

        # Attempt to submit the order, passing the bankcard object so that it
        # gets passed back to the 'handle_payment' method below.
        submission = self.build_submission()
        submission['payment_kwargs']['bankcard'] = bankcard_form.bankcard
        return self.submit(**submission)
Example #5
0
 def get_context_data(self, **kwargs):
     """
     Add data for Bpoint.
     """
     # Override method so the bankcard and billing address forms can be
     # added to the context.
     ctx = super(PaymentDetailsView, self).get_context_data(**kwargs)
     method = self.checkout_session.payment_method()
     custom_template = self.checkout_session.custom_template()
     if not self.checkout_session.checkoutWithToken():
         ctx['store_card'] = True
     ctx['custom_template'] = custom_template
     ctx['payment_method'] = method
     ctx['bankcard_form'] = kwargs.get('bankcard_form',
                                       forms.BankcardForm())
     ctx['billing_address_form'] = kwargs.get('billing_address_form',
                                              forms.BillingAddressForm())
     return ctx
Example #6
0
    def post(self, request, *args, **kwargs):
        # Override so we can validate the bankcard/billingaddress submission.
        # If it is valid, we render the preview screen with the forms hidden
        # within it.  When the preview is submitted, we pick up the 'action'
        # parameters and actually place the order.
        if request.POST.get('action', '') == 'place_order':
            if self.checkout_session.payment_method() == 'card':
                return self.do_place_order(request)
            else:
                return self.handle_place_order_submission(request)
        # Validate the payment method
        payment_method = request.POST.get('payment_method', '')
        if payment_method == 'bpay' and settings.BPAY_ALLOWED:
            self.checkout_session.pay_by('bpay')
        elif payment_method == 'card':
            self.checkout_session.pay_by('card')
        elif payment_method:  # someone's trying to pull a fast one, refresh the page
            self.preview = False
            return self.render_to_response(self.get_context_data())

        # Get if user wants to store the card
        store_card = request.POST.get('store_card', False)
        self.checkout_session.permit_store_card(bool(store_card))
        # Get if user wants to checkout using a stored card
        checkout_token = request.POST.get('checkout_token', False)
        if checkout_token:
            self.checkout_session.checkout_using_token(
                request.POST.get('card', ''))

        if self.checkout_session.payment_method(
        ) == 'card' and not checkout_token:
            bankcard_form = forms.BankcardForm(request.POST)
            if not bankcard_form.is_valid():
                # Form validation failed, render page again with errors
                self.preview = False
                ctx = self.get_context_data(bankcard_form=bankcard_form)
                return self.render_to_response(ctx)

        # Render preview with bankcard hidden
        if self.checkout_session.payment_method(
        ) == 'card' and not checkout_token:
            return self.render_preview(request, bankcard_form=bankcard_form)
        else:
            return self.render_preview(request)