Commit 09a5689c authored by bsarmiento31's avatar bsarmiento31
Browse files

Comando de iniciar chec

parent 76d8455b
using EvaPOS_API_FRAME.RespuestasXML;
using EvaPosSrvDTO;
using EvaPosSrvResp;
using GatewaySCO;
using RestSharp;
using SCOGateway.POSGk;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
namespace gatewayGK.ComandosGk
{
public class InitializeRequestCmdGk : IComando
{
public string Referencia { get; set; } = "scsns:Initialize";
/// <summary>
/// DTO con solicitud.
/// </summary>
public InitializeRequestDTO Request { get; private set; }
/// <summary>
/// Url servicio autenticación Gk.
/// </summary>
public const string UrlLogin = ConstantesGK.UrlBaseMaquetaProd + "/com.gk_software.pos.api.service.session.PosSessionService/login";
/// <summary>
/// Procesa y responde el login.
/// </summary>
///
public Respuestas Ejecutar()
{
// Crea una instancia de IConfiguration para acceder a la configuración
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
//Llamar valores del archivo de configuración
string retailStoreId = configuration["DataGK:RetailStoreId"];
string workstationId = configuration["DataGK:WorkstationId"];
string workstationAddress = configuration["DataGK:WorkstationAddress"];
string workstationTypeCode = configuration["DataGK:WorkstationTypeCode"];
string loginName = configuration["DataGK:LoginName"];
string businessUnitGroupID = configuration["DataGK:BusinessUnitGroupID"];
string tillID = configuration["DataGK:TillID"];
string password = configuration["DataGK:Password"];
string jSessionId = configuration["DataGK:SessionID"]; ;
string cookieValue = $"JSESSIONID={jSessionId}";
Respuestas respuestaChec = null;
int terminalNumber = Request.TerminalNumber;
Log.Debug("Cmd InitializeRequestCmd ejecutado - Gk pruebas. Request id: {id}, terminal: {terminal}, recovery: {recovery}", Request.OperatorID, Request.TerminalNumber, Request.Recovery);
// Contactar Smart POS Gk.
var options = new RestClientOptions(UrlLogin)
{
MaxTimeout = -1,
RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true
};
var client = new RestClient(options);
var request = new RestRequest(UrlLogin, Method.Post);
request.AddHeader("Accept", "application/json;Format=GK-PLAIN-JSON");
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Cookie", cookieValue);
var datosAutenticacion = new AutenticationReq
{
RetailStoreId = retailStoreId,
WorkstationId = workstationId,
WorkstationAddress = workstationAddress,
WorkstationTypeCode = workstationTypeCode,
LoginName = loginName,
Password = password,
TrainingMode = false,
FinalizeControlTransactionFlag = false,
UseLoginTypeTechnicalForLoginManager = false,
TillId = new Till
{
TillDoKey = new TillDoKey
{
BusinessUnitGroupID = businessUnitGroupID,
TillID = tillID
}
}
};
var loginRequestWrapper = new LoginRequestWrapper
{
LoginRequest = datosAutenticacion
};
string json = JsonSerializer.Serialize(loginRequestWrapper, new JsonSerializerOptions { WriteIndented = true });
request.AddJsonBody(json);
var response = client.Execute(request);
if (response.IsSuccessful)
{
Log.Debug($"Gk: Autenticate - POST - response {response}");
var autenticacionResp = JsonSerializer.Deserialize<AuthenticateResp>(response.Content);
var transactionId = autenticacionResp.primaryEntry.transaction.key.transactionID;
var operatorID = autenticacionResp.primaryEntry.transaction.operatorID;
Log.Debug($"Transaction ID: {transactionId}, operatorID: {operatorID} ");
// Salvar Transaccion y id de la session.
Entorno<EntornoGK>.Instancia.getDatos().TransactionID = transactionId;
Entorno<EntornoGK>.Instancia.getDatos().SeccionId = jSessionId;
// Respuestas a SCO.
var posbcStatus1 = new POSBCStatusEvent(1, TipoMensaje.Event, "INFO", "CONNECTING_TO_POS", "Connecting to POS system");
var posbcStatus2 = new POSBCStatusEvent(1, TipoMensaje.Event, "INFO", "CONNECTED_TO_POS", "Connected to POS system");
var posbcStatus3 = new POSBCStatusEvent(1, TipoMensaje.Event, "INFO", "POS_RESOURCES_INITIALIZED", "POS Resources Initialized");
var inicializacionOk = new InitializeResponse(1, TipoMensaje.Resp, terminalNumber);
respuestaChec = new Respuestas { posbcStatus1, posbcStatus2, posbcStatus3, inicializacionOk };
}
else
{
Log.Error($"Failed to connect to GK web service: {response.StatusCode}");
Log.Error(response.Content);
throw new ApplicationException("Servicio POST 'Login' en error.");
}
return respuestaChec;
}
public IComando CreaCopia()
{
return (InitializeRequestCmdGk)this.MemberwiseClone();
}
public void CargaDTO(DTOBase initializeRequestDTO)
{
Request = (InitializeRequestDTO)initializeRequestDTO;
}
}
}
using EvaPOS_API_FRAME.Comandos;
using EvaPOS_API_FRAME.DTO;
using EvaPOS_API_FRAME.RespuestasXML;
using EvaPosSrvDTO;
using EvaPosSrvResp;
using Serilog;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace gatewayGK.ComandosGk
{
/// <summary>
/// Procesa solicitudes de QueryStatusRequest.
/// </summary>
public class QueryStatusRequestCmdGk : IComando
{
public string Referencia { get; set; } = "scsns:QueryStatus";
/// <summary>
/// DTO con solicitud.
/// </summary>
public QueryStatusRequestDTO Request { get; private set; }
/// <summary>
/// Procesa y responde QueryStatusRequest.
/// </summary>
public Respuestas Ejecutar()
{
//Mirar las tildes que hay problema con el chec
var date = DateTime.Now.ToString("dd MM yyyy");
CultureInfo culture = new CultureInfo("en-US");
culture.DateTimeFormat.AMDesignator = "AM";
culture.DateTimeFormat.PMDesignator = "PM";
var time = DateTime.Now.ToString("hh:mm tt", culture);
Log.Debug("Cmd QueryStatusRequesttDTO ejecutado. QueryStatusRequest : {QueryStatusRequest}", Request.QueryStatusRequest);
var queryStatusResponse = new QueryStatusResponse(1, TipoMensaje.Resp, 2, "NOT_IN_TRANSACTION", 4, 2, 2067, "Toshiba Store Integrator Application Extension Facility version: 4.2.2067 Built: Jun 08, 2021 06:49 PM (SI.base.wyvern )", "28 de abril de 2023 05:31:35 PM COT", 2, false);
return (new Respuestas { queryStatusResponse });
}
public IComando CreaCopia()
{
return (QueryStatusRequestCmdGk)this.MemberwiseClone();
}
public void CargaDTO(DTOBase queryStatusRequestDTO)
{
Request = (QueryStatusRequestDTO)queryStatusRequestDTO;
}
}
}
using EvaPOS_API_FRAME.Comandos;
using EvaPOS_API_FRAME.DTO;
using EvaPOS_API_FRAME.RespuestasXML;
using EvaPOS_API_FRAME.RespuestasXML.Printer;
using EvaPosSrvDTO;
using EvaPosSrvResp;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace gatewayGK.ComandosGk
{
///<summary>
/// Procesa solicitudes de ReportStatusEventsRequest.
/// </summary>
public class ReportStatusEventsRequestCmdGk : IComando
{
public string Referencia { get; set; } = "scsns:ReportStatusEvents";
/// <summary>
/// DTO con solicitud.
/// </summary>
public ReportStatusEventsRequestDTO Request { get; private set; }
/// <summary>
/// Procesa y responde ReportStatusEventsRequest.
/// </summary>
public Respuestas Ejecutar()
{
Log.Debug("Cmd ReportStatusEventsRequestDTO ejecutado. ReportStatusEventsRequest : {ReportStatusEventsRequest}", Request.RequestID);
POSBCStatusEventPrinterSingle posbcStatusPrinter = null;
int requestId = Request.RequestID;
var reportStatusEventsResponse = new ReportStatusEventsResponse(1, TipoMensaje.Resp, requestId);
return (new Respuestas { reportStatusEventsResponse });
}
public IComando CreaCopia()
{
return (ReportStatusEventsRequestCmdGk)this.MemberwiseClone();
}
public void CargaDTO(DTOBase reportStatusEventsRequestDTO)
{
Request = (ReportStatusEventsRequestDTO)reportStatusEventsRequestDTO;
}
}
}
...@@ -20,7 +20,7 @@ namespace gatewayGK.ComandosGkPruebas ...@@ -20,7 +20,7 @@ namespace gatewayGK.ComandosGkPruebas
/// <summary> /// <summary>
/// Comando para agregar un cliente /// Comando para agregar un cliente
/// </summary> /// </summary>
public class AddCustomerCmdGK : IComando public class AddCustomerCmdGKTest : IComando
{ {
public string Referencia { get; set; } = "scsns:AddCustomer"; public string Referencia { get; set; } = "scsns:AddCustomer";
......
...@@ -14,7 +14,7 @@ namespace EvaPOS_API_FRAME.Comandos ...@@ -14,7 +14,7 @@ namespace EvaPOS_API_FRAME.Comandos
///<summary> ///<summary>
/// Procesa solicitudes del primer item agregado. /// Procesa solicitudes del primer item agregado.
/// </summary> /// </summary>
public class AddItemRequestCmdGk : IComando public class AddItemRequestCmdGKTest : IComando
{ {
public string Referencia { get; set; } = "scsns:AddItem"; public string Referencia { get; set; } = "scsns:AddItem";
/// <summary> /// <summary>
......
...@@ -17,7 +17,7 @@ using RestSharp; ...@@ -17,7 +17,7 @@ using RestSharp;
namespace gatewayGK.ComandosGkPruebas namespace gatewayGK.ComandosGkPruebas
{ {
public class AddTenderCmdGk : IComando public class AddTenderCmdGkTest : IComando
{ {
public string Referencia { get; set; } = "scsns:AddTender"; public string Referencia { get; set; } = "scsns:AddTender";
/// <summary> /// <summary>
......
...@@ -9,7 +9,7 @@ using GatewaySCO; ...@@ -9,7 +9,7 @@ using GatewaySCO;
namespace SCOGateway.POSGkPruebas namespace SCOGateway.POSGkPruebas
{ {
public class InitializeRequestCmd : IComando public class InitializeRequestCmdTest : IComando
{ {
public string Referencia { get; set; } = "scsns:Initialize"; public string Referencia { get; set; } = "scsns:Initialize";
/// <summary> /// <summary>
...@@ -40,8 +40,8 @@ namespace SCOGateway.POSGkPruebas ...@@ -40,8 +40,8 @@ namespace SCOGateway.POSGkPruebas
Log.Debug($"GkPruebas: Autenticate - POST - response {autenticacionResp}"); Log.Debug($"GkPruebas: Autenticate - POST - response {autenticacionResp}");
// Salvar el token de autenticación y demás datos. // Salvar el token de autenticación y demás datos.
Entorno<EntornoGK>.Instancia.getDatos().RealmId = autenticacionResp.RealmId; //Entorno<EntornoGK>.Instancia.getDatos().RealmId = autenticacionResp.RealmId;
Entorno<EntornoGK>.Instancia.getDatos().ExpirationCountDays = autenticacionResp.ExpirationCountDays; //Entorno<EntornoGK>.Instancia.getDatos().ExpirationCountDays = autenticacionResp.ExpirationCountDays;
// Respuestas a SCO. // Respuestas a SCO.
var posbcStatus1 = new POSBCStatusEvent(1, TipoMensaje.Event, "INFO", "CONNECTING_TO_POS", "Connecting to POS system"); var posbcStatus1 = new POSBCStatusEvent(1, TipoMensaje.Event, "INFO", "CONNECTING_TO_POS", "Connecting to POS system");
...@@ -53,7 +53,7 @@ namespace SCOGateway.POSGkPruebas ...@@ -53,7 +53,7 @@ namespace SCOGateway.POSGkPruebas
public IComando CreaCopia() public IComando CreaCopia()
{ {
return (InitializeRequestCmd)this.MemberwiseClone(); return (InitializeRequestCmdTest)this.MemberwiseClone();
} }
public void CargaDTO(DTOBase initializeRequestDTO) public void CargaDTO(DTOBase initializeRequestDTO)
......
...@@ -15,7 +15,7 @@ using System.Threading.Tasks; ...@@ -15,7 +15,7 @@ using System.Threading.Tasks;
namespace gatewayGK.ComandosGkPruebas namespace gatewayGK.ComandosGkPruebas
{ {
public class SubtotalCmdGK : IComando public class SubtotalCmdGKTest : IComando
{ {
public string Referencia { get; set; } = "scsns:GetTotals"; public string Referencia { get; set; } = "scsns:GetTotals";
/// <summary> /// <summary>
......
...@@ -20,7 +20,7 @@ namespace gatewayGK.ComandosGkPruebas ...@@ -20,7 +20,7 @@ namespace gatewayGK.ComandosGkPruebas
///<summary> ///<summary>
/// Comando para suspender transacción /// Comando para suspender transacción
/// </summary> /// </summary>
public class SuspendTransactionCmdGK : IComando public class SuspendTransactionCmdGKTest : IComando
{ {
public string Referencia { get; set; } = "scsns:Suspend"; public string Referencia { get; set; } = "scsns:Suspend";
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
/// </summary> /// </summary>
public sealed class Config public sealed class Config
{ {
public required string POS { get; set; } = "pruebas"; public required string POS { get; set; } = "gk";
public required string IpSCO { get; set; } = "127.0.0.1"; public required string IpSCO { get; set; } = "192.168.168.99";
public required int PortSCO { get; set; } = 6697; public required int PortSCO { get; set; } = 6697;
public required string Language { get; set; } = "en"; public required string Language { get; set; } = "en";
......
using EvaPOS_API_FRAME.Comandos;
using gatewayGK.ComandosGk;
using GatewaySCO;
using Serilog; using Serilog;
/// <summary> /// <summary>
...@@ -13,8 +16,13 @@ public class DispensaDirectorioCmdsGK : IDispensaDirectorioCmds ...@@ -13,8 +16,13 @@ public class DispensaDirectorioCmdsGK : IDispensaDirectorioCmds
public static CreaDirectorioCmds Dispensa(Config config) public static CreaDirectorioCmds Dispensa(Config config)
{ {
Log.Information("Instancia comandos de GK Smart POS."); Log.Information("Instancia comandos de GK Smart POS.");
EntornoGK e = new EntornoGK();
e.Language = config.Language;
Entorno<EntornoGK>.Instancia.setDatos(e);
return new IniciaDirectorioCmds() return new IniciaDirectorioCmds()
//.AgregaCmd(new Gk.InitializeRequestCmd()) .AgregaCmd(new InitializeRequestCmdGk())
.AgregaCmd(new QueryStatusRequestCmdGk())
.AgregaCmd(new ReportStatusEventsRequestCmdGk())
.DirectorioCmds; .DirectorioCmds;
} }
} }
\ No newline at end of file
...@@ -21,7 +21,7 @@ public class DispensaDirectorioCmdsGKPruebas : IDispensaDirectorioCmds ...@@ -21,7 +21,7 @@ public class DispensaDirectorioCmdsGKPruebas : IDispensaDirectorioCmds
Entorno<EntornoGK>.Instancia.setDatos(e); Entorno<EntornoGK>.Instancia.setDatos(e);
return new IniciaDirectorioCmds() return new IniciaDirectorioCmds()
.AgregaCmd(new Gk.InitializeRequestCmd()) .AgregaCmd(new Gk.InitializeRequestCmdTest())
.DirectorioCmds; .DirectorioCmds;
} }
} }
\ No newline at end of file
...@@ -5,11 +5,56 @@ namespace SCOGateway.POSGk ...@@ -5,11 +5,56 @@ namespace SCOGateway.POSGk
/// <summary> /// <summary>
/// Registro para solicitar autenticación a cliente Smart POS GK. /// Registro para solicitar autenticación a cliente Smart POS GK.
/// </summary> /// </summary>
record AutenticationReq public class LoginRequestWrapper
{ {
[JsonPropertyName("loginName")] public string LoginName { get; set; } = ""; [JsonPropertyName("com.gk_software.pos.api.service.session.LoginRequest")]
[JsonPropertyName("password")] public string Password { get; set; } = ""; public AutenticationReq LoginRequest { get; set; }
[JsonPropertyName("businessUnitId")] public string BusinessUnitId { get; set; } = ""; }
[JsonPropertyName("passwordRequired")] public bool PasswordRequired { get; set; } = true; public record AutenticationReq
{
[JsonPropertyName("retailStoreId")]
public string RetailStoreId { get; set; } = "";
[JsonPropertyName("workstationId")]
public string WorkstationId { get; set; } = "";
[JsonPropertyName("workstationAddress")]
public string WorkstationAddress { get; set; } = "";
[JsonPropertyName("workstationTypeCode")]
public string WorkstationTypeCode { get; set; } = "";
[JsonPropertyName("loginName")]
public string LoginName { get; set; } = "";
[JsonPropertyName("tillId")]
public Till TillId { get; set; } = new Till();
[JsonPropertyName("password")]
public string Password { get; set; } = "";
[JsonPropertyName("trainingMode")]
public bool TrainingMode { get; set; } = false;
[JsonPropertyName("finalizeControlTransactionFlag")]
public bool FinalizeControlTransactionFlag { get; set; } = false;
[JsonPropertyName("useLoginTypeTechnicalForLoginManager")]
public bool UseLoginTypeTechnicalForLoginManager { get; set; } = false;
}
public record Till
{
[JsonPropertyName("com.gk_software.pos.api.model.dom.app.services.transaction.TillDoKey")]
public TillDoKey TillDoKey { get; set; } = new TillDoKey();
}
public record TillDoKey
{
[JsonPropertyName("businessUnitGroupID")]
public string BusinessUnitGroupID { get; set; } = "";
[JsonPropertyName("tillID")]
public string TillID { get; set; } = "";
} }
} }
\ No newline at end of file
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Transactions;
namespace SCOGateway.POSGk namespace SCOGateway.POSGk
{ {
record AuthenticateResp public class AuthenticateResp
{ {
[JsonPropertyName("operatorID")] public string OperatorID { get; set; } = ""; [JsonPropertyName("primaryEntry")]
[JsonPropertyName("workerID")] public string WorkerID { get; set; } = ""; public PrimaryEntry primaryEntry { get; set; }
[JsonPropertyName("firstName")] public string FirstName { get; set; } = ""; }
[JsonPropertyName("lastName")] public string LastName { get; set; } = "";
[JsonPropertyName("languageID")] public string LanguageID { get; set; } = ""; public class PrimaryEntry
[JsonPropertyName("realmId")] public string RealmId { get; set; } = ""; {
[JsonPropertyName("expirationCountDays")] public int ExpirationCountDays { get; set; } = 0; [JsonPropertyName("transaction")]
[JsonPropertyName("passwordBeforeExpiration")] public bool PasswordBeforeExpiration { get; set; } = true; public Transaction transaction { get; set; }
}
public class Transaction
{
[JsonPropertyName("key")]
public Key key { get; set; }
[JsonPropertyName("operatorID")]
public string operatorID { get; set; }
}
public class Key
{
[JsonPropertyName("transactionID")]
public string transactionID { get; set; }
[JsonPropertyName("businessUnitGroupID")]
public string businessUnitGroupID { get; set; }
} }
} }
\ No newline at end of file
...@@ -9,5 +9,10 @@ namespace SCOGateway.POSGk ...@@ -9,5 +9,10 @@ namespace SCOGateway.POSGk
/// Url base ambiente de pruebas Gk maqueta. /// Url base ambiente de pruebas Gk maqueta.
/// </summary> /// </summary>
public const string UrlBaseMaqueta = "https://julia.redsis.com/castlemock/mock/rest/project/KdLiqe/application/l4KAuU"; public const string UrlBaseMaqueta = "https://julia.redsis.com/castlemock/mock/rest/project/KdLiqe/application/l4KAuU";
/// <summary>
/// Url base produccion de GK.
/// </summary>
public const string UrlBaseMaquetaProd = "https://10.10.117.10:8443/smartpos-service/tenants/001/services";
} }
} }
\ No newline at end of file
...@@ -15,6 +15,10 @@ public class EntornoGK ...@@ -15,6 +15,10 @@ public class EntornoGK
/// </summary> /// </summary>
public int ExpirationCountDays { get; set; } = 0; public int ExpirationCountDays { get; set; } = 0;
public string TransactionID { get; set; } = "";
public string SeccionId { get; set; } = "";
/// <summary> /// <summary>
/// GK Language. /// GK Language.
/// </summary> /// </summary>
......
{ {
"GatewayConfig": { "GatewayConfig": {
"POS": "gk_test", "POS": "gk",
"POS_comment": "Indicates the set of commands to instantiate, according to the type of POS: evapos, tests, gk, etc.", "POS_comment": "Indicates the set of commands to instantiate, according to the type of POS: evapos, tests, gk, etc.",
"IpSCO": "127.0.0.1", "IpSCO": "192.168.168.99",
"IpSCO_comment": "SCO IP, local or remote", "IpSCO_comment": "SCO IP, local or remote",
"PortSCO": 6697, "PortSCO": 6697,
"PortSCO_comment": "SCO IP Port", "PortSCO_comment": "SCO IP Port",
...@@ -26,6 +26,17 @@ ...@@ -26,6 +26,17 @@
} }
] ]
}, },
"DataGK": {
"RetailStoreId": "1000",
"workstationId": "103",
"WorkstationAddress": "001_1000_103",
"WorkstationTypeCode": "MOB",
"LoginName": "1004",
"Password": "1",
"BusinessUnitGroupID": "1000",
"TillID": "103",
"SessionID": "CF7005486990AE0AA52CA1C89308C286"
},
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Debug", "Default": "Debug",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment