Skip to content

Instantly share code, notes, and snippets.

@ryonlife
Created February 9, 2012 00:42
Show Gist options
  • Save ryonlife/1775940 to your computer and use it in GitHub Desktop.
Save ryonlife/1775940 to your computer and use it in GitHub Desktop.
Monkey patch Braintree's Python API wrapper so results/responses are serializable.
from types import MethodType
import braintree
import jsonpickle
import json
def serialize(self):
""" Serialize a Braintree SuccessfulResult or ErrorResult object to a Python dict """
return json.loads(jsonpickle.encode(self))
braintree.ErrorResult.serialize = MethodType(serialize, None, braintree.ErrorResult)
braintree.SuccessfulResult.serialize = MethodType(serialize, None, braintree.SuccessfulResult)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment