Beispiel #1
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 #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);
        }