If you want to check the credit card before accepting the form and 
inserting the record into the db, you might consider an 
onvalidation<http://web2py.com/books/default/chapter/29/07#onvalidation>function
 instead. Otherwise, if you just want to add an error message to a 
particular form field, you can do form.errors.fieldname = 'error message'. 
You might consider delivering a different error message depending on 
whether the card is declined or there is some other exception thrown when 
running the make_payment code.

Anthony

On Wednesday, January 23, 2013 10:16:57 PM UTC-5, Ragtime AllTime wrote:
>
>  I think I may be going about this wrong, but I want to throw new form 
> errors if something happens after doing form.accepts(...). I'm not using 
> SQLFORM or CRUD, just the FORM().
>
> The scenario is something like this: The user enters payment information 
> correctly, but when I charge the card, the card is returned declined. Then, 
> the form should display an error saying that there are errors with the card 
> and present the user with the form again, as though validation had failed. 
> The same flow would go with emailing the user too.
>
>
> form = FORM(...)
>
> if form.accepts(request, session):
>     try:
>          makePayment(....)    
>          redirect(URL('successful_payment'))   # Redirect after success
>     except ...
>          # Display Errors on form here and show the form to the user.
>
> elif form.errors:   # Validation has failed
>     response.flash = 'form has errors'
>
>
>
> What would go in the except block?
>

-- 



Reply via email to