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_handlercalls thebraintree_success_handlerwhich renders thebilling/braintree_success.htmlwith theresponseobject. Theresponseobject is a standard braintree result described here.braintree_failure_handler(self, request, response): If the transaction fails, thebraintree_notify_handlercalls thebraintree_failure_handlerwhich renders thebilling/braintree_error.htmlwith theresponsewhich 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_fieldsoradd_fieldmethods) 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 %}