Possible bug found in authorize.net test mode

38 views
Skip to first unread message

Stever

unread,
Feb 26, 2007, 1:33:00 AM2/26/07
to Active Merchant
Hello,

I found a possible bug in your product. Although (just like last
time), this may be due to my ignorance.

Ok, I am opening a new gateway object via this code:
> gateway = ActiveMerchant::Billing::Base.gateway(:authorized_net).new(
> :login => "xxxxxx",
> :password => "xxxxx",
> :test => true
>)

This should send the request to the authorize.net test server (url:
https://test.authorize.net/gateway/transact.dll). However,
ActiveMerchant still sends the request to https://secure.authorize.net/gateway.

Upon closer examination, it seems that "def test?" function that runs
in object gateway.rb checks to see if the server is in test mode by
seeing if Base.gateway_mode is ":test" or not:
> def test?
> Base.gateway_mode == :test
> end

However, it seems that Base.gateway_mode is ALWAYS ":production" and
NEVER as ":test" as evidenced in this code in base.rb:
> def self.mode=(mode)
> @@mode = mode
> self.gateway_mode = mode
> self.integration_mode = mode
> end
>
> self.mode = :production

method ".mode" does not seem to be referenced anywhere else in the
program, except in the unit tests. so method "test?" will ALWAYS
report 'false'.

i would imagine, although I am not certain, that the following patch
would fix things:
--- old_authorized_net.rb 2007-02-14 23:25:57.000000000 -0800
+++ new_authorized_net.rb 2007-02-14 23:28:00.000000000 -0800
@@ -105,7 +105,7 @@
return result
end
- url = test? ? TEST_URL : LIVE_URL
+ url = @options[:test] ? TEST_URL : LIVE_URL
data = ssl_post url, post_data(action, parameters)

@response = parse(data)
@@ -119,7 +119,7 @@
# (TESTMODE) Successful Sale
#
- test_mode = test? || message =~ /TESTMODE/
+ test_mode = @options[:test] || message =~ /TESTMODE/
Response.new(success, message, @response,
:test => test_mode,

The version I am using is from the subversion repository on 2/16/07.
Again, I apologize if I am wrong. I checked the documentation, went
through the source code, checked google, and checked the google group.
Writing to the author/community is my last resort. In addition, if
this IS a bug, I figure it would be a good thing to get it fixed, for
everyone involved.

- Steve

PS If you have any additional question, write me at steve {at sign}
thestever.net

Cody Fauser

unread,
Feb 26, 2007, 10:07:11 AM2/26/07
to activem...@googlegroups.com
Steve,

This was actually done on purpose. The reason is that you may want to
send a test transaction with your live account to the live URL after
you've already deployed to the production environment without changing
back to your test account credentials. Authorize.net is strange
because they actually have a TEST_URL, a LIVE_URL and an additional
field x_test_request which can be used with environments. Setting
:test => true during construction of the gateway will set the field
x_test_request = TRUE, but still use the URLs Base.mode has
configured.

# Development Mode
# Requests go to the TEST_URL
# x_test_request = FALSE
ActiveMerchant::Billing::Base.mode = :test

# Production Mode
# Requests go to the PRODUCTION_URL
# x_test_request = FALSE
ActiveMerchant::Billing::Base.mode = :production

# Force Authorize.net to run a test transaction in the production environment


gateway = ActiveMerchant::Billing::Base.gateway(:authorized_net).new(
:login => "xxxxxx",
:password => "xxxxx",
:test => true
)

# Now x_test_request = TRUE, but we're still using the LIVE_URL

So, for your purposes, just make sure you set
ActiveMerchant::Billing::Base.mode = :test while you're in development
mode of your app. If you're using Rails, a great place to do this is
in the config.after_initialize block in
config/environments/development.rb.


--
Cody Fauser
http://shopify.com - e-commerce done right
http://www.codyfauser.com - blog
http://www.oreilly.com/catalog/rjsrails - RJS Templates for Rails

Reply all
Reply to author
Forward
0 new messages