Skip to content

Commit

Permalink
FIX: NoMethodError when state wasn't supplied for US/CA country. Adde…
Browse files Browse the repository at this point in the history
…d description from Wirecard to phone number regex.
  • Loading branch information
Soleone authored and Cody Fauser committed Apr 28, 2009
1 parent 474f09a commit 9dc7cce
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= ActiveMerchant CHANGELOG

* Update Wirecard to make country and state processing more robust [Soleone]
* Update ProTX to use the latest v2.23 protocol [Tekin]

== Version 1.4.2 (April 24, 2009)
Expand Down
12 changes: 9 additions & 3 deletions lib/active_merchant/billing/gateways/wirecard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ class WirecardGateway < Gateway

RETURN_CODES = %w[ ACK NOK ]

# it seems that Wirecard only allows phone numbers with a format like this: +xxx(yyy)zzz-zzzz-ppp
VALID_PHONE_FORMAT = /\+\d{3}(\(?\d{3}\)?)?\d{3}-\d{4}-\d{3}/
# Wirecard only allows phone numbers with a format like this: +xxx(yyy)zzz-zzzz-ppp, where:
# xxx = Country code
# yyy = Area or city code
# zzz-zzzz = Local number
# ppp = PBX extension
# For example, a typical U.S. or Canadian number would be "+1(202)555-1234-739" indicating PBX extension 739 at phone
# number 5551234 within area code 202 (country code 1).
VALID_PHONE_FORMAT = /\+\d{1,3}(\(?\d{3}\)?)?\d{3}-\d{4}-\d{3}/

# The countries the gateway supports merchants from as 2 digit ISO country codes
# TODO: Check supported countries
Expand Down Expand Up @@ -205,7 +211,7 @@ def add_address(xml, address)
xml.tag! 'Address2', address[:address2] if address[:address2]
xml.tag! 'City', address[:city]
xml.tag! 'ZipCode', address[:zip]
xml.tag! 'State', address[:state].upcase if address[:country] =~ /^(us|ca)$/i
xml.tag! 'State', address[:state].upcase if address[:state] && address[:country] =~ /^(us|ca)$/i
xml.tag! 'Country', address[:country]
xml.tag! 'Phone', address[:phone] if address[:phone] =~ VALID_PHONE_FORMAT
xml.tag! 'Email', address[:email]
Expand Down
18 changes: 18 additions & 0 deletions test/unit/gateways/wirecard_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ def setup
:description => 'Wirecard Purchase',
:email => 'soleone@example.com'
}

@address_without_state = {
:name => 'Jim Smith',
:address1 => '1234 My Street',
:company => 'Widgets Inc',
:city => 'Ottawa',
:zip => 'K12 P2A',
:country => 'CA',
:state => nil,
}
end

def test_successful_authorization
Expand Down Expand Up @@ -61,6 +71,14 @@ def test_unauthorized_capture
assert response.message["Could not find referenced transaction for GuWID 1234567890123456789012."]
end

def test_doesnt_raise_an_error_if_no_state_is_provided_in_address
options = @options.merge(:billing_address => @address_without_state)
@gateway.expects(:ssl_post).returns(unauthorized_capture_response)
assert_nothing_raised do
@gateway.authorize(@amount, @credit_card, options)
end
end

private

# Authorization success
Expand Down

0 comments on commit 9dc7cce

Please sign in to comment.