/// <summary>
        /// Realiza el proceso de notificación al oficial de cumplimento para un cliente en listas restrictivas
        /// </summary>
        /// <param name="request">Objeto que contiene todos los datos de autenticacion del usuario e información de la notificación</param>
        /// <returns>Respuesta de la notificación</returns>
        public NotificacionOficialCumplimientoResponse NotificacionOficialCumplimiento(NotificacionOficialCumplimientoRequest request)
        {
            string methodName = string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

            this.LogRequest(request);

            NotificacionOficialCumplimientoResponse response = new NotificacionOficialCumplimientoResponse();
            string sessionId = this.GetSessionId(request, response, out this.errorMessage);

            if (this.errorMessage != ErrorMessagesMnemonics.None)
            {
                this.LogResponse(response);
                return(response);
            }

            if (!request.IsValidRequest())
            {
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.InvalidRequiredFields);
                this.LogResponse(response);
                return(response);
            }

            DwhModel.Cliente infoCliente = this.GetInfoCliente(sessionId, request.TipoIdentificacion, request.NumeroIdentificacion.Trim(), out this.errorMessage);
            if (this.errorMessage != ErrorMessagesMnemonics.None)
            {
                this.SetResponseErrorCode(response, this.errorMessage);
                this.LogResponse(response);
                return(response);
            }

            try
            {
                string mail    = ConfigurationManager.AppSettings["MailOficialCumplimiento"].ToString();
                string subject = string.Format("Giros - {0} en Listas Restrictivas", request.TipoCliente.ToString());
                string body    = string.Concat(
                    "<div style='font-family: Tahoma, \"Arial\", Tahoma, sans-serif;'>",
                    "El usuario con Tipo Documento : ",
                    request.TipoIdentificacion.ToString(),
                    " Número: ",
                    request.NumeroIdentificacion,
                    request.TipoCliente == TipoCliente.Emisor ? " está emitiendo un giro" : " tiene giros para ser pagados",
                    " y se encontró una coincidencia en listas restrictivas (ONU, OFAC).",
                    "<br/><br/><p style='color:Gray'>PD: por favor no responda este mensaje</p></div>");

                Utils.Mailer.SendMail(mail, subject, body);
            }
            catch (Exception ex)
            {
                this.ProviderLogger.ExceptionLow(() => TagValue.New()
                                                 .MethodName(methodName)
                                                 .Message("[" + sessionId + "] " + "Error enviando correo")
                                                 .Exception(ex));
                return(response);
            }

            response.ResponseCode = 0;
            this.LogResponse(response);
            return(response);
        }
Beispiel #2
0
        /// <summary>
        /// Crea un nuevo cliente
        /// </summary>
        /// <param name="request">Objeto que contiene todos los datos de autenticacion del usuario e información del cliente</param>
        /// <returns>Respuesta de la creación</returns>
        public NuevoClienteResponse NuevoCliente(NuevoClienteRequest request)
        {
            string methodName = string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

            this.LogRequest(request);

            NuevoClienteResponse response = new NuevoClienteResponse();
            string sessionId = this.GetSessionId(request, response, out this.errorMessage);

            if (this.errorMessage != ErrorMessagesMnemonics.None)
            {
                this.LogResponse(response);
                return(response);
            }

            if (!request.IsValidRequest())
            {
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.InvalidRequiredFields);
                this.LogResponse(response);
                return(response);
            }

            DwhModel.Cliente infoCliente = this.GetInfoCliente(sessionId, request.Cliente.TipoIdentificacion, request.Cliente.NumeroIdentificacion.Trim(), out this.errorMessage);
            if ((this.errorMessage != ErrorMessagesMnemonics.None && this.errorMessage != ErrorMessagesMnemonics.UnableToFindUserInLocalDatabase) ||
                infoCliente != null)
            {
                this.errorMessage = infoCliente != null ? ErrorMessagesMnemonics.UserAlreadyExistsInLocalDatabase : this.errorMessage;
                this.SetResponseErrorCode(response, this.errorMessage);
                this.LogResponse(response);
                return(response);
            }

            int id = this.InsertNuevoCliente(sessionId, request.Cliente, out this.errorMessage);

            if (this.errorMessage != ErrorMessagesMnemonics.None || id == 0)
            {
                this.errorMessage = id == 0 ? ErrorMessagesMnemonics.InternalDatabaseErrorCreatingUser : this.errorMessage;
                this.SetResponseErrorCode(response, this.errorMessage);
                this.LogResponse(response);
                return(response);
            }

            response.ResponseCode = 0;
            response.Id           = id;
            this.LogResponse(response);
            return(response);
        }
Beispiel #3
0
        /// <summary>
        /// Actualiza un cliente
        /// </summary>
        /// <param name="request">Objeto que contiene todos los datos de autenticacion del usuario e información del cliente</param>
        /// <returns>Respuesta de la actualización</returns>
        public ActualizarClienteResponse ActualizarCliente(ActualizarClienteRequest request)
        {
            string methodName = string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

            this.LogRequest(request);

            ActualizarClienteResponse response = new ActualizarClienteResponse();
            string sessionId = this.GetSessionId(request, response, out this.errorMessage);

            if (this.errorMessage != ErrorMessagesMnemonics.None)
            {
                this.LogResponse(response);
                return(response);
            }

            if (!request.IsValidRequest())
            {
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.InvalidRequiredFields);
                this.LogResponse(response);
                return(response);
            }

            DwhModel.Cliente infoCliente = this.GetInfoCliente(sessionId, request.Cliente.TipoIdentificacion, request.Cliente.NumeroIdentificacion.Trim(), out this.errorMessage);
            if (this.errorMessage != ErrorMessagesMnemonics.None)
            {
                this.SetResponseErrorCode(response, this.errorMessage);
                this.LogResponse(response);
                return(response);
            }

            bool ok = this.ActualizarCliente(sessionId, infoCliente.Id, request.Cliente, out this.errorMessage);

            if (this.errorMessage != ErrorMessagesMnemonics.None || !ok)
            {
                this.errorMessage = !ok ? ErrorMessagesMnemonics.InternalDatabaseErrorUpdatingUser : this.errorMessage;
                this.SetResponseErrorCode(response, this.errorMessage);
                this.LogResponse(response);
                return(response);
            }

            response.ResponseCode = 0;
            this.LogResponse(response);
            return(response);
        }
Beispiel #4
0
        /// <summary>
        /// Emite un nuevo giro a partir de llamados directos a los WS de Movilway - Kinacu
        /// </summary>
        /// <param name="request">Objeto que contiene todos los datos de autenticacion del usuario e información del giro</param>
        /// <returns>Respuesta de la cotización</returns>
        public EmitirResponse Emitir(EmitirRequest request)
        {
            string methodName = string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

            this.LogRequest(request);

            EmitirResponse response  = new EmitirResponse();
            string         sessionId = this.GetSessionId(request, response, out this.errorMessage);

            if (this.errorMessage != ErrorMessagesMnemonics.None)
            {
                this.LogResponse(response);
                return(response);
            }

            if (!request.IsValidRequest())
            {
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.InvalidRequiredFields);
                this.LogResponse(response);
                return(response);
            }

            DwhModel.Cliente infoEmisor   = this.GetInfoCliente(sessionId, request.Emisor.TipoIdentificacion, request.Emisor.NumeroIdentificacion, out this.errorMessage);
            DwhModel.Cliente infoReceptor = this.GetInfoCliente(sessionId, request.Receptor.TipoIdentificacion, request.Receptor.NumeroIdentificacion, out this.errorMessage);
            DwhModel.Agencia agencia      = this.GetInfoAgencia(sessionId, request.AuthenticationData.Username);

            if (agencia == null)
            {
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.UnableToFindAgentInLocalDatabase);
                this.LogResponse(response);
                return(response);
            }

            if (infoEmisor == null || infoReceptor == null)
            {
                if (infoEmisor == null && infoReceptor == null)
                {
                    this.SetResponseErrorCode(response, ErrorMessagesMnemonics.UnableToFindIssuingAndReceiverUserInLocalDatabase);
                }
                else if (infoEmisor == null)
                {
                    this.SetResponseErrorCode(response, ErrorMessagesMnemonics.UnableToFindIssuingUserInLocalDatabase);
                }
                else
                {
                    this.SetResponseErrorCode(response, ErrorMessagesMnemonics.UnableToFindReceiverUserInLocalDatabase);
                }

                this.LogResponse(response);
                return(response);
            }

            if (infoEmisor.Id == infoReceptor.Id)
            {
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.IssuingUserAndReceiverUserAreTheSame);
                this.LogResponse(response);
                return(response);
            }

            request.CiudadPdv = agencia.Ciudad;

            int id = this.InsertGiro(sessionId, request, infoEmisor, infoReceptor, agencia, out this.errorMessage);

            if (this.errorMessage != ErrorMessagesMnemonics.None || id == 0)
            {
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.InternalDatabaseErrorInsertingOrder);
                this.LogResponse(response);
                return(response);
            }

            Exception ex = null;

            DataContract.TopUpResponseBody topup = null;

            if (this.errorMessage == ErrorMessagesMnemonics.None)
            {
                topup = this.EmitirPaso2(request, id, sessionId, out ex);
            }

            int topupResponseCode = topup != null && topup.ResponseCode.HasValue ? topup.ResponseCode.Value : -1;

            if (this.errorMessage == ErrorMessagesMnemonics.None && topupResponseCode == 0)
            {
                response.ResponseCode = 0;
                DwhModel.GiroUltimaTransaccion infoGiro = this.GetInfoGiro(sessionId, id, out this.errorMessage);

                response.Pin = Multipay472TripleDes.Decrypt(this.multipayTripleDesKey, infoGiro.Pin);
                response.CodigoTransaccion  = infoGiro.CodigoTransaccion ?? " ";
                response.NumeroFactura      = infoGiro.NumeroFactura;
                response.CodigoAutorizacion = infoGiro.CodigoAutorizacion472;
                response.Fecha           = infoGiro.Fecha.DateTime;
                response.ResponseMessage = topup.ResponseMessage;
                response.Id         = infoGiro.Id;
                response.ExternalId = infoGiro.ExternalId;

                if (this.smssEnabled)
                {
                    // Envios SMSs
                    string message = string.Format(
                        "Se emitio un giro por {0} con PIN: {1}. Servicio prestado por Movilway S.A.S",
                        this.FormatMoney(request.ValorAEntregar),
                        response.Pin);

                    SmsApi.SmsApiSoapClient smsapi = new SmsApi.SmsApiSoapClient();

                    string phonePayer = string.Concat("57", infoEmisor.Telefono.ToString());
                    string phonePayee = string.Concat("57", infoReceptor.Telefono.ToString());

                    try
                    {
                        smsapi.SendSms(new SmsApi.SendSmsRequest()
                        {
                            To = phonePayer, Message = message
                        });

                        if (phonePayer != phonePayee)
                        {
                            smsapi.SendSms(new SmsApi.SendSmsRequest()
                            {
                                To = phonePayee, Message = message
                            });
                        }
                    }
                    catch (Exception exs)
                    {
                        this.ProviderLogger.ExceptionLow(() => TagValue.New()
                                                         .MethodName(methodName)
                                                         .Message("[" + sessionId + "] " + "Error envíando SMSs")
                                                         .Exception(exs));
                    }
                }
            }
            else
            {
                string error = string.Empty;
                //if (transfer != null && transferResponseCode != 0)
                //{
                //    error = "Error en llamado a Transfer";
                //    response.ResponseCode = transfer.ResponseCode;
                //    response.ResponseMessage = transfer.ResponseMessage;
                //}
                //else
                if (topup != null && topupResponseCode != 0)
                {
                    error = "Error en llamado a TopUp";
                    response.ResponseCode    = topup.ResponseCode;
                    response.ResponseMessage = topup.ResponseMessage;
                }
                else
                {
                    error = "Error API/Otros";
                    response.ResponseCode    = (int)this.errorMessage;
                    response.ResponseMessage = string.Concat(this.errorMessage.ToDescription(), ex != null ? string.Concat(" => ", ex.Message) : string.Empty);
                }

                this.AnularGiro(sessionId, id, error, response.ResponseMessage, out this.errorMessage);

                this.LogResponse(response);
                return(response);
            }

            this.LogResponse(response);
            return(response);
        }
Beispiel #5
0
        /// <summary>
        /// Inserta en base de datos la información del giro
        /// </summary>
        /// <param name="sessionId">Session ID que será escrito en los logs</param>
        /// <param name="request">Petición original</param>
        /// <param name="emisor">Cliente emisor</param>
        /// <param name="receptor">Cliente receptor</param>
        /// <param name="agencia">Información de la agencia originadora</param>
        /// <param name="returnCode">Codigo de error en caso de que algo falle (-1 = OK, >-1 = Error)</param>
        /// <param name="connection">Objeto de conexión a base de datos</param>
        /// <returns>Un <c>int</c> que contiene el ID del cliente creado, cero en caso de falla</returns>
        private int InsertGiro(string sessionId, EmitirRequest request, DwhModel.Cliente emisor, DwhModel.Cliente receptor, DwhModel.Agencia agencia, out ErrorMessagesMnemonics returnCode, SqlConnection connection = null)
        {
            string methodName = string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

            returnCode = ErrorMessagesMnemonics.None;
            int ret = 0;

            try
            {
                this.ProviderLogger.InfoLow(() => TagValue.New()
                                            .MethodName(methodName)
                                            .Message("[" + sessionId + "] " + "Ejecutando query ..."));

                Dictionary <string, object> queryParams = new Dictionary <string, object>()
                {
                    { "@EmisorId", emisor.Id },
                    { "@ReceptorId", receptor.Id },
                    { "@EstadoId", Cash472.CashProvider.ObtenerCodigoEstadoGiro(EstadoGiro.EnProceso) },
                    { "@Pdv", request.Pdv },
                    { "@TotalRecibido", request.ValorRecibido },
                    { "@TotalAEntregar", request.ValorAEntregar },
                    { "@Flete", request.ValorFlete },
                    { "@IncluyeFlete", request.IncluyeFlete },
                    { "@CiudadOrigenDANE", request.CiudadPdv },
                    { "@CiudadDestinoDANE", request.CiudadDestino },
                    { "@AgenciaId", agencia.BranchId },
                    { "@AgenciaNombre", agencia.LegalName.Replace("'", "''") },
                    { "@AgenciaDireccion", agencia.Address.Replace("'", "''") },
                    { "@AccesoTipo", request.DeviceType },
                    { "@Acceso", request.AuthenticationData.Username }
                };

                if (connection == null)
                {
                    using (connection = Utils.Database.GetCash472DbConnection())
                    {
                        connection.Open();
                        ret = (int)Utils.Dwh <int> .ExecuteScalar(
                            connection,
                            Queries.Cash.InsertGiro,
                            queryParams,
                            null);
                    }
                }
                else
                {
                    ret = (int)Utils.Dwh <int> .ExecuteScalar(
                        connection,
                        Queries.Cash.InsertGiro,
                        queryParams,
                        null);
                }

                this.ProviderLogger.InfoLow(() => TagValue.New()
                                            .MethodName(methodName)
                                            .Message("[" + sessionId + "] " + "Query ejecutado"));
            }
            catch (Exception ex)
            {
                this.ProviderLogger.ExceptionLow(() => TagValue.New()
                                                 .MethodName(methodName)
                                                 .Message("[" + sessionId + "] " + "Error ejecutando query")
                                                 .Exception(ex));
                returnCode = ErrorMessagesMnemonics.InternalDatabaseError;
                ret        = 0;
            }

            return(ret);
        }
Beispiel #6
0
        /// <summary>
        /// Emite un nuevo giro a partir de llamados directos a los WS de MultiPay 472
        /// </summary>
        /// <param name="request">Objeto que contiene todos los datos de autenticacion del usuario e información del giro</param>
        /// <returns>Respuesta de la cotización</returns>
        public EmitirResponse Emitir472(EmitirRequest request)
        {
            string methodName = string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

            this.LogRequest(request);

            EmitirResponse response  = new EmitirResponse();
            string         sessionId = this.GetSessionId(request, response, out this.errorMessage);

            if (this.errorMessage != ErrorMessagesMnemonics.None)
            {
                return(response);
            }

            DwhModel.Cliente infoEmisor   = this.GetInfoCliente(sessionId, request.Emisor.TipoIdentificacion, request.Emisor.NumeroIdentificacion, out this.errorMessage);
            DwhModel.Cliente infoReceptor = this.GetInfoCliente(sessionId, request.Receptor.TipoIdentificacion, request.Receptor.NumeroIdentificacion, out this.errorMessage);

            if (infoEmisor == null || infoReceptor == null)
            {
                if (infoEmisor == null && infoReceptor == null)
                {
                    this.SetResponseErrorCode(response, ErrorMessagesMnemonics.UnableToFindIssuingAndReceiverUserInLocalDatabase);
                }
                else if (infoEmisor == null)
                {
                    this.SetResponseErrorCode(response, ErrorMessagesMnemonics.UnableToFindIssuingUserInLocalDatabase);
                }
                else
                {
                    this.SetResponseErrorCode(response, ErrorMessagesMnemonics.UnableToFindReceiverUserInLocalDatabase);
                }

                return(response);
            }

            if (infoEmisor.Id == infoReceptor.Id)
            {
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.IssuingUserAndReceiverUserAreTheSame);
                return(response);
            }

            Exception ex;

            MultiPay472.RespuestaValidacionConstitucionGiro constitucion = this.EmitirPaso1Cash472(request, sessionId, out ex);
            MultiPay472.RespuestaEmisionGiro emision = null;

            if (this.errorMessage == ErrorMessagesMnemonics.None)
            {
                emision = this.EmitirPaso2Cash472(request, sessionId, constitucion, out ex);
            }

            if (this.errorMessage == ErrorMessagesMnemonics.None && emision != null)
            {
                response.ResponseCode                  = 0;
                response.Pin                           = emision.PIN;
                response.CodigoTransaccion             = emision.CodigoTransaccion;
                response.CodigoTransaccionConstitucion = constitucion.CodigoTransaccion;
                response.NumeroTransaccion472          = emision.NumeroReferencia;

                response.NumeroFactura      = string.IsNullOrEmpty(emision.NumeroFactura) ? string.Empty : emision.NumeroFactura;
                response.CodigoAutorizacion = string.IsNullOrEmpty(emision.CodigoAutorizacion) ? string.Empty : emision.CodigoAutorizacion;
                response.Fecha = Cash472.CashProvider.ObtenerFechaDesdeString(emision.Fecha);

                int id = this.InsertGiroCash472(sessionId, request, infoEmisor, infoReceptor, constitucion, emision, out this.errorMessage);
                if (this.errorMessage != ErrorMessagesMnemonics.None || id == 0)
                {
                    // TODO: manejar excepción de creación del giro
                }
            }
            else
            {
                response.ResponseCode = (int)this.errorMessage;
                if (this.errorMessage == ErrorMessagesMnemonics.WebServiceException)
                {
                    response.ResponseMessage = string.Concat(this.errorMessage.ToDescription(), " => ", ex != null ? ex.Message : string.Empty);
                }
                else
                {
                    response.ResponseMessage = this.errorMessage == ErrorMessagesMnemonics.WebServiceDoesNotRespond ?
                                               this.errorMessage.ToDescription() :
                                               CashProvider.ObtenerMensajeCodigoRespuesta(constitucion.CodigoRespuesta);
                }
            }

            return(response);
        }
Beispiel #7
0
        /// <summary>
        /// Inserta en base de datos la información del giro creado
        /// </summary>
        /// <param name="sessionId">Session ID que será escrito en los logs</param>
        /// <param name="request">Petición original</param>
        /// <param name="emisor">Cliente emisor</param>
        /// <param name="receptor">Cliente receptor</param>
        /// <param name="constitucion">Respuesta WS constitución</param>
        /// <param name="emision">Respuesta WS emisión</param>
        /// <param name="returnCode">Codigo de error en caso de que algo falle (-1 = OK, >-1 = Error)</param>
        /// <param name="connection">Objeto de conexión a base de datos</param>
        /// <returns>Un <c>int</c> que contiene el ID del cliente creado, cero en caso de falla</returns>
        private int InsertGiroCash472(
            string sessionId,
            EmitirRequest request,
            DwhModel.Cliente emisor,
            DwhModel.Cliente receptor,
            MultiPay472.RespuestaValidacionConstitucionGiro constitucion,
            MultiPay472.RespuestaEmisionGiro emision,
            out ErrorMessagesMnemonics returnCode,
            SqlConnection connection = null)
        {
            string methodName = string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

            returnCode = ErrorMessagesMnemonics.None;
            int ret = 0;

            try
            {
                this.ProviderLogger.ExceptionLow(() => TagValue.New()
                                                 .MethodName(methodName)
                                                 .Message("[" + sessionId + "] " + "Ejecutando query ..."));

                Dictionary <string, object> queryParams = new Dictionary <string, object>()
                {
                    { "@EmisorId", emisor.Id },
                    { "@ReceptorId", receptor.Id },
                    { "@Pdv", request.Pdv },
                    { "@TotalRecibido", request.ValorRecibido },
                    { "@TotalAEntregar", Convert.ToInt64(constitucion.Monto) },
                    { "@Flete", Convert.ToInt64(constitucion.ValorFlete) },
                    { "@IncluyeFlete", request.IncluyeFlete },
                    { "@FechaConstitucion", Cash472.CashProvider.ObtenerFechaDesdeString(constitucion.Fecha) },
                    { "@FechaEmision", Cash472.CashProvider.ObtenerFechaDesdeString(emision.Fecha) },
                    { "@CiudadOrigen", request.CiudadPdv },
                    { "@CiudadDestino", request.CiudadDestino },
                    { "@CodigoTransaccionConstitucion", constitucion.CodigoTransaccion },
                    { "@CodigoTransaccionEmision", emision.CodigoTransaccion },
                    { "@Token", constitucion.Token },
                    { "@Pin", emision.PIN },
                    { "@CodigoAutorizacion", emision.CodigoAutorizacion },
                    { "@NumeroFactura", emision.NumeroFactura },
                    { "@NumeroTransaccion", emision.NumeroReferencia },
                    { "@ExternalId", emision.IdGiro }
                };

                if (connection == null)
                {
                    using (connection = Utils.Database.GetCash472DbConnection())
                    {
                        connection.Open();
                        ret = (int)Utils.Dwh <int> .ExecuteScalar(
                            connection,
                            Queries.Cash.InsertGiroCash472,
                            queryParams,
                            null);
                    }
                }
                else
                {
                    ret = (int)Utils.Dwh <int> .ExecuteScalar(
                        connection,
                        Queries.Cash.InsertGiroCash472,
                        queryParams,
                        null);
                }

                this.ProviderLogger.ExceptionLow(() => TagValue.New()
                                                 .MethodName(methodName)
                                                 .Message("[" + sessionId + "] " + "Query ejecutado"));
            }
            catch (Exception ex)
            {
                this.ProviderLogger.ExceptionLow(() => TagValue.New()
                                                 .MethodName(methodName)
                                                 .Message("[" + sessionId + "] " + "Error ejecutando query")
                                                 .Exception(ex));
                returnCode = ErrorMessagesMnemonics.InternalDatabaseError;
                ret        = 0;
            }

            return(ret);
        }
Beispiel #8
0
        /// <summary>
        /// Realiza el proceso de reverso de pago para un giro
        /// </summary>
        /// <param name="request">Objeto que contiene todos los datos de autenticacion del usuario e información del reverso de pago</param>
        /// <returns>Respuesta del pago</returns>
        public ReversoPagoResponse ReversoPago(ReversoPagoRequest request)
        {
            string methodName = string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

            this.LogRequest(request);

            ReversoPagoResponse response = new ReversoPagoResponse();
            string sessionId             = this.GetSessionId(request, response, out this.errorMessage);

            if (this.errorMessage != ErrorMessagesMnemonics.None)
            {
                this.LogResponse(response);
                return(response);
            }

            if (!request.IsValidRequest())
            {
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.InvalidRequiredFields);
                this.LogResponse(response);
                return(response);
            }

            DwhModel.Cliente infoCliente = this.GetInfoCliente(sessionId, request.TipoIdentificacion, request.NumeroIdentificacion, out this.errorMessage);
            if (this.errorMessage != ErrorMessagesMnemonics.None)
            {
                this.SetResponseErrorCode(response, this.errorMessage);
                this.LogResponse(response);
                return(response);
            }

            MultiPay472.Service1SoapClient client = this.GetSoapClient();
            string endpointName = "ReversoPagoGiro";

            try
            {
                MultiPay472.PagoGiro peticion = new MultiPay472.PagoGiro();
                peticion.NitRed            = this.multipayNitRed;
                peticion.CodigoTerminal    = this.multipayTerminal;
                peticion.CodigoTransaccion = this.GenerarCodigoTransaccion(sessionId);
                peticion.ConHuella         = false;

                peticion.IdGiro = request.Id;
                peticion.NumeroComprobantePago      = request.NumeroComprobantePago;
                peticion.CodigoPuntoVenta           = request.Pdv;
                peticion.CodigoDaneCiudadPuntoVenta = request.CiudadPdv;
                peticion.Valor = request.Valor;
                peticion.OIdentificacionCliente = new MultiPay472.IdentificacionCliente();
                peticion.OIdentificacionCliente.TipoIdentificacion   = Cash472.CashProvider.ObtenerCodigoTipoIdentificacion(request.TipoIdentificacion);
                peticion.OIdentificacionCliente.NumeroIdentificacion = request.NumeroIdentificacion;

                this.ProviderLogger.InfoLow(() => TagValue.New()
                                            .MethodName(methodName)
                                            .Message("[" + sessionId + "] " + "Llamando servicio \"" + endpointName + "\" ..."));

                MultiPay472.RespuestaPagoGiro resp = client.ReversoPagoGiro(peticion, this.multipayUsuario);

                this.ProviderLogger.InfoLow(() => TagValue.New()
                                            .MethodName(methodName)
                                            .Message("[" + sessionId + "] " + "Respuesta servicio \"" + endpointName + "\"")
                                            .Tag("Respuesta").Value(resp != null ? resp.CodigoRespuesta : "NULL"));

                if (resp != null && resp.CodigoRespuesta == CashProvider.CodigoRespuestaExitoso)
                {
                    response.ResponseCode          = 0;
                    response.NumeroFactura         = resp.NumeroFactura;
                    response.CodigoTransaccion     = !string.IsNullOrEmpty(resp.CodigoTransaccion) ? resp.CodigoTransaccion : string.Empty;
                    response.CodigoAutorizacion    = resp.CodigoAutorizacion;
                    response.NumeroComprobantePago = resp.NumeroComprobantePago;
                    response.NumeroReferencia      = resp.NumeroReferencia;
                    response.Valor = resp.ValorPago;
                    response.Fecha = CashProvider.ObtenerFechaDesdeString(resp.Fecha);
                }
                else
                {
                    if (resp == null)
                    {
                        this.errorMessage        = ErrorMessagesMnemonics.WebServiceDoesNotRespond;
                        response.ResponseCode    = (int)this.errorMessage;
                        response.ResponseMessage = this.errorMessage.ToDescription();
                    }
                    else
                    {
                        response.ResponseMessage = CashProvider.ObtenerMensajeCodigoRespuesta(resp.CodigoRespuesta);
                    }
                }
            }
            catch (Exception ex)
            {
                this.ProviderLogger.ExceptionLow(() => TagValue.New()
                                                 .MethodName(methodName)
                                                 .Message("[" + sessionId + "] " + "Error llamando servicio \"" + endpointName + "\"")
                                                 .Exception(ex));
            }

            this.LogResponse(response);
            return(response);
        }
Beispiel #9
0
        /// <summary>
        /// Inserta en base de datos la información de un pago
        /// </summary>
        /// <param name="sessionId">Session ID que será escrito en los logs</param>
        /// <param name="request">Petición original</param>
        /// <param name="giro">Giro original</param>
        /// <param name="cliente">Información del cliente</param>
        /// <param name="returnCode">Codigo de error en caso de que algo falle (-1 = OK, >-1 = Error)</param>
        /// <param name="connection">Objeto de conexión a base de datos</param>
        /// <returns>Un <c>int</c> que contiene el ID del pago creado, cero en caso de falla</returns>
        private int InsertPago(
            string sessionId,
            PagoRequest request,
            DwhModel.GiroUltimaTransaccion giro,
            DwhModel.Cliente cliente,
            out ErrorMessagesMnemonics returnCode,
            SqlConnection connection = null)
        {
            string methodName = string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

            returnCode = ErrorMessagesMnemonics.None;
            int ret = 0;

            try
            {
                this.ProviderLogger.InfoLow(() => TagValue.New()
                                            .MethodName(methodName)
                                            .Message("[" + sessionId + "] " + "Ejecutando query ..."));

                bool exists = giro.Id != 0;
                Dictionary <string, object> queryParams = new Dictionary <string, object>()
                {
                    { "@GiroId", giro.Id > 0   ? (object)giro.Id : DBNull.Value },
                    { "@ExternalId", request.Id },
                    { "@EmisorId", giro.EmisorId > 0 ? (object)giro.EmisorId : DBNull.Value },
                    { "@ReceptorId", cliente.Id },
                    { "@Pdv", request.Pdv },
                    { "@CiudadPdv", request.CiudadPdv },
                    { "@TotalRecibido", request.ValorRecibidoTotal },
                    { "@TotalAEntregar", request.Valor },
                    { "@Flete", request.ValorFlete },
                    { "@IncluyeFlete", request.IncluyeFlete },
                    { "@ValorPago", request.Valor }
                };

                if (connection == null)
                {
                    using (connection = Movilway.API.Utils.Database.GetCash472DbConnection())
                    {
                        connection.Open();
                        ret = (int)Movilway.API.Utils.Dwh <int> .ExecuteScalar(
                            connection,
                            Queries.Cash.InsertPago,
                            queryParams,
                            null);
                    }
                }
                else
                {
                    ret = (int)Movilway.API.Utils.Dwh <int> .ExecuteScalar(
                        connection,
                        Queries.Cash.InsertPago,
                        queryParams,
                        null);
                }

                this.ProviderLogger.InfoLow(() => TagValue.New()
                                            .MethodName(methodName)
                                            .Message("[" + sessionId + "] " + "Query ejecutado"));
            }
            catch (Exception ex)
            {
                this.ProviderLogger.ExceptionLow(() => TagValue.New()
                                                 .MethodName(methodName)
                                                 .Message("[" + sessionId + "] " + "Error ejecutando query")
                                                 .Exception(ex));
                returnCode = ErrorMessagesMnemonics.InternalDatabaseError;
                ret        = 0;
            }

            return(ret);
        }
Beispiel #10
0
        /// <summary>
        /// Realiza el proceso de pago de un giro
        /// </summary>
        /// <param name="request">Objeto que contiene todos los datos de autenticacion del usuario e información del pago</param>
        /// <returns>Respuesta del pago</returns>
        public PagoResponse Pago(PagoRequest request)
        {
            string methodName = string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

            this.LogRequest(request);

            PagoResponse response  = new PagoResponse();
            string       sessionId = this.GetSessionId(request, response, out this.errorMessage);

            if (this.errorMessage != ErrorMessagesMnemonics.None)
            {
                this.LogResponse(response);
                return(response);
            }

            if (!request.IsValidRequest())
            {
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.InvalidRequiredFields);
                this.LogResponse(response);
                return(response);
            }

            DwhModel.Cliente infoCliente = this.GetInfoCliente(sessionId, request.TipoIdentificacion, request.NumeroIdentificacion, out this.errorMessage);
            if (this.errorMessage != ErrorMessagesMnemonics.None)
            {
                this.SetResponseErrorCode(response, this.errorMessage);
                this.LogResponse(response);
                return(response);
            }

            DwhModel.Agencia agencia = this.GetInfoAgencia(sessionId, request.AuthenticationData.Username);
            if (agencia == null)
            {
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.UnableToFindAgentInLocalDatabase);
                this.LogResponse(response);
                return(response);
            }

            request.CiudadPdv = Convert.ToInt64(agencia.Ciudad);
            DwhModel.GiroUltimaTransaccion infoGiro = this.GetInfoGiroPorExternalId(sessionId, request.Id, request.Pin, out this.errorMessage);
            int id = this.InsertPago(sessionId, request, infoGiro, infoCliente, out this.errorMessage);

            if (this.errorMessage != ErrorMessagesMnemonics.None || id == 0)
            {
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.InternalDatabaseErrorInsertingPayment);
                this.LogResponse(response);
                return(response);
            }

            Exception ex    = null;
            string    error = string.Empty;

            // Quitar el valor de la Agencia que va a efectuar el pago con valor facial -1
            DataContract.TopUpResponseBody topup = this.PagoPaso1(request, id, sessionId, out ex);
            int topupResponseCode = topup != null && topup.ResponseCode.HasValue ? topup.ResponseCode.Value : -1;

            if (this.errorMessage == ErrorMessagesMnemonics.None && topupResponseCode == 0)
            {
                response.ResponseCode = 0;
                DwhModel.Pago infoPago = this.GetInfoPago(sessionId, id, out this.errorMessage);

                response.NumeroFactura         = infoPago.NumeroFactura;
                response.CodigoTransaccion     = !string.IsNullOrEmpty(infoPago.CodigoTransaccion) ? infoPago.CodigoTransaccion : string.Empty;
                response.CodigoAutorizacion    = infoPago.CodigoAutorizacion;
                response.NumeroComprobantePago = infoPago.NumeroComprobantePago;
                response.NumeroReferencia      = infoPago.NumeroReferencia;
                response.Valor = infoPago.ValorPagoRespuesta;
                response.Fecha = infoPago.FechaPago != null && infoPago.FechaPago.HasValue ? infoPago.FechaPago.Value : DateTime.MinValue;

                if (this.smssEnabled)
                {
                    // Envios SMSs
                    string message = string.Format(
                        "Se pago un giro por {0} correspondiente al PIN: {1}. Servicio prestado por Movilway S.A.S",
                        this.FormatMoney(request.Valor),
                        request.Pin);

                    SmsApi.SmsApiSoapClient smsapi = new SmsApi.SmsApiSoapClient();

                    try
                    {
                        smsapi.SendSms(new SmsApi.SendSmsRequest()
                        {
                            To = string.Concat("57", infoCliente.Telefono.ToString()), Message = message
                        });
                    }
                    catch (Exception exs)
                    {
                        this.ProviderLogger.ExceptionLow(() => TagValue.New()
                                                         .MethodName(methodName)
                                                         .Message("[" + sessionId + "] " + "Error envíando SMSs")
                                                         .Exception(exs));
                    }
                }
            }
            else
            {
                if (topup != null && topupResponseCode != 0)
                {
                    error = "Error en llamado a TopUp";
                    response.ResponseCode    = topup.ResponseCode;
                    response.ResponseMessage = topup.ResponseMessage;
                }
                else
                {
                    error = "Error en llamado a TopUp";
                    response.ResponseCode    = (int)this.errorMessage;
                    response.ResponseMessage = string.Concat(this.errorMessage.ToDescription(), ex != null ? string.Concat(" => ", ex.Message) : string.Empty);
                }
            }

            this.LogResponse(response);
            return(response);
        }
Beispiel #11
0
        /// <summary>
        /// Consulta de un cliente
        /// </summary>
        /// <param name="request">Objeto que contiene todos los datos de autenticacion del usuario e información de la consulta</param>
        /// <returns>Información del cliente en caso de que exista</returns>
        public ConsultaClienteResponse ConsultaCliente(ConsultaClienteRequest request)
        {
            string methodName = string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

            this.LogRequest(request);

            ConsultaClienteResponse response = new ConsultaClienteResponse();
            string sessionId = this.GetSessionId(request, response, out this.errorMessage);

            if (this.errorMessage != ErrorMessagesMnemonics.None)
            {
                this.LogResponse(response);
                return(response);
            }

            if (!request.IsValidRequest())
            {
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.InvalidRequiredFields);
                this.LogResponse(response);
                return(response);
            }

            // Validar en listas restrictivas
            ErrorMessagesMnemonics errorMessageRestrictiva = ErrorMessagesMnemonics.None;
            int ocurrenciaListas = this.GetInfoClienteListasRestrictivas(sessionId, request.TipoIdentificacion, request.NumeroIdentificacion, out errorMessageRestrictiva);

            // Obtener informacion del cliente en BD
            ErrorMessagesMnemonics errorMessageCliente = ErrorMessagesMnemonics.None;

            DwhModel.Cliente infoCliente = this.GetInfoCliente(sessionId, request.TipoIdentificacion, request.NumeroIdentificacion, out errorMessageCliente);

            if (errorMessageRestrictiva != ErrorMessagesMnemonics.None && errorMessageCliente == ErrorMessagesMnemonics.None)
            {
                // Cliente en listas restrictivas y enrolado
                if (request.FechaExpedicion != null && request.FechaExpedicion.HasValue)
                {
                    if (infoCliente.FechaExpedicion == null && !infoCliente.FechaExpedicion.HasValue)
                    {
                        // Cliente enrolado sin Fecha de expedicion
                        this.SetResponseErrorCode(response, ErrorMessagesMnemonics.ClientWithoutDateEspeditionLists);
                        response.Cliente = new DataContract.Cash472.Cliente();
                        this.EstablecerValoresCliente(response.Cliente, infoCliente);
                    }
                    else if (request.FechaExpedicion.Value.ToString("yyyy-MM-dd").Equals(infoCliente.FechaExpedicion.Value.ToString("yyyy-MM-dd")))
                    {
                        // Cliente enrolado con la misma fecha de expedicion
                        this.SetResponseErrorCode(response, ErrorMessagesMnemonics.ClientInRestrictiveListsAndDatabase);
                        response.Cliente = new DataContract.Cash472.Cliente();
                        this.EstablecerValoresCliente(response.Cliente, infoCliente);
                    }
                    else
                    {
                        // Cliente enrolado con otra fecha de expedicion
                        this.SetResponseErrorCode(response, ErrorMessagesMnemonics.ClientWithAnotherDateEspeditionLists);
                    }
                }
                else
                {
                    // Cliente enrolado no importa la fecha de expedicion
                    this.SetResponseErrorCode(response, ErrorMessagesMnemonics.ClientInRestrictiveListsAndDatabase);
                    response.Cliente = new DataContract.Cash472.Cliente();
                    this.EstablecerValoresCliente(response.Cliente, infoCliente);
                }
            }
            else if (errorMessageRestrictiva != ErrorMessagesMnemonics.None && errorMessageCliente != ErrorMessagesMnemonics.None)
            {
                // Cliente en listas restrictivas y no enrolado.
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.ClientInRestrictiveListsAndNotInDatabase);
            }
            else if (errorMessageRestrictiva == ErrorMessagesMnemonics.None && errorMessageCliente != ErrorMessagesMnemonics.None)
            {
                // Cliente No esta en listas restrictivas y no esta enrolado.
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.ClientNotInRestrictiveListsAndNotInDatabase);
            }
            else if (errorMessageRestrictiva == ErrorMessagesMnemonics.None && errorMessageCliente == ErrorMessagesMnemonics.None)
            {
                // Cliente No esta en listas restrictivas y enrolado.
                if (request.FechaExpedicion != null && request.FechaExpedicion.HasValue)
                {
                    if (infoCliente.FechaExpedicion == null && !infoCliente.FechaExpedicion.HasValue)
                    {
                        // Cliente enrolado con  fecha de expedicion null
                        this.SetResponseErrorCode(response, ErrorMessagesMnemonics.ClientWithoutDateEspeditionNoLists);
                        response.Cliente = new DataContract.Cash472.Cliente();
                        this.EstablecerValoresCliente(response.Cliente, infoCliente);
                    }
                    else if (request.FechaExpedicion.Value.ToString("yyyy-MM-dd").Equals(infoCliente.FechaExpedicion.Value.ToString("yyyy-MM-dd")))
                    {
                        // Cliente enrolado con la misma fecha de expedicion
                        this.SetResponseErrorCode(response, ErrorMessagesMnemonics.ClientNotInRestrictiveListsAndInDatabase);
                        response.Cliente = new DataContract.Cash472.Cliente();
                        this.EstablecerValoresCliente(response.Cliente, infoCliente);
                    }
                    else
                    {
                        // Cliente enrolado con otra fecha de expedicion
                        this.SetResponseErrorCode(response, ErrorMessagesMnemonics.ClientWithAnotherDateEspeditionNoLists);
                    }
                }
                else
                {
                    // Cliente enrolado no importa la fecha de expedicion
                    this.SetResponseErrorCode(response, ErrorMessagesMnemonics.ClientNotInRestrictiveListsAndInDatabase);
                    response.Cliente = new DataContract.Cash472.Cliente();
                    this.EstablecerValoresCliente(response.Cliente, infoCliente);
                }
            }
            else
            {
                this.SetResponseErrorCode(response, ErrorMessagesMnemonics.ClientNotInRestrictiveListsAndNotInDatabase);
            }

            this.LogResponse(response);
            return(response);
        }
Beispiel #12
0
        /// <summary>
        /// Obtiene la información de un cliente dado
        /// </summary>
        /// <param name="sessionId">Session ID que será escrito en los logs</param>
        /// <param name="tipoIdentificacion">Tipo de identificación del cliente</param>
        /// <param name="numeroIdentificacion">Número de identificación del cliente</param>
        /// <param name="returnCode">Codigo de error en caso de que algo falle (-1 = OK, >-1 = Error)</param>
        /// <param name="connection">Objeto de conexión a base de datos</param>
        /// <returns>Un objeto <c>DwhModel.Cliente</c> que contiene la información del cliente</returns>
        private DwhModel.Cliente GetInfoCliente(string sessionId, TipoIdentificacion tipoIdentificacion, string numeroIdentificacion, out ErrorMessagesMnemonics returnCode, SqlConnection connection = null)
        {
            string methodName = string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

            returnCode = ErrorMessagesMnemonics.None;
            DwhModel.Cliente ret = null;

            try
            {
                this.ProviderLogger.InfoLow(() => TagValue.New()
                                            .MethodName(methodName)
                                            .Message("[" + sessionId + "] " + "Ejecutando query ..."));

                long tipo = Cash472.CashProvider.ObtenerCodigoTipoIdentificacion(tipoIdentificacion);
                Dictionary <string, object> queryParams = new Dictionary <string, object>()
                {
                    { "@TipoIdentificacionId", tipo },
                    { "@NumeroIdentificacion", numeroIdentificacion }
                };

                if (connection == null)
                {
                    using (connection = Utils.Database.GetCash472DbConnection())
                    {
                        connection.Open();
                        ret = Utils.Dwh <DwhModel.Cliente> .ExecuteSingle(
                            connection,
                            Queries.Cash.GetInfoCliente,
                            queryParams,
                            null);
                    }
                }
                else
                {
                    ret = Utils.Dwh <DwhModel.Cliente> .ExecuteSingle(
                        connection,
                        Queries.Cash.GetInfoCliente,
                        queryParams,
                        null);
                }

                if (ret == null || ret.Id == 0)
                {
                    returnCode = ErrorMessagesMnemonics.UnableToFindUserInLocalDatabase;
                    ret        = null;
                }

                this.ProviderLogger.InfoLow(() => TagValue.New()
                                            .MethodName(methodName)
                                            .Message("[" + sessionId + "] " + "Query ejecutado"));
            }
            catch (Exception ex)
            {
                this.ProviderLogger.ExceptionLow(() => TagValue.New()
                                                 .MethodName(methodName)
                                                 .Message("[" + sessionId + "] " + "Error ejecutando query")
                                                 .Exception(ex));
                returnCode = ErrorMessagesMnemonics.InternalDatabaseError;
                ret        = null;
            }

            return(ret);
        }