Search code examples
pythonbraintree

Flask gateway equlivent in Django


I'm setting up my Braintree web-hooks in Django, as Braintree docs says i have to add this method

from flask import Flask, request, render_template, Response
...
def webhook():
    webhook_notification = gateway.webhook_notification.parse(str(request.form['bt_signature']), request.form['bt_payload'])

    # Example values for webhook notification properties
    print(webhook_notification.kind)
    print(webhook_notification.timestamp) 

    return Response(status=200)

everything is ok except i have no idea what gateway is, and I'm getting undefined name error

my Django code

@csrf_exempt
def webhook(request):
    print("post:: ", request.POST)

    webhook_notification = gateway.webhook_notification.parse(str(request.form["bt_signature"]), request.form["bt_payload"])
    
    print(webhook_notification.kind)
    print(webhook_notification.timestamp)

    return HttpResponse("Ok")

sorry if missed up things, I haven't try flask yet.


Solution

  • That's not related to Flask nor Django.

    It's the gateway object you configure for any use of the Braintree Python SDK, á la

    import braintree
    
    gateway = braintree.BraintreeGateway(
        braintree.Configuration(
            braintree.Environment.Sandbox,
            merchant_id="use_your_merchant_id",
            public_key="use_your_public_key",
            private_key="use_your_private_key",
        )
    )