Skip to content

Commit

Permalink
Merge pull request #261 from jduff/fix_optimal_payments_state_tag
Browse files Browse the repository at this point in the history
Optimal Payments: submit region instead of state when billing address is not CA or US
  • Loading branch information
jduff committed Feb 6, 2012
2 parents fd27ecd + ff7c7c4 commit dac747f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/active_merchant/billing/gateways/optimal_payment.rb
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/remote/gateways/remote_optimal_payment_test.rb
Expand Up @@ -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',
Expand Down
27 changes: 27 additions & 0 deletions test/unit/gateways/optimal_payment_test.rb
Expand Up @@ -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)

Expand Down

0 comments on commit dac747f

Please sign in to comment.