Exemple #1
0
        /// <summary>
        /// Obtiene la información de un pago dado
        /// </summary>
        /// <param name="sessionId">Session ID que será escrito en los logs</param>
        /// <param name="id">ID pago</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.Pago</c> que contiene la información del giro</returns>
        private DwhModel.Pago GetInfoPago(
            string sessionId,
            int id,
            out ErrorMessagesMnemonics returnCode,
            SqlConnection connection = null)
        {
            string methodName = string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

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

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

                Dictionary <string, object> queryParams = new Dictionary <string, object>()
                {
                    { "@IdPago", id > 0  ? (object)id : DBNull.Value }
                };

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

            return(ret);
        }
Exemple #2
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);
        }