Flag Account#external_account into save_with_parent system

In #433, we built a framework under which subresources are usually not
persisted, but in certain cases they can be. At the time,
`Customer#source` was the only field that I knew about that had to be
flagged into it.

Issue #456 has raised that we also be doing `Account#external_account`.
This patch adds support for that.

Fixes #456.
This commit is contained in:
Brandur 2016-08-29 10:34:08 -07:00
parent 5573cc73fc
commit d6514ef633
2 changed files with 31 additions and 0 deletions

View File

@ -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)

View File

@ -289,5 +289,19 @@ module Stripe
}
assert_equal(expected, obj.serialize_params)
end
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
end