Skip to main content

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.

Release files for django-payments-redsys 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-payments-redsys 0.6.0
File Size Uploaded
django_payments_redsys-0.6.0.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-payments-redsys 0.6.0
File Interpreter ABI Platform
django_payments_redsys-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.2 kB

Release files / django_payments_redsys-0.6.0.tar.gz

Download URL django_payments_redsys-0.6.0.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fc17f452fb7b83d0539881ee697d768439d2372567bef0f78c9431c46122d3ec
BLAKE2b-256 checksum
How to use checksums
7934e7a6a41d795bd3d6d6d3a91797341087955d081f32814d0ee4086e96f49a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.2 Linux/6.11.0-25-generic

Release files / django_payments_redsys-0.6.0-py3-none-any.whl

Download URL django_payments_redsys-0.6.0-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
602a31ee7d396db690fee8725634299cf7f0253a1e0cd7127f076d1d1235f8e8
BLAKE2b-256 checksum
How to use checksums
fe1e51922c6b652ea5ad1249051dccc1aaf83c26f4cd10ad3e9c2f4c058b19f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.2 Linux/6.11.0-25-generic

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page