Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ss759 #157

Merged
merged 5 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,66 @@ namespace ExampleSDK
}
}
```
**Ejemplo de consumo de la librería para validar el XML pero no consultar su estatus en el SAT mediante usuario y contraseña**
```cs
using System;
using System.IO;
using System.Text;
using SW.Helpers;
using SW.Services.Validate;
namespace ExampleSDK
{
class Program
{
static void Main(string[] args)
{
try
{
//Creamos una instancia de tipo Validate
//A esta le pasamos la Url, Usuario y Contraseña para obtener el token
//Automaticamente despues de obtenerlo se procedera a validar el XML
Validate validate = new Validate ("http://services.test.sw.com.mx", "user", "password");
var xml = GetXml(build);
ValidateXmlResponse response = validate.ValidateXml(xml, false);
//Para iterar la lista sobre la validacion estructura
List<Detail> detail1 = response.detail;
Console.Write("Status: "+response.status);
Console.Write("\ndetail: ");
foreach (var i in detail1)
{
foreach(var j in i.detail)
{
Console.Write("\n\tdetail: ");
Console.Write("\n\t\tMessage: "+ j.message);
Console.Write("\n\t\tMessageDetail: "+ j.messageDetail);
TextBoxOut.AppendText("\n\t\tType: "+ j.type);
}
Console.Write("\n\tSection: \n"+ i.section);
}
//Para obtener la cadena original SAT
Console.Write(response.cadenaOriginalSAT + "\n");
//Para obtener la cadena original del comprobante
Console.Write(response.cadenaOriginalComprobante + "\n");
//Para obtener el uuid
Console.Write(response.uuid + "\n");
//Para obtener el status SAT
Console.Write(response.statusSat + "\n");
//Para obtener el status code SAT
Console.Write(response.statusCodeSat + "\n");
//En caso de error se pueden consultar los siguientes campos
Console.WriteLine(response.message);
Console.WriteLine(response.messageDetail);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
```
:pushpin: ***NOTA:*** Este método permite validar la estructura del XML pero no su estatus en SAT, optimizando tiempos. En los atributos como
"statusSat" y "statusCodeSat" se obtendra un "No Aplica".
</details>

## PDF ##
Expand Down
4 changes: 2 additions & 2 deletions SW-sdk-45/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.30.1")]
[assembly: AssemblyFileVersion("0.0.30.1")]
[assembly: AssemblyVersion("0.0.31.1")]
[assembly: AssemblyFileVersion("0.0.31.1")]
16 changes: 7 additions & 9 deletions SW-sdk-45/Services/Validate/BaseValidate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Activation;
using System.Net.NetworkInformation;

namespace SW.Services.Validate
{
public abstract class BaseValidate : ValidateService
{
private string _operation;
public BaseValidate(string url, string user, string password, string operation, string proxy, int proxyPort) : base(url, user, password, proxy, proxyPort)
public BaseValidate(string url, string user, string password, string proxy, int proxyPort) : base(url, user, password, proxy, proxyPort)
{
_operation = operation;
}
public BaseValidate(string url, string token, string operation, string proxy, int proxyPort) : base(url, token, proxy, proxyPort)
public BaseValidate(string url, string token, string proxy, int proxyPort) : base(url, token, proxy, proxyPort)
{
_operation = operation;
}
public virtual ValidateXmlResponse ValidateXml(string XML)
public virtual ValidateXmlResponse ValidateXml(string XML, bool? status=true)
{
ValidateXmlResponseHandler handler = new ValidateXmlResponseHandler();
try
Expand All @@ -26,9 +25,8 @@ public virtual ValidateXmlResponse ValidateXml(string XML)
var headers = GetHeaders();
var content = GetMultipartContent(xmlBytes);
var proxy = Helpers.RequestHelper.ProxySettings(this.Proxy, this.ProxyPort);
return handler.GetPostResponse(this.Url,
string.Format("validate/cfdi33/",
_operation), headers, content, proxy);
string path = (status == false) ? "validate/cfdi?validatestatus=false" : "validate/cfdi";
return handler.GetPostResponse(this.Url,path, headers, content, proxy);
}
catch (Exception ex)
{
Expand Down
4 changes: 2 additions & 2 deletions SW-sdk-45/Services/Validate/Validate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace SW.Services.Validate
{
public class Validate : BaseValidate
{
public Validate(string url, string user, string password, int proxyPort = 0, string proxy = null) : base(url, user, password, "validate", proxy, proxyPort)
public Validate(string url, string user, string password, int proxyPort = 0, string proxy = null) : base(url, user, password, proxy, proxyPort)
{
}
public Validate(string url, string token, int proxyPort = 0, string proxy = null) : base(url, token, "validate", proxy, proxyPort)
public Validate(string url, string token, int proxyPort = 0, string proxy = null) : base(url, token, proxy, proxyPort)
{
}
}
Expand Down
4 changes: 2 additions & 2 deletions SW-sdk/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.30.1")]
[assembly: AssemblyFileVersion("0.0.30.1")]
[assembly: AssemblyVersion("0.0.31.1")]
[assembly: AssemblyFileVersion("0.0.31.1")]
11 changes: 4 additions & 7 deletions SW-sdk/Services/Validate/BaseValidate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@ namespace SW.Services.Validate
{
public abstract class BaseValidate : ValidateService
{
private string _operation;
public BaseValidate(string url, string user, string password, string operation, string proxy, int proxyPort) : base(url, user, password, proxy, proxyPort)
public BaseValidate(string url, string user, string password, string proxy, int proxyPort) : base(url, user, password, proxy, proxyPort)
{
_operation = operation;
}
public BaseValidate(string url, string token, string operation, string proxy, int proxyPort) : base(url, token, proxy, proxyPort)
public BaseValidate(string url, string token, string proxy, int proxyPort) : base(url, token, proxy, proxyPort)
{
_operation = operation;
}
public virtual ValidateXMLResponse ValidateXML(string XML)
public virtual ValidateXMLResponse ValidateXML(string XML, bool? Status = true)
{
ValidateXMLResponseHandler handler = new ValidateXMLResponseHandler();
try
{
var xmlBytes = Encoding.UTF8.GetBytes(XML);
var request = this.RequestValidateXml(xmlBytes);
var request = this.RequestValidateXml(xmlBytes,Status);
return handler.GetResponse(request);
}
catch (Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions SW-sdk/Services/Validate/Validate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace SW.Services.Validate
{
public class Validate : BaseValidate
{
public Validate(string url, string user, string password, int proxyPort = 0, string proxy=null) : base(url, user, password, "validate", proxy, proxyPort)
public Validate(string url, string user, string password, int proxyPort = 0, string proxy=null) : base(url, user, password, proxy, proxyPort)
{
}
public Validate(string url, string token, int proxyPort = 0, string proxy = null) : base(url, token, "validate", proxy, proxyPort)
public Validate(string url, string token, int proxyPort = 0, string proxy = null) : base(url, token, proxy, proxyPort)
{
}
}
Expand Down
5 changes: 3 additions & 2 deletions SW-sdk/Services/Validate/ValidateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ protected ValidateService(string url, string user, string password, string proxy
protected ValidateService(string url, string token, string proxy, int proxyPort) : base(url, token, proxy, proxyPort)
{
}
internal virtual HttpWebRequest RequestValidateXml(byte[] xml)
internal virtual HttpWebRequest RequestValidateXml(byte[] xml, bool? status = true)
{
this.SetupRequest();
var request = (HttpWebRequest)WebRequest.Create(this.Url + "/validate/cfdi33");
string path = (status == false) ? "validate/cfdi?validatestatus=false" : "validate/cfdi";
var request = (HttpWebRequest)WebRequest.Create(this.Url + path);
request.Method = WebRequestMethods.Http.Post;
request.Headers.Add(HttpRequestHeader.Authorization.ToString(), "bearer " + this.Token);
request.ContentLength = xml != null ? xml.Length : 0;
Expand Down
15 changes: 15 additions & 0 deletions Test_SW-sdk-45/Resources/cfdi40_stamp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<cfdi:Comprobante xsi:schemaLocation="http://www.sat.gob.mx/cfd/4 http://www.sat.gob.mx/sitio_internet/cfd/4/cfdv40.xsd" Version="4.0" Serie="SW" Folio="123456" Fecha="2024-04-29T00:00:00" Sello="mCvBiMAejE88ZAaOq01cdiZv+mD6lCG04keed7Gr2RJzJPdZvKJ4vQmKo7b1pHkQVJ4vSlEk/4kqp4kYfAApmVR8A4r1Oaz8MehtOni7fAKJVE1tyf02SN9Jqb/sh8UzKV491pSIKp1Dc3G1hQ3KeLxcHXy7e6Dh7GB9MJqWtZp149lG9C2FzqQrRw1kXDoCIX3WgyBu8D7ycs4JsMSmyz7d0apvOEekFbD9oM0QDyBklwFmTcYkLXMWVBNSCHXs7z/HxqhBYfxyWg+5lpVKFRPlAg3cP85Bw8y0Cv4MfJO+EKA9+iwMyowlJTkQnNDuba/BsvRT7tGoOgmeN/X5Ww==" FormaPago="01" NoCertificado="30001000000500003416" Certificado="MIIFsDCCA5igAwIBAgIUMzAwMDEwMDAwMDA1MDAwMDM0MTYwDQYJKoZIhvcNAQELBQAwggErMQ8wDQYDVQQDDAZBQyBVQVQxLjAsBgNVBAoMJVNFUlZJQ0lPIERFIEFETUlOSVNUUkFDSU9OIFRSSUJVVEFSSUExGjAYBgNVBAsMEVNBVC1JRVMgQXV0aG9yaXR5MSgwJgYJKoZIhvcNAQkBFhlvc2Nhci5tYXJ0aW5lekBzYXQuZ29iLm14MR0wGwYDVQQJDBQzcmEgY2VycmFkYSBkZSBjYWxpejEOMAwGA1UEEQwFMDYzNzAxCzAJBgNVBAYTAk1YMRkwFwYDVQQIDBBDSVVEQUQgREUgTUVYSUNPMREwDwYDVQQHDAhDT1lPQUNBTjERMA8GA1UELRMIMi41LjQuNDUxJTAjBgkqhkiG9w0BCQITFnJlc3BvbnNhYmxlOiBBQ0RNQS1TQVQwHhcNMjMwNTE4MTE0MzUxWhcNMjcwNTE4MTE0MzUxWjCB1zE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J2UA2ktDKHk+zWnsDmaeleSzonv2CHW42yXYPCvWi88oE1DJNYLNkIjua7MxAnkNZbScNw01A6zbLsZ3y8G6eEYnxSTRfwjd8EP4kdiHNJftm7Z4iRU7HOVh79/lRWB+gd171s3d/mI9kte3MRy6V8MMEMCAnMboGpaooYwgAmwclI2XZCczNWXfhaWe0ZS5PmytD/GDpXzkX0oEgY9K/uYo5V77NdZbGAjmyi8cE2B2ogvyaN2XfIInrZPgEffJ4AB7kFA2mwesdLOCh0BLD9itmCve3A1FGR4+stO2ANUoiI3w3Tv2yQSg4bjeDlJ08lXaaFCLW2peEXMXjQUk7fmpb5MNuOUTW6BE=" CondicionesDePago="CondicionesDePago" SubTotal="10.00" Descuento="0.00" Moneda="MXN" Total="10.00" TipoDeComprobante="I" Exportacion="01" MetodoPago="PUE" LugarExpedicion="45610"
xmlns:cfdi="http://www.sat.gob.mx/cfd/4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<cfdi:Emisor Rfc="EKU9003173C9" Nombre="ESCUELA KEMPER URGATE" RegimenFiscal="603" />
<cfdi:Receptor Rfc="URE180429TM6" Nombre="UNIVERSIDAD ROBOTICA ESPAÑOLA" DomicilioFiscalReceptor="86991" RegimenFiscalReceptor="601" UsoCFDI="CP01" />
<cfdi:Conceptos>
<cfdi:Concepto ClaveProdServ="50211503" NoIdentificacion="None" Cantidad="1.0" ClaveUnidad="H87" Unidad="Pieza" Descripcion="Cigarros" ValorUnitario="10.00" Importe="10.00" Descuento="0.00" ObjetoImp="01" />
</cfdi:Conceptos>
<cfdi:Complemento>
<tfd:TimbreFiscalDigital xsi:schemaLocation="http://www.sat.gob.mx/TimbreFiscalDigital http://www.sat.gob.mx/sitio_internet/cfd/TimbreFiscalDigital/TimbreFiscalDigitalv11.xsd" Version="1.1" UUID="d3db1e48-4d81-41dd-834a-f43e926626f4" FechaTimbrado="2024-04-29T11:15:58" RfcProvCertif="SPR190613I52" SelloCFD="mCvBiMAejE88ZAaOq01cdiZv+mD6lCG04keed7Gr2RJzJPdZvKJ4vQmKo7b1pHkQVJ4vSlEk/4kqp4kYfAApmVR8A4r1Oaz8MehtOni7fAKJVE1tyf02SN9Jqb/sh8UzKV491pSIKp1Dc3G1hQ3KeLxcHXy7e6Dh7GB9MJqWtZp149lG9C2FzqQrRw1kXDoCIX3WgyBu8D7ycs4JsMSmyz7d0apvOEekFbD9oM0QDyBklwFmTcYkLXMWVBNSCHXs7z/HxqhBYfxyWg+5lpVKFRPlAg3cP85Bw8y0Cv4MfJO+EKA9+iwMyowlJTkQnNDuba/BsvRT7tGoOgmeN/X5Ww==" NoCertificadoSAT="30001000000500003456" SelloSAT="cIkI880UREczt2NMAbDiUCslhJAWUvLUjJDOvSzD1Yr//igqnz9fKzM/RptByQpdxfXhS8nxeIJITCrfPalbtr2sqMfj9DhGGNwtlu2qkY0RBFxrOdjMA5uWWpwB5H5gLWjv8TOfIZxF+xknRq3qSdrpCnKFhK1SFScWIkjxcIJYIU64A8wToqZresLnh8yU0e23qUQ+/9kP/4PF5FeYB1Qf6NqBT6Yh32koDRLYXDKJmsHGYhakSWOm0WDFQ+TfnV5/Fmn34+dC/uZfmMYhR29Uc4WVhu35baQvtLRkDN9Z5GX7KoCSoq4cHDaLWbDCt8EYWUrdBPFKdQHAVcNJeA=="
xmlns:tfd="http://www.sat.gob.mx/TimbreFiscalDigital"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</cfdi:Complemento>
</cfdi:Comprobante>
36 changes: 30 additions & 6 deletions Test_SW-sdk-45/Services/Validate/Validate_UT.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Text;
using System.Collections.Generic;
using SW.Helpers;
using SW.Services.Validate;
using Test_SW.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand All @@ -19,9 +17,35 @@ public void ValidateXML_UT_Ok()
Validate validate = new Validate(build.Url, build.User, build.Password);
var xml = GetXml(build);
ValidateXmlResponse response = validate.ValidateXml(xml.ToString());
Assert.IsTrue(response.status == "success"
&& !string.IsNullOrEmpty(response.statusCodeSat), "N - 601: La expresión impresa proporcionada no es válida.");
Assert.IsTrue(response.status == "success");
Assert.IsTrue(response.statusSat == "Vigente");
Assert.IsTrue(response.statusCodeSat == "S - Comprobante obtenido satisfactoriamente");
}

[TestMethod]
public void ValidateXML_UT_Ok_With_Status()
{
var build = new BuildSettings();
Validate validate = new Validate(build.Url, build.User, build.Password);
var xml = GetXml(build);
ValidateXmlResponse response = validate.ValidateXml(xml.ToString(),true);
Assert.IsTrue(response.status == "success");
Assert.IsTrue(response.statusSat == "Vigente");
Assert.IsTrue(response.statusCodeSat == "S - Comprobante obtenido satisfactoriamente");
}

[TestMethod]
public void ValidateXML_UT_Ok_Without_Status()
{
var build = new BuildSettings();
Validate validate = new Validate(build.Url, build.User, build.Password);
var xml = GetXml(build);
ValidateXmlResponse response = validate.ValidateXml(xml.ToString(),false);
Assert.IsTrue(response.status == "success");
Assert.IsTrue(response.statusSat == "No Aplica");
Assert.IsTrue(response.statusCodeSat == "No Aplica");
}

[TestMethod]
public void Validate_Test_ValidateXMLError()
{
Expand All @@ -32,10 +56,10 @@ public void Validate_Test_ValidateXMLError()
Assert.IsTrue(response.status == "error"
&& !string.IsNullOrEmpty(response.status), "Error al leer el documento XML. La estructura del documento no es un Xml valido y/o la codificación del documento no es UTF8. Root element is missing.");
}

private object GetXml(BuildSettings build)
{
var xml = Encoding.UTF8.GetString(File.ReadAllBytes("Resources/cfdi40.xml"));
xml = SignTools.SigXml(xml, Convert.FromBase64String(build.Pfx), build.PfxPassword);
var xml = Encoding.UTF8.GetString(File.ReadAllBytes("Resources/cfdi40_stamp.xml"));
return xml;
}
}
Expand Down
3 changes: 3 additions & 0 deletions Test_SW-sdk-45/Test_SW-sdk-45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
<Content Include="Resources\CancelacionXML.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Resources\cfdi40_stamp.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Resources\cfdi40.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
Loading