Skip to content

Commit

Permalink
Braintree Blue: actually, really, truly fix nil address fields
Browse files Browse the repository at this point in the history
Previously, on Battlestar Galactica, we only filtered out the address
if the fields were nil. But some of our library consumers like to pass
in empty strings, which we treated as actual data, whereas Braintree
Blue weirdly insists "" is not a valid address. Treat empty strings
the same as nil values.

Unit: 57 tests, 150 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Remote: 66 tests, 378 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
  • Loading branch information
bpollack committed Nov 26, 2018
1 parent ad6ffd4 commit 90e4c10
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/active_merchant/billing/gateways/braintree_blue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module Billing #:nodoc:
#
class BraintreeBlueGateway < Gateway
include BraintreeCommon
include Empty

self.display_name = 'Braintree (Blue Platform)'

Expand Down Expand Up @@ -261,7 +262,7 @@ def add_credit_card_to_customer(credit_card, options)
}
if options[:billing_address]
address = map_address(options[:billing_address])
parameters[:credit_card][:billing_address] = address unless address.all? { |_k, v| v.nil? }
parameters[:credit_card][:billing_address] = address unless address.all? { |_k, v| empty?(v) }
end

result = @braintree_gateway.credit_card.create(parameters)
Expand Down Expand Up @@ -309,7 +310,7 @@ def merge_credit_card_options(parameters, options)
parameters[:credit_card][:options] = valid_options
if options[:billing_address]
address = map_address(options[:billing_address])
parameters[:credit_card][:billing_address] = address unless address.all? { |_k, v| v.nil? }
parameters[:credit_card][:billing_address] = address unless address.all? { |_k, v| empty?(v) }
end
parameters
end
Expand Down
2 changes: 1 addition & 1 deletion test/remote/gateways/remote_braintree_blue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_successful_authorize_with_nil_billing_address_options
:phone => '123-456-7890',
:company => nil,
:address1 => nil,
:address2 => nil,
:address2 => '',
:city => nil,
:state => nil,
:zip => nil,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/gateways/braintree_blue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def test_store_with_nil_billing_address_options
:phone => '123-456-7890',
:company => nil,
:address1 => nil,
:address2 => nil,
:address2 => '',
:city => nil,
:state => nil,
:zip => nil,
Expand Down

0 comments on commit 90e4c10

Please sign in to comment.