-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Se agregó el servicio Taxpayer (validar RFC en lista 69-b definitivos)
- Loading branch information
1 parent
8695fb1
commit dce89b8
Showing
6 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package Services.Taxpayer; | ||
|
||
import java.io.IOException; | ||
|
||
import Exceptions.AuthException; | ||
import Exceptions.GeneralException; | ||
import Services.SWService; | ||
import Utils.Requests.Cancelation.CancelationOptionsRequest; | ||
import Utils.Requests.Cancelation.CancelationRequest; | ||
import Utils.Requests.Taxpayer.TaxpayerOptionsRequest; | ||
import Utils.Requests.Taxpayer.TaxpayerRequest; | ||
import Utils.Responses.IResponse; | ||
|
||
public class SWTaxpayerService extends SWService{ | ||
public SWTaxpayerService(String user, String password, String URI) throws AuthException { | ||
super(user, password, URI); | ||
} | ||
|
||
public SWTaxpayerService(String token, String URI) { | ||
super(token, URI); | ||
} | ||
|
||
public SWTaxpayerService(String user, String password, String URI, String proxyHost, int proxyPort) throws AuthException { | ||
super(user, password, URI, proxyHost, proxyPort); | ||
} | ||
|
||
public SWTaxpayerService(String token, String URI, String proxyHost, int proxyPort) { | ||
super(token, URI, proxyHost, proxyPort); | ||
} | ||
public IResponse Taxpayer(String rfc) throws AuthException, GeneralException, IOException { | ||
TaxpayerOptionsRequest settings = new TaxpayerOptionsRequest(getToken(), getURI(), rfc, getProxyHost(), getProxyPort()); | ||
TaxpayerRequest req = new TaxpayerRequest(); | ||
return req.sendRequestrfc(settings); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/Utils/Requests/Taxpayer/TaxpayerOptionsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package Utils.Requests.Taxpayer; | ||
|
||
import Utils.Constants; | ||
import Utils.Requests.IRequest; | ||
|
||
public class TaxpayerOptionsRequest extends IRequest { | ||
public TaxpayerOptionsRequest(String token, String URI,String rfc, String proxyHost, int proxyPort) { | ||
super(token, URI + Constants.TAXPAYERS_PATH + rfc, proxyHost, proxyPort); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/Utils/Requests/Taxpayer/TaxpayerRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package Utils.Requests.Taxpayer; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.http.HttpEntity; | ||
import org.apache.http.client.ClientProtocolException; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.message.BasicHeader; | ||
import org.apache.http.util.EntityUtils; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import Exceptions.GeneralException; | ||
import Utils.Helpers.RequestHelper; | ||
import Utils.Requests.IRequest; | ||
import Utils.Requests.Cancelation.CancelationOptionsRequest; | ||
import Utils.Responses.IResponse; | ||
import Utils.Responses.Cancelation.CancelationResponse; | ||
import Utils.Responses.Taxplayer.TaxplayerResponse; | ||
import Utils.Requests.Taxpayer.TaxpayerOptionsRequest; | ||
|
||
public class TaxpayerRequest { | ||
|
||
public IResponse sendRequestrfc(IRequest request) throws ClientProtocolException, IOException, GeneralException { | ||
try { | ||
CloseableHttpClient client = HttpClients.createDefault(); | ||
HttpGet httpget = new HttpGet(request.URI); | ||
RequestHelper.setTimeOut(request.options, 4000); | ||
RequestHelper.setProxy(request.options, request.proxyHost, request.proxyPort); | ||
httpget.setConfig(request.options.build()); | ||
httpget.setHeader(new BasicHeader("Authorization", "bearer " + request.Token)); | ||
CloseableHttpResponse responseB = client.execute(httpget); | ||
|
||
HttpEntity entity = responseB.getEntity(); | ||
String responseString = EntityUtils.toString(entity, "UTF-8"); | ||
int status = responseB.getStatusLine().getStatusCode(); | ||
client.close(); | ||
responseB.close(); | ||
if (!responseString.isEmpty() && status < 500) { | ||
JSONObject body = new JSONObject(responseString); | ||
if (status == 200) { | ||
JSONObject data = body.getJSONObject("data"); | ||
return new TaxplayerResponse(status, body.getString("status"),data.getString("id"), | ||
data.getString("rfc"), | ||
data.getString("nombre_Contribuyente"), | ||
data.getString("situacion_del_contribuyente"), | ||
data.getString("numero_y_fecha_oficio_global_presuncion"), | ||
data.getString("publicacion_pagina_SAT_presuntos"), | ||
data.getString("publicacion_DOF_presuntos"), | ||
data.getString("publicacion_pagina_SAT_desvirtuados"), | ||
data.getString("numero_fecha_oficio_global_contribuyentes_que_desvirtuaron"), | ||
data.getString("publicacion_DOF_desvirtuados"), | ||
data.getString("numero_fecha_oficio_global_definitivos"), | ||
data.getString("publicacion_pagina_SAT_definitivos"), | ||
data.getString("publicacion_DOF_definitivos"), | ||
data.getString("numero_fecha_oficio_global_sentencia_favorable"), | ||
data.getString("publicacion_pagina_SAT_sentencia_favorable"), | ||
data.getString("publicacion_DOF_sentencia_favorable"), "OK", "OK"); | ||
} else { | ||
String messageDetail = ""; | ||
if (!body.isNull("messageDetail")) { | ||
messageDetail = body.getString("messageDetail"); | ||
} | ||
return new TaxplayerResponse(status, body.getString("status"), body.getString("message"), | ||
messageDetail); | ||
} | ||
} else { | ||
return new TaxplayerResponse(status, "error", responseB.getStatusLine().getReasonPhrase(), | ||
responseString); | ||
} | ||
} catch (JSONException e) { | ||
throw new GeneralException(500, e.getMessage()); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/Utils/Responses/Taxplayer/TaxplayerResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package Utils.Responses.Taxplayer; | ||
|
||
import Utils.Responses.IResponse; | ||
|
||
public class TaxplayerResponse extends IResponse { | ||
public String id; | ||
public String rfc; | ||
public String nombre_Contribuyente; | ||
public String situacion_del_contribuyente; | ||
public String numero_y_fecha_oficio_global_presuncion; | ||
public String publicacion_pagina_SAT_presuntos; | ||
public String publicacion_DOF_presuntos; | ||
public String publicacion_pagina_SAT_desvirtuados; | ||
public String numero_fecha_oficio_global_contribuyentes_que_desvirtuaron; | ||
public String publicacion_DOF_desvirtuados; | ||
public String numero_fecha_oficio_global_definitivos; | ||
public String publicacion_pagina_SAT_definitivos; | ||
public String publicacion_DOF_definitivos; | ||
public String numero_fecha_oficio_global_sentencia_favorable; | ||
public String publicacion_pagina_SAT_sentencia_favorable; | ||
public String publicacion_DOF_sentencia_favorable; | ||
|
||
public TaxplayerResponse(int httpStatusCode, String status, String id, String rfc, String nombre_Contribuyente, | ||
String situacion_del_contribuyente, String numero_y_fecha_oficio_global_presuncion, | ||
String publicacion_pagina_SAT_presuntos, String publicacion_DOF_presuntos, | ||
String publicacion_pagina_SAT_desvirtuados, | ||
String numero_fecha_oficio_global_contribuyentes_que_desvirtuaron, String publicacion_DOF_desvirtuados, | ||
String numero_fecha_oficio_global_definitivos, String publicacion_pagina_SAT_definitivos, | ||
String publicacion_DOF_definitivos, String numero_fecha_oficio_global_sentencia_favorable, | ||
String publicacion_pagina_SAT_sentencia_favorable, String publicacion_DOF_sentencia_favorable, String msg, | ||
String msgDetail) { | ||
super(httpStatusCode, status, msg, msgDetail); | ||
this.id = id; | ||
this.rfc = rfc; | ||
this.nombre_Contribuyente = nombre_Contribuyente; | ||
this.situacion_del_contribuyente = situacion_del_contribuyente; | ||
this.numero_y_fecha_oficio_global_presuncion = numero_y_fecha_oficio_global_presuncion; | ||
this.publicacion_pagina_SAT_presuntos = publicacion_pagina_SAT_presuntos; | ||
this.publicacion_DOF_presuntos = publicacion_DOF_presuntos; | ||
this.publicacion_pagina_SAT_desvirtuados = publicacion_pagina_SAT_desvirtuados; | ||
this.numero_fecha_oficio_global_contribuyentes_que_desvirtuaron = numero_fecha_oficio_global_contribuyentes_que_desvirtuaron; | ||
this.publicacion_DOF_desvirtuados = publicacion_DOF_desvirtuados; | ||
this.numero_fecha_oficio_global_definitivos = numero_fecha_oficio_global_definitivos; | ||
this.publicacion_pagina_SAT_definitivos = publicacion_pagina_SAT_definitivos; | ||
this.publicacion_DOF_definitivos = publicacion_DOF_definitivos; | ||
this.numero_fecha_oficio_global_sentencia_favorable = numero_fecha_oficio_global_sentencia_favorable; | ||
this.publicacion_pagina_SAT_sentencia_favorable = publicacion_pagina_SAT_sentencia_favorable; | ||
this.publicacion_DOF_sentencia_favorable = publicacion_DOF_sentencia_favorable; | ||
|
||
} | ||
|
||
public TaxplayerResponse(int httpStatusCode, String status, String msg, String msgDetail) { | ||
super(httpStatusCode, status, msg, msgDetail); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package Tests.Taxpayer; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import Services.Cancelation.SWCancelationService; | ||
import Services.Taxpayer.SWTaxpayerService; | ||
import Tests.Utils; | ||
import Utils.Responses.Cancelation.CancelationResponse; | ||
import Utils.Responses.Taxplayer.TaxplayerResponse; | ||
|
||
public class SWTaxpayerServiceTest { | ||
public String token = "T2lYQ0t4L0RHVkR4dHZ5Nkk1VHNEakZ3Y0J4Nk9GODZuRyt4cE1wVm5tbXB3YVZxTHdOdHAwVXY2NTdJb1hkREtXTzE3dk9pMmdMdkFDR2xFWFVPUXpTUm9mTG1ySXdZbFNja3FRa0RlYURqbzdzdlI2UUx1WGJiKzViUWY2dnZGbFloUDJ6RjhFTGF4M1BySnJ4cHF0YjUvbmRyWWpjTkVLN3ppd3RxL0dJPQ.T2lYQ0t4L0RHVkR4dHZ5Nkk1VHNEakZ3Y0J4Nk9GODZuRyt4cE1wVm5tbFlVcU92YUJTZWlHU3pER1kySnlXRTF4alNUS0ZWcUlVS0NhelhqaXdnWTRncklVSWVvZlFZMWNyUjVxYUFxMWFxcStUL1IzdGpHRTJqdS9Zakw2UGRiMTFPRlV3a2kyOWI5WUZHWk85ODJtU0M2UlJEUkFTVXhYTDNKZVdhOXIySE1tUVlFdm1jN3kvRStBQlpLRi9NeWJrd0R3clhpYWJrVUMwV0Mwd3FhUXdpUFF5NW5PN3J5cklMb0FETHlxVFRtRW16UW5ZVjAwUjdCa2g0Yk1iTExCeXJkVDRhMGMxOUZ1YWlIUWRRVC8yalFTNUczZXdvWlF0cSt2UW0waFZKY2gyaW5jeElydXN3clNPUDNvU1J2dm9weHBTSlZYNU9aaGsvalpQMUxrUndzK0dHS2dpTittY1JmR3o2M3NqNkh4MW9KVXMvUHhZYzVLQS9UK2E1SVhEZFJKYWx4ZmlEWDFuSXlqc2ZRYXlUQk1ldlZkU2tEdU10NFVMdHZKUURLblBxakw0SDl5bUxabDFLNmNPbEp6b3Jtd2Q1V2htRHlTdDZ6eTFRdUNnYnVvK2tuVUdhMmwrVWRCZi9rQkU9.7k2gVCGSZKLzJK5Ky3Nr5tKxvGSJhL13Q8W-YhT0uIo"; | ||
public String rigthRfc = "ZNS1101105T3"; | ||
public String wrongRfc = "ZNS1101105T4"; | ||
public String User = "demo"; | ||
public String Pass = "123456789"; | ||
|
||
|
||
@Test | ||
public void SWTaxpayerServiceTestRigthRfc_authToken() throws Exception { | ||
SWTaxpayerService app = new SWTaxpayerService(token, Utils.url_pruebas); | ||
TaxplayerResponse response = null; | ||
response = (TaxplayerResponse) app.Taxpayer(rigthRfc); | ||
System.out.println(response.Status); | ||
System.out.println(response.HttpStatusCode); | ||
System.out.println(response.id); | ||
System.out.println(response.rfc); | ||
System.out.println(response.nombre_Contribuyente); | ||
System.out.println(response.situacion_del_contribuyente); | ||
System.out.println(response.numero_y_fecha_oficio_global_presuncion); | ||
System.out.println(response.publicacion_pagina_SAT_presuntos); | ||
System.out.println(response.publicacion_DOF_presuntos); | ||
System.out.println(response.publicacion_pagina_SAT_desvirtuados); | ||
System.out.println(response.numero_fecha_oficio_global_contribuyentes_que_desvirtuaron); | ||
System.out.println(response.publicacion_DOF_desvirtuados); | ||
System.out.println(response.numero_fecha_oficio_global_definitivos); | ||
System.out.println(response.publicacion_pagina_SAT_definitivos); | ||
System.out.println(response.publicacion_DOF_definitivos); | ||
System.out.println(response.numero_fecha_oficio_global_sentencia_favorable); | ||
System.out.println(response.publicacion_pagina_SAT_sentencia_favorable); | ||
System.out.println(response.publicacion_DOF_sentencia_favorable); | ||
String expect_status = "success"; | ||
Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); | ||
} | ||
|
||
@Test | ||
public void SWTaxpayerServiceTestWrongRfc_authToken() throws Exception { | ||
SWTaxpayerService app = new SWTaxpayerService(token, Utils.url_pruebas); | ||
TaxplayerResponse response = null; | ||
response = (TaxplayerResponse) app.Taxpayer(wrongRfc); | ||
System.out.println(response.Status); | ||
System.out.println(response.HttpStatusCode); | ||
System.out.println(response.message); | ||
String expect_status = "error"; | ||
Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); | ||
} | ||
@Test | ||
public void SWTaxpayerServiceTestWrongRfc_authCredentials() throws Exception { | ||
SWTaxpayerService app = new SWTaxpayerService(User,Pass, Utils.url_pruebas); | ||
TaxplayerResponse response = null; | ||
response = (TaxplayerResponse) app.Taxpayer(wrongRfc); | ||
System.out.println(response.Status); | ||
System.out.println(response.HttpStatusCode); | ||
System.out.println(response.message); | ||
String expect_status = "error"; | ||
Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); | ||
} | ||
@Test | ||
public void SWTaxpayerServiceTestRigthRfc_authCredentials() throws Exception { | ||
SWTaxpayerService app = new SWTaxpayerService(User,Pass, Utils.url_pruebas); | ||
TaxplayerResponse response = null; | ||
response = (TaxplayerResponse) app.Taxpayer(rigthRfc); | ||
System.out.println(response.Status); | ||
System.out.println(response.HttpStatusCode); | ||
System.out.println(response.id); | ||
System.out.println(response.rfc); | ||
System.out.println(response.nombre_Contribuyente); | ||
System.out.println(response.situacion_del_contribuyente); | ||
System.out.println(response.numero_y_fecha_oficio_global_presuncion); | ||
System.out.println(response.publicacion_pagina_SAT_presuntos); | ||
System.out.println(response.publicacion_DOF_presuntos); | ||
System.out.println(response.publicacion_pagina_SAT_desvirtuados); | ||
System.out.println(response.numero_fecha_oficio_global_contribuyentes_que_desvirtuaron); | ||
System.out.println(response.publicacion_DOF_desvirtuados); | ||
System.out.println(response.numero_fecha_oficio_global_definitivos); | ||
System.out.println(response.publicacion_pagina_SAT_definitivos); | ||
System.out.println(response.publicacion_DOF_definitivos); | ||
System.out.println(response.numero_fecha_oficio_global_sentencia_favorable); | ||
System.out.println(response.publicacion_pagina_SAT_sentencia_favorable); | ||
System.out.println(response.publicacion_DOF_sentencia_favorable); | ||
String expect_status = "success"; | ||
Assert.assertTrue(expect_status.equalsIgnoreCase(response.Status)); | ||
} | ||
|
||
} |