Thursday, October 18, 2007

Testing ActiveMerchant Billing

There are some good resources for ActiveMerchant billing plugin such as:

1. Processing Credit Cards
2. Active Merchant and AuthorizeNet
3. Active Merchant Thread
4. Good blog post on ActiveMerchant

Gotchas:

1. The transaction key that is provided by AuthorizeNet expires automatically in 24 hours. So you must recreate it. Login to your AuthorizeNet test account, go to settings -> Create a new Transaction key.

Use this your login id and the newly generated transaction key in the following code.

require File.dirname(__FILE__) + '/../test_helper'

class ActiveMerchantTest < Test::Unit::TestCase
include ActiveMerchant::Billing

def test_gateway
ActiveMerchant::Billing::Base.mode = :test

creditcard = ActiveMerchant::Billing::CreditCard.new(
:first_name => "dummy",
:last_name => "dummmy 2",
:number => "4779139500118580",
:verification_value => "410",
:type => "Visa",
:month => "10",
:year => "2008"
)

options = {
:name => "Bugs Bunny",
:email => "bbunny@gmail.com",
:phone => "4048615540",
:card_code => "410",
:order_id => "12345",
:description => "Conference reservation",
:billing_address => {
:address1 => "1234 Facke street",
:city => "Wichita",
:state => "Kansas",
:zip => "27606",
:country => "US" }
}
# If you do not immediately disable the old value, it will automatically expire in 24 hours.
gateway = AuthorizeNetGateway.new({:login => "Your API Login ID",
:password => "Your Transaction Key"})

response = gateway.purchase(10000, creditcard, options)

puts response.inspect
assert response.success?
end
end

The output response:

Response

No comments:

Post a Comment