Skip to content
Ashish Singh edited this page Jan 25, 2018 · 5 revisions

Using AM is fairly straightforward, and the RDOC is fairly comprehensive, however, the following quickstart guide may be helpful.

First note that AM is (mostly) unrelated to Rails, it’s a payment interface and your application needs to handle the actual collection of customer details and the whole order process. AM will only help you with interfacing to the payment gateway and taking payments (and interpreting the gateway reply)

OK, so assuming you have built some application which has somehow captured the customers billing details and credit card info, a simple example to bill that customer would be as follows:

require 'active_merchant'

charge_amount=1000 #$10.00 in cents
LOGIN_ID = 'your_login_id_here'
TRANSACTION_KEY = 'your_trans_key_here'
ActiveMerchant::Billing::Base.mode = :test

#number = '4222222222222' #Authorize.net test card, error-producing
number = '4007000000027' #Authorize.net test card, non-error-producing
billing_address = { :name => 'Bob Smith', :address1 => '123 Down the Road',
  :city => 'San Francisco', :state => 'CA',
  :country => 'US', :zip => '23456', :phone => '(555)555-5555' }

credit_card = ActiveMerchant::Billing::CreditCard.new(
  :number => number,
  :month => 10,
  :year => 2010,
  :first_name => 'Bob',
  :last_name => 'Smith',
  :verification_value => '111', #verification codes are now required
  :type => 'visa'
)

if credit_card.valid?
  gateway = ActiveMerchant::Billing::AuthorizeNetGateway.new(
   :login  => LOGIN_ID,
   :password => TRANSACTION_KEY
  )

  options = {:address => {}, :billing_address => billing_address}
  response = gateway.purchase(charge_amount, credit_card, options)

  if response.success?
   puts "success!"
  else
   raise StandardError.new( response.message )
  end
end

Some useful URLs:
http://www.gotripod.com/ruby-on-rails-paypal-express-recurring-payments-using-active-merchant