Проблема с Redsys (проект MVC. net) - не показывает платежное сообщение - PullRequest
1 голос
/ 08 января 2020

У меня проблема с платежным шлюзом в проекте. Мое намерение состоит в том, чтобы интегрировать платежный шлюз из сети. Пользователь нажимает кнопку оплаты, мое приложение собирает все данные и показывает окно оплаты. Когда пользователь pu sh кнопка приложение выполняет функцию с AngularJS:

 function CreaPago() {      

        $http({
            method: 'POST',
            url: './PagoTarjeta/CrearPago',
            data: {
                valores: $scope.listadoLineasDeclaracion
            }
        }).then(function (response) {
            $scope.parametros = response.data;
        }, function (response) {
            $scope.parametros = response.data || 'Request failed';
        }).finally(function () {
            window.open($scope.parametros);
        });
    }

Однажды на сервере (PagoTarjetaController.cs) я собираю данные Мне нужно для оплаты и пересылки в Интернет в html (C#).

**[HttpPost]
        public string CrearPago(List<DeclaracionLinea> valores)
        {
            if (valores == null || valores.Count == 0) return string.Empty;
            string cadenaConexion = System.Configuration.ConfigurationManager.AppSettings["CadenaDeConexion"];

            ControladoraGuardado ctrGuarda = new ControladoraGuardado();
            HistoricoPagos hist = new HistoricoPagos();

            hist.Correcto = false;
            hist.FechaEnvio = DateTime.Now;
            hist.Id_Usuario = SoporteConversion.AEntero(System.Web.HttpContext.Current.Session["userid"].ToString());
            hist.Id_Declaracion = valores[0].Id_Declaracion;
            hist.FechaRespuesta = new DateTime(1900, 1, 1);
            hist.Respuesta = string.Empty;
            foreach (DeclaracionLinea lin in valores)
            {
                if (!lin.Pagada)
                    hist.Importe += lin.Importe;
            }

            ctrGuarda.GuardaHistoricoPagos(cadenaConexion, hist);

            return System.Configuration.ConfigurationManager.AppSettings["urlFinal"] + "/PagoTarjeta/PagoTarjeta?importe=" + hist.Importe + "&pedido=" + hist.Id + "&iddeclaracion=" + hist.Id_Declaracion;
        }**

На данный момент мы go до HTML page:

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script src="~/Scripts/Controllers/pagoTarjetaController.js"></script>

<div id="login col-12">
    <div class="container col-xs-12" ng-controller='pagoTarjetaController'>      
        <div class="row text-center">
            <img src="~/Content/images/genericas/cargando.gif" />
        </div>
        <div id="login-row" class="row justify-content-center align-items-center">
            <div id="login-column" class="col-sm-6 col-md-offset-3 col-sm-offset-3">
                <div class="login-box col-sm-12">
                    <form action="https://sis-t.redsys.es:25443/sis/realizarPago" method="post">
                    <!--<form action="https://sis.redsys.es/sis/realizarPago" method="post">-->
                        <input runat="server" type="hidden" id="Ds_SignatureVersion" name="Ds_SignatureVersion" value="@TempData["Ds_SignatureVersion"]" />
                        <input runat="server" size="100" type="hidden" id="Ds_MerchantParameters" name="Ds_MerchantParameters" value="@TempData["Ds_MerchantParameters"]" />
                        <input runat="server" type="hidden" size="50" id="Ds_Signature" name="Ds_Signature" value="@TempData["Ds_Signature"]" />
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

При выполнении загруженной страницы HTML контроллер платежа де JavaScript PagoTarjetaController. js и выполняет функцию Cargar ():

function Cargar() {
        $http({
            method: 'POST',
            url: './PagoTarjeta/Cargar',
            data: { importe: valores.importe, pedido: valores.pedido, iddeclaracion : valores.iddeclaracion }
        }).then(function (response) {
            $scope.status = response.status;
            $scope.listado = response.data;
        }, function (response) {
            $scope.listado = response.data || 'Request failed';
            $scope.status = response.status;
        }).finally(function () {
            setTimeout(document.forms[0].submit(), 2000);
        });
    }

При этом мы возвращаемся, чтобы вызвать действие «Cargar» контроллера «PagoTarjetaController.cs» (C#).

public void Cargar(string importe, string pedido, string iddeclaracion)
        {       
            string version = "HMAC_SHA256_V1";

            // New instance of RedysAPI
            RedsysAPI r = new RedsysAPI();

            //Parameters. This is an example. Use your own parameters
            var fuc = System.Configuration.ConfigurationManager.AppSettings["TPVfuc"];
            var terminal = System.Configuration.ConfigurationManager.AppSettings["TPVterminal"];
            var currency = "978";
            var trans = "0";
            //This is the url of SOAP merchant service. This is an example use your own url
            // In url is the path of InotificacionSIS.asmx
            var url = "";

            // OK url 
            var urlOK = System.Configuration.ConfigurationManager.AppSettings["urlFinal"] + "/PagoTarjeta/PagosOK?pedido=" + pedido.ToString() + "&iddeclaracion=" + iddeclaracion;
            // KO url
            var urlKO = System.Configuration.ConfigurationManager.AppSettings["urlFinal"] + "/PagoTarjeta/PagosKO?pedido=" + pedido.ToString() + "&iddeclaracion=" + iddeclaracion;
            // Generate randomly with Customer's platform
            var id = pedido;

            // Amount
            string amount = RevisarImporte(importe); // ;

            // Main Key 
            var kc = System.Configuration.ConfigurationManager.AppSettings["TPVkc"];
            // Fill Ds_MerchantParameters parameters
            r.SetParameter("DS_MERCHANT_AMOUNT", amount);
            r.SetParameter("DS_MERCHANT_ORDER", id);
            r.SetParameter("DS_MERCHANT_MERCHANTCODE", fuc);
            r.SetParameter("DS_MERCHANT_CURRENCY", currency);
            r.SetParameter("DS_MERCHANT_TRANSACTIONTYPE", trans);
            r.SetParameter("DS_MERCHANT_TERMINAL", terminal);
            r.SetParameter("DS_MERCHANT_MERCHANTURL", url);
            r.SetParameter("DS_MERCHANT_URLOK", urlOK);
            r.SetParameter("DS_MERCHANT_URLKO", urlKO);
            r.SetParameter("DS_MERCHANT_SUMTOTAL", amount);

            // Calculate Ds_SignatureVersion
            TempData["Ds_SignatureVersion"] = version;
            // Calculate Ds_MerchantParameters
            string parms = r.createMerchantParameters();
            TempData["Ds_MerchantParameters"] = parms;

            // Calculate Ds_Signature
            string sig = r.createMerchantSignature(kc);
            TempData["Ds_Signature"] = sig;
        }

Проблема в том, что, наконец, окно, которое отображается, выглядит следующим образом:

enter image description here

Я обнаружил, что если я добавлю время ожидания в 'Cargar () 'функция в PagoTarjetaController.cs, приложение работает хорошо в 90% случаев.

enter image description here

The example with time to wait is(c#):

public void Cargar(string importe, string pedido, string iddeclaracion)
        {
            System.Threading.Thread.Sleep(12000);

            string version = "HMAC_SHA256_V1";

            // New instance of RedysAPI
            RedsysAPI r = new RedsysAPI();

            //Parameters. This is an example. Use your own parameters
            // PONER EN EL WEB.CONFIG
            var fuc = System.Configuration.ConfigurationManager.AppSettings["TPVfuc"];
            var terminal = System.Configuration.ConfigurationManager.AppSettings["TPVterminal"];
            var currency = "978";
            var trans = "0";
            //This is the url of SOAP merchant service. This is an example use your own url
            // In url is the path of InotificacionSIS.asmx
            var url = "";

            // OK url 
            var urlOK = System.Configuration.ConfigurationManager.AppSettings["urlFinal"] + "/PagoTarjeta/PagosOK?pedido=" + pedido.ToString() + "&iddeclaracion=" + iddeclaracion;
            // KO url
            var urlKO = System.Configuration.ConfigurationManager.AppSettings["urlFinal"] + "/PagoTarjeta/PagosKO?pedido=" + pedido.ToString() + "&iddeclaracion=" + iddeclaracion;
            // Generate randomly with Customer's platform
            var id = pedido;

            // Amount
            System.Threading.Thread.Sleep(2000);
            string amount = RevisarImporte(importe); // importe + "00";

            // Main Key 
            var kc = System.Configuration.ConfigurationManager.AppSettings["TPVkc"];
            // Fill Ds_MerchantParameters parameters
            r.SetParameter("DS_MERCHANT_AMOUNT", amount);
            r.SetParameter("DS_MERCHANT_ORDER", id);
            r.SetParameter("DS_MERCHANT_MERCHANTCODE", fuc);
            r.SetParameter("DS_MERCHANT_CURRENCY", currency);
            r.SetParameter("DS_MERCHANT_TRANSACTIONTYPE", trans);
            r.SetParameter("DS_MERCHANT_TERMINAL", terminal);
            r.SetParameter("DS_MERCHANT_MERCHANTURL", url);
            r.SetParameter("DS_MERCHANT_URLOK", urlOK);
            r.SetParameter("DS_MERCHANT_URLKO", urlKO);
            r.SetParameter("DS_MERCHANT_SUMTOTAL", amount);

            // Calculate Ds_SignatureVersion
            TempData["Ds_SignatureVersion"] = version;
            // Calculate Ds_MerchantParameters
            string parms = r.createMerchantParameters();
            TempData["Ds_MerchantParameters"] = parms;

            // Calculate Ds_Signature
            string sig = r.createMerchantSignature(kc);
            TempData["Ds_Signature"] = sig;
        }

Мой вопрос, как сделать приложение работа с время ожидания и почему оно не работает 100% времени ..

...