Agile Web Development with Rails, Edition 4

26.2 HAML 25.2 rake

26.1 Active Merchant

Determine if a credit card is valid

edit Gemfile
gem 'activemerchant', '~> 1.31'
bundle install --local
Resolving dependencies...
Using rake (10.2.1)
Using i18n (0.6.9)
Using multi_json (1.9.2)
Using activesupport (3.2.17) from source at /home/rubys/git/rails
Using builder (3.0.4)
Using activemodel (3.2.17) from source at /home/rubys/git/rails
Using erubis (2.7.0)
 
journey at /home/rubys/git/journey did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
  duplicate dependency on rdoc (~> 3.10, development), (~> 3.11) use:
    add_runtime_dependency 'rdoc', '~> 3.10', '~> 3.11'
Using journey (1.0.4.20120614141756) from source at /home/rubys/git/journey
Using rack (1.4.5)
Using rack-cache (1.2)
Using rack-test (0.6.2)
Using hike (1.2.3)
Using tilt (1.4.1)
Using sprockets (2.2.2)
Using actionpack (3.2.17) from source at /home/rubys/git/rails
Using mime-types (1.25.1)
Using polyglot (0.3.4)
Using treetop (1.4.15)
Using mail (2.5.4)
Using actionmailer (3.2.17) from source at /home/rubys/git/rails
Using active_utils (2.0.2)
Using json (1.8.1)
Using monetize (0.1.4)
Using money (6.0.1)
Using mini_portile (0.5.3)
Using nokogiri (1.6.1)
Using activemerchant (1.42.7)
Using arel (3.0.3.20131114190737) from source at /home/rubys/git/arel
Using tzinfo (0.3.39)
Using activerecord (3.2.17) from source at /home/rubys/git/rails
Using activeresource (3.2.17) from source at /home/rubys/git/rails
Using bcrypt-ruby (3.0.1)
Using bundler (1.5.3)
Using highline (1.6.21)
Using net-ssh (2.8.0)
Using net-scp (1.1.2)
Using net-sftp (2.1.2)
Using net-ssh-gateway (1.2.0)
Using capistrano (2.15.5)
Using coffee-script-source (1.7.0)
Using execjs (2.0.2)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.4)
Using rdoc (3.12.2)
Using thor (0.19.1)
Using railties (3.2.17) from source at /home/rubys/git/rails
Using coffee-rails (3.2.2) from source at /home/rubys/git/coffee-rails
Using jquery-rails (3.1.0)
Using jquery-ui-rails (4.2.0)
Using mysql2 (0.3.15)
Using rails (3.2.17) from source at /home/rubys/git/rails
Using rvm-capistrano (1.5.1)
Using sass (3.3.4)
Using sass-rails (3.2.6) from source at /home/rubys/git/sass-rails
Using sqlite3 (1.3.9)
Using uglifier (2.5.0)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
edit script/creditcard.rb
credit_card = ActiveMerchant::Billing::CreditCard.new(
  number:     '4111111111111111',
  month:      '8',
  year:       '2009',
  first_name: 'Tobias',
  last_name:  'Luetke',
  verification_value:  '123' 
)
 
puts "Is #{credit_card.number} valid?  #{credit_card.valid?}"
rails runner script/creditcard.rb
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
Is 4111111111111111 valid?  false

26.2 HAML 25.2 rake