How / where to stop the Django Formwizards method caused by a payment failure

I went through the django documentation, did a lot of search queries, and tried quite a few different solutions, but to no avail.

I created a three-part form using the Django FormWizard. After checking the last form (payment form), I send a payment request to the payment gateway.

I handle the processing in the process_step FormWizard method.

It’s hard for me to figure out how to get FormWizard to show the payment page again when the payment failed. As now, the FormWizard "done" method is called (after I have completed my processing in process_step), since all forms have been verified.

I am wondering if I need to override the call method . Not quite sure how to do this, but now I'm trying to figure it out.

Any help would be greatly appreciated. Regards, Sean

class TrainingWizard(FormWizard):

def process_step(self,request,form,step):
    if step == 0:
        self.extra_context = {'stepOne': "One"}
    if step == 1:
        self.extra_context = {'stepTwo': "Two"}
    if step == 2:
        if self.get_response != "Success":
            #Payment Failed
            #Add error message
            #Show Payment Form Again to allow user to retry     
    return

def get_response(self):
    #return "Success"
    return "Declined"

def done(self, request, form_list):
    return HttpResponseRedirect('/training-registration-complete/')
+5
source share
2 answers

I finally found a solution. I am using the SessionWizardView class in Django 1.4.

I overridden the render_done () function (I copied it directly from django / django / contrib / formtools / wizard / views.py and changed it.

Between 'final_form_list.append (form_obj)' and the last three lines (starting with 'done_response = self.done (final_form_list, ** kwargs)') I process the conversation with the payment gateway.

, ( self.render.revalidation_failure()), .

:

try:
    charge = stripe.Charge.create(
        amount=price_in_cents,
        currency="usd",
        card=token,
        description="BlahStore Order Number: %s" %(self.order.pk),
    )
except (stripe.APIConnectionError, stripe.APIError, stripe.AuthenticationError, stripe.CardError, stripe.InvalidRequestError, stripe.StripeError) as e:
    from django.forms import forms
    from django.forms.util import ErrorList
    errors = final_form_list[3]._errors.setdefault(forms.NON_FIELD_ERRORS, ErrorList())
    errors.append(e.message)
    return self.render_revalidation_failure(3, final_form_list[3], **kwargs)

, "3" - , . , , . , , process_step(), , TheRightWay render_done().

+6

FormWizard , - , , ( - ), .

POST , / (w/RequestContext), . forms.py.

0

All Articles