Search code examples
djangobraintreepython-rqdjango-rq

Django-RQ + Braintree: Submit for settlement


I have read this stackoverflow Q&A but it did not worked it my case.

In my scenario I push a function (submit_transaction_for_settlement(transaction_id)) to the redis queue using the excellent package django-rq. The job of this function is to submit a transaction for settlement.

In the sandbox, whenever this function is executed I keep getting the same error: AttributeError: type object 'Configuration' has no attribute 'environment'.

I tried agf's proposal about instantiate a new gateway for each transaction inside my function, but it did not work!

Maybe this has something to do with the environment of the redis queue or the worker environment?

def submit_transaction_for_settlement(transaction_id):
    from braintree import Configuration, BraintreeGateway

    config = Configuration(environment=settings.BRAINTREE_ENVIRONMENT, merchant_id=settings.BRAINTREE_MERCHANT_ID,
                                   public_key=settings.BRAINTREE_PUBLIC_KEY, private_key=settings.BRAINTREE_PRIVATE_KEY)
    gateway = BraintreeGateway(config=config)
    result = gateway.transaction.submit_for_settlement(transaction_id)

Solution

  • Ahrg!

    I hate the moments where I answer a question and minutes after I find myself the solution!

    The fault was in the command running the rqworker. I was using the command python manage.py rqworker --worker-class rq.SimpleWorker because I had this issue because I used python 2.7 (or something else caused this issue). The command generated this issue was python manage.py rqworker.

    Upgrading now to python 3.4, the last command works like a charm! So, running python manage.py rqworker did the trick and no such errors!