Skip to content

Instantly share code, notes, and snippets.

@mkelley33
Created March 28, 2011 19:16
Show Gist options
  • Save mkelley33/891073 to your computer and use it in GitHub Desktop.
Save mkelley33/891073 to your computer and use it in GitHub Desktop.
An almost working view for django-braintree
# Note: this is just for testing, and doesn't do stuff like set the amount or redirect if successful.
#
# This tidbit was created primarily to troubleshoot why I couldn't submit a form with validation errors
# twice without being redirected to https://sandbox.braintreegateway.com/login
#
# Tested using Python 2.6.6, django 1.2.5, django-braintree 1.5, and braintree 1.8
def make_payment(request):
result = TransactionForm.get_result(request)
form = TransactionForm(result, redirect_url='http://127.0.0.1:8000/make_payment/')
form.generate_tr_data()
# When I'm redirected back to make_payment with validation errors,
# inspection of form.fields['tr_data'].initial reveals the expected data.
#
# However, if you fire up Chrome, CMD-alt-i, and examine the source,
# you'll see the hidden input has been rendered, but without any data.
#
# What gives?
return direct_to_template(request, 'make_payment.html', { 'form': form })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment