コード例 #1
0
        public void HasherCryptoService_GetStringHash_ShouldHash()
        {
            HasherCryptoService <MD5Cng> hashingService = new HasherCryptoService <MD5Cng>();

            string hashing = hashingService.GetStringHash("4Vj8eK4rloUd272L48hsrarnUA~508029~TestPayU~3~USD");

            Assert.IsNotNull(hashing);
            Assert.AreEqual(hashing, "ba9ffa71559580175585e45ce70b6c37");
        }
コード例 #2
0
        public async Task <PayUModel> ConfigurarPayU(HistorialPagosPersonas pagoParaProcesar)
        {
            using (SportsGoEntities context = new SportsGoEntities(false))
            {
                PagosRepository pagosRepo = new PagosRepository(context);

                HistorialPagosPersonasDTO pagoBuscado = await pagosRepo.BuscarHistorialPagoPersona(pagoParaProcesar);

                if (pagoBuscado.EstadoDelPago != EstadoDeLosPagos.EsperaPago && pagoBuscado.EstadoDelPago != EstadoDeLosPagos.Rechazado)
                {
                    throw new InvalidOperationException("El pago no se puede procesar porque no esta en un estado valido");
                }

                string descripcion = string.Empty;
                switch (pagoBuscado.Personas.IdiomaDeLaPersona)
                {
                case Idioma.Español:
                    descripcion = "PayU Pago para el plan " + pagoBuscado.Planes.DescripcionIdiomaBuscado;
                    break;

                case Idioma.Ingles:
                    descripcion = "PayU Payment for plan " + pagoBuscado.Planes.DescripcionIdiomaBuscado;
                    break;

                case Idioma.Portugues:
                    descripcion = "PayU Plano de pagamento " + pagoBuscado.Planes.DescripcionIdiomaBuscado;
                    break;
                }

                HasherCryptoService <MD5Cng> hashingService = new HasherCryptoService <MD5Cng>();
                string signatureBuilder = AppConstants.PayUApiKey + "~" + AppConstants.PayUMerchantID + "~" + pagoBuscado.Consecutivo + "~" + Math.Round(pagoBuscado.Precio, 2, MidpointRounding.AwayFromZero).ToString().Replace(",", ".") + "~COP";

                PayUModel payUModel = new PayUModel
                {
                    merchantId    = AppConstants.PayUMerchantID,
                    accountId     = AppConstants.PayUAccountID,
                    tax           = 0,
                    taxReturnBase = 0,
                    test          = AppConstants.PayUTest,
                    Url           = AppConstants.PayUURL,
                    currency      = "COP",
                    amount        = pagoBuscado.Precio,
                    referenceCode = pagoBuscado.Consecutivo.ToString(),
                    buyerEmail    = pagoBuscado.Personas.Usuarios.Email,
                    description   = descripcion,
                    signature     = hashingService.GetStringHash(signatureBuilder)
                };

                return(payUModel);
            }
        }