Skip to content

Commit

Permalink
[FIX] payment_redsys Add timestamp in reference. Pedro Baeza recomend…
Browse files Browse the repository at this point in the history
…ations.
  • Loading branch information
sergio-teruel committed Dec 19, 2014
1 parent c1b9560 commit 5408a2a
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 14 deletions.
52 changes: 52 additions & 0 deletions payment_redsys/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Pasarela de pago Redsys
========================


Este modulo añade la opcion de pago a traves de la pasarela de Redsys



PARAMETROS:

Nombre del comercio: Indicaremos el nombre del comercio.

Número de comercio (FUC): Indicaremos el número de comercio que

nuestra entidad nos ha comunicado.

Clave secreta de encriptación: Indicaremos la clave de encriptación

que tiene el comercio.

Número de terminal: Indicaremos el terminal del TPV.

Tipo de firma: Seleccionaremos el tipo de firma del comercio.

Tipo de moneda: Seleccionaremos la moneda de nuestro terminal TPV
(Normalmente Euros).

Tipo de transacción: Indicaremos el tipo de transacción, 0.

Idiomas TPV: Indicaremos el idiomas en el TPV.

URL_OK/URL_KO: durante el proceso del pago, y una vez que
se muestra al cliente la pantalla con el resultado del mismo, es
posible redirigir su navegador a una URL para las transacciones
autorizadas y a otra si la transacción ha sido denegada. A estas
se las denomina URL_OK y URL_KO, respectivamente. Se trata
de dos URL que pueden ser proporcionadas por el comercio.



Requirements
------------

Odoo v8.0


Note
----

Se tiene que verificar la configuración del comercio en el
módulo de administración de Redsys, donde la opción “Parámetros en las
URLs” debe tener el valor “SI”.
41 changes: 40 additions & 1 deletion payment_redsys/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,46 @@
'summary': 'Payment Acquirer: Redsys Implementation',
'version': '1.0',
'description': """
This modulo add redsys payment gateway
========================
Pasarela de pago Redsys
========================
Este modulo añade la opcion de pago a traves de la pasarela de Redsys
PARAMETROS:
Nombre del comercio: Indicaremos el nombre del comercio.
Número de comercio (FUC): Indicaremos el número de comercio que
nuestra entidad nos ha comunicado.
Clave secreta de encriptación: Indicaremos la clave de encriptación
que tiene el comercio.
Número de terminal: Indicaremos el terminal del TPV.
Tipo de firma: Seleccionaremos el tipo de firma del comercio.
Tipo de moneda: Seleccionaremos la moneda de nuestro terminal TPV
(Normalmente Euros).
Tipo de transacción: Indicaremos el tipo de transacción, 0.
Idiomas TPV: Indicaremos el idiomas en el TPV.
URL_OK/URL_KO: durante el proceso del pago, y una vez que
se muestra al cliente la pantalla con el resultado del mismo, es
posible redirigir su navegador a una URL para las transacciones
autorizadas y a otra si la transacción ha sido denegada. A estas
se las denomina URL_OK y URL_KO, respectivamente. Se trata
de dos URL que pueden ser proporcionadas por el comercio.
""",
'author': 'Incaser Informatica S.L.',
'depends': ['payment'],
Expand Down
11 changes: 6 additions & 5 deletions payment_redsys/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ class RedsysController(http.Controller):
def redsys_return(self, **post):
""" Redsys."""
_logger.info('Redsys: entering form_feedback with post data %s',
pprint.pformat(post)) # debug
request.registry['payment.transaction'].form_feedback(
request.cr, SUPERUSER_ID, post, 'redsys',
context=request.context)
pprint.pformat(post))
if post:
request.registry['payment.transaction'].form_feedback(
request.cr, SUPERUSER_ID, post, 'redsys',
context=request.context)
return_url = post.pop('return_url', '')
if not return_url:
return_url = 'http://localhost:8069/page/gracias-por-su-compra'
return_url = '/shop'
return werkzeug.utils.redirect(return_url)
2 changes: 1 addition & 1 deletion payment_redsys/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

import redsys
from . import redsys
19 changes: 12 additions & 7 deletions payment_redsys/models/redsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from openerp import models, fields, api, _
from openerp.addons.payment.models.payment_acquirer import ValidationError
from openerp.tools.float_utils import float_compare

from datetime import datetime
_logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -103,6 +103,7 @@ def get_value(key):
@api.model
def redsys_form_generate_values(self, id, partner_values, tx_values):
acquirer = self.browse(id)
tx_values['reference'] += datetime.now().strftime('%M%S')
redsys_tx_values = dict(tx_values)
redsys_tx_values.update({
'Ds_Sermepa_Url':
Expand All @@ -111,17 +112,21 @@ def redsys_form_generate_values(self, id, partner_values, tx_values):
'Ds_Merchant_Amount': int(tx_values['amount'] * 100),
'Ds_Merchant_Currency': acquirer.redsys_currency or '978',
'Ds_Merchant_Order': tx_values['reference'][:12],
'Ds_Merchant_MerchantCode': acquirer.redsys_merchant_code[:9],
'Ds_Merchant_MerchantCode': acquirer.redsys_merchant_code and
acquirer.redsys_merchant_code[:9],
'Ds_Merchant_Terminal': acquirer.redsys_terminal or '1',
'Ds_Merchant_TransactionType': (
acquirer.redsys_transaction_type or '0'),
'Ds_Merchant_Titular': acquirer.redsys_merchant_titular[:60],
'Ds_Merchant_MerchantName': acquirer.redsys_merchant_name[:25],
'Ds_Merchant_Titular': acquirer.redsys_merchant_titular[:60] and
acquirer.redsys_merchant_titular[:60],
'Ds_Merchant_MerchantName': acquirer.redsys_merchant_name and
acquirer.redsys_merchant_name[:25],
'Ds_Merchant_MerchantURL':
(acquirer.redsys_merchant_url
and acquirer.redsys_merchant_url[:250] or ''),
'Ds_Merchant_MerchantData': acquirer.redsys_merchant_data or '',
'Ds_Merchant_ProductDescription': (
acquirer.redsys_merchant_description and
acquirer.redsys_merchant_description[:125]),
'Ds_Merchant_ConsumerLanguage': (
acquirer.redsys_merchant_lang or '001'),
Expand Down Expand Up @@ -153,7 +158,7 @@ class TxRedsys(models.Model):
def _redsys_form_get_tx_from_data(self, data):
""" Given a data dict coming from redsys, verify it and
find the related transaction record. """
reference = data.get('Ds_Order')
reference = data.get('Ds_Order', '')[:-4]
pay_id = data.get('Ds_AuthorisationCode')
shasign = data.get('Ds_Signature')
if not reference or not pay_id or not shasign:
Expand Down Expand Up @@ -196,8 +201,8 @@ def _redsys_form_get_invalid_parameters(self, tx, data):
# check what is buyed
if (float_compare(float(data.get('Ds_Amount', '0.0'))/100,
tx.amount, 2) != 0):
invalid_parameters.append('Amount', data.get('Ds_Amount'),
'%.2f' % tx.amount)
invalid_parameters.append(('Amount', data.get('Ds_Amount'),
'%.2f' % tx.amount))
return invalid_parameters

@api.model
Expand Down
Binary file modified payment_redsys/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified payment_redsys/static/src/img/redsys_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5408a2a

Please sign in to comment.