Skip to main content

A django-payments backend for the Redsys payment gateway

Project description

django-payments-redsys

A Redsys payment gateway backend for django-payments.

Redsys was previously known as Sermepa.

Install

pip install django-payments-redsys

Configuration

Configure django payments with this provider by adding the following to settings.py:

PAYMENT_VARIANTS = {
    'redsys': ('payments_redsys.RedsysProvider', {
        'merchant_code': '123456789',
        'terminal': '1',
        'shared_secret': 'qwertyasdf0123456789',
    })
}

Here's a list with all available options:

  • merchant_code (required): Merchant Code - Redsys parameter.
  • terminal (required): Terminal - Redsys parameter.
  • shared_secret (required): Terminal Key - Redsys parameter.
    • "obtained by accessing the Administration Module, Merchant Data Query option in the 'See Key' section"
  • currency (default:'978'): ISO-4217 currency code.
  • environment: (default: "test", other valid option is "real").
  • order_number_prefix (optional, default: '0000'): Payment PK is suffixed to this to create Redsys order number
  • signature_version (default: 'HMAC_SHA256_V1'): Only supported signature type.
  • direct_payment (default: False): True or False
  • process_on_redirect (default: False): whether the payment will also be processed upon redirect (see explanation below)

process_on_redirect and testing environments

Once a payment has been made, Redsys provides the payment data twice: once via a POST to a webhook endpoint (while still within the Redsys website), and later upon redirect as GET querystring arguments. The latter is particularly convenient during local development, as Redsys won't be able to call a "localhost" webhook. When setting process_on_redirect to True, his Redsys provider will process the payment upon redirect, before finally redirecting to your success_url/failure_url - this way you can test the whole payment flow end to end without needing to set up some sort of reverse proxy.

Our recommendation is to do something like this in your settings.py:

import os
ENVIRONMENT = os.getenv("ENVIRONMENT", "dev")
PAYMENT_VARIANTS = {
    "redsys": (
        "payments_redsys.RedsysProvider",
        {
            # ...
            "process_on_redirect": ENVIRONMENT == "dev",
        },
    )
}

process_on_redirect can also be convenient in other situations (e.g. private intranets) where your application is not accessible via the public internet.

Besides this, as already mentioned above, Redsys has a test environment and provides some test credit card numbers you may use. Check out Tarjetas y entornos de prueba (spanish) for details.

About order numbers

Redsys requires your payments to include an order number (alphanumeric, 4 to 12 chars) that must be unique per merchant.

With this RedsysProvider you can either include an order_number in your Payment model (field or property), or a default one will be generated based on the setting order_number_prefix and the payment instance's primary key.

Sample project

This repo contains the seed of sample project that you can look at for inspiration and reference. It is a minimalistic django project, it has enough to be used in automated tests. You can also run it with just sample-app.

Contributing to this codebase

You may use the Justfile tool to run most commands in the development workflow (run the sample app, tests, etc.). Call just on a terminal to see all available options.

We use poetry and pyproject.toml. Get set up and check that things work with:

poetry install
just test

Credits

  • Copyright (C) 2018 AJ Ostergaard
  • Additional contributions by Carles Barrobés

This code is published as free software. See pyproject.toml for details about the license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_payments_redsys-0.6.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

django_payments_redsys-0.6.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file django_payments_redsys-0.6.0.tar.gz.

File metadata

  • Download URL: django_payments_redsys-0.6.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.2 Linux/6.11.0-25-generic

File hashes

Hashes for django_payments_redsys-0.6.0.tar.gz
Algorithm Hash digest
SHA256 fc17f452fb7b83d0539881ee697d768439d2372567bef0f78c9431c46122d3ec
MD5 c209ed0d838ff5aec9896d4833199b82
BLAKE2b-256 7934e7a6a41d795bd3d6d6d3a91797341087955d081f32814d0ee4086e96f49a

See more details on using hashes here.

File details

Details for the file django_payments_redsys-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_payments_redsys-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 602a31ee7d396db690fee8725634299cf7f0253a1e0cd7127f076d1d1235f8e8
MD5 bf29a3f6e6fda01bb4037db06448d52b
BLAKE2b-256 fe1e51922c6b652ea5ad1249051dccc1aaf83c26f4cd10ad3e9c2f4c058b19f7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page