diff --git a/lib/stripe/account.rb b/lib/stripe/account.rb index bb8ea152..e0519a3d 100644 --- a/lib/stripe/account.rb +++ b/lib/stripe/account.rb @@ -28,6 +28,23 @@ module Stripe super(id, opts) end + # Set or replace an account's external account. + def external_account=(value) + super + + # The parent setter will perform certain useful operations like + # converting to an APIResource if appropriate. + value = self.external_account + + # Note that external_account may be a card, but could also be a tokenized + # card's ID (which is a string), and so we check its type here. + if value.is_a?(APIResource) + value.save_with_parent = true + end + + value + end + def reject(params={}, opts={}) opts = Util.normalize_opts(opts) response, opts = request(:post, resource_url + '/reject', params, opts) @@ -93,6 +110,22 @@ module Stripe ARGUMENT_NOT_PROVIDED = Object.new + # Set or replace an account's bank account. + # + # This method is deprecated. Please use #external_account instead. + def bank_account=(value) + super + value = self.bank_account + + if value.is_a?(APIResource) + value.save_with_parent = true + end + + value + end + extend Gem::Deprecate + deprecate :bank_account=, "#external_account=", 2017, 8 + private def serialize_additional_owners(legal_entity, additional_owners) diff --git a/test/stripe/account_test.rb b/test/stripe/account_test.rb index 0b12331f..651de898 100644 --- a/test/stripe/account_test.rb +++ b/test/stripe/account_test.rb @@ -289,5 +289,63 @@ module Stripe } assert_equal(expected, obj.serialize_params) end + + context "#external_account=" do + should "can have a token source set" do + a = Stripe::Account.new("test_account") + a.external_account = "tok_123" + assert_equal "tok_123", a.external_account + end + + should "set a flag if given an object source" do + a = Stripe::Account.new("test_account") + a.external_account = { + :object => 'card' + } + assert_equal true, a.external_account.save_with_parent + end + end + + context "#bank_account=" do + should "can have a token source set" do + old_stderr = $stderr + $stderr = StringIO.new + begin + a = Stripe::Account.new("test_account") + a.bank_account = "tok_123" + assert_equal "tok_123", a.bank_account + ensure + $stderr = old_stderr + end + end + + should "set a flag if given an object source" do + old_stderr = $stderr + $stderr = StringIO.new + begin + a = Stripe::Account.new("test_account") + a.bank_account = { + :object => 'bank_account' + } + assert_equal true, a.bank_account.save_with_parent + ensure + $stderr = old_stderr + end + end + + should "warn that #bank_account= is deprecated" do + old_stderr = $stderr + $stderr = StringIO.new + begin + a = Stripe::Account.new("test_account") + a.bank_account = "tok_123" + message = "NOTE: Stripe::Account#bank_account= is " + + "deprecated; use #external_account= instead" + assert_match Regexp.new(message), $stderr.string + ensure + $stderr = old_stderr + end + end + end end end