<commit_before># -*- coding: utf-8 -*-
import hashlib
import hmac
import base64
import logging
import json

from openerp import models, fields, api, _
from openerp.addons.payment.models.payment_acquirer import ValidationError
from openerp.tools.float_utils import float_compare
_logger = logging.getLogger(__name__)

try:
    from Crypto.Cipher import DES3
except ImportError:
    _logger.info("Missing dependency (pycrypto). See README.")


class AcquirerRedsys(models.Model):
    _inherit = 'payment.acquirer'

    def _get_redsys_urls(self, environment):
        """ Redsys URLs
        """
        if environment == 'prod':
            return {
                'redsys_form_url':
                'https://sis.redsys.es/sis/realizarPago/',
            }
        else:
            return {
                'redsys_form_url':
                'https://sis-t.redsys.es:25443/sis/realizarPago/',
            }

    @api.model
    def _get_providers(self):
        providers = super(AcquirerRedsys, self)._get_providers()
        providers.append(['redsys', 'Redsys'])
        return providers

    redsys_merchant_url = fields.Char('Merchant URL',
                                      required_if_provider='redsys')
    redsys_merchant_name = fields.Char('Merchant Name',
                                       required_if_provider='redsys')
    redsys_merchant_titular = fields.Char('Merchant Titular',
                                          required_if_provider='redsys')
    redsys_merchant_code = fields.Char('Merchant code',
                                       required_if_provider='redsys')
    redsys_merchant_description = fields.Char('Product Description',
                                              required_if_provider='redsys')
    redsys_secret_key = fields.Char('Secret Key',
                                    required_if_provider='redsys')
    redsys_terminal = fields.Char('Terminal', default='1',
                                  required_if_provider='redsys')
    redsys_currency = fields.Char('Currency', default='978',
                                  required_if_provider='redsys')
    redsys_transaction_type = fields.Char('Transtaction Type', default='0',
                                          required_if_provider='redsys')
    redsys_merchant_data = fields.Char('Merchant Data')
    redsys_merchant_lang = fields.Selection([('001', 'Castellano'),
                                             ('002', 'Inglés'),
                                             ('003', 'Catalán'),
                                             ('004', 'Francés'),
                                             ('005', 'Alemán'),
                                             ('006', 'Holandés'),
                                             ('007', 'Italiano'),
                                             ('008', 'Sueco'),
                                             ('009', 'Portugués'),
                                             ('010', 'Valenciano'),
                                             ('011', 'Polaco'),
                                             ('012', 'Gallego'),
                                             ('013', 'Euskera'),
                                             ], 'Merchant Consumer Language',
                                            default='001')
    redsys_pay_method = fields.Selection([('T', 'Pago con Tarjeta'),
                                          ('R', 'Pago por Transferencia'),
                                          ('D', 'Domiciliacion'),
                                          ], 'Payment Method',
                                         default='T')
    redsys_signature_version = fields.Selection(
        [('HMAC_SHA256_V1', 'HMAC SHA256 V1')], default='HMAC_SHA256_V1')
    redsys_url_ok = fields.Char('URL OK')
    redsys_url_ko = fields.Char('URL KO')
    send_quotation = fields.Boolean('Send quotation', default=True)

    def _prepare_merchant_parameters(self, acquirer, tx_values):
        base_url = self.env['ir.config_parameter'].get_param('web.base.url')
        sale_order = self.env['sale.order'].search(
            [('name', '=', tx_values['reference'])])
        values = {
            'Ds_Sermepa_Url': (
                self._get_redsys_urls(acquirer.environment)[
                    'redsys_form_url']),
            'Ds_Merchant_Amount': str(int(tx_values['amount'] * 100)),
            'Ds_Merchant_Currency': acquirer.redsys_currency or '978',
            'Ds_Merchant_Order': (
                tx_values['reference'] and tx_values['reference'][-12:] or
                False),
            '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] 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 ''),<commit_msg>[IMP] payment_redsys: Default values for urk_KO and url_OK<commit_after># -*- coding: utf-8 -*-
import hashlib
import hmac
import base64
import logging
import json

from openerp import models, fields, api, _
from openerp.addons.payment.models.payment_acquirer import ValidationError
from openerp.tools.float_utils import float_compare
_logger = logging.getLogger(__name__)

try:
    from Crypto.Cipher import DES3
except ImportError:
    _logger.info("Missing dependency (pycrypto). See README.")


class AcquirerRedsys(models.Model):
    _inherit = 'payment.acquirer'

    def _get_redsys_urls(self, environment):
        """ Redsys URLs
        """
        if environment == 'prod':
            return {
                'redsys_form_url':
                'https://sis.redsys.es/sis/realizarPago/',
            }
        else:
            return {
                'redsys_form_url':
                'https://sis-t.redsys.es:25443/sis/realizarPago/',
            }

    @api.model
    def _get_providers(self):
        providers = super(AcquirerRedsys, self)._get_providers()
        providers.append(['redsys', 'Redsys'])
        return providers

    redsys_merchant_url = fields.Char('Merchant URL',
                                      required_if_provider='redsys')
    redsys_merchant_name = fields.Char('Merchant Name',
                                       required_if_provider='redsys')
    redsys_merchant_titular = fields.Char('Merchant Titular',
                                          required_if_provider='redsys')
    redsys_merchant_code = fields.Char('Merchant code',
                                       required_if_provider='redsys')
    redsys_merchant_description = fields.Char('Product Description',
                                              required_if_provider='redsys')
    redsys_secret_key = fields.Char('Secret Key',
                                    required_if_provider='redsys')
    redsys_terminal = fields.Char('Terminal', default='1',
                                  required_if_provider='redsys')
    redsys_currency = fields.Char('Currency', default='978',
                                  required_if_provider='redsys')
    redsys_transaction_type = fields.Char('Transtaction Type', default='0',
                                          required_if_provider='redsys')
    redsys_merchant_data = fields.Char('Merchant Data')
    redsys_merchant_lang = fields.Selection([('001', 'Castellano'),
                                             ('002', 'Inglés'),
                                             ('003', 'Catalán'),
                                             ('004', 'Francés'),
                                             ('005', 'Alemán'),
                                             ('006', 'Holandés'),
                                             ('007', 'Italiano'),
                                             ('008', 'Sueco'),
                                             ('009', 'Portugués'),
                                             ('010', 'Valenciano'),
                                             ('011', 'Polaco'),
                                             ('012', 'Gallego'),
                                             ('013', 'Euskera'),
                                             ], 'Merchant Consumer Language',
                                            default='001')
    redsys_pay_method = fields.Selection([('T', 'Pago con Tarjeta'),
                                          ('R', 'Pago por Transferencia'),
                                          ('D', 'Domiciliacion'),
                                          ], 'Payment Method',
                                         default='T')
    redsys_signature_version = fields.Selection(
        [('HMAC_SHA256_V1', 'HMAC SHA256 V1')], default='HMAC_SHA256_V1')
    redsys_url_ok = fields.Char('URL OK', default='redsys_result_ok')
    redsys_url_ko = fields.Char('URL KO', default='redsys_result_ko')
    send_quotation = fields.Boolean('Send quotation', default=True)

    def _prepare_merchant_parameters(self, acquirer, tx_values):
        base_url = self.env['ir.config_parameter'].get_param('web.base.url')
        sale_order = self.env['sale.order'].search(
            [('name', '=', tx_values['reference'])])
        values = {
            'Ds_Sermepa_Url': (
                self._get_redsys_urls(acquirer.environment)[
                    'redsys_form_url']),
            'Ds_Merchant_Amount': str(int(tx_values['amount'] * 100)),
            'Ds_Merchant_Currency': acquirer.redsys_currency or '978',
            'Ds_Merchant_Order': (
                tx_values['reference'] and tx_values['reference'][-12:] or
                False),
            '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] 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 ''),
{'fraction_non_alphanumeric': 0.10807062956457428, 'fraction_numerical': 0.01627068503281871, 'mean_word_length': 1.5311183902667291, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 96, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6791992', 'n_tokens_mistral': 2918, 'n_tokens_neox': 2717, 'n_words': 457}