Skip to content

Commit

Permalink
Sage: Default billing state when outside US
Browse files Browse the repository at this point in the history
Sage requires an address state be sent even if transacting outside of
the US/North America and the country does not have states.
Unfortunately Sage support is unwilling to say what exactly should be
sent in the state field (they say you can send anything) if no state is
part of a billing address so this commit mimics the behaviour of the
virtual terminal which uses the text "Outside of US".

Moreover Sage now supports countries outside of the US so it would
appear as though the supported_countries field could be updated.

Closes activemerchant#2340
  • Loading branch information
shasum authored and davidsantoso committed Feb 17, 2017
1 parent 84ba622 commit 2681ea7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Revert "Authorize.net: Allow settings to be passed for CIM purchases" [curiousepic] #2339
* Digitzs: Add gateway [davidsantoso]
* Credorax: Return failure response reason [shasum] #2341
* Sage: Default billing state when outside US [shasum] #2340

== Version 1.63.0 (February 2, 2017)
* Authorize.net: Add #unstore support [jimryan] #2293
Expand Down
8 changes: 5 additions & 3 deletions lib/active_merchant/billing/gateways/sage.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class SageGateway < Gateway
include Empty

self.display_name = 'http://www.sagepayments.com'
self.homepage_url = 'Sage Payment Solutions'
self.live_url = 'https://www.sagepayments.net/cgi-bin'
Expand Down Expand Up @@ -204,8 +206,8 @@ def parse_credit_card(data)

def add_invoice(post, options)
post[:T_ordernum] = (options[:order_id] || generate_unique_id).slice(0, 20)
post[:T_tax] = amount(options[:tax]) unless options[:tax].blank?
post[:T_shipping] = amount(options[:shipping]) unless options[:shipping].blank?
post[:T_tax] = amount(options[:tax]) unless empty?(options[:tax])
post[:T_shipping] = amount(options[:shipping]) unless empty?(options[:shipping])
end

def add_reference(post, reference)
Expand All @@ -226,7 +228,7 @@ def add_addresses(post, options)

post[:C_address] = billing_address[:address1]
post[:C_city] = billing_address[:city]
post[:C_state] = billing_address[:state]
post[:C_state] = empty?(billing_address[:state]) ? "Outside of US" : billing_address[:state]
post[:C_zip] = billing_address[:zip]
post[:C_country] = billing_address[:country]
post[:C_telephone] = billing_address[:phone]
Expand Down
7 changes: 7 additions & 0 deletions test/remote/gateways/remote_sage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ def test_successful_with_minimal_options
assert_false response.authorization.blank?
end

def test_successful_purchase_with_blank_state
assert response = @gateway.purchase(@amount, @visa, billing_address: address(state: ""))
assert_success response
assert response.test?
assert_false response.authorization.blank?
end

def test_authorization_and_capture
assert auth = @gateway.authorize(@amount, @visa, @options)
assert_success auth
Expand Down
10 changes: 5 additions & 5 deletions test/unit/gateways/sage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def test_cvv_result
assert_equal 'M', response.cvv_result['code']
end

def test_us_address_with_state
def test_address_with_state
post = {}
options = {
:billing_address => { :country => "US", :state => "CA"}
Expand All @@ -196,15 +196,15 @@ def test_us_address_with_state
assert_equal "CA", post[:C_state]
end

def test_us_address_without_state
def test_address_without_state
post = {}
options = {
:billing_address => { :country => "US", :state => ""}
:billing_address => { :country => "NZ", :state => ""}
}
@gateway.send(:add_addresses, post, options)

assert_equal "US", post[:C_country]
assert_equal "", post[:C_state]
assert_equal "NZ", post[:C_country]
assert_equal "Outside of US", post[:C_state]
end

def test_successful_check_purchase
Expand Down

0 comments on commit 2681ea7

Please sign in to comment.