Cody,
Here's a patch that lets you set x_duplicate_window like this:
Gateway = ActiveMerchant::Billing::Base.gateway(:authorize_net).new(
:login => AUTHORIZE_NET_LOGIN,
:password => AUTHORIZE_NET_PASSWORD,
:duplicate_window => 0
)
This made sense in the context of my application, but I believe it is
not the cattr_accessor approach that you specified. Please let me know
if you would like me to re-implement this in a different way and I
will submit a new patch.
Best,
Seamus
*********************
From a92cc8d9a58c38da456e24b59f30dbe47960dae1 Mon Sep 17 00:00:00 2001
From: Seamus Abshere <
sea...@abshere.net>
Date: Tue, 30 Dec 2008 15:15:57 -0500
Subject: [PATCH] Add duplicate_window as a Gateway initialization
option for Authorize.Net
---
.../billing/gateways/authorize_net.rb | 15 ++++++++++++
+++
test/unit/gateways/authorize_net_test.rb | 17 ++++++++++++
+++++
2 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/lib/active_merchant/billing/gateways/authorize_net.rb b/
lib/active_merchant/billing/gateways/authorize_net.rb
index 2ae4ebd..c9cb1b3 100644
--- a/lib/active_merchant/billing/gateways/authorize_net.rb
+++ b/lib/active_merchant/billing/gateways/authorize_net.rb
@@ -66,6 +66,10 @@ module ActiveMerchant #:nodoc:
# * <tt>:password</tt> -- The Authorize.Net Transaction Key.
(REQUIRED)
# * <tt>:test</tt> -- +true+ or +false+. If true, perform
transactions against the test server.
# Otherwise, perform transactions against the production
server.
+ # * <tt>:duplicate_window</tt> -- Indicates in seconds the
window of time after a transaction is
+ # submitted during which the payment gateway will check for a
duplicate transaction. The maximum
+ # time allowed is 8 hours (28,800 seconds). Default is 120
seconds. If this option is set,
+ # an enhanced duplicate transaction response will be sent.
def initialize(options = {})
requires!(options, :login, :password)
@options = options
@@ -86,6 +90,7 @@ module ActiveMerchant #:nodoc:
add_creditcard(post, creditcard)
add_address(post, options)
add_customer_data(post, options)
+ add_duplicate_window(post)
commit('AUTH_ONLY', money, post)
end
@@ -103,6 +108,7 @@ module ActiveMerchant #:nodoc:
add_creditcard(post, creditcard)
add_address(post, options)
add_customer_data(post, options)
+ add_duplicate_window(post)
commit('AUTH_CAPTURE', money, post)
end
@@ -332,6 +338,15 @@ module ActiveMerchant #:nodoc:
post[:state] = address[:state].blank? ? 'n/a' : address
[:state]
end
end
+
+ # x_duplicate_window won't be sent by default, because sending
it changes the response.
+ # "If this field is present in the request with or without a
value, an enhanced duplicate transaction response will be sent."
+ # (as of 2008-12-30)
http://www.authorize.net/support/AIM_guide_SCC.pdf
+ def add_duplicate_window(post)
+ if @options.has_key? :duplicate_window
+ post[:duplicate_window] = @options[:duplicate_window]
+ end
+ end
# Make a ruby type out of the response string
def normalize(field)
diff --git a/test/unit/gateways/authorize_net_test.rb b/test/unit/
gateways/authorize_net_test.rb
index 0b6a81b..d6f4f8f 100644
--- a/test/unit/gateways/authorize_net_test.rb
+++ b/test/unit/gateways/authorize_net_test.rb
@@ -73,6 +73,23 @@ class AuthorizeNetTest < Test::Unit::TestCase
assert_equal 'My Purchase is great', result[:description]
end
+ def test_add_duplicate_window_without_duplicate_window
+ result = {}
+ @gateway.send(:add_duplicate_window, result)
+ assert_nil result[:duplicate_window]
+ end
+
+ def test_add_duplicate_window_with_duplicate_window
+ gateway = AuthorizeNetGateway.new(
+ :login => 'X',
+ :password => 'Y',
+ :duplicate_window => 0
+ )
+ result = {}
+ gateway.send(:add_duplicate_window, result)
+ assert_equal 0, result[:duplicate_window]
+ end
+
def test_purchase_is_valid_csv
params = { :amount => '1.01' }
--
1.6.0.2