views:

31

answers:

2

So I have a subscription form where a user is simultaneously creating a new account plus subscribing to a monthly plan.

So they're entering username, email, password, and all the usual credit card/billing info.

But the problem I'm having is say they accidentally enter an incorrect credit card number...what's the best way to handle that?

I need to create the user account first so I can have a database row ID (for the third-party billing service), but since I have all of that handled in one swoop in my create method, if the user corrects their card info and re-submits, it tells them the account already exists (since the user account was actually already created).

So, question here is how would you handle this? Would you take them to an error page that's only the billing data? Or what else? Not sure what the best way to handle this is...

A: 

Not aware of any standard, but I'm sure that the best way is to delete the newly created user account if billing service check failed (a field created_at may help to detect timeouts).

This mechanism is implemented via database transactions and it doesn't take much effort in Rails. But make sure you're not using exclusive locking on your database.

Pavel Shved
A: 

in my opinion, you could handle this in two different ways

1) just save the data after everything was successfully verified. you can use a custom validation for checking the credit card. see snippets.dzone.com/posts/show/5266

2) use two different models (users and credit_cards) and use find_or_create (actually you could use find_or_create also with one model) see http://blogs.law.harvard.edu/lianaleahy/2008/05/19/find_or_create/

z3cko