Permalink
Browse files

Merge pull request #261 from jduff/fix_optimal_payments_state_tag

Optimal Payments: submit region instead of state when billing address is not CA or US
  • Loading branch information...
2 parents fd27ecd + ff7c7c4 commit dac747f16ee7505e2828be8f0a3d3209e15a3e6f @jduff jduff committed Feb 6, 2012
@@ -246,13 +246,16 @@ def build_billing_details(xml, opts)
xml.tag! 'firstName', CGI.escape(addr[:name].split(' ').first) # TODO: parse properly
xml.tag! 'lastName' , CGI.escape(addr[:name].split(' ').last )
end
- xml.tag! 'street' , CGI.escape(addr[:address1]) if addr[:address1] && !addr[:address1].empty?
- xml.tag! 'street2', CGI.escape(addr[:address2]) if addr[:address2] && !addr[:address2].empty?
- xml.tag! 'city' , CGI.escape(addr[:city] ) if addr[:city] && !addr[:city].empty?
- xml.tag! 'state' , CGI.escape(addr[:state] ) if addr[:state] && !addr[:state].empty?
- xml.tag! 'country', CGI.escape(addr[:country] ) if addr[:country] && !addr[:country].empty?
+ xml.tag! 'street' , CGI.escape(addr[:address1]) if addr[:address1].present?
+ xml.tag! 'street2', CGI.escape(addr[:address2]) if addr[:address2].present?
+ xml.tag! 'city' , CGI.escape(addr[:city] ) if addr[:city].present?
+ if addr[:state].present?
+ state_tag = %w(US CA).include?(addr[:country]) ? 'state' : 'region'
+ xml.tag! state_tag, CGI.escape(addr[:state])
+ end
+ xml.tag! 'country', CGI.escape(addr[:country] ) if addr[:country].present?
xml.tag! 'zip' , CGI.escape(addr[:zip] ) # this one's actually required
- xml.tag! 'phone' , CGI.escape(addr[:phone] ) if addr[:phone] && !addr[:phone].empty?
+ xml.tag! 'phone' , CGI.escape(addr[:phone] ) if addr[:phone].present?
#xml.tag! 'email' , ''
end
end
@@ -21,6 +21,14 @@ def test_successful_purchase
assert_equal 'no_error', response.message
end
+ def test_successful_great_britain
+ @options[:billing_address][:country] = "GB"
+ @options[:billing_address][:state] = "North West England"
+ assert response = @gateway.purchase(@amount, @credit_card, @options)
+ assert_success response
+ assert_equal 'no_error', response.message
+ end
+
def test_minimal_successful_purchase
options = {
:order_id => '1',
@@ -58,6 +58,33 @@ def test_successful_purchase
assert response.test?
end
+ def test_purchase_from_canada_includes_state_field
+ @options[:billing_address][:country] = "CA"
+ @gateway.expects(:ssl_post).with do |url, data|
+ data =~ /state/ && data !~ /region/
+ end.returns(successful_purchase_response)
+
+ assert response = @gateway.purchase(@amount, @credit_card, @options)
+ end
+
+ def test_purchase_from_us_includes_state_field
+ @options[:billing_address][:country] = "US"
+ @gateway.expects(:ssl_post).with do |url, data|
+ data =~ /state/ && data !~ /region/
+ end.returns(successful_purchase_response)
+
+ assert response = @gateway.purchase(@amount, @credit_card, @options)
+ end
+
+ def test_purchase_from_any_other_country_includes_region_field
+ @options[:billing_address][:country] = "GB"
+ @gateway.expects(:ssl_post).with do |url, data|
+ data =~ /region/ && data !~ /state/
+ end.returns(successful_purchase_response)
+
+ assert response = @gateway.purchase(@amount, @credit_card, @options)
+ end
+
def test_successful_void
@gateway.expects(:ssl_post).returns(successful_purchase_response)

0 comments on commit dac747f

Please sign in to comment.