Exemplo n.º 1
0
    def __init__(self, environment=None, merchant_id=None, public_key=None, private_key=None,
            client_id=None, client_secret=None, access_token=None, *args, **kwargs):
        if len(args) == 2:
            public_key, private_key = args

        parser = CredentialsParser(client_id=client_id, client_secret=client_secret, access_token=access_token)
        if parser.access_token is not None:
            parser.parse_access_token()
            self.environment = parser.environment
            self.merchant_id = parser.merchant_id
        elif (parser.client_id is not None or parser.client_secret is not None):
            parser.parse_client_credentials()
            self.environment = parser.environment
            self.merchant_id = merchant_id
        else:
            self.environment = Environment.parse_environment(environment)
            self.merchant_id = merchant_id

        self.public_key = public_key
        self.private_key = private_key
        self.client_id = parser.client_id
        self.client_secret = parser.client_secret
        self.access_token = parser.access_token
        self.timeout = kwargs.get("timeout", 60)
        self.wrap_http_exceptions = kwargs.get("wrap_http_exceptions", False)

        http_strategy = kwargs.get("http_strategy", None)

        if http_strategy:
            self._http_strategy = http_strategy(self, self.environment)
        else:
            self._http_strategy = self.http()
    def test_parses_access_token(self):
        parser = CredentialsParser(access_token="access_token$development$integration_merchant_id$fb27c79dd")
        parser.parse_access_token()

        self.assertEqual(parser.access_token, "access_token$development$integration_merchant_id$fb27c79dd")
        self.assertEqual(parser.merchant_id, "integration_merchant_id")
        self.assertEqual(parser.environment, braintree.Environment.Development)
Exemplo n.º 3
0
    def __init__(self, environment=None, merchant_id=None, public_key=None, private_key=None,
            client_id=None, client_secret=None, access_token=None, *args, **kwargs):
        if len(args) == 2:
            public_key, private_key = args

        parser = CredentialsParser(client_id=client_id, client_secret=client_secret, access_token=access_token)
        if parser.access_token is not None:
            parser.parse_access_token()
            self.environment = parser.environment
            self.merchant_id = parser.merchant_id
        elif (parser.client_id is not None or parser.client_secret is not None):
            parser.parse_client_credentials()
            self.environment = parser.environment
            self.merchant_id = merchant_id
        else:
            self.environment = environment
            self.merchant_id = merchant_id

        self.public_key = public_key
        self.private_key = private_key
        self.client_id = parser.client_id
        self.client_secret = parser.client_secret
        self.access_token = parser.access_token
        self.timeout = kwargs.get("timeout", 60)
        self.wrap_http_exceptions = kwargs.get("wrap_http_exceptions", False)

        http_strategy = kwargs.get("http_strategy", None)

        if http_strategy:
            self._http_strategy = http_strategy(self, self.environment)
        else:
            self._http_strategy = self.http()
Exemplo n.º 4
0
    def test_parses_access_token(self):
        parser = CredentialsParser(
            access_token=
            "access_token$development$integration_merchant_id$fb27c79dd")
        parser.parse_access_token()

        self.assertEqual(
            "access_token$development$integration_merchant_id$fb27c79dd",
            parser.access_token)
        self.assertEqual("integration_merchant_id", parser.merchant_id)
        self.assertEqual(braintree.Environment.Development, parser.environment)