views:

41

answers:

1

Hi there, I've looked through the django documentation, done lots of googling and have tried quite a few different solutions but to no avail.

I've created a 3 part form using Django's FormWizard. Once the last form (a payment form) is validated, I send a payment request to a payment gateway.

I'm doing the payment processing in the 'process_step' method of the FormWizard.

I'm having difficulty figuring out how to have the FormWizard show the payment page again when the payment fails. As it is now, the FormWizard's 'done' method gets called (after I've done my processing in process_step), as all of the forms have been validated.

I'm wondering if I need to override the call method. Not really sure how to do that, but I'm currently trying to figure that out.

Any help would be much appreciated. Regards, Shawn

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/')
A: 

The FormWizard is aware of field validation but anything outside that, such as credit card processing is up to your view (or elsewhere) to catch and respond to.

Since the form validated, and you now have a POST of the users input, each exception/result in your view can render to the page (w/ RequestContext on) and also add to it your error messages . Same should apply to forms.py.

Flowpoke
Hi Flowpoke, thanks for the response. I'm still not quite clear on this. I'm not sure how to stay within the form wizard's processing when the payment fails on the last step. Could you take a look at the additional comments I've added and possibly provide a bit more detail, or a line of code to help out. In the meantime, I'll keep working at it. Cheers.
shawn