Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Orbital: Don't send AVS address details for any country besides US, C…

…A, GB and UK
  • Loading branch information...
commit e589e5729a564b20eb1a8711c4f510d0e211fa98 1 parent fb9b3a9
@Soleone Soleone authored
View
21 lib/active_merchant/billing/gateways/orbital.rb
@@ -77,6 +77,8 @@ class OrbitalGateway < Gateway
"EUR" => '978'
}
+ AVS_SUPPORTED_COUNTRIES = ['US', 'CA', 'UK', 'GB']
+
def initialize(options = {})
requires!(options, :merchant_id)
requires!(options, :login, :password) unless options[:ip_authentication]
@@ -148,12 +150,7 @@ def add_soft_descriptors(xml, soft_desc)
def add_address(xml, creditcard, options)
if address = options[:billing_address] || options[:address]
- xml.tag! :AVSzip, address[:zip]
- xml.tag! :AVSaddress1, address[:address1]
- xml.tag! :AVSaddress2, address[:address2]
- xml.tag! :AVScity, address[:city]
- xml.tag! :AVSstate, address[:state]
- xml.tag! :AVSphoneNum, address[:phone] ? address[:phone].scan(/\d/).join.to_s : nil
+ add_avs_details(xml, address)
xml.tag! :AVSname, creditcard.name
xml.tag! :AVScountryCode, address[:country]
end
@@ -177,6 +174,18 @@ def add_refund(xml, currency=nil)
xml.tag! :CurrencyExponent, '2' # Will need updating to support currencies such as the Yen.
end
+ def add_avs_details(xml, address)
+ return unless AVS_SUPPORTED_COUNTRIES.include?(address[:country].to_s)
+
+ xml.tag! :AVSzip, address[:zip]
+ xml.tag! :AVSaddress1, address[:address1]
+ xml.tag! :AVSaddress2, address[:address2]
+ xml.tag! :AVScity, address[:city]
+ xml.tag! :AVSstate, address[:state]
+ xml.tag! :AVSphoneNum, address[:phone] ? address[:phone].scan(/\d/).join.to_s : nil
+ end
+
+
def parse(body)
response = {}
xml = REXML::Document.new(body)
View
43 test/unit/gateways/orbital_test.rb
@@ -59,13 +59,54 @@ def test_expiry_date
def test_phone_number
response = stub_comms do
- @gateway.purchase(50, credit_card, :order_id => 1, :billing_address => {:phone => '123-456-7890'})
+ @gateway.purchase(50, credit_card, :order_id => 1, :billing_address => address(:phone => '123-456-7890'))
end.check_request do |endpoint, data, headers|
assert_match(/1234567890/, data)
end.respond_with(successful_purchase_response)
assert_success response
end
+
+ # <AVSzip>K1C2N6</AVSzip>
+ # <AVSaddress1>1234 My Street</AVSaddress1>
+ # <AVSaddress2>Apt 1</AVSaddress2>
+ # <AVScity>Ottawa</AVScity>
+ # <AVSstate>ON</AVSstate>
+ # <AVSphoneNum>5555555555</AVSphoneNum>
+ # <AVSname>Longbob Longsen</AVSname>
+ # <AVScountryCode>CA</AVScountryCode>
+ def test_send_address_details_for_united_states
+ response = stub_comms do
+ @gateway.purchase(50, credit_card, :order_id => 1, :billing_address => address)
+ end.check_request do |endpoint, data, headers|
+ assert_match(/<AVSzip>K1C2N6/, data)
+ assert_match(/<AVSaddress1>1234 My Street/, data)
+ assert_match(/<AVSaddress2>Apt 1/, data)
+ assert_match(/<AVScity>Ottawa/, data)
+ assert_match(/<AVSstate>ON/, data)
+ assert_match(/<AVSphoneNum>5555555555/, data)
+ assert_match(/<AVSname>Longbob Longsen/, data)
+ assert_match(/<AVScountryCode>CA/, data)
+ end.respond_with(successful_purchase_response)
+ assert_success response
+ end
+
+ def test_dont_send_address_details_for_germany
+ response = stub_comms do
+ @gateway.purchase(50, credit_card, :order_id => 1, :billing_address => address(:country => 'DE'))
+ end.check_request do |endpoint, data, headers|
+ assert_no_match(/<AVSzip>K1C2N6/, data)
+ assert_no_match(/<AVSaddress1>1234 My Street/, data)
+ assert_no_match(/<AVSaddress2>Apt 1/, data)
+ assert_no_match(/<AVScity>Ottawa/, data)
+ assert_no_match(/<AVSstate>ON/, data)
+ assert_no_match(/<AVSphoneNum>5555555555/, data)
+ assert_match(/<AVSname>Longbob Longsen/, data)
+ assert_match(/<AVScountryCode>DE/, data)
+ end.respond_with(successful_purchase_response)
+ assert_success response
+ end
+
private
# Place raw successful response from gateway here
Please sign in to comment.
Something went wrong with that request. Please try again.