Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgtaylor committed May 11, 2010
0 parents commit 8110873
Show file tree
Hide file tree
Showing 7 changed files with 774 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Daniel G. Taylor <[email protected]>
19 changes: 19 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) <2010> <Daniel G. Taylor>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Braintree Django Module
=======================
This module provides an easy to use interface to Braintree using Django's built-in form system to allow Django developers to easily make use of the Braintree transparent redirect functionality to help with PCI DSS compliance issues.

The btdjango module supports all documented fields in the official transparent redirect documentation. You can selectively turn on/off fields as required by your use scenario (for example, hiding the shipping address in the transaction form).

This module depends on the Braintree Python module, so please install it first.

External Documentation
----------------------

* http://www.braintreepaymentsolutions.com/gateway/transparent-redirect
* http://www.braintreepaymentsolutions.com/gateway/python
* http://www.braintreepaymentsolutions.com/gateway/python/docs/index.html

Simple Example
--------------
Download and install the btdjango module, then create a form in one of your views. Start by installing the module in settings.py:

import braintree

INSTALLED_APPS = [
...
"btdjango",
...
]

# Braintree sandbox settings
BRAINTREE_ENV = braintree.Environment.Sandbox
BRAINTREE_MERCHANT = 'your_merchant_key'
BRAINTREE_PUBLIC_KEY = 'your_public_key'
BRAINTREE_PRIVATE_KEY = 'your_private_key'

braintree.Configuration.configure(
BRAINTREE_ENV,
BRAINTREE_MERCHANT,
BRAINTREE_PUBLIC_KEY,
BRAINTREE_PRIVATE_KEY
)

Next, create a view to use one of the transparent redirect forms:

from btdjango.forms import TransactionForm

def myview(request):
result = TransactionForm.get_result(request)

# If successful redirect to a thank you page
if result and result.is_success:
return HttpResponseRedirect("/thanks")

# Create the form. You MUST pass in the result to get error messages!
myform = TransactionForm(result, redirect_url="http://mysite.com/myview")

# Remove items we don't need
myform.remove_section("transaction[shipping_address]")
myform.remove_section("transaction[amount]")

# Set fields we want passed along
myform.tr_fields["transaction"]["amount"] = "19.99"

# Generate the tr_data signed field; this MUST be called!
myform.generate_tr_data()

return render("template.html", {
"form": myform,
})

Then, in your template rendering the form is easy:

<form action={{ form.action }}" method="POST">
{{ form.as_table }}
<button type="submit">Submit order</button>
</form>

8 changes: 8 additions & 0 deletions btdjango/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env python

"""
Braintree Django Python Module
"""

VERSION = "0.1"

Loading

0 comments on commit 8110873

Please sign in to comment.