public
Description: Active Merchant is a simple payment abstraction library used in and sponsored by Shopify. It is written by Tobias Luetke, Cody Fauser, and contributors. The aim of the project is to feel natural to Ruby users and to abstract as many parts as possible away from the user to offer a consistent interface across all supported gateways.
Home | Edit | New

GettingStarted

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'

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 #missing end to if creditcard.valid?

Some useful URLs:
http://www.codyfauser.com/2008/1/17/paypal-express-payments-with-activemerchant

Last edited by wesgarrison, Thu Aug 27 08:09:45 -0700 2009
Home | Edit | New
Versions: