Skip to content

Commit

Permalink
Merge pull request #57 from lunasoft/feature/cancela22.0
Browse files Browse the repository at this point in the history
Actualización cancelaciones
  • Loading branch information
martinfnsw authored Jan 7, 2022
2 parents ca3b266 + c163da8 commit 8a7afd7
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 72 deletions.
14 changes: 7 additions & 7 deletions src/main/java/Services/Cancelation/SWCancelationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ public SWCancelationService(String token, String URI, String proxyHost, int prox
super(token, URI, proxyHost, proxyPort);
}

public IResponse Cancelation(String uuid, String password_csd, String rfc, String b64Cer, String b64Key) throws AuthException, GeneralException, IOException {
CancelationOptionsRequest settings = new CancelationOptionsRequest(getToken(), getURI(), uuid, password_csd, rfc, b64Cer, b64Key, getProxyHost(), getProxyPort());
public IResponse Cancelation(String uuid, String password_csd, String rfc, String b64Cer, String b64Key, String motivo, String foliosustitucion) throws AuthException, GeneralException, IOException {
CancelationOptionsRequest settings = new CancelationOptionsRequest(getToken(), getURI(), uuid, password_csd, rfc, b64Cer, b64Key, motivo, foliosustitucion, getProxyHost(), getProxyPort());
CancelationRequest req = new CancelationRequest();
return req.sendRequest(settings);
}

public IResponse Cancelation(String xml) throws AuthException, GeneralException, IOException {
CancelationOptionsRequest settings = new CancelationOptionsRequest(getToken(), getURI(), xml, getProxyHost(), getProxyPort());
CancelationRequest req = new CancelationRequest();
return req.sendRequest(settings, true);
return req.sendRequestxml(settings, true);
}

public IResponse Cancelation(String uuid, String password_csd, String rfc, String b64Pfx) throws AuthException, GeneralException, IOException {
CancelationOptionsRequest settings = new CancelationOptionsRequest(getToken(), getURI(), uuid, password_csd, rfc, b64Pfx, getProxyHost(), getProxyPort());
public IResponse Cancelation(String uuid, String password_csd, String rfc, String b64Pfx, String motivo, String foliosustitucion) throws AuthException, GeneralException, IOException {
CancelationOptionsRequest settings = new CancelationOptionsRequest(getToken(), getURI(), uuid, password_csd, rfc, b64Pfx, motivo, foliosustitucion, getProxyHost(), getProxyPort());
CancelationRequest req = new CancelationRequest();
return req.sendRequestPfx(settings);
}

public IResponse Cancelation(String uuid, String rfc) throws AuthException, GeneralException, IOException {
CancelationOptionsRequest settings = new CancelationOptionsRequest(getToken(), getURI(), uuid, rfc, getProxyHost(), getProxyPort());
public IResponse Cancelationuuid(String uuid, String rfc, String motivo, String foliosustitucion) throws AuthException, GeneralException, IOException {
CancelationOptionsRequest settings = new CancelationOptionsRequest(getToken(), getURI(), uuid, rfc, motivo, foliosustitucion, getProxyHost(), getProxyPort());
CancelationRequest req = new CancelationRequest();
return req.sendRequestUuid(settings);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Services/StatusCfdi/StatusCfdiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public StatusCfdiService(String URL, String Action) {
this.Action = Action;
}

public IResponse StatusCfdi(String rfcEmisor, String rfcReceptor, String total, String uuid) throws AuthException, GeneralException, IOException, SOAPException {
StatusCancelationOptionsRequest settings = new StatusCancelationOptionsRequest(URL, Action, rfcEmisor, rfcReceptor, total, uuid, null, 0);
public IResponse StatusCfdi(String rfcEmisor, String rfcReceptor, String total, String uuid, String caract_sello) throws AuthException, GeneralException, IOException, SOAPException {
StatusCancelationOptionsRequest settings = new StatusCancelationOptionsRequest(URL, Action, rfcEmisor, rfcReceptor, total, uuid, caract_sello, null, 0);
StatusCancelationRequest req = new StatusCancelationRequest();
return req.sendRequest(settings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,42 @@ public class CancelationOptionsRequest extends IRequest{
private String b64key;
private String b64Pfx;
private String xml;
private String motivo;
private String foliosustitucion;


public CancelationOptionsRequest(String token, String URI, String uuid, String password_csd, String rfc, String b64Cer, String b64Key, String proxyHost, int proxyPort) {
public CancelationOptionsRequest(String token, String URI, String uuid, String password_csd, String rfc, String b64Cer, String b64Key, String motivo, String foliosustitucion, String proxyHost, int proxyPort) {
super(token, URI+ Constants.CANCELATION_CSD_PATH, proxyHost, proxyPort);
this.uuid = uuid;
this.password_csd = password_csd;
this.rfc = rfc;
this.b64Cer = b64Cer;
this.b64key = b64Key;
this.motivo=motivo;
this.foliosustitucion=foliosustitucion;
}

public CancelationOptionsRequest(String token, String URI, String uuid, String password_csd, String rfc, String b64Pfx, String proxyHost, int proxyPort) {
public CancelationOptionsRequest(String token, String URI, String uuid, String password_csd, String rfc, String b64Pfx, String motivo, String foliosustitucion, String proxyHost, int proxyPort) {
super(token, URI+ Constants.CANCELATION_PFX_PATH, proxyHost, proxyPort);
this.uuid = uuid;
this.password_csd = password_csd;
this.rfc = rfc;
this.b64Pfx = b64Pfx;
this.motivo=motivo;
this.foliosustitucion=foliosustitucion;
}

public CancelationOptionsRequest(String token, String URI, String xml, String proxyHost, int proxyPort) {
super(token, URI+ Constants.CANCELATION_XML_PATH, proxyHost, proxyPort);
this.xml = xml;
}
public CancelationOptionsRequest(String token, String URI, String uuid, String rfc, String proxyHost, int proxyPort) {
super(token, URI + Constants.CANCELATION_UUID_PATH + rfc + "/" + uuid, proxyHost, proxyPort);
public CancelationOptionsRequest(String token, String URI, String uuid, String rfc, String motivo, String foliosustitucion, String proxyHost, int proxyPort) {
//super(token, URI + Constants.CANCELATION_UUID_PATH + rfc + "/" + uuid + "/" + motivo + "/" + foliosustitucion, proxyHost, proxyPort);
super(token, URI + Constants.CANCELATION_UUID_PATH + String.format("%s/%s/%s/%s", rfc, uuid, motivo, foliosustitucion ), proxyHost, proxyPort);
this.uuid = uuid;
this.rfc = rfc;
this.motivo=motivo;
this.foliosustitucion=foliosustitucion;
}

public String getUuid() {
Expand Down Expand Up @@ -66,5 +75,11 @@ public String getXml() {
public String getB64Pfx() {
return b64Pfx;
}
public String getmotivo() {
return motivo;
}
public String getfoliosust() {
return foliosustitucion;
}

}
12 changes: 8 additions & 4 deletions src/main/java/Utils/Requests/Cancelation/CancelationRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
StringEntity sEntity = new StringEntity(
"{\r\n \"uuid\": \"" + ((CancelationOptionsRequest) request).getUuid() + "\",\r\n \"password\": \""
+ ((CancelationOptionsRequest) request).getPassword_csd() + "\",\r\n \"rfc\": \""
+ ((CancelationOptionsRequest) request).getRfc() + "\",\r\n \"b64Cer\": \""
+ ((CancelationOptionsRequest) request).getRfc()+ "\",\r\n \"motivo\": \""
+ ((CancelationOptionsRequest) request).getmotivo()+ "\",\r\n \"foliosustitucion\": \""
+ ((CancelationOptionsRequest) request).getfoliosust()+ "\",\r\n \"b64Cer\": \""
+ ((CancelationOptionsRequest) request).getB64Cer() + "\",\r\n \"b64Key\": \""
+ ((CancelationOptionsRequest) request).getB64key() + "\"\r\n}");
httppost.setEntity(builder.build());
Expand Down Expand Up @@ -83,7 +85,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
}
}

public IResponse sendRequest(IRequest request, boolean isXml) throws GeneralException, AuthException, IOException {
public IResponse sendRequestxml(IRequest request, boolean isXml) throws GeneralException, AuthException, IOException {

try {
String xmlStr = ((CancelationOptionsRequest) request).getXml();
Expand Down Expand Up @@ -116,7 +118,7 @@ public IResponse sendRequest(IRequest request, boolean isXml) throws GeneralExce
if (status == 200) {
JSONObject data = body.getJSONObject("data");
String xml = ((CancelationOptionsRequest) request).getXml();
String uuid = xml.substring(xml.indexOf("<UUID>") + 6, xml.indexOf("</UUID>")).toUpperCase();
String uuid = xml.substring(xml.indexOf("<Folio UUID=") +13, xml.indexOf("Motivo")-2).toUpperCase();
JSONObject uuid_data = data.getJSONObject("uuid");
String uuidSC = uuid_data.getString(uuid);
return new CancelationResponse(status, body.getString("status"), data.getString("acuse"), uuid,
Expand Down Expand Up @@ -152,7 +154,9 @@ public IResponse sendRequestPfx(IRequest request) throws ClientProtocolException
StringEntity sEntity = new StringEntity(
"{\r\n \"uuid\": \"" + ((CancelationOptionsRequest) request).getUuid() + "\",\r\n \"password\": \""
+ ((CancelationOptionsRequest) request).getPassword_csd() + "\",\r\n \"rfc\": \""
+ ((CancelationOptionsRequest) request).getRfc() + "\",\r\n \"b64Pfx\": \""
+ ((CancelationOptionsRequest) request).getRfc() + "\",\r\n \"motivo\": \""
+ ((CancelationOptionsRequest) request).getmotivo()+ "\",\r\n \"foliosustitucion\": \""
+ ((CancelationOptionsRequest) request).getfoliosust() + "\",\r\n \"b64Pfx\": \""
+ ((CancelationOptionsRequest) request).getB64Pfx() + "\"\r\n}");
httppost.setEntity(builder.build());
httppost.setEntity(sEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ public class StatusCancelationOptionsRequest extends IRequest{
private String rfcReceptor;
private String total;
private String uuid;
private String caract_sello;
private String action;

public StatusCancelationOptionsRequest(String URI, String action, String rfcEmisor, String rfcReceptor, String total, String uuid, String proxyHost, int proxyPort) {
public StatusCancelationOptionsRequest(String URI, String action, String rfcEmisor, String rfcReceptor, String total, String uuid, String caract_sello, String proxyHost, int proxyPort) {
super("", URI, proxyHost, proxyPort);
this.rfcEmisor = rfcEmisor;
this.rfcReceptor = rfcReceptor;
this.total = total;
this.uuid = uuid;
this.caract_sello = caract_sello;
this.action = action;
}

Expand All @@ -30,6 +32,9 @@ public String getTotal() {
public String getUuid() {
return uuid;
}
public String getCSello() {
return caract_sello;
}
public String getAction() {
return action;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
String rfcReceptor = ((StatusCancelationOptionsRequest) request).getRfcReceptor();
String total = ((StatusCancelationOptionsRequest) request).getTotal();
String uuid = ((StatusCancelationOptionsRequest) request).getUuid();
String caract_sello = ((StatusCancelationOptionsRequest) request).getCSello();

SOAPMessage Response = callSoapWebService(soapEndpointUrl, soapAction, rfcEmisor, rfcReceptor, total, uuid);
SOAPMessage Response = callSoapWebService(soapEndpointUrl, soapAction, rfcEmisor, rfcReceptor, total, uuid, caract_sello);
SOAPBody body = Response.getSOAPBody();
SOAPFault error = body.getFault();
if (error != null) {
Expand Down Expand Up @@ -74,7 +75,7 @@ public IResponse sendRequest(IRequest request) throws GeneralException, AuthExce
}
}

private static void createSoapEnvelope(SOAPMessage soapMessage, String rfcEmisor, String rfcReceptor, String total, String uuid) throws SOAPException {
private static void createSoapEnvelope(SOAPMessage soapMessage, String rfcEmisor, String rfcReceptor, String total, String uuid, String caract_sello) throws SOAPException {
SOAPPart soapPart = soapMessage.getSOAPPart();
String myNamespace = "tem";
String myNamespaceURI = "http://tempuri.org/";
Expand All @@ -83,13 +84,13 @@ private static void createSoapEnvelope(SOAPMessage soapMessage, String rfcEmisor
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("Consulta", myNamespace);
SOAPElement soapExpresionImpresa = soapBodyElem.addChildElement("expresionImpresa", myNamespace);
soapExpresionImpresa.addTextNode("<![CDATA[?re="+rfcEmisor+"&rr="+rfcReceptor+"&tt="+total+"&id="+uuid+"]]>");
soapExpresionImpresa.addTextNode("<![CDATA[?re="+rfcEmisor+"&rr="+rfcReceptor+"&tt="+total+"&id="+uuid+"&fe"+caract_sello+"]]>");
}
private SOAPMessage callSoapWebService(String soapEndpointUrl, String soapAction, String rfcEmisor, String rfcReceptor, String total, String uuid) {
private SOAPMessage callSoapWebService(String soapEndpointUrl, String soapAction, String rfcEmisor, String rfcReceptor, String total, String uuid, String caract_sello) {
try {
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
SOAPMessage soapRequest = createSOAPRequest(soapAction, rfcEmisor, rfcReceptor, total, uuid);
SOAPMessage soapRequest = createSOAPRequest(soapAction, rfcEmisor, rfcReceptor, total, uuid, caract_sello);
SOAPMessage soapResponse = soapConnection.call(soapRequest, soapEndpointUrl);
return soapResponse;
} catch (Exception e) {
Expand All @@ -99,10 +100,10 @@ private SOAPMessage callSoapWebService(String soapEndpointUrl, String soapAction
return null;
}

private static SOAPMessage createSOAPRequest(String soapAction, String rfcEmisor, String rfcReceptor, String total, String uuid) throws Exception {
private static SOAPMessage createSOAPRequest(String soapAction, String rfcEmisor, String rfcReceptor, String total, String uuid, String caract_sello) throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
createSoapEnvelope(soapMessage, rfcEmisor, rfcReceptor, total, uuid);
createSoapEnvelope(soapMessage, rfcEmisor, rfcReceptor, total, uuid, caract_sello );
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", soapAction);
soapMessage.saveChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ public class CancelationResponse extends IResponse {

public String acuse;
public String uuid;
public String msgDetail;
public int uuidStatusCode;

public CancelationResponse(int httpStatusCode, String status, String acuse, String uuid, int uuidStatusCode, String msg, String msgDetail) {
super(httpStatusCode, status, msg, msgDetail);
this.acuse = acuse;
this.uuid = uuid;
this.msgDetail=msgDetail;
this.uuidStatusCode = uuidStatusCode;
}
public CancelationResponse(int httpStatusCode, String status, String msg, String msgDetail) {
Expand Down
Loading

0 comments on commit 8a7afd7

Please sign in to comment.