I have an issue with ActiveMerchant credit card validation in my rails 2.3.2 application.(ActiveMerchant 1.4.1)
I followed the railscast #145 episode codes exactly.
My problem is when I am validation the credit card with invalid data like :first_name,:last_name as empty, ActiveMerchant is not giving validations errors
I tried this in my script/console
credit_card = ActiveMerchant::Billing::CreditCard.new(:number => "",:first_name => "")
credit_card.errors.full_messages #=> []
credit_card.errors #=> {}
My payment.rb contains
validate_on_create :validate_card
private
def validate_card
unless credit_card.valid?
credit_card.errors.full_messages.each do |message|
errors.add_to_base message
end
end
end
def credit_card
@credit_card = ActiveMerchant::Billing::CreditCard.new(
:number => card_number,
:month => card_expires_on.month,
:year => card_expires_on.year,
:first_name => first_name,
:last_name => last_name,
:verification_value => cvv_number,
:type => card_type
)
end
The credit card errors are not added to @payment object I created in my controller#create Please tell me where I did mistake
Please add an an || in ur credit_card function