I was overwhelmed with the reception of my last python post and the many conversations it initiated, mainly in Twitter. The main thing that I think was more interesting for people reading my blog is the Proof of Concept that Python is good for MVP, Production and even more.
In this post I am going to discuss another python use case inspired once again from a real life project that I am currently working. In my previous post I discussed about Flask, while now I give emphasis to Django.
A BattleHack
This story is a bit different from other ones. It starts by joining the BattleHack organised in Athens by BrainTree. There, apart from the nice food, the awesome games and the super cool mentors, there were also nice tutorials and a lot of Hack! This is something that I particularly enjoyed as well as anyone attending BattleHack in general.
Bellow you can see some of our awesome moments!
For me as a developer and evangelist, the tutorials were the most interesting part of the overall event.
The most important tools for integrating payments with BrainTree into my Django app that I was developing in the hack are listed below:
- The official BrainTree Python library
- A community Django implementation for BrainTree
- Another community Django Implementation that can be found also through pip
- Django-Payment, which is a multi-payment backend for Django
- V.Zero BrainTree SDK
For the hack we used the last one, and within a few minutes we had a functional payment system within our application, even though none of us has ever done something similar before.
Just to conclude this experience, we finally couldn’t perform well on the stage because we had so much to eat!!!
Nevertheless, it was super fun!

Buying your Music at Orfium
I will be talking about Orfium in a future post, but now I want to reference it here, as the overall result from the Battlehack experience was actually the know-how that lead us to implement the payment functionality that anyone can interact with, at the Payment Tab.

A Python Sample of Code doing Some Payment Stuff
[code language=”python”]
braintree.Configuration.configure(
braintree.Environment.Sandbox,
"23nd25g4kn7gnqbb",
"8552x2ym5bvhsycp",
"17f3279171d4fd90ee9cd5256be17abf"
)
@app.route("/")
def index():
# Generate client token for the dropin ui
client_token = braintree.ClientToken.generate({})
return render_template(‘index.html’, token=client_token)
@app.route("/proc", methods=[‘GET’, ‘POST’])
def proc():
result = braintree.Transaction.sale({
"amount": request.form["amount"],
"payment_method_nonce": request.form["payment_method_nonce"]
})
return render_template(‘proc.html’, result=result, request=request.form)
[/code]
APIs Can be Production Ready from Day 1
This is a proof that even the simplest integration can be secure and can be production ready if you are implementing on top of a good API.
BrainTree has managed to do a great job on their API. It is super easy to integrate their various features, including payments with paypal, credit card, fraud detection, subscriptions and more.
They also have a sandbox which is a practice that anyone providing an API as the core product should actually think of. The steps to going in production are super easy:
- Receive your Sandbox API Keys
- Make sure that everything is working with any of the listed above libraries
- Receive your Production API Keys
- Replace the Sandbox keys with the Production ones
- Receive real money!
APIs are here to make our life simpler and help us create products collaboratively with others.
Braintree is such a good example of an API. Hack it!