Beispiel #1
0
        public BaseResponse ValidateUserCredentials(DataContracts.MobileModel.User pNewUser, bool pIsProduction = false)
        {
            var vResponse = new BaseResponse();

            vResponse.IsSuccessful = false;

            // Validacion de Credenciales
            var   vServicioBLL       = new ServicioBLL();
            Reply vTokenReplyMessage = new Reply();
            var   vUsuarioHacienda   = new UsuarioHacienda();

            vUsuarioHacienda.modalidadProduccion          = pIsProduction;
            vUsuarioHacienda.urlhaciendaAuthApiDesarrollo = BillingConstants.UrlhaciendaAuthApiDesarrollo;
            vUsuarioHacienda.urlhaciendaAuthApiProduccion = BillingConstants.UrlhaciendaAuthApiProduccion;
            vUsuarioHacienda.username = pNewUser.HaciendaUsername;
            vUsuarioHacienda.password = pNewUser.HaciendaPassword;

            vTokenReplyMessage = vServicioBLL.fGenerarToken(vUsuarioHacienda);
            if (vTokenReplyMessage != null && vTokenReplyMessage.ok &&
                vTokenReplyMessage.token != null && !string.IsNullOrEmpty(vTokenReplyMessage.token.access_token))
            {
                vTokenReplyMessage           = new Reply();
                vUsuarioHacienda.Certificado = Convert.FromBase64String(pNewUser.HaciendaCryptographicFile);
                vUsuarioHacienda.Pin         = Convert.ToString(pNewUser.HaciendaCryptographicPIN);

                vTokenReplyMessage = vServicioBLL.fValidarCertificado(vUsuarioHacienda);

                if (vTokenReplyMessage != null && vTokenReplyMessage.ok)
                {
                    vResponse.UserMessage  = "Usuario Validado con éxito";
                    vResponse.IsSuccessful = true;
                }
                else
                {
                    vResponse.UserMessage  = vTokenReplyMessage?.msg;
                    vResponse.IsSuccessful = false;
                }

                /*
                 * Dim vUsuarioHacienda As New UsuarioHacienda()
                 * Dim vReply As New Reply
                 *
                 * ' Asigna datos
                 * vUsuarioHacienda.Certificado = IO.File.ReadAllBytes(txtCertificado.Text)
                 * vUsuarioHacienda.Pin = txtCertificadoPIN.Text
                 *
                 * ' Valida PIN y Certificado
                 * vReply = vServicioBLL.fValidarCertificado(vUsuarioHacienda)
                 */
            }
            else
            {
                vResponse.UserMessage  = vTokenReplyMessage?.msg;
                vResponse.IsSuccessful = false;
            }

            /*
             * Dim vUsuarioHacienda As New UsuarioHacienda()
             *
             * ' Asigna datos
             * vUsuarioHacienda.modalidadProduccion = False
             * vUsuarioHacienda.urlhaciendaAuthApiDesarrollo = vUrlhaciendaAuthApiDesarrollo
             * vUsuarioHacienda.urlhaciendaAuthApiProduccion = vUrlhaciendaAuthApiProduccion
             * vUsuarioHacienda.username = txtUsuarioHacienda.Text
             * vUsuarioHacienda.password = txtClaveHacienda.Text
             *
             * ' Genera Token
             * vReply = vServicioBLL.fGenerarToken(vUsuarioHacienda)
             *
             * If Not vReply.token Is Nothing Then
             * MessageBox.Show("Mensaje: " & vReply.msg & Chr(13) & _
             *              "Token: " & vReply.token.access_token)
             * Else
             * MessageBox.Show("Mensaje: " & vReply.msg & Chr(13) & "Token: NULL")
             * End If
             */
            return(vResponse);
        }
Beispiel #2
0
        public static string GenerateDocumentKey(DataContracts.MobileModel.Bill pBill, DataContracts.MobileModel.User pUser, string pDocumentType)
        {
            string vCountryCode = "506";

            //Date Set
            string vDateString = DateTime.Now.ToString("ddMMyy");

            // Identification
            string vIdentification = pUser.UserLegalNumber.PadLeft(12, '0');

            // BIll ConsecutiveNumber
            // https://tribunet.hacienda.go.cr/tribunet/docs/esquemas/2016/v4.2/ResolucionComprobantesElectronicosDGT-R-48-2016_4.2.pdf
            string vConsecutiveNumber = "001" + "00001" + pDocumentType + pBill.ConsecutiveNumber.ToString().PadLeft(10, '0');

            //Situacion del Comprobante Electronico
            string vElectronicVoucher = "1";

            //Security Code
            string vSecurityCode = "1".PadLeft(8, '0');  // Es un codigo de seguridad interno


            string vResultKey = vCountryCode + vDateString + vIdentification + vConsecutiveNumber + vElectronicVoucher + vSecurityCode;

            return(vResultKey);
        }