예제 #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()
예제 #2
0
    def configure_braintree(self):
        sandbox = Environment(
            'sandbox',
            'api.sandbox.braintreegateway.com',
            '443',
            'https://auth.sandbox.venmo.com',
            True,
            Environment.braintree_root() + '/ssl/api_braintreegateway_com.ca.crt'
        )

        braintree.Configuration.configure(
            environment=sandbox,
            merchant_id=self.BRAINTREE_MERCHANT_ID,
            public_key=self.BRAINTREE_PUBLIC_KEY,
            private_key=self.BRAINTREE_PRIVATE_KEY
        )
예제 #3
0
 def configure(environment, merchant_id, public_key, private_key, **kwargs):
     Configuration.environment = Environment.parse_environment(environment)
     Configuration.merchant_id = merchant_id
     Configuration.public_key = public_key
     Configuration.private_key = private_key
     Configuration.default_http_strategy = kwargs.get("http_strategy", None)
     Configuration.timeout = kwargs.get("timeout", 60)
     Configuration.wrap_http_exceptions = kwargs.get("wrap_http_exceptions", False)
예제 #4
0
 def configure(environment, merchant_id, public_key, private_key, **kwargs):
     Configuration.environment = Environment.parse_environment(environment)
     Configuration.merchant_id = merchant_id
     Configuration.public_key = public_key
     Configuration.private_key = private_key
     Configuration.default_http_strategy = kwargs.get("http_strategy", None)
     Configuration.timeout = kwargs.get("timeout", 60)
     Configuration.wrap_http_exceptions = kwargs.get(
         "wrap_http_exceptions", False)
예제 #5
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)
            if merchant_id == "":
                raise ConfigurationError("Missing merchant_id")
            else:
                self.merchant_id = merchant_id

            if public_key == "":
                raise ConfigurationError("Missing public_key")
            else:
                self.public_key = public_key

            if private_key == "":
                raise ConfigurationError("Missing private_key")
            else:
                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()
예제 #6
0
 def test_ok(self):
     self.req.get.return_value = self.get_response('foo', 200)
     assert self.get(reverse('braintree:auth')).status_code, 200
     self.req.get.assert_called_with(
         'https://b.c/some/url/',
         verify=(Environment.braintree_root() +
                 '/ssl/api_braintreegateway_com.ca.crt'),
         data='', timeout=settings.DEFAULT_TIMEOUT, headers={
             'Authorization': 'Basic Og==',
             'Content-Type': 'application/xml; charset=utf-8'
         })
예제 #7
0
 def test_ok(self):
     self.req.get.return_value = self.get_response('foo', 200)
     assert self.get(reverse('braintree:auth')).status_code, 200
     self.req.get.assert_called_with(
         'https://b.c/some/url/',
         verify=(Environment.braintree_root() +
                 '/ssl/api_braintreegateway_com.ca.crt'),
         data='',
         timeout=settings.DEFAULT_TIMEOUT,
         headers={
             'Authorization': 'Basic Og==',
             'Content-Type': 'application/xml; charset=utf-8'
         })
예제 #8
0
def braintree(request):
    """
    Pass the request through to Braintree. There are two jobs to do:
    1) Add in the Braintree auth into the HTTP headers
    2) Ensure that requests will check the correct Braintree crt.
    """
    new_request = prepare(request)
    # Until https://github.com/mozilla/solitude-auth/pull/3 is merged.
    new_request['headers']['Content-Type'] = 'application/xml; charset=utf-8'
    # Add in the correct Braintree Authorization.
    new_request['headers']['Authorization'] = b"Basic " + encodebytes(
        settings.BRAINTREE_PUBLIC_KEY.encode('ascii') + b":" +
        settings.BRAINTREE_PRIVATE_KEY.encode('ascii')).strip()
    # Taken from http://bit.ly/1cBESdC and ensures that the
    # crt is passed through to the requests verify parameter.
    new_request['verify'] = (Environment.braintree_root() +
                             '/ssl/api_braintreegateway_com.ca.crt')

    return send(new_request)
예제 #9
0
def braintree(request):
    """
    Pass the request through to Braintree. There are two jobs to do:
    1) Add in the Braintree auth into the HTTP headers
    2) Ensure that requests will check the correct Braintree crt.
    """
    new_request = prepare(request)
    # Until https://github.com/mozilla/solitude-auth/pull/3 is merged.
    new_request['headers']['Content-Type'] = 'application/xml; charset=utf-8'
    # Add in the correct Braintree Authorization.
    new_request['headers']['Authorization'] = b"Basic " + encodebytes(
        settings.BRAINTREE_PUBLIC_KEY.encode('ascii') + b":" +
        settings.BRAINTREE_PRIVATE_KEY.encode('ascii')).strip()
    # Taken from http://bit.ly/1cBESdC and ensures that the
    # crt is passed through to the requests verify parameter.
    new_request['verify'] = (
        Environment.braintree_root() + '/ssl/api_braintreegateway_com.ca.crt')

    return send(new_request)