Coder Social home page Coder Social logo

cartridge_braintree's Introduction

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 use

  1. Install cartridge_braintree:

    pip install cartridge_braintree
    

    If 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.

  2. Add 'cartridge_braintree' to your INSTALLED_APPS. List it higher than 'cartridge.shop', otherwise the cartridge_braintree template will not be selected.

  3. Set up the following settings in your settings.py or local_settings.py:

    BRAINTREE_MERCHANT_ID = <your merchant ID>
    BRAINTREE_PUBLIC_KEY = <your public key>
    BRAINTREE_PRIVATE_KEY = <your private key>
    

    Note

    When DEBUG is True the Braintree Sandbox environment will be used, otherwise the Braintree Production environment is used.

    See also https://developer.paypal.com/braintree/articles/control-panel/important-gateway-credentials

  4. cartridge_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 in settings.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 using settings.SHOP_DEFAULT_COUNTRY as an alpha2 code. By default the user is expected to choose their country (set to None).

      The country/countries (as alpha2 codes) listed in settings.SHOP_PRIMARY_COUNTRIES will show up at the top of the country selection fields, after the settings.SHOP_DEFAULT_COUNTRY if set.

    • Credit Card number and CCV fields are rendered using the NoNameTextInput widget so that the data is not submitted to the server. Javascript processes these fields to create a payment_method_nonce, which is then stored in a hidden form element.

    • Uses jquery.payment from stripe for client-side validation of the payment form and submits the errors in the hidden braintree_errors field to the server to handle them as Django errors.

    See https://developer.paypal.com/braintree/docs/guides/transactions/python

  5. Set 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 relevant braintreejs.html template.

  6. Include cartridge_braintree.urls for shop/checkout in urls.py before 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"),
    
  7. 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 in settings.py in the form:

    BRAINTREE_PAYPAL_ACTIVATE = True
    BRAINTREE_PAYPAL_CURRENCY = "EUR"
    

    In this case the settings will not be shown in the Admin.

  8. 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',
            },
        },
    }
    

    See https://docs.djangoproject.com/en/4.0/topics/logging/#configuring-logging for all configuration options

    Log levels are as follows:
    • Client token creation: info
    • Transaction start: debug
    • Transaction complete: debug
    • Transaction fail: warning

    Confidential information is never output to the logger.

cartridge_braintree's People

Contributors

henri-hulski avatar ianare avatar molokov avatar ryneeverett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cartridge_braintree's Issues

Country code (alpha2) is not an accepted country.

I'm getting this error message when submitting payment details:

Credit Card error: Country code (alpha2) is not an accepted country. Country code (alpha2) is not an accepted country. Country code (alpha2) is not an accepted country.

I'm hoping this is just a temporary glitch in braintree's API but I'm consistently reproducing it right now.

is this Package support Python3?

i have do according readme.rst my,is this Package support Python3?

D:\Python34\lib\site-packages\mezzanine\utils\conf.py:47: UserWarning: You haven
't defined the ALLOWED_HOSTS settings, which Django requires. Will fall back to
the domains configured as sites.
  warn("You haven't defined the ALLOWED_HOSTS settings, which "
              .....
          _d^^^^^^^^^b_
       .d''           ``b.
     .p'                `q.
    .d'                   `b.
   .d'                     `b.   * Mezzanine 4.1.0
   ::                       ::   * Django 1.9.5
  ::    M E Z Z A N I N E    ::  * Python 3.4.3
   ::                       ::   * SQLite 3.8.3.1
   `p.                     .q'   * Windows 8
    `p.                   .q'
     `b.                 .d'
       `q..          ..p'
          ^q........p^
              ''''

Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper
 at 0x0444E4F8>
Traceback (most recent call last):
  File "D:\Python34\lib\site-packages\django\utils\autoreload.py", line 226, in
wrapper
    fn(*args, **kwargs)
  File "D:\Python34\lib\site-packages\mezzanine\core\management\commands\runserv
er.py", line 154, in inner_run
    super(Command, self).inner_run(*args, **kwargs)
  File "D:\Python34\lib\site-packages\django\core\management\commands\runserver.
py", line 116, in inner_run
    self.check(display_num_errors=True)
  File "D:\Python34\lib\site-packages\django\core\management\base.py", line 426,
 in check
    include_deployment_checks=include_deployment_checks,
  File "D:\Python34\lib\site-packages\django\core\checks\registry.py", line 75,
in run_checks
    new_errors = check(app_configs=app_configs)
  File "D:\Python34\lib\site-packages\django\core\checks\urls.py", line 13, in c
heck_url_config
    return check_resolver(resolver)
  File "D:\Python34\lib\site-packages\django\core\checks\urls.py", line 23, in c
heck_resolver
    for pattern in resolver.url_patterns:
  File "D:\Python34\lib\site-packages\django\utils\functional.py", line 33, in _
_get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "D:\Python34\lib\site-packages\django\core\urlresolvers.py", line 417, in
 url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "D:\Python34\lib\site-packages\django\utils\functional.py", line 33, in _
_get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "D:\Python34\lib\site-packages\django\core\urlresolvers.py", line 410, in
 urlconf_module
    return import_module(self.urlconf_name)
  File "D:\Python34\lib\importlib\__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "D:\0MyCMS\cartridge\project\project\urls.py", line 36, in <module>
    url("^shop/checkout%s" % _slash, include("cartridge_braintree.urls")),
  File "D:\Python34\lib\site-packages\django\conf\urls\__init__.py", line 52, in
 include
    urlconf_module = import_module(urlconf_module)
  File "D:\Python34\lib\importlib\__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "D:\Python34\lib\site-packages\cartridge_braintree\urls.py", line 10, in
<module>
    extra_context = {"client_token": braintree_payment.client_token()}
  File "D:\Python34\lib\site-packages\cartridge_braintree\braintree_payment.py",
 line 50, in client_token
    return braintree.ClientToken.generate()
  File "D:\Python34\lib\site-packages\braintree\client_token.py", line 16, in ge
nerate
    return gateway.generate(params)
  File "D:\Python34\lib\site-packages\braintree\client_token_gateway.py", line 2
4, in generate
    response = self.config.http().post(self.config.base_merchant_path() + "/clie
nt_token", params)
  File "D:\Python34\lib\site-packages\braintree\configuration.py", line 96, in b
ase_merchant_path
    return "/merchants/" + self.merchant_id
TypeError: Can't convert 'NoneType' object to str implicitly

Upgrade to v.zero API and adding PayPal integration

I have upgraded cartridge_braintree to the v.zero API and added PayPal as optional payment method.
Actually rewriting most of the app.
I also used some code from cartridge-pinpayments.
You can find it at https://github.com/henri-hulski/cartridge_braintree/tree/v.zero, which is the v.zero branch.

If you want I can make a PR here or if you prefer I can maintain it on my account.
I think in this case we have to make a transfer.

I have turned it also in a full Pypi package.
For now I have uploaded it to testpypi and you can install it with
pip install -i https://testpypi.python.org/pypi cartridge_braintree
or with utf-8 sorting support for country names with
pip install -i https://testpypi.python.org/pypi cartridge_braintree[countries_utf8_sorting]

Please take a look and tell me what you think.
Regards,
Henri

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.