Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gateway.transaction.find raises a TypeError when initialised with client_id and secret #128

Open
jvn145 opened this issue Mar 10, 2021 · 2 comments
Labels

Comments

@jvn145
Copy link

jvn145 commented Mar 10, 2021

General information

  • SDK/Library version: 4.6.0
  • Environment: Sandbox
  • Language, language version, and OS: Python 3.9.1 on a python:alpine docker container

Issue description

When I try and gateway.transaction.find a transaction using a gateway that was initialised with a client_id and secret, I receive a TypeError "can only concatenate str (not "NoneType") to str".

Had a look, this happens because the BraintreeGateway.merchant_id is not set if you initialise it using a client_id and secret.

Steps to reproduce:

# gateway using my credentials
gateway = braintree.BraintreeGateway(
    client_id=os.getenv('BT_CID'), 
    client_secret=os.getenv('BT_SECRET')
)

result = gateway.transaction.sale({
    "amount": '1.00',
    "payment_method_nonce": 'fake-valid-nonce',
    "options": {
        "submit_for_settlement": True
    }
})

transaction = result.transaction

result = gateway.transaction.find(transaction.id)

Traceback:

Traceback (most recent call last):
  File "/test.py", line 89, in <module>
    result = my_gateway.transaction.sale({
  File "/usr/local/lib/python3.9/site-packages/braintree/transaction_gateway.py", line 84, in sale
    return self.create(params)
  File "/usr/local/lib/python3.9/site-packages/braintree/transaction_gateway.py", line 31, in create
    return self._post("/transactions", {"transaction": params})
  File "/usr/local/lib/python3.9/site-packages/braintree/transaction_gateway.py", line 168, in _post
    response = self.config.http().post(self.config.base_merchant_path() + url, params)
  File "/usr/local/lib/python3.9/site-packages/braintree/configuration.py", line 113, in base_merchant_path
    return "/merchants/" + self.merchant_id
TypeError: can only concatenate str (not "NoneType") to str
@hollabaq86
Copy link

👋 @jvn145 thanks for reaching out. Creating a Braintree gateway using a client ID and client secret is only intended for oAuth management, not transaction management like transaction.sale calls. If you're trying to create a transaction using a shared vault, you'll need to create an access token first and create your gateway instance with that access token.

If you're not using an oAuth scenario to manage your vault and transact with a shared vault, you should be creating your gateway using API credentials. For any assistance with oAuth or setting up your gateway with API credentials, please contact Support.

All this said, this error message isn't helpful in understanding the limitations of making a gateway via oAuth, and we should definitely update the SDK to surface a better error message. I'll leave this issue open to track improving our error messaging around this scenario.

@hollabaq86
Copy link

for internal tracking, ticket 836

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants