Example #1
0
 def get_context_data(self, **kwargs):
     # Override method so the bankcard and billing address forms can be
     # added to the context.
     ctx = super(PaymentDetailsView, self).get_context_data(**kwargs)
     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 get_context_data(self, **kwargs):
        # Override method so the bankcard and billing address forms can be added
        # to the context.
        ctx = super(PaymentDetailsView, self).get_context_data(**kwargs)

        ctx['bankcard_form'] = kwargs.get('bankcard_form', forms.BankcardForm())
        
        ctx['billing_address_form'] = kwargs.get('billing_address_form', forms.BillingAddressForm())

        if self.get_default_billing_address() is not None and kwargs.get('billing_address_form') is None:
            
            # initialize billing address form with user's address
            default_billing_address_form = forms.BillingAddressForm(initial=self.get_default_billing_address().__dict__)            
            
            # pass the updated form to the context
            ctx['billing_address_form'] = default_billing_address_form

        return ctx
Example #3
0
 def get_context_data(self, **kwargs):
     """
     Add data for Paypal Express flow.
     """
     # Override method so the bankcard and billing address forms can be
     # added to the context.
     ctx = super(PaymentDetailsView, self).get_context_data(**kwargs)
     ctx['bankcard_form'] = kwargs.get(
         'bankcard_form', forms.BankcardForm())
     ctx['billing_address_form'] = kwargs.get(
         'billing_address_form', forms.BillingAddressForm())
     ctx['PAYPAL_CLIENT_ID'] = settings.PAYPAL_API_CLIENT_ID
     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)
        billing_address_form = forms.BillingAddressForm(request.POST)
        if not all([bankcard_form.is_valid(), billing_address_form.is_valid()]):
            messages.error(request, "Invalid submission")
            return HttpResponseRedirect(reverse('checkout:payment-details'))
        bankcard = bankcard_form.get_bankcard_obj()

        # Attempt to submit the order, passing the bankcard object so that it
        # gets passed back to the 'handle_payment' method below.
        return self.submit(
            request.basket,
            payment_kwargs={'bankcard': bankcard,
                            'billing_address': billing_address_form.cleaned_data})
    def do_place_order(self, request):
        # Helper method to check that the hidden forms wasn't tinkered
        # with.
        bankcard_form = forms.BankcardForm(request.POST)
        billing_address_form = forms.BillingAddressForm(request.POST)
        if not all([bankcard_form.is_valid(),
                    billing_address_form.is_valid()]):
            messages.error(request, "Invalid submission")
            return redirect('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
        submission['payment_kwargs'][
            'billing_address'] = billing_address_form.cleaned_data
        return self.submit(**submission)
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':
            return self.do_place_order(request)

        bankcard_form = forms.BankcardForm(request.POST)
        billing_address_form = forms.BillingAddressForm(request.POST)

        if not all([bankcard_form.is_valid(), billing_address_form.is_valid()]):
            # Form validation failed, render page again with errors
            self.preview = False
            ctx = self.get_context_data(bankcard_form=bankcard_form,
                                        billing_address_form=billing_address_form)
            return self.render_to_response(ctx)

        # Render preview with bankcard and billing address details hidden
        return self.render_preview(request,
                                   bankcard_form=bankcard_form,
                                   billing_address_form=billing_address_form)
Example #7
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':
            submission = self.build_submission()
            self.submit(**submission)
            return redirect(reverse('payfast-redirect'))

        # bankcard_form = forms.BankcardForm(request.POST)
        billing_address_form = forms.BillingAddressForm(request.POST)
        #
        if not billing_address_form.is_valid():
            # Form validation failed, render page again with errors
            self.preview = False
            ctx = self.get_context_data(
                billing_address_form=billing_address_form)
            return self.render_to_response(ctx)

        # Render billing address details hidden
        return self.render_preview(request,
                                   billing_address_form=billing_address_form)