Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle individual serialization #525

Merged
merged 1 commit into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion stripe/api_resources/account.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import, division, print_function

from stripe import oauth, util
import stripe
from stripe import oauth, six, util
from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import DeletableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
Expand Down Expand Up @@ -60,3 +61,17 @@ def reject(self, idempotency_key=None, **params):
def deauthorize(self, **params):
params["stripe_user_id"] = self.id
return oauth.OAuth.deauthorize(**params)

def serialize(self, previous):
params = super(Account, self).serialize(previous)
previous = previous or self._previous or {}

for k, v in six.iteritems(self):
if (
k == "individual"
and isinstance(v, stripe.api_resources.Person)
and k not in params
):
params[k] = v.serialize(previous.get(k, None))

return params
26 changes: 26 additions & 0 deletions tests/api_resources/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,32 @@ def test_is_saveable_with_additional_owners(self, request_mock):
assert isinstance(resource, stripe.Account)
assert resource is account

def test_is_saveable_with_individual(self, request_mock):
individual = stripe.Person.construct_from(
{"id": "person_123", "object": "person", "first_name": "Jenny"},
stripe.api_key,
)
account = stripe.Account.construct_from(
{"id": "acct_123", "object": "account", "individual": individual},
stripe.api_key,
)

account.individual.first_name = "Jane"

request_mock.stub_request(
"post",
"/v1/accounts/%s" % TEST_RESOURCE_ID,
account.to_dict_recursive(),
)
resource = account.save()
request_mock.assert_requested(
"post",
"/v1/accounts/%s" % TEST_RESOURCE_ID,
{"individual": {"first_name": "Jane"}},
)
assert isinstance(resource, stripe.Account)
assert resource is account

def test_is_modifiable(self, request_mock):
resource = stripe.Account.modify(
TEST_RESOURCE_ID, metadata={"key": "value"}
Expand Down