diff --git a/CHANGELOG b/CHANGELOG index e333dafae30..b819fe8b830 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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] diff --git a/lib/active_merchant/billing/gateways/authorize_net.rb b/lib/active_merchant/billing/gateways/authorize_net.rb index 2ae4ebd389c..f790fdcd14c 100644 --- a/lib/active_merchant/billing/gateways/authorize_net.rb +++ b/lib/active_merchant/billing/gateways/authorize_net.rb @@ -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) diff --git a/test/unit/gateways/authorize_net_test.rb b/test/unit/gateways/authorize_net_test.rb index 0b6a81bbfab..85c9947eb78 100644 --- a/test/unit/gateways/authorize_net_test.rb +++ b/test/unit/gateways/authorize_net_test.rb @@ -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' }