Provider backends

These are the payment provider backend implementations included in this package. Note that you should not usually instantiate these yourself, but use provider_factory() instead.

Dummy

class payments.dummy.DummyProvider(capture=True)

Dummy payment provider.

This is a dummy backend suitable for testing your store without contacting any payment gateways. Instead of using an external service it will simply show you a form that allows you to confirm or reject the payment.

You should only use this in development or in test servers.

Example:

PAYMENT_VARIANTS = {
    'dummy': ('payments.dummy.DummyProvider', {})
}

Authorize.Net

class payments.authorizenet.AuthorizeNetProvider(login_id, transaction_key, endpoint='https://test.authorize.net/gateway/transact.dll', **kwargs)

Payment provider for Authorize.Net.

This backend implements payments using the Advanced Integration Method (AIM) from Authorize.Net.

This backend does not support fraud detection.

Parameters:
  • login_id – Your API Login ID assigned by Authorize.net

  • transaction_key – Your unique Transaction Key assigned by Authorize.net

  • endpoint – The API endpoint to use. For the production environment, use 'https://secure.authorize.net/gateway/transact.dll' instead.

Example:

# use staging environment
PAYMENT_VARIANTS = {
    'authorizenet': (
        'payments.authorizenet.AuthorizeNetProvider',
        {
            'login_id': '1234login',
            'transaction_key': '1234567890abcdef',
            'endpoint': 'https://test.authorize.net/gateway/transact.dll'
        },
    )
}

Braintree

class payments.braintree.BraintreeProvider(merchant_id, public_key, private_key, sandbox=True, **kwargs)

Payment provider for Braintree.

This backend implements payments using Braintree.

This backend does not support fraud detection.

Parameters:
  • merchant_id – Merchant ID assigned by Braintree

  • public_key – Public key assigned by Braintree

  • private_key – Private key assigned by Braintree

  • sandbox – Whether to use a sandbox environment for testing

Example:

# use sandbox
PAYMENT_VARIANTS = {
    'braintree': (
        'payments.braintree.BraintreeProvider',
        {
            'merchant_id': '112233445566',
            'public_key': '1234567890abcdef',
            'private_key': 'abcdef123456',
            'sandbox': True,
        }
    )
}

Coinbase

class payments.coinbase.CoinbaseProvider(key, secret, endpoint='sandbox.coinbase.com', **kwargs)

Payment provider for coinbase.

This backend implements payments using Coinbase.

This backend does not support fraud detection.

Parameters:
  • key – Api key generated by Coinbase

  • secret – Api secret generated by Coinbase

  • endpoint – Coinbase endpoint domain to use. For the production environment, use 'coinbase.com' instead

__init__(key, secret, endpoint='sandbox.coinbase.com', **kwargs)

Create a new provider instance.

This method should not be called directly; use provider_factory() instead.

Example:

# use sandbox
PAYMENT_VARIANTS = {
    'coinbase': (
        'payments.coinbase.CoinbaseProvider',
        {
            'key': '123abcd',
            'secret': 'abcd1234',
            'endpoint': 'sandbox.coinbase.com',
        }
    )
}

Cybersource

class payments.cybersource.CyberSourceProvider(merchant_id, password, org_id=None, fingerprint_url='https://h.online-metrix.net/fp/', sandbox=True, capture=True)

Payment provider for CyberSource

This backend implements payments using Cybersource.

This backend supports fraud detection.

Parameters:
  • merchant_id – Your Merchant ID

  • password – Generated transaction security key for the SOAP toolkit

  • org_id – Provide this parameter to enable Cybersource Device Fingerprinting

  • fingerprint_url – Address of the fingerprint server

  • sandbox – Whether to use a sandbox environment for testing

  • capture – Whether to capture the payment automatically. See Authorization and capture for more details.

Example:

# use sandbox
PAYMENT_VARIANTS = {
    'cybersource': (
        'payments.cybersource.CyberSourceProvider',
        {
            'merchant_id': 'example',
            'password': '1234567890abcdef',
            'capture': False,
            'sandbox': True,
        }
    )
}

Merchant-Defined Data

Cybersource allows you to pass Merchant-Defined Data, which is additional information about the payment or the order, such as an order number, additional customer information, or a special comment or request from the customer. This can be accomplished by passing your data to the Payment instance:

>>> payment.attrs.merchant_defined_data = {'01': 'foo', '02': 'bar'}

Fingerprinting:

Cybersource allows you to pass a fingerprint data to help identify fraud

    >>> payment.attrs.fingerprint_session_id

Dotpay

class payments.dotpay.DotpayProvider(seller_id, pin, endpoint='https://ssl.dotpay.pl/test_payment/', channel=0, channel_groups=None, ignore_last_payment_channel=False, lang='pl', lock=False, type=2, **kwargs)

Payment provider for dotpay.pl

This backend implements payments using a popular Polish gateway, Dotpay.pl.

Due to API limitations there is no support for transferring purchased items.

This backend does not support fraud detection.

Parameters:
  • seller_id – Seller ID assigned by Dotpay

  • pin – PIN assigned by Dotpay

  • channel – Default payment channel (consult reference guide). Ignored if channel_groups is set.

  • channel_groups – Payment channels to choose from (consult reference guide). Overrides channel.

  • lang – UI language

  • lock – Whether to disable channels other than the default selected above

  • endpoint – The API endpoint to use. For the production environment, use 'https://ssl.dotpay.pl/' instead

  • ignore_last_payment_channel – Display default channel or channel groups instead of last used channel.

  • type – Determines what should be displayed after payment is completed (consult reference guide).

Example:

# use defaults for channel and lang but lock available channels
PAYMENT_VARIANTS = {
    'dotpay': (
        'payments.dotpay.DotpayProvider',
        {
            'seller_id': '123',
            'pin': '0000',
            'lock': True,
            'endpoint': 'https://ssl.dotpay.pl/test_payment/',
        }
    )
}

PayPal

class payments.paypal.PaypalProvider(client_id, secret, endpoint='https://api.sandbox.paypal.com', capture=True)

Payment provider for Paypal, redirection-based.

This backend implements payments using PayPal.com.

Parameters:
  • client_id – Client ID assigned by PayPal or your email address

  • secret – Secret assigned by PayPal

  • endpoint – The API endpoint to use. For the production environment, use 'https://api.paypal.com' instead

  • capture – Whether to capture the payment automatically. See Authorization and capture for more details.

Example:

# use sandbox
PAYMENT_VARIANTS = {
    'paypal': (
        'payments.paypal.PaypalProvider',
        {
            'client_id': 'user@example.com',
            'secret': 'iseedeadpeople',
            'endpoint': 'https://api.sandbox.paypal.com',
            'capture': False,
        }
    )
}
class payments.paypal.PaypalCardProvider(client_id, secret, endpoint='https://api.sandbox.paypal.com', capture=True)

Payment provider for Paypal, form-based.

This backend implements payments using PayPal.com but the credit card data is collected by your site.

Parameters are the same as PaypalProvider.

This backend does not support fraud detection.

Example:

PAYMENT_VARIANTS = {
    'paypal': (
        'payments.paypal.PaypalCardProvider',
        {
            'client_id': 'user@example.com',
            'secret': 'iseedeadpeople',
        }
    )
}

Sage Pay

class payments.sagepay.SagepayProvider(vendor, encryption_key, endpoint='https://test.sagepay.com/Simulator/VSPFormGateway.asp', **kwargs)

Payment provider for sagepay.com

This backend implements payments using SagePay.com Form API.

This backend does not support fraud detection. Purchased items are not currently transferred.

Parameters:
  • vendor – Your vendor code

  • encryption_key – Encryption key assigned by Sage Pay

  • endpoint – The API endpoint to use. For the production environment, use 'https://live.sagepay.com/gateway/service/vspform-register.vsp' instead

Example:

# use simulator
PAYMENT_VARIANTS = {
    'sage': (
        'payments.sagepay.SagepayProvider',
        {
            'vendor': 'example',
            'encryption_key': '1234567890abcdef',
            'endpoint': 'https://test.sagepay.com/Simulator/VSPFormGateway.asp',
        }
    )
}

Sofort / Klarna

class payments.sofort.SofortProvider(key, id, project_id, endpoint='https://api.sofort.com/api/xml', **kwargs)

Payment provider for Sofort.

This backend implements payments using sofort.com API.

This backend does not support fraud detection.

Parameters:
  • key – Your secret key

  • id – Your sofort.com user id

  • project_id – Your sofort.com project id

  • endpoint – The API endpoint to use.

Example:

PAYMENT_VARIANTS = {
    'sage': (
        'payments.sofort.SofortProvider',
        {
            'id': '123456',
            'key': '1234567890abcdef',
            'project_id': '654321',
            'endpoint': 'https://api.sofort.com/api/xml',
        }
    )
}

Stripe

class payments.stripe.StripeProviderV3(api_key, use_token=True, endpoint_secret=None, secure_endpoint=True, **kwargs)

Provider backend using Stripe api version 3.

Parameters:
  • api_key – Secret key assigned by Stripe.

  • use_token – Use instance.token instead of instance.pk in client_reference_id

  • endpoint_secret – Endpoint Signing Secret.

  • secure_endpoint – Validate the recieved data, useful for development.

Example:

# Settings for Production
PAYMENT_VARIANTS = {
    'stripe': (
        'payments.stripe.StripeProviderV3',
        {
            'api_key': 'sk_test_123456',
            'use_token': True,
            'endpoint_secret': 'whsec_123456',
            'secure_endpoint': True
        }
    )
}
# Settings for Development
PAYMENT_VARIANTS = {
    'stripe': (
        'payments.stripe.StripeProviderV3',
        {
            'api_key': 'sk_test_123456',
            'use_token': True,
            'secure_endpoint': False
        }
    )
}
class payments.stripe.StripeProvider(public_key, secret_key, image='', name='', **kwargs)

Provider backend using Stripe.

This backend does not support fraud detection.

Parameters:
  • secret_key – Secret key assigned by Stripe.

  • public_key – Public key assigned by Stripe.

  • name – A friendly name for your store.

  • image – Your logo.

Deprecated since version 2.0.

Example:

# use sandbox
PAYMENT_VARIANTS = {
    'stripe': (
        'payments.stripe.StripeProvider',
        {
            'secret_key': 'sk_test_123456',
            'public_key': 'pk_test_123456',
        }
    )
}
class payments.stripe.StripeCardProvider(public_key, secret_key, image='', name='', **kwargs)

Provider backend using Stripe, form-based.

This backend implements payments using Stripe but the credit card data is collected by your site.

Parameters are the same as StripeProvider.

Deprecated since version 2.0.

MercadoPago

class payments.mercadopago.MercadoPagoProvider(access_token: str, sandbox: bool)

This backend implements payments using MercadoPago.

You’ll need to install with extra dependencies to use this:

pip install "django-payments[mercadopago]"
Parameters:
  • access_token – The access token provided by MP.

  • sandbox – Whether to use sandbox more.

Example:

PAYMENT_VARIANTS: = {
    "mercadopago": (
        "payments.mercadopago.MercadoPagoProvider",
        {
            "access_token": "APP_USR-3453454363464444-645434-7f8da79f8da7f98ad7f98ad7f98df78e-454545466",
            "sandbox": DEBUG,
        },
    ),
}

Note that the API sandbox does not return Payment details, so all payments will seem unpaid.

Community Backends

These are the community providers compatible with django-payments

Community Backends

Payment Backend

Country

Repo

Mollie

Worldwide

fourdigits/django-payments-mollie

Redsys

ES

ajostergaard/django-payments-redsys

click

UZ

click-llc/click-integration-django

BNL Positivity

IT

esistgut/django-payments-bnlepos

PayU

World Wide

PetrDlouhy/django-payments-payu

RazorPay

IN

NyanKiyoshi/django-payments-razorpay

Flow Chile

CL

mariofix/django-payments-flow

Khipu

CL

mariofix/django-payments-khipu

Creating a New Provider Backend

Django Payments provides a flexible framework for integrating various payment providers into your Django application. This guide will walk you through the steps to create a new payment provider in Django Payments.

Create a Provider Class

  • Create a new Python module for your provider in the Django Payments project.

  • Inside the module, define a class for your provider, inheriting from the base BaseProvider class provided by Django Payments.

from payments.providers.base import BaseProvider

class MyPaymentProvider(BaseProvider):
  def process_data(self, payment, request):
      # Implement webhook processing logic
      pass

  def get_form(self, payment, data=None):
      # Implement payment form rendering logic
      pass

  def capture(self, payment, amount=None):
      # Implement payment capture logic
      raise NotImplementedError("Capture method not implemented.")

  def refund(self, payment, amount=None):
      # Implement payment refund logic
      raise NotImplementedError("Refund method not implemented.")

Hint

Check with the integrator to see if they suppoer capture/refund

Implement the mandatory methods specific to your payment provider. Here are the mandatory methods used by Django Payments:

  • process_data(payment, request): This method is responsible for processing webhook calls from the payment gateway. It receives a payment object representing the payment being processed and the request object. Implement the logic to handle the webhook data received from the payment gateway and update the payment status or perform any necessary actions.

  • get_form(payment, data=None): This method is responsible for rendering the payment form to be displayed within your Django application. It receives a payment object representing the payment being made and an optional data parameter if form submission data is provided. Implement the logic to render the payment form, customize it based on your payment gateway requirements, and handle form submission.

  • capture(payment, amount=None): This method is responsible for capturing the payment amount. It receives a payment object representing the payment to be captured and an optional amount parameter. Implement the logic to interact with your payment gateway’s API and perform the necessary actions to capture the payment amount. If capturing is not supported by your payment gateway, set capture: False. to skip capture.

  • refund(payment, amount=None): This method is responsible for refunding a payment. It receives a payment object representing the payment to be refunded and an optional amount parameter. Implement the logic to interact with your payment gateway’s API and initiate the refund process. If refunding is not supported by your payment gateway, raise a NotImplementedError.

Make sure to implement these methods in your provider class and handle any exceptions or errors that may occur during the payment processing or refunding process.

By implementing these mandatory methods in your provider class, you can integrate your payment gateway with Django Payments and provide the necessary functionality to process payments, display payment forms, capture payments, and handle refunds.