Permalink
Browse files

Add support for Authorize.net duplicate window [#52 state:resolved]

  • Loading branch information...
1 parent 612ef96 commit 2530eec7c1708d3de925a96a6dec1248b585269e Cody Fauser committed Jan 8, 2009
Showing with 28 additions and 0 deletions.
  1. +1 −0 CHANGELOG
  2. +13 −0 lib/active_merchant/billing/gateways/authorize_net.rb
  3. +14 −0 test/unit/gateways/authorize_net_test.rb
View
@@ -1,5 +1,6 @@
= ActiveMerchant CHANGELOG
+* Add support for Authorize.net duplicate window [Seamus Abshere]
* Return transaction id for PayPal refunds [jxtps435]
* Allow storage of e-checks with BraintreeGateway [jimiray]
* Add test URL to PayJunction gateway [boomtowndesigngroup]
@@ -33,6 +33,8 @@ class AuthorizeNetGateway < Gateway
self.arb_test_url = 'https://apitest.authorize.net/xml/v1/request.api'
self.arb_live_url = 'https://api.authorize.net/xml/v1/request.api'
+
+ class_inheritable_accessor :duplicate_window
APPROVED, DECLINED, ERROR, FRAUD_REVIEW = 1, 2, 3, 4
@@ -86,6 +88,7 @@ def authorize(money, creditcard, options = {})
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 +106,7 @@ def purchase(money, creditcard, options = {})
add_creditcard(post, creditcard)
add_address(post, options)
add_customer_data(post, options)
+ add_duplicate_window(post)
commit('AUTH_CAPTURE', money, post)
end
@@ -319,6 +323,15 @@ def add_customer_data(post, options)
post[:customer_ip] = options[:ip]
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)
+ unless duplicate_window.nil?
+ post[:duplicate_window] = duplicate_window
+ end
+ end
def add_address(post, options)
@@ -73,6 +73,20 @@ def test_add_description
assert_equal 'My Purchase is great', result[:description]
end
+ def test_add_duplicate_window_without_duplicate_window
+ result = {}
+ ActiveMerchant::Billing::AuthorizeNetGateway.duplicate_window = nil
+ @gateway.send(:add_duplicate_window, result)
+ assert_nil result[:duplicate_window]
+ end
+
+ def test_add_duplicate_window_with_duplicate_window
+ result = {}
+ ActiveMerchant::Billing::AuthorizeNetGateway.duplicate_window = 0
+ @gateway.send(:add_duplicate_window, result)
+ assert_equal 0, result[:duplicate_window]
+ end
+
def test_purchase_is_valid_csv
params = { :amount => '1.01' }

0 comments on commit 2530eec

Please sign in to comment.