Closed PhilipGarnero closed 9 years ago
@PhilipGarnero You can do this kind of thing without monkey patching (untested):
def braintree_object_tree_to_dict(braintree_object):
data = braintree_object.__dict__.copy()
for key, value in data.items():
if isinstance(value, braintree.AttributeGetter):
data[key] = braintree_object_tree_to_dict(value)
return data
Since it's pretty straightforward and we haven't had requests for this before, I'm going to close the issue.
@agfor It would be great to have that feature added directly in the braintree python client. There is several situations where this could be useful. Passing customer information to another micro-service, storing customer information in a nosql database and update it via webhooks, ...
It would be great if we could get the dictionnary representing a braintree object. We could extract data or send some objects directly to the clients like plans for example.
I managed to do this by adding this small function to your
AttributeGetter
but it's just monkey patching :If I want to get the dictionnary from an object, I'll be able to do
my_object.serialize()