Skip to content

Commit

Permalink
Merge pull request #41 from lunasoft/feature/0.0.4.3
Browse files Browse the repository at this point in the history
Feature/0.0.4.3
  • Loading branch information
JuanGamezSW authored Sep 6, 2019
2 parents 8695fb1 + 6ee80b8 commit 602c922
Show file tree
Hide file tree
Showing 45 changed files with 2,033 additions and 895 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
</properties>
<artifactId>SW-JAVA</artifactId>
<version>0.0.4.2</version>
<version>0.0.4.3</version>
<packaging>jar</packaging>
<scm>
<url>https://github.com/lunasoft/sw-sdk-java</url>
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/Services/Csd/SWCsdService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,47 @@ public IResponse UploadMyCsd(String b64Cer, String b64Key, String passwordCsd, S
CsdRequest req = new CsdRequest();
return req.sendRequest(settings);
}

public IResponse DisableMyCsd(String certificateNumber) throws AuthException, GeneralException, IOException {
CsdOptionsRequest settings = null;
settings = new CsdOptionsRequest(getToken(), getURI(), certificateNumber, getProxyHost(), getProxyPort());
CsdRequest req = new CsdRequest();
return req.DisableCsdRequest(settings);
}

public IResponse GetListCsd() throws AuthException, GeneralException, IOException {
CsdOptionsRequest settings = null;
settings = new CsdOptionsRequest(getToken(), getURI(), getProxyHost(), getProxyPort());
CsdRequest req = new CsdRequest();
return req.GetListCsdRequest(settings);
}

public IResponse GetListCsdByType(String type) throws AuthException, GeneralException, IOException {
CsdOptionsRequest settings = null;
settings = new CsdOptionsRequest(getToken(), getURI(), "type/" + type, getProxyHost(), getProxyPort());
CsdRequest req = new CsdRequest();
return req.GetListCsdRequest(settings);
}

public IResponse GetListCsdByRfc(String rfc) throws AuthException, GeneralException, IOException {
CsdOptionsRequest settings = null;
settings = new CsdOptionsRequest(getToken(), getURI(), "rfc/" + rfc, getProxyHost(), getProxyPort());
CsdRequest req = new CsdRequest();
return req.GetListCsdRequest(settings);
}

public IResponse SearchMyCsd(String certificateNumber) throws AuthException, GeneralException, IOException {
CsdOptionsRequest settings = null;
settings = new CsdOptionsRequest(getToken(), getURI(), certificateNumber, getProxyHost(), getProxyPort());
CsdRequest req = new CsdRequest();
return req.GetInfoCsdRequest(settings);
}

public IResponse SearchActiveCsd(String rfc, String type) throws AuthException, GeneralException, IOException {
CsdOptionsRequest settings = null;
settings = new CsdOptionsRequest(getToken(), getURI(), "rfc/" + rfc, type, getProxyHost(), getProxyPort());
CsdRequest req = new CsdRequest();
return req.GetInfoCsdRequest(settings);
}
}

4 changes: 2 additions & 2 deletions src/main/java/Services/Issue/SWIssueService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public IResponse IssueJson(byte[] jsonFile, String version) throws AuthException
return req.sendRequest(settings);
}
public IResponse IssueXml(String xml, String version) throws AuthException, GeneralException, IOException {
IssueOptionsRequest settings = new IssueOptionsRequest(getToken(), getURI(), xml, version, true, getProxyHost(), getProxyPort());
IssueOptionsRequest settings = new IssueOptionsRequest(getToken(), getURI(), xml, version, true, getProxyHost(), getProxyPort(), false);
IssueRequest req = new IssueRequest();
return req.sendRequestXml(settings);
}
public IResponse IssueXml(byte[] xmlfile, String version) throws AuthException, GeneralException, IOException {
String xmlProcess = new String(xmlfile, Charset.forName("UTF-8"));
IssueOptionsRequest settings = new IssueOptionsRequest(getToken(), getURI(), xmlProcess, version, true, getProxyHost(), getProxyPort());
IssueOptionsRequest settings = new IssueOptionsRequest(getToken(), getURI(), xmlProcess, version, true, getProxyHost(), getProxyPort(), false);
IssueRequest req = new IssueRequest();
return req.sendRequestXml(settings);
}
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/Services/Issue/SWIssueServiceV2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package Services.Issue;

import Exceptions.AuthException;
import Exceptions.GeneralException;
import Utils.Requests.Issue.IssueOptionsRequest;
import Utils.Requests.Issue.IssueRequest;
import Utils.Responses.IResponse;

import java.io.IOException;
import java.nio.charset.Charset;

public class SWIssueServiceV2 extends SWIssueService {

public SWIssueServiceV2(String user, String password, String URI) throws AuthException {
super(user, password, URI);
}

public SWIssueServiceV2(String token, String URI) {
super(token, URI);
}

public SWIssueServiceV2(String user, String password, String URI, String proxyHost, int proxyPort) throws AuthException {
super(user, password, URI, proxyHost, proxyPort);
}

public SWIssueServiceV2(String token, String URI, String proxyHost, int proxyPort) {
super(token, URI, proxyHost, proxyPort);
}

public IResponse IssueXml(String xml, String version) throws AuthException, GeneralException, IOException {
IssueOptionsRequest settings = new IssueOptionsRequest(getToken(), getURI(), xml, version, true, getProxyHost(), getProxyPort(), true);
IssueRequest req = new IssueRequest();
return req.sendRequestXml(settings);
}
public IResponse IssueXml(byte[] xmlfile, String version) throws AuthException, GeneralException, IOException {
String xmlProcess = new String(xmlfile, Charset.forName("UTF-8"));
IssueOptionsRequest settings = new IssueOptionsRequest(getToken(), getURI(), xmlProcess, version, true, getProxyHost(), getProxyPort(), true);
IssueRequest req = new IssueRequest();
return req.sendRequestXml(settings);
}
}
10 changes: 5 additions & 5 deletions src/main/java/Services/Stamp/SWStampService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ public SWStampService(String token, String URI, String proxyHost, int proxyPort)
}

public IResponse Stamp(String xml, String version) throws AuthException, GeneralException, IOException {
StampOptionsRequest settings = new StampOptionsRequest(getToken(), getURI(), xml, version, getProxyHost(), getProxyPort());
StampOptionsRequest settings = new StampOptionsRequest(getToken(), getURI(), xml, version, getProxyHost(), getProxyPort(), false);
StampRequest req = new StampRequest();
return req.sendRequest(settings);
}

public IResponse Stamp(String xml, String version, boolean isb64)
throws AuthException, GeneralException, IOException {
if (isb64) {
StampOptionsRequest settings = new StampOptionsRequest(getToken(), getURI(), xml, version, isb64, getProxyHost(), getProxyPort());
StampOptionsRequest settings = new StampOptionsRequest(getToken(), getURI(), xml, version, isb64, getProxyHost(), getProxyPort(), false);
StampRequest req = new StampRequest();
return req.sendRequest(settings);
} else {
StampOptionsRequest settings = new StampOptionsRequest(getToken(), getURI(), xml, version, getProxyHost(), getProxyPort());
StampOptionsRequest settings = new StampOptionsRequest(getToken(), getURI(), xml, version, getProxyHost(), getProxyPort(), false);
StampRequest req = new StampRequest();
return req.sendRequest(settings);
}
Expand All @@ -51,14 +51,14 @@ public IResponse Stamp(String xml, String version, boolean isb64)
public IResponse Stamp(byte[] xmlFile, String version, boolean isb64)
throws AuthException, GeneralException, IOException {
String xmlProcess = new String(xmlFile, Charset.forName("UTF-8"));
StampOptionsRequest settings = new StampOptionsRequest(getToken(), getURI(), xmlProcess, version, getProxyHost(), getProxyPort());
StampOptionsRequest settings = new StampOptionsRequest(getToken(), getURI(), xmlProcess, version, getProxyHost(), getProxyPort(), false);
StampRequest req = new StampRequest();
return req.sendRequest(settings);
}

public IResponse Stamp(byte[] xmlFile, String version) throws AuthException, GeneralException, IOException {
String xmlProcess = new String(xmlFile, Charset.forName("UTF-8"));
StampOptionsRequest settings = new StampOptionsRequest(getToken(), getURI(), xmlProcess, version, getProxyHost(), getProxyPort());
StampOptionsRequest settings = new StampOptionsRequest(getToken(), getURI(), xmlProcess, version, getProxyHost(), getProxyPort(), false);
StampRequest req = new StampRequest();
return req.sendRequest(settings);

Expand Down
66 changes: 66 additions & 0 deletions src/main/java/Services/Stamp/SWStampServiceV2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package Services.Stamp;

import Exceptions.AuthException;
import Exceptions.GeneralException;
import Services.SWService;
import Utils.Requests.Stamp.StampOptionsRequest;
import Utils.Requests.Stamp.StampRequest;

import Utils.Responses.IResponse;

import java.io.IOException;
import java.nio.charset.Charset;

public class SWStampServiceV2 extends SWService {

public SWStampServiceV2(String user, String password, String URI) throws AuthException {
super(user, password, URI);
}

public SWStampServiceV2(String token, String URI) {
super(token, URI);
}

public SWStampServiceV2(String user, String password, String URI, String proxyHost, int proxyPort) throws AuthException {
super(user, password, URI, proxyHost, proxyPort);
}

public SWStampServiceV2(String token, String URI, String proxyHost, int proxyPort) {
super(token, URI, proxyHost, proxyPort);
}

public IResponse Stamp(String xml, String version) throws AuthException, GeneralException, IOException {
StampOptionsRequest settings = new StampOptionsRequest(getToken(), getURI(), xml, version, getProxyHost(), getProxyPort(), true);
StampRequest req = new StampRequest();
return req.sendRequest(settings);
}

public IResponse Stamp(String xml, String version, boolean isb64)
throws AuthException, GeneralException, IOException {
if (isb64) {
StampOptionsRequest settings = new StampOptionsRequest(getToken(), getURI(), xml, version, isb64, getProxyHost(), getProxyPort(), true);
StampRequest req = new StampRequest();
return req.sendRequest(settings);
} else {
StampOptionsRequest settings = new StampOptionsRequest(getToken(), getURI(), xml, version, getProxyHost(), getProxyPort(), true);
StampRequest req = new StampRequest();
return req.sendRequest(settings);
}
}

public IResponse Stamp(byte[] xmlFile, String version, boolean isb64)
throws AuthException, GeneralException, IOException {
String xmlProcess = new String(xmlFile, Charset.forName("UTF-8"));
StampOptionsRequest settings = new StampOptionsRequest(getToken(), getURI(), xmlProcess, version, getProxyHost(), getProxyPort(), true);
StampRequest req = new StampRequest();
return req.sendRequest(settings);
}

public IResponse Stamp(byte[] xmlFile, String version) throws AuthException, GeneralException, IOException {
String xmlProcess = new String(xmlFile, Charset.forName("UTF-8"));
StampOptionsRequest settings = new StampOptionsRequest(getToken(), getURI(), xmlProcess, version, getProxyHost(), getProxyPort(), true);
StampRequest req = new StampRequest();
return req.sendRequest(settings);

}
}
6 changes: 5 additions & 1 deletion src/main/java/Utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ public class Constants {
public static String BASE_PATH = "http://services.test.sw.com.mx";
public static String AUTH_PATH = "/security/authenticate";
public static String STAMP_PATH = "/cfdi33/stamp/";
public static String STAMP_V2_PATH = "/cfdi33/v2/stamp/";
public static String ISSUE_JSON_PATH = "/v3/cfdi33/issue/json/";
public static String ISSUE_XML_PATH = "/cfdi33/issue/";
public static String ISSUE_XML_V2_PATH = "/cfdi33/v2/issue/";
public static String CANCELATION_CSD_PATH = "/cfdi33/cancel/csd";
public static String CANCELATION_XML_PATH = "/cfdi33/cancel/xml";
public static String CANCELATION_PFX_PATH = "/cfdi33/cancel/pfx";
Expand All @@ -24,5 +26,7 @@ public class Constants {
public static String RELACIONADOS_XML_PATH = "/relations/xml";
public static String RELACIONADOS_UUID_PATH = "/relations/";
public static String PENDIENTES_CANCELAR_PATH = "/pendings/";
public static String SAVE_CSD = "/csd/save";
public static String SAVE_CSD = "/certificates/save";
public static String DISABLE_SEARCH_CSD = "/certificates/";
public static String LIST_CSD = "/certificates";
}
10 changes: 8 additions & 2 deletions src/main/java/Utils/Helpers/BuildResponseV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class BuildResponseV1 extends ResponseStamp {
public IResponse getResponse() {
if(!response.trim().isEmpty()) {
if(!response.trim().isEmpty() && status < 500) {
JSONObject body = new JSONObject(response);
if(status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -18,11 +18,17 @@ public IResponse getResponse() {
if (!body.isNull("messageDetail")){
messageDetail = body.getString("messageDetail");
}
if(body.getString("message").equals("307. El comprobante contiene un timbre previo.")) {
if(!body.isNull("data")) {
JSONObject data = body.getJSONObject("data");
return new SuccessV1Response(status, body.getString("status"), data.getString("tfd"), body.getString("message"), messageDetail);
}
}
return new SuccessV1Response(status, body.getString("status"), "", body.getString("message"), messageDetail);
}
}
else {
return new SuccessV1Response(status, "error", "","Error con código "+status+": "+reason.getReasonPhrase(), reason.getProtocolVersion().getProtocol());
return new SuccessV1Response(status, "error", "","Error con código "+status+": "+reason.getReasonPhrase(), response);
}
}
}
13 changes: 10 additions & 3 deletions src/main/java/Utils/Helpers/BuildResponseV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import org.json.JSONObject;

import Utils.Responses.IResponse;
import Utils.Responses.Stamp.SuccessV1Response;
import Utils.Responses.Stamp.SuccessV2Response;

public class BuildResponseV2 extends ResponseStamp {
public IResponse getResponse() {
if(!response.trim().isEmpty()) {
if(!response.trim().isEmpty() && status < 500) {
JSONObject body = new JSONObject(response);
if(status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -18,11 +19,17 @@ public IResponse getResponse() {
if (!body.isNull("messageDetail")){
messageDetail = body.getString("messageDetail");
}
return new SuccessV2Response(status, body.getString("status"), "", "",body.getString("message"), messageDetail);
if(body.getString("message").equals("307. El comprobante contiene un timbre previo.")) {
if(!body.isNull("data")) {
JSONObject data = body.getJSONObject("data");
return new SuccessV2Response(status, body.getString("status"), data.getString("tfd"), data.getString("cfdi"), body.getString("message"), messageDetail);
}
}
return new SuccessV2Response(status, body.getString("status"), "", "", body.getString("message"), messageDetail);
}
}
else {
return new SuccessV2Response(status, "error", "", "","Error con código "+status+": "+reason.getReasonPhrase(), reason.getProtocolVersion().getProtocol());
return new SuccessV2Response(status, "error", "", "","Error con código "+status+": "+reason.getReasonPhrase(), response);
}
}
}
15 changes: 11 additions & 4 deletions src/main/java/Utils/Helpers/BuildResponseV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,33 @@
import org.json.JSONObject;

import Utils.Responses.IResponse;
import Utils.Responses.Stamp.SuccessV2Response;
import Utils.Responses.Stamp.SuccessV3Response;

public class BuildResponseV3 extends ResponseStamp {
public IResponse getResponse() {
if(!response.trim().isEmpty()) {
if(!response.trim().isEmpty() && status < 500) {
JSONObject body = new JSONObject(response);
if(status == 200) {
JSONObject data = body.getJSONObject("data");
return new SuccessV3Response(status, body.getString("status"), data.getString("cfdi"),reason.getReasonPhrase(), reason.getReasonPhrase());
return new SuccessV3Response(status, body.getString("status"), data.getString("cfdi"), "OK", "OK");
}
else {
String messageDetail = "";
if (!body.isNull("messageDetail")){
messageDetail = body.getString("messageDetail");
}
return new SuccessV3Response(status, body.getString("status"), "",body.getString("message"), messageDetail);
if(body.getString("message").equals("307. El comprobante contiene un timbre previo.")) {
if(!body.isNull("data")) {
JSONObject data = body.getJSONObject("data");
return new SuccessV3Response(status, body.getString("status"), data.getString("cfdi"), body.getString("message"), messageDetail);
}
}
return new SuccessV3Response(status, body.getString("status"), "", body.getString("message"), messageDetail);
}
}
else {
return new SuccessV3Response(status, "error", "","Error con código "+status+": "+reason.getReasonPhrase(), reason.getProtocolVersion().getProtocol());
return new SuccessV3Response(status, "error", "","Error con código "+status+": "+reason.getReasonPhrase(), response);
}
}
}
18 changes: 15 additions & 3 deletions src/main/java/Utils/Helpers/BuildResponseV4.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import org.json.JSONObject;

import Utils.Responses.IResponse;
import Utils.Responses.Stamp.SuccessV3Response;
import Utils.Responses.Stamp.SuccessV4Response;

public class BuildResponseV4 extends ResponseStamp {
public IResponse getResponse() {
if(!response.trim().isEmpty()) {
if(!response.trim().isEmpty() && status < 500) {
JSONObject body = new JSONObject(response);
if(status == 200) {
JSONObject data = body.getJSONObject("data");
Expand All @@ -16,18 +17,29 @@ public IResponse getResponse() {
data.getString("noCertificadoSAT"), data.getString("noCertificadoCFDI"),
data.getString("uuid"), data.getString("selloSAT"),
data.getString("selloCFDI"), data.getString("fechaTimbrado"),
data.getString("qrCode"), reason.getReasonPhrase(), reason.getReasonPhrase());
data.getString("qrCode"), "OK", "OK");
}
else {
String messageDetail = "";
if (!body.isNull("messageDetail")){
messageDetail = body.getString("messageDetail");
}
if(body.getString("message").equals("307. El comprobante contiene un timbre previo.")) {
if(!body.isNull("data")) {
JSONObject data = body.getJSONObject("data");
return new SuccessV4Response(status, body.getString("status"),
data.getString("cfdi"), data.getString("cadenaOriginalSAT"),
data.getString("noCertificadoSAT"), data.getString("noCertificadoCFDI"),
data.getString("uuid"), data.getString("selloSAT"),
data.getString("selloCFDI"), data.getString("fechaTimbrado"),
data.getString("qrCode"), body.getString("message"), messageDetail);
}
}
return new SuccessV4Response(status, body.getString("status"), "", "", "", "", "", "", "", "", "", body.getString("message"), messageDetail);
}
}
else {
return new SuccessV4Response(status, "error", "", "", "", "", "", "", "", "", "", "Error con código "+status+": "+reason.getReasonPhrase(), reason.getProtocolVersion().getProtocol());
return new SuccessV4Response(status, "error", "", "", "", "", "", "", "", "", "", "Error con código "+status+": "+reason.getReasonPhrase(), response);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/Utils/Helpers/RequestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static JSONArray buildJSONFromMap(Map<String, String> map) throws General
}

public static void setProxy(Builder build, String host, int port) throws GeneralException {
if(host != null){
if(!stringEmptyOrNull(host)){
try {
HttpHost proxy = new HttpHost(host, port);
build.setProxy(proxy);
Expand Down
Loading

0 comments on commit 602c922

Please sign in to comment.