Braintree Payments Transparent Redirect¶
Braintree Payments Transparent Redirect is a service offered by Braintree Payments to reduce the complexity of PCI compliance.
Note
This integration makes use of the official braintree python package offered by Braintree Payments. Please install it before you use this integration.
Refer to the Braintree Payments Server to Server
Gateway for the settings attributes.
Here are the methods and attributes implemented on the BraintreePaymentsIntegration
class:
__init__(self, options=None)
: The constructor method that configures the Braintree environment setting it either to production or sandbox mode based on the value ofsettings.MERCHANT_TEST_MODE
.service_url(self)
: A property that provides the URL to which the Transparent Redirect form is submitted.get_urls(self)
: The method sets the url to which Braintree redirects after the form submission is successful. This method is generally mapped directly in theurls.py
.from billing import get_integration braintree = get_integration("braintree_payments") urlpatterns += patterns('', (r'^braintree/', include(braintree.urls)), )
braintree_notify_handler(self, request)
: The view method that handles the confirmation of the transaction after successful redirection from Braintree.braintree_success_handler(self, request, response)
: If the transaction is successful, thebraintree_notify_handler
calls thebraintree_success_handler
which renders thebilling/braintree_success.html
with theresponse
object. Theresponse
object is a standard braintree result described here.braintree_failure_handler(self, request, response)
: If the transaction fails, thebraintree_notify_handler
calls thebraintree_failure_handler
which renders thebilling/braintree_error.html
with theresponse
which is a standar braintree error object.generate_tr_data(self)
: The method that calculates the tr_data to prevent a form from being tampered post-submission.generate_form(self)
: The method that generates and returns the form (present inbilling.forms.braintree_payments_form
) and populates the initial data with theself.fields
(added through either theadd_fields
oradd_field
methods) andtr_data
.
Example:¶
In the views.py:
braintree_obj = get_integration("braintree_payments") # Standard braintree fields fields = {"transaction": { "order_id": "some_unique_id", "type": "sale", "options": { "submit_for_settlement": True }, }, "site": "%s://%s" %("https" if request.is_secure() else "http", RequestSite(request).domain) } braintree_obj.add_fields(fields) return render_to_response("some_template.html", {"bp": braintree_obj}, context_instance=RequestContext(request))In the urls.py:
braintree_obj = get_integration("braintree_payments") urlpatterns += patterns('', (r'^braintree/', include(braintree.urls)), )In the template:
{% load render_integration from billing_tags %} {% render_integration bp %}