Skip to main content

PyPI version

Welcome to python-redsys!

A simple, clean and less dependant client to handle payments through the Redsys platform using one of the available methods: redirect connection or (secure method).

The purpose of this library is to provide a normalized interface between Redsys and other Python applications.

About RedirectClient

Although redirect connection depends on a webserver to resolve the communication step, the RedirectClient provided in this library does not assume any kind of procedure to resolve that step; it merely prepares the necessary parameters to make a request and handles the corresponding response parameters. That's what less dependant means.

Example using redirect connection

0. Install python-redsys

You can add python-redsys to your project with pip:

pip install python-redsys

Or with poetry:

poetry add python-redsys

1. Instantiate the redirect client

from decimal import Decimal as D, ROUND_HALF_UP
from redsys.constants import EUR, STANDARD_PAYMENT
from redsys.client import RedirectClient

secret_key = "123456789abcdef"
client = RedirectClient(secret_key)

2. Set up the request parameters

parameters = {
  "merchant_code": "100000001",
  "terminal": "1",
  "transaction_type": STANDARD_PAYMENT,
  "currency": EUR,
  "order": "000000001",
  "amount": D("10.56489").quantize(D(".01"), ROUND_HALF_UP),
  "merchant_data": "test merchant data",
  "merchant_name": "Example Commerce",
  "titular": "Example Ltd.",
  "product_description": "Products of Example Commerce",
  "merchant_url": "https://example.com/redsys/response",
}

3. Prepare the request

This method returns a dict with the necessary post parameters that are needed during the communication step.

args = client.prepare_request(parameters)

4. Communication step

Redirect the user-agent to the corresponding Redsys' endpoint using the post parameters given in the previous step.

After the payment process is finish, Redsys will respond making a request to the merchant_url defined in step 2.

5. Create and check the response

Create the response object using the received parameters from Redsys. The method create_response() throws a ValueError in case the received signature is not equal to the calculated one using the given merchant_parameters. This normally means that the response is not coming from Redsys or that it has been compromised.

signature = "YqFenHc2HpB273l8c995...."
merchant_parameters = "AndvIh66VZdkC5TG3nYL5j4XfCnFFbo3VkOu9TAeTs58fxddgc..."
response = client.create_response(signature, merchant_parameters)
if response.is_paid():
    # Do the corresponding actions after a successful payment
else:
    # Do the corresponding actions after a failed payment
    raise Exception(response.code, response.message)

Methods for checking the response:

According to the Redsys documentation:

  • response.is_paid: Returns True if the response code is between 0 and 99 (both included).
  • response.is_canceled: Returns True if the response code is 400.
  • response.is_refunded: Returns True if the response code is 900.
  • response.is_authorized: Returns True if the response is paid, refunded or canceled.

Also, you can directly access the code or the message defined in Redsys documentation using response.code or response.message.

Contributions

Please, feel free to send any contribution that maintains the less dependant philosophy.

Metadata

Release files for python-redsys 1.0.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 python-redsys 1.0.0
File Size Uploaded
python-redsys-1.0.0.tar.gz 11.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-redsys 1.0.0
File Interpreter ABI Platform
python_redsys-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.0 kB

Release files / python-redsys-1.0.0.tar.gz

Download URL python-redsys-1.0.0.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
cc5fd4d423a0c392b5f9490b74b3db10d0440eada6e7c8d5dafdb7213b2b8089
BLAKE2b-256 checksum
How to use checksums
b74a40ba24cda9387d0c52d7e50451bf78f2688aafbdd94ce06b44aff5c6d195
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.0 Darwin/20.2.0

Release files / python_redsys-1.0.0-py3-none-any.whl

Download URL python_redsys-1.0.0-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70401805f04cdef03eedd59e4631f67c1960445cf5dad9cd7e9e03babae23106
BLAKE2b-256 checksum
How to use checksums
43958391c146299905ebfa167eb60db92cb8ccf23d3a59a7cadf883e97cd742f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.0 Darwin/20.2.0

Release history Release notifications | RSS feed

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

This release

1.0.0 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

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