{"id":15645882,"url":"https://github.com/danielgtaylor/braintree_django","last_synced_at":"2025-10-09T11:32:14.013Z","repository":{"id":904545,"uuid":"661583","full_name":"danielgtaylor/braintree_django","owner":"danielgtaylor","description":"Braintree Django Module","archived":false,"fork":false,"pushed_at":"2019-12-17T21:31:40.000Z","size":124,"stargazers_count":52,"open_issues_count":5,"forks_count":16,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-27T17:21:25.071Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielgtaylor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-05-11T21:42:23.000Z","updated_at":"2022-06-11T21:03:29.000Z","dependencies_parsed_at":"2022-07-17T01:16:26.649Z","dependency_job_id":null,"html_url":"https://github.com/danielgtaylor/braintree_django","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/danielgtaylor/braintree_django","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielgtaylor%2Fbraintree_django","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielgtaylor%2Fbraintree_django/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielgtaylor%2Fbraintree_django/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielgtaylor%2Fbraintree_django/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielgtaylor","download_url":"https://codeload.github.com/danielgtaylor/braintree_django/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielgtaylor%2Fbraintree_django/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001302,"owners_count":26083058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T12:10:27.955Z","updated_at":"2025-10-09T11:32:13.994Z","avatar_url":"https://github.com/danielgtaylor.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Info\n====\n\nThis 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.\n\nThe django_braintree 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).\n\nThis module depends on the Braintree Python module, so please install it first.\n\nBraintree API Documentation\n---------------------------\n\n * [Transparent redirect][1]\n * [Python module][2]\n * [Python module API documentation][3]\n\n[1]: http://www.braintreepaymentsolutions.com/gateway/transparent-redirect\n[2]: http://www.braintreepaymentsolutions.com/gateway/python\n[3]: http://www.braintreepaymentsolutions.com/gateway/python/docs/index.html\n\nExample 1: Simple\n-----------------\nDownload and install the django_braintree module, then create a form in one of your views. Start by installing the module in settings.py:\n\n    import braintree\n\n    INSTALLED_APPS = [\n        ...\n        \"django_braintree\",\n        ...\n    ]\n\n    # Braintree sandbox settings\n    BRAINTREE_ENV = braintree.Environment.Sandbox\n    BRAINTREE_MERCHANT = 'your_merchant_key'\n    BRAINTREE_PUBLIC_KEY = 'your_public_key'\n    BRAINTREE_PRIVATE_KEY = 'your_private_key'\n\n    # If you cannot install M2Crypto (e.g. AppEngine):\n    BRAINTREE_UNSAFE_SSL = True\n\nNext, create a view to use one of the transparent redirect forms:\n\n    from django_braintree.forms import TransactionForm\n\n    def myview(request):\n        result = TransactionForm.get_result(request)\n\n        # If successful redirect to a thank you page\n        if result and result.is_success:\n            return HttpResponseRedirect(\"/thanks\")\n\n        # Create the form. You MUST pass in the result to get error messages!\n        myform = TransactionForm(result, redirect_url=\"http://mysite.com/myview\")\n\n        # Remove items we don't need\n        myform.remove_section(\"transaction[shipping_address]\")\n        myform.remove_section(\"transaction[amount]\")\n        myform.remove_section(\"transaction[options]\")\n\n        # Set fields we want passed along\n        myform.tr_fields[\"transaction\"][\"amount\"] = \"19.99\"\n\n        # Generate the tr_data signed field; this MUST be called!\n        myform.generate_tr_data()\n\n        return render(\"template.html\", {\n            \"form\": myform,\n        })\n\nThen, in your template rendering the form is easy:\n\n    \u003cform action=\"{{ form.action }}\" method=\"POST\"\u003e\n        {{ form.as_table }}\n        \u003cbutton type=\"submit\"\u003eSubmit order\u003c/button\u003e\n    \u003c/form\u003e\n\nExample 2: Custom Form\n----------------------\n\nCreating a custom form like the one below provides an alternative to:\n\n    myform.remove_section(\"transaction[amount]\")\n    myform.tr_fields[\"transaction\"][\"amount\"] = \"19.99\"\n\nFollow steps shown in Example 1 above. In your Django application, create a\nforms.py module, and add the following to it:\n\n    from django_braintree.forms import BraintreeForm\n    from django_braintree.odict import OrderedDict\n\n    class ProtectedAmountForm(BraintreeForm):\n\n        tr_type = \"Transaction\"\n        tr_fields = OrderedDict([\n            (\"transaction\", OrderedDict([\n                (\"customer\", OrderedDict([\n                    (\"first_name\", None),\n                    (\"last_name\", None),\n                    (\"email\", None),\n                    (\"phone\", None),]),\n                ),\n                (\"credit_card\", OrderedDict([\n                    (\"cardholder_name\", None),\n                    (\"number\", None),\n                    (\"expiration_month\", None),\n                    (\"expiration_year\", None),\n                    (\"cvv\", None)]),\n                ),\n                (\"billing\", OrderedDict([\n                    (\"postal_code\", None),\n                    (\"country_name\", None)]),\n                ),\n            ])),\n        ])\n        tr_labels = {\n            \"transaction\": {\n                \"credit_card\": {\n                    \"cvv\": \"CVV\",\n                    \"expiration_month\": \"Expiration Month\",\n                    \"expiration_year\": \"Expiration Year\",\n                },\n            },\n        }\n        tr_protected = {\n            \"transaction\": {\n                \"amount\": None,\n                \"type\": None,\n                \"order_id\": None,\n                \"customer_id\": None,\n                \"payment_method_token\": None,\n                \"customer\": {\n                    \"id\": None,\n                },\n                \"credit_card\": {\n                    \"token\": None,\n                },\n                \"options\": {\n                    \"store_in_vault\": True\n                },\n            },\n        }\n\n        def __init__(self, amount, result=None, redirect_url=None, *args, **kwargs):\n            self.tr_protected[\"transaction\"][\"amount\"] = amount\n            super(ProtectedAmountForm, self).__init__(result, redirect_url=redirect_url, *args, **kwargs)\n\nLicense\n-------\nDjango Braintree uses the MIT license. Please see the LICENSE file for full details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielgtaylor%2Fbraintree_django","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielgtaylor%2Fbraintree_django","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielgtaylor%2Fbraintree_django/lists"}