Package: cartridge_braintree
Braintree Payments processing for Mezzanine/Cartridge.
Supports Django 3.2 or 4.0, Mezzanine 5.1 or newer and
Cartridge 1.3 or newer.Instructions for useInstall cartridge_braintree:pip install cartridge_braintreeIf you need the correct sorting of not ASCII country names use:pip install cartridge_braintree[countries_utf8_sorting]This will add ‘pyuca’ to the requirements.Add ‘cartridge_braintree’ to yourINSTALLED_APPS. List it higher than
‘cartridge.shop’, otherwise the cartridge_braintree template will
not be selected.Set up the following settings in yoursettings.pyorlocal_settings.py:BRAINTREE_MERCHANT_ID = <your merchant ID>
BRAINTREE_PUBLIC_KEY = <your public key>
BRAINTREE_PRIVATE_KEY = <your private key>NoteWhenDEBUGisTruetheBraintree Sandbox environmentwill be
used, otherwise theBraintree Production environmentis used.See alsohttps://developer.paypal.com/braintree/articles/control-panel/important-gateway-credentialscartridge_braintree uses a modified checkout form, which does the following:Changes the shipping and billing country fields to a Select
widget. This ensures that the country selected can be converted to
a valid code for Braintree’s payment processing.
The supported countries can be set insettings.SHOP_SUPPORTED_COUNTRIES,
which is a list of alpha2 country codes and/or tuples in the form
(alpha2, country_name).For example if you want to select the countries in the EU area use:SHOP_SUPPORTED_COUNTRIES = [
    'AL', 'AT', 'BA', 'BE', 'BG', 'CH', 'CY', 'DE', 'DK', 'EE', 'ES',
    'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE', 'IS', 'IT', 'LT', 'LV',
    'MK', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'RS', 'SE', 'SI'
 ]A pre-selected country in the select field can be specified usingsettings.SHOP_DEFAULT_COUNTRYas an alpha2 code.
By default the user is expected to choose their country (set toNone).The country/countries (as alpha2 codes) listed insettings.SHOP_PRIMARY_COUNTRIESwill show up at the top of the
country selection fields, after thesettings.SHOP_DEFAULT_COUNTRYif set.Credit Card number and CCV fields are rendered using theNoNameTextInputwidget so that the data is not submitted to the
server. Javascript processes these fields to create apayment_method_nonce, which is then stored in a hidden form
element.Usesjquery.paymentfrom stripe
for client-side validation of the payment form and submits the errors in the
hiddenbraintree_errorsfield to the server to handle them as Django errors.Seehttps://developer.paypal.com/braintree/docs/guides/transactions/pythonSet the payment handler to be the Braintree payment handler:SHOP_HANDLER_PAYMENT = 'cartridge_braintree.braintree_payment.payment_handler'If you are overriding the templates in your own apps, then be sure to
include the relevantbraintreejs.htmltemplate.Includecartridge_braintree.urlsforshop/checkoutinurls.pybefore Cartridge urls:urlpatterns += [

    # cartridge_braintree URLs.
    re_path(r"^shop/(?=checkout(/?)$)", include("cartridge_braintree.urls")),

    # Cartridge URLs.
    path("shop/", include("cartridge.shop.urls")),
    path("account/orders/", order_history, name="shop_order_history"),If you want to use PayPal payments with Braintree activate them in
the Admin Site Settings and set the currency to use with PayPal.Alternatively you can set them insettings.pyin the form:BRAINTREE_PAYPAL_ACTIVATE = True
BRAINTREE_PAYPAL_CURRENCY = "EUR"In this case the settings will not be shown in the Admin.Optionally add logging to your Django configuration if you want to have more details
on transactions:LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'braintree_file': {
            'class': 'logging.FileHandler',
            'filename': '/path/to/django/braintree.log',
        },
    },
    'loggers': {
        'braintree_payment': {
            'handlers': ['braintree_file'],
            'level': 'DEBUG',
        },
    },
}Seehttps://docs.djangoproject.com/en/4.0/topics/logging/#configuring-loggingfor all
configuration optionsLog levels are as follows:Client token creation: infoTransaction start: debugTransaction complete: debugTransaction fail: warningConfidential information is never output to the logger.