Not sure why but my form is not displaying errors. One of the first
parts of my method is to check for errors and display them before
processing the credit card. It just skips that part regardless of
errors or not and tries to process the credit card.
def signup_unlimited
@user = User.new
end
def signup_unlimited_create
User.transaction do
@user = User.new(params[:user])
@user.account_type = “Unlimited”
@user.login = @user.email
@number = params[:card_number]
@month = params[:card_expiration_month]
@year = params[:card_expiration_year]
@type = params[:card_type]
gateway = ActiveMerchant::Billing::BraintreeGateway.new({
:login => 'btdemo',
:password => 'btdemo123'
})
if @user.errors.empty?
if @number != "" and @month != "" and @year != "" and @type !=
“”
@card =
ActiveMerchant::Billing::CreditCard.new(:first_name =>
@user.first_name,
:last_name => @user.last_name,
:number => params[:card_number],
:month => params[:card_expiration_month],
:year => params[:card_expiration_year],
:type => params[:card_type])
@amount = 430.50
@options = { :store => true, :order_id => "1212451" }
response = gateway.authorize(@amount, @card,
@options)
if @card.id != nil
self.current_user = @user
@user.credit_card_id =
response.params[“customer_vault_id”]
end
if @user.credit_card_id != nil
@user.save
@invoice = Invoice.new(params[:invoice])
@invoice.amount = "9.95"
@invoice.due_date = Date.today + 30
@invoice.generated_date = Date.today
@invoice.status = "Due"
@invoice.user_id = @user.id
@invoice.save
self.current_user = @user
flash[:notice] = "Thanks for signing up"
redirect_to :action => 'index'
end
if @user.credit_card_id == nil
flash[:notice] = "Please verify your credit card
information below."
render :action => ‘signup_unlimited’
end
else
flash[:notice] = “Please fill out all the necessary billing
information.”
render :action => ‘signup_unlimited’
end
else
flash[:notice] = “errors with your user form”
render :action => ‘signup_unlimited’
end
end
end
Form is pretty standard, including the error_messages part
<%= error_messages_for :user %>
<%= image_tag ‘signup_header.jpg’ %>