# Path: payment_todopago/todopago/todopagoconnector.py
# def deprecated(func):
#     def newFunc(*args, **kwargs):
#     def __init__(self, http_header, *mode):
#     def sendAuthorize(self, options_comercio, options_operacion):
#     def sendAuthorizeRequest(self, options_comercio, options_operacion):
#     def getAuthorize(self, optionsAnwser):
#     def getAuthorizeAnswer(self, optionsAnwser):
#     def returnRequest(self, optionsReturn):
#     def voidRequest(self, optionsVoid):
#     def getAllPaymentMethods(self, optionsGAPM):
#     def discoverPaymentMethods(self):
#     def getByOperationId(self, optionsGBOI):
#     def getStatus(self, optionsGS):
#     def getByRangeDateTime(self, optionsGBRDT):
#     def getCredentials(self, user):
#     def _sendAuthorizeRequest(self, options_comercio, options_operacion):
#     def _getAuthorizeAnswer(self, optionsAnwser):
#     def _parse_gaa(self, obj):
#     def _get_wsdl_url(self, filename):
#     def _parse_to_service(self, data, servicio):
#     def _getClientSoap(self, operacion):
#     def _client_soap_header(self, data):
#     def _get_payload(self, diccionario):
#     def _sort_rest_params(self, data, keys_order):
#     def _parse_rest_params(self, params):
#     def _parse_rest_response(self, response):
#     def _do_rest(self, service, params, keys_order):
# class TodoPagoConnector:
# 
# Path: payment_todopago/controllers/main.py
# class TodoPagoController(http.Controller):
#     _success_url = '/payment/todopago/success'
#     _failure_url = '/payment/todopago/failure'
#     _create_preference_url = '/payment/todopago/create_preference'
# 
#     @http.route([
#         '/payment/todopago/create_preference',
#     ],
#         type='http', auth="none", csrf=False)
#     def todopago_create_preference(self, **post):
#         _logger.info(
#             'todopago: create preference with post data %s',
#             pprint.pformat(post))
#         # TODO podriamos pasar cada elemento por separado para no necesitar
#         # el safe_eval
#         todopago_data = safe_eval(post.get('todopago_data', {}))
#         if not todopago_data:
#             return werkzeug.utils.redirect("/")
#         acquirer_id = todopago_data.get('acquirer_id')
#         request_url = request.env['payment.acquirer'].sudo().browse(
#             acquirer_id)._todopago_create_transaction(post)
#         return werkzeug.utils.redirect(request_url)
# 
#     def todopago_validate(self, **post):
#         "Validate mercado pago payment from a return URL or IPN"
#         _logger.info(
#             'Validating todopago payment with post data %s',
#             pprint.pformat(post))
#         request.env['payment.transaction'].sudo().form_feedback(
#             post, 'todopago')
#         return None
# 
#     @http.route([
#         '/payment/todopago/failure',
#         '/payment/todopago/success',
#     ],
#         type='http', auth="public", csrf=False)
#     def todopago_back_with_return(self, **post):
#         _logger.info(
#             'todopago: returning data %s',
#             pprint.pformat(post))
#         self.todopago_validate(**post)
#         return werkzeug.utils.redirect("/payment/process")


import logging
import string
from urllib.parse import urljoin
from werkzeug import urls
from email.utils import parseaddr
from odoo import fields, models, _
from odoo.http import request
from odoo.tools.safe_eval import safe_eval
from odoo.addons.payment.models.payment_acquirer import ValidationError
from ..todopago import todopagoconnector as tp
from ..controllers.main import TodoPagoController
            "Security": str(todopago_secret_key),
            "EncodingMethod": "XML",
            "URL_OK": str(URL_OK),
            "URL_ERROR": str(URL_ERROR),
            # "EMAILCLIENTE": email,
            "Merchant":  str(todopago_client_id),
        }

        tx_values.update({
            'todopago_data': {
                'optionsSAR_operacion': optionsSAR_operacion,
                'optionsSAR_comercio': optionsSAR_comercio,
                'todopago_client_id': todopago_client_id,
                'todopago_secret_key': todopago_secret_key,
                # 'environment': self.environment,
                'acquirer_id': self.id,
                'partner_id': commercial_partner.id,
                'amount': tx_values['amount'],
                'currency_id': tx_values['currency'].id,
                'return_url': tx_values['return_url'],
            }
        })
        return tx_values

    def todopago_get_form_action_url(self):
        """
        Este metodo se llama cada vez que se ve el boton asi que no
        lo podemos usar para mucho
        """
        self.ensure_one()

# Path: payment_todopago/todopago/todopagoconnector.py
# def deprecated(func):
#     def newFunc(*args, **kwargs):
#     def __init__(self, http_header, *mode):
#     def sendAuthorize(self, options_comercio, options_operacion):
#     def sendAuthorizeRequest(self, options_comercio, options_operacion):
#     def getAuthorize(self, optionsAnwser):
#     def getAuthorizeAnswer(self, optionsAnwser):
#     def returnRequest(self, optionsReturn):
#     def voidRequest(self, optionsVoid):
#     def getAllPaymentMethods(self, optionsGAPM):
#     def discoverPaymentMethods(self):
#     def getByOperationId(self, optionsGBOI):
#     def getStatus(self, optionsGS):
#     def getByRangeDateTime(self, optionsGBRDT):
#     def getCredentials(self, user):
#     def _sendAuthorizeRequest(self, options_comercio, options_operacion):
#     def _getAuthorizeAnswer(self, optionsAnwser):
#     def _parse_gaa(self, obj):
#     def _get_wsdl_url(self, filename):
#     def _parse_to_service(self, data, servicio):
#     def _getClientSoap(self, operacion):
#     def _client_soap_header(self, data):
#     def _get_payload(self, diccionario):
#     def _sort_rest_params(self, data, keys_order):
#     def _parse_rest_params(self, params):
#     def _parse_rest_response(self, response):
#     def _do_rest(self, service, params, keys_order):
# class TodoPagoConnector:
# 
# Path: payment_todopago/controllers/main.py
# class TodoPagoController(http.Controller):
#     _success_url = '/payment/todopago/success'
#     _failure_url = '/payment/todopago/failure'
#     _create_preference_url = '/payment/todopago/create_preference'
# 
#     @http.route([
#         '/payment/todopago/create_preference',
#     ],
#         type='http', auth="none", csrf=False)
#     def todopago_create_preference(self, **post):
#         _logger.info(
#             'todopago: create preference with post data %s',
#             pprint.pformat(post))
#         # TODO podriamos pasar cada elemento por separado para no necesitar
#         # el safe_eval
#         todopago_data = safe_eval(post.get('todopago_data', {}))
#         if not todopago_data:
#             return werkzeug.utils.redirect("/")
#         acquirer_id = todopago_data.get('acquirer_id')
#         request_url = request.env['payment.acquirer'].sudo().browse(
#             acquirer_id)._todopago_create_transaction(post)
#         return werkzeug.utils.redirect(request_url)
# 
#     def todopago_validate(self, **post):
#         "Validate mercado pago payment from a return URL or IPN"
#         _logger.info(
#             'Validating todopago payment with post data %s',
#             pprint.pformat(post))
#         request.env['payment.transaction'].sudo().form_feedback(
#             post, 'todopago')
#         return None
# 
#     @http.route([
#         '/payment/todopago/failure',
#         '/payment/todopago/success',
#     ],
#         type='http', auth="public", csrf=False)
#     def todopago_back_with_return(self, **post):
#         _logger.info(
#             'todopago: returning data %s',
#             pprint.pformat(post))
#         self.todopago_validate(**post)
#         return werkzeug.utils.redirect("/payment/process")


# Path: payment_todopago/models/payment_acquirer.py
import logging
import string
from urllib.parse import urljoin
from werkzeug import urls
from email.utils import parseaddr
from odoo import fields, models, _
from odoo.http import request
from odoo.tools.safe_eval import safe_eval
from odoo.addons.payment.models.payment_acquirer import ValidationError
from ..todopago import todopagoconnector as tp
from ..controllers.main import TodoPagoController

            "Security": str(todopago_secret_key),
            "EncodingMethod": "XML",
            "URL_OK": str(URL_OK),
            "URL_ERROR": str(URL_ERROR),
            # "EMAILCLIENTE": email,
            "Merchant":  str(todopago_client_id),
        }

        tx_values.update({
            'todopago_data': {
                'optionsSAR_operacion': optionsSAR_operacion,
                'optionsSAR_comercio': optionsSAR_comercio,
                'todopago_client_id': todopago_client_id,
                'todopago_secret_key': todopago_secret_key,
                # 'environment': self.environment,
                'acquirer_id': self.id,
                'partner_id': commercial_partner.id,
                'amount': tx_values['amount'],
                'currency_id': tx_values['currency'].id,
                'return_url': tx_values['return_url'],
            }
        })
        return tx_values

    def todopago_get_form_action_url(self):
        """
        Este metodo se llama cada vez que se ve el boton asi que no
        lo podemos usar para mucho
        """
        self.ensure_one()

        return TodoPagoController._create_preference_url