Ejemplo n.º 1
0
        /// <summary>
        /// Obtiene la información de un giro dado a partir de su ExternalId (ID Multipay 472)
        /// </summary>
        /// <param name="sessionId">Session ID que será escrito en los logs</param>
        /// <param name="id">ID Multipay 472 del giro</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.Giro</c> que contiene la información del giro</returns>
        private DwhModel.GiroUltimaTransaccion GetInfoGiroPorExternalId(
            string sessionId,
            long id,
            string pin,
            out ErrorMessagesMnemonics returnCode,
            SqlConnection connection = null)
        {
            string methodName = string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

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

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

                Dictionary <string, object> queryParams = new Dictionary <string, object>()
                {
                    { "@IdGiro", id.ToString() }
                };

                if (connection == null)
                {
                    using (connection = Movilway.API.Utils.Database.GetCash472DbConnection())
                    {
                        connection.Open();
                        ret = Movilway.API.Utils.Dwh <DwhModel.GiroUltimaTransaccion> .ExecuteSingle(
                            connection,
                            Queries.Cash.GetInfoGiroPorExternalId,
                            queryParams,
                            null);
                    }
                }
                else
                {
                    ret = Movilway.API.Utils.Dwh <DwhModel.GiroUltimaTransaccion> .ExecuteSingle(
                        connection,
                        Queries.Cash.GetInfoGiroPorExternalId,
                        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        = new DwhModel.GiroUltimaTransaccion();
            }

            return(ret);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }