Search code examples
pythonbraintree

Finding out which mode I am in with Braintree


Is there a method to call to see if I am in Sandbox or Production mode? Here is what I have so far:

import braintree
braintree.Configuration.configure(braintree.Environment.Sandbox, BRAINTREE_MERCHANT, BRAINTREE_PUBLIC_KEY, BRAINTREE_SECRET_KEY)

>>> braintree.environment # how would I do this?
'Sandbox'

Solution

  • From the braintree_python source code (3.6), it would just be: braintree.Configuration.environment

    Here's the relevant source code for your convenience:

    class Configuration(object):
        """
        A class representing the configuration of your Braintree account.
        You must call configure before any other Braintree operations. ::
            braintree.Configuration.configure(
                braintree.Environment.Sandbox,
                "your_merchant_id",
                "your_public_key",
                "your_private_key"
            )
        """
        @staticmethod
        def configure(environment, merchant_id, public_key, private_key, **kwargs):
            Configuration.environment = environment
            Configuration.merchant_id = merchant_id
            # .. see more on github
    

    So, in your example above:

    import braintree
    braintree.Configuration.configure(braintree.Environment.Sandbox, BRAINTREE_MERCHANT, BRAINTREE_PUBLIC_KEY, BRAINTREE_SECRET_KEY)
    
    >>> braintree.Configuration.environment._Environment__server
    'api.sandbox.braintreegateway.com'