22Welcome to python-redsys!
33=========================
44
5- A simple, clean and less dependant client for handle payments through RedSys platform (previously known as Sermepa)
6- using the two types of conexion defined by the platform: *direct conexion * (or webservice) and *redirect conexion *.
5+ A simple, clean and less dependant client to handle payments through RedSys platform
6+ (previously known as Sermepa) using the two types of connection defined by the platform:
7+ *direct connection * (or webservice) and *redirect connection * or (secure method).
78
8- The aim of this package is to provide a normalized interface between RedSys and other applications.
9+ The purpose of this library is just provide a normalized interface between RedSys and other applications.
910
10- Although RedSys platform's *redirect conexion * depends on a webserver to resolve the communication step,
11- the `RedirectClient ` provided in this package does not assumes any kind of procedure to resolve this
12- communication step; it merely prepares the necessary parameters for making a request and handle the
13- response parameters.
11+ **About `RedirectClient` **
12+ Although *redirect connection * depends on a webserver to resolve the communication step,
13+ the `RedirectClient ` provided in this library does not assumes any kind of procedure to resolve that
14+ step; it merely prepares the necessary parameters to make a request and handle the corresponding response parameters.
15+ That's what less dependant means.
1416
15- Example using *redirect conexion *
16- =================================
17+ If you are intend to use this library with django, take a look at <https://github.com/ddiazpinto/django-redsys>.
18+ Django-redsys uses this library and extends it to resolve all the communication step. Unfortunately it is not
19+ documented at all but if you need some help, let me know submitting an issue.
1720
18- 1. Create the client
19- --------------------
21+ Example using *redirect connection *
22+ ===================================
23+
24+ 1. Instantiate the redirect client
25+ ----------------------------------
2026.. code-block :: python
2127
2228 from decimal import Decimal as D, ROUND_HALF_UP
@@ -34,8 +40,8 @@ Example using *redirect conexion*
3440
3541 request = client.create_request()
3642
37- 3. Pass the necessary parameters to the request
38- -----------------------------------------------
43+ 3. Set up the request parameters
44+ --------------------------------
3945.. code-block :: python
4046
4147 request.merchant_code = u ' 100000001'
@@ -45,24 +51,32 @@ Example using *redirect conexion*
4551 request.order = u ' 000000001'
4652 # The amount must be defined as decimal and pre-formated with only two decimals
4753 request.amount = D(' 10.56489' ).quantize(D(' .01' ), ROUND_HALF_UP )
48- request.merchant_data = ' merchant data for tracking purpose'
54+ request.merchant_data = ' merchant data for tracking purpose like order_id, session_key, ... '
4955 request.merchant_name = " Example Commerce"
5056 request.titular = " Example Ltd."
5157 request.product_description = " Products of Example Commerce"
5258 request.merchant_url = " https://example.com/redsys/response"
5359
54- 4. Prepare de request
55- ---------------------
56- Returns a dict using the provided request, that can be directly used as post parameters .
60+ 4. Prepare the request
61+ ----------------------
62+ This method returns a dict with the necessary post parameters that are needed during the communication step .
5763
5864.. code-block :: python
5965
6066 args = client.prepare_request(request)
6167
62- 5. Create a response and check the response
63- -------------------------------------------
64- The `create_response() ` throws an `ValueError ` in case that the `signature ` does not corresponding
65- with the provided `merchant_paramenters `. This normally means that the response *is not comming from RedSys *.
68+ 5. Communication step
69+ ---------------------
70+ Redirect the *user-agent * to the corresponding RedSys's endpoint using the post parameters given in the previous step.
71+
72+ After the payment process is finish, RedSys will respond making a request to the `merchant_url ` defined in the step 3.
73+
74+ 6. Create and check the response
75+ --------------------------------
76+ Create the response object using the received parameters from RedSys. This `create_response() ` method
77+ throws a ``ValueError `` in case of the received `signature ` does not be equal to the calculated one using
78+ the given merchant_parameters. This normally means that the response **is not comming from RedSys ** or that
79+ **has been compromised **.
6680
6781.. code-block :: python
6882
@@ -71,7 +85,25 @@ with the provided `merchant_paramenters`. This normally means that the response
7185 signature_version = " HMAC_SHA256_V1"
7286 response = client.create_response(signature, merchant_parameters, signature_version)
7387 if response.is_paid():
74- # Make the corresponding actions after a successful payment
88+ # Do the corresponding actions after a successful payment
7589 else :
76- # Make the corresponding actions after a failed payment
90+ # Do the corresponding actions after a failed payment
7791 raise Exception (response.response, response.message)
92+
93+ **Methods for checking the response: **
94+ According to the RedSys documentation:
95+ - `response.is_paid() `: Returns ``True `` if the response code is between 0 and 99 (both included).
96+ - `response.is_canceled() `: Returns ``True `` if the response code is 400.
97+ - `response.is_refunded() `: Returns ``True `` if the response code is 900.
98+ - `response.is_authorized() `: Returns ``True `` if the response is **paid **, **refunded ** or **canceled **.
99+
100+ Also, you can directly access the code or the message defined in RedSys documentation using `response.response_code `
101+ or `response.response_message `.
102+
103+ Example using *direct connection * or *webservice *
104+ =================================================
105+ This connection method is not implemented yet.
106+
107+ Contributions
108+ =============
109+ Please, feel free to send any contribution that maintains the *less dependant * philosophy.
0 commit comments