Skip to content

Commit

Permalink
Beanstream fixes by Dennis Theisen
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Lütke committed Feb 9, 2010
1 parent 3765fa1 commit 6027f51
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Expand Up @@ -105,7 +105,9 @@ def add_reference(post, reference)
post[:adjId] = reference
end

def add_address(post, options)
def add_address(post, options)
prepare_address_for_non_american_countries(options)

if billing_address = options[:billing_address] || options[:address]
post[:ordName] = billing_address[:name]
post[:ordEmailAddress] = options[:email]
Expand All @@ -132,6 +134,16 @@ def add_address(post, options)
end
end

def prepare_address_for_non_american_countries(options)
[ options[:billing_address], options[:shipping_address] ].compact.each do |address|
country = Country.find(address[:country])
unless country.name == 'Canada' || country.name == 'United States'
address[:state] = '--'
address[:zip] = '000000' unless address[:zip]
end
end
end

def add_invoice(post, options)
post[:trnOrderNumber] = options[:order_id]
post[:trnComments] = options[:description]
Expand Down
36 changes: 36 additions & 0 deletions test/unit/gateways/beanstream_test.rb
Expand Up @@ -87,6 +87,34 @@ def test_successful_check_purchase
assert_equal '10000072;15.00;D', response.authorization
assert_equal 'Approved', response.message
end


# Testing Non-American countries

def test_german_address_sets_state_to_the_required_dummy_value
@gateway.expects(:commit).with(german_address_params_without_state)
billing = @options[:billing_address]
billing[:country] = 'DE'
billing[:city] = 'Berlin'
billing[:zip] = '12345'
billing[:state] = nil
@options[:shipping_address] = billing

@gateway.purchase(@amount, @credit_card, @options)
end

def test_brazilian_address_sets_state_and_zip_to_the_required_dummy_values
@gateway.expects(:commit).with(brazilian_address_params_without_zip_and_state)
billing = @options[:billing_address]
billing[:country] = 'BR'
billing[:city] = 'Rio de Janeiro'
billing[:zip] = nil
billing[:state] = nil
@options[:shipping_address] = billing

@gateway.purchase(@amount, @credit_card, @options)
end


private

Expand All @@ -105,4 +133,12 @@ def unsuccessful_purchase_response
def successful_check_purchase_response
"trnApproved=1&trnId=10000072&messageId=1&messageText=Approved&trnOrderNumber=5d9f511363a0f35d37de53b4d74f5b&authCode=&errorType=N&errorFields=&responseType=T&trnAmount=15%2E00&trnDate=6%2F4%2F2008+6%3A33%3A55+PM&avsProcessed=0&avsId=0&avsResult=0&avsAddrMatch=0&avsPostalMatch=0&avsMessage=Address+Verification+not+performed+for+this+transaction%2E&trnType=D&paymentMethod=EFT&ref1=reference+one&ref2=&ref3=&ref4=&ref5="
end

def brazilian_address_params_without_zip_and_state
{ :shipProvince => '--', :shipPostalCode => '000000', :ordProvince => '--', :ordPostalCode => '000000', :ordCountry => 'BR', :trnCardOwner => 'Longbob Longsen', :shipCity => 'Rio de Janeiro', :ordAddress1 => '1234 Levesque St.', :ordShippingPrice => '1.00', :deliveryEstimate => nil, :shipName => 'xiaobo zzz', :trnCardNumber => '4242424242424242', :trnAmount => '10.00', :trnType => 'P', :ordAddress2 => 'Apt B', :ordTax1Price => '1.00', :shipEmailAddress => 'xiaobozzz@example.com', :trnExpMonth => '09', :ordCity => 'Rio de Janeiro', :shipPhoneNumber => '555-555-5555', :ordName => 'xiaobo zzz', :trnExpYear => '11', :trnOrderNumber => '1234', :shipCountry => 'BR', :ordTax2Price => '1.00', :shipAddress1 => '1234 Levesque St.', :ordEmailAddress => 'xiaobozzz@example.com', :trnCardCvd => '123', :trnComments => nil, :shippingMethod => nil, :ref1 => 'reference one', :shipAddress2 => 'Apt B', :ordPhoneNumber => '555-555-5555', :ordItemPrice => '8.00' }
end

def german_address_params_without_state
{ :shipProvince => '--', :shipPostalCode => '12345', :ordProvince => '--', :ordPostalCode => '12345', :ordCountry => 'DE', :trnCardOwner => 'Longbob Longsen', :shipCity => 'Berlin', :ordAddress1 => '1234 Levesque St.', :ordShippingPrice => '1.00', :deliveryEstimate => nil, :shipName => 'xiaobo zzz', :trnCardNumber => '4242424242424242', :trnAmount => '10.00', :trnType => 'P', :ordAddress2 => 'Apt B', :ordTax1Price => '1.00', :shipEmailAddress => 'xiaobozzz@example.com', :trnExpMonth => '09', :ordCity => 'Berlin', :shipPhoneNumber => '555-555-5555', :ordName => 'xiaobo zzz', :trnExpYear => '11', :trnOrderNumber => '1234', :shipCountry => 'DE', :ordTax2Price => '1.00', :shipAddress1 => '1234 Levesque St.', :ordEmailAddress => 'xiaobozzz@example.com', :trnCardCvd => '123', :trnComments => nil, :shippingMethod => nil, :ref1 => 'reference one', :shipAddress2 => 'Apt B', :ordPhoneNumber => '555-555-5555', :ordItemPrice => '8.00' }
end
end

0 comments on commit 6027f51

Please sign in to comment.