Skip to content

Commit 7463a0d

Browse files
Updating and adding new endpoints
1 parent bacf7c6 commit 7463a0d

File tree

15 files changed

+620
-389
lines changed

15 files changed

+620
-389
lines changed

.classpath

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
<attributes>
1111
<attribute name="optional" value="true"/>
1212
<attribute name="maven.pomderived" value="true"/>
13+
<attribute name="test" value="true"/>
1314
</attributes>
1415
</classpathentry>
1516
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
1617
<attributes>
1718
<attribute name="maven.pomderived" value="true"/>
1819
</attributes>
1920
</classpathentry>
20-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
21+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
2122
<attributes>
2223
<attribute name="maven.pomderived" value="true"/>
2324
</attributes>
@@ -27,5 +28,22 @@
2728
<attribute name="maven.pomderived" value="true"/>
2829
</attributes>
2930
</classpathentry>
31+
<classpathentry kind="src" path="target/generated-sources/annotations">
32+
<attributes>
33+
<attribute name="optional" value="true"/>
34+
<attribute name="maven.pomderived" value="true"/>
35+
<attribute name="ignore_optional_problems" value="true"/>
36+
<attribute name="m2e-apt" value="true"/>
37+
</attributes>
38+
</classpathentry>
39+
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
40+
<attributes>
41+
<attribute name="optional" value="true"/>
42+
<attribute name="maven.pomderived" value="true"/>
43+
<attribute name="ignore_optional_problems" value="true"/>
44+
<attribute name="m2e-apt" value="true"/>
45+
<attribute name="test" value="true"/>
46+
</attributes>
47+
</classpathentry>
3048
<classpathentry kind="output" path="target/classes"/>
3149
</classpath>

.project

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,15 @@
2020
<nature>org.eclipse.m2e.core.maven2Nature</nature>
2121
<nature>org.eclipse.jdt.core.javanature</nature>
2222
</natures>
23+
<filteredResources>
24+
<filter>
25+
<id>1665500716441</id>
26+
<name></name>
27+
<type>30</type>
28+
<matcher>
29+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
30+
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
31+
</matcher>
32+
</filter>
33+
</filteredResources>
2334
</projectDescription>

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 2.0.0
2+
- Added: API Open Finance
3+
- Added: API Pagamentos
4+
- Added: new endpoints of API Pix
5+
- Updated: PixSend example
6+
- Updated: rename "pix_cert" to "certificate" in credentials.json
7+
18
# 1.0.2
29

310
- Fix: Error message

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ java 7.0 and 8.0
2222
**Via gradle:**
2323

2424
```gradle
25-
compile 'br.com.gerencianet.gnsdk:gn-api-sdk-java:1.0.2'
25+
compile 'br.com.gerencianet.gnsdk:gn-api-sdk-java:2.0.0'
2626
```
2727

2828
**Via maven:**
@@ -31,7 +31,7 @@ compile 'br.com.gerencianet.gnsdk:gn-api-sdk-java:1.0.2'
3131
<dependency>
3232
    <groupId>br.com.gerencianet.gnsdk</groupId>
3333
    <artifactId>gn-api-sdk-java</artifactId>
34-
    <version>1.0.2</version>
34+
    <version>2.0.0</version>
3535
</dependency>
3636
```
3737

@@ -60,7 +60,7 @@ Instantiate the module passing using your client_id, client_secret and sandbox e
6060
JSONObject options = new JSONObject();
6161
options.put("client_id", "client_id");
6262
options.put("client_secret", "client_secret");
63-
options.put("pix_cert", "./certs/developmentCertificate.p12");
63+
options.put("certificate", "./certs/developmentCertificate.p12");
6464
options.put("sandbox", true);
6565

6666
Gerencianet gn = new Gerencianet($options);
@@ -71,7 +71,7 @@ Or
7171
Map<String, Object> options = new HashMap<String, Object>();
7272
options.put("client_id", "client_id");
7373
options.put("client_secret", "client_secret");
74-
options.put("pix_cert", "./certs/developmentCertificate.p12");
74+
options.put("certificate", "./certs/developmentCertificate.p12");
7575
options.put("sandbox", true);
7676

7777
Gerencianet gn = new Gerencianet($options);
@@ -83,7 +83,7 @@ To change the environment to production, just set the third sandbox to false:
8383
JSONObject options = new JSONObject();
8484
options.put("client_id", "client_id");
8585
options.put("client_secret", "client_secret");
86-
options.put("pix_cert", "./certs/productionCertificate.p12");
86+
options.put("certificate", "./certs/productionCertificate.p12");
8787
options.put("sandbox", false);
8888

8989
Gerencianet gn = new Gerencianet($options);
@@ -94,7 +94,7 @@ Or
9494
Map<String, Object> options = new HashMap<String, Object>();
9595
options.put("client_id", "client_id");
9696
options.put("client_secret", "client_secret");
97-
options.put("pix_cert", "./certs/productionCertificate.p12");
97+
options.put("certificate", "./certs/productionCertificate.p12");
9898
options.put("sandbox", false);
9999

100100
Gerencianet gn = new Gerencianet($options);

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>br.com.gerencianet.gnsdk</groupId>
55
<artifactId>gn-api-sdk-java</artifactId>
6-
<version>1.0.2</version>
6+
<version>2.0.0</version>
77

88
<name>GN API SDK JAVA</name>
99
<description>Java SDK for integrating with Gerencianet API</description>
@@ -148,7 +148,7 @@
148148
<plugin>
149149
<groupId>org.apache.maven.plugins</groupId>
150150
<artifactId>maven-surefire-plugin</artifactId>
151-
<version>2.19.1</version>
151+
<version>2.22.0</version>
152152
<configuration>
153153
<testFailureIgnore>true</testFailureIgnore>
154154
</configuration>
@@ -157,7 +157,7 @@
157157
<plugin>
158158
<groupId>org.jacoco</groupId>
159159
<artifactId>jacoco-maven-plugin</artifactId>
160-
<version>0.7.7.201606060606</version>
160+
<version>0.7.8</version>
161161
<configuration>
162162
<excludes>
163163
<exclude>**/exceptions/*</exclude>
@@ -210,7 +210,7 @@
210210
<plugin>
211211
<groupId>org.apache.maven.plugins</groupId>
212212
<artifactId>maven-gpg-plugin</artifactId>
213-
<version>1.5</version>
213+
<version>3.0.1</version>
214214
<executions>
215215
<execution>
216216
<id>sign-artifacts</id>

src/main/java/br/com/gerencianet/gnsdk/APIRequest.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
/**
1414
* This class instance a Auth Object, to authenticate client credentials in
15-
* Gerencianet API. After client's credentials are validated a client Object
16-
* send a given request body to a given endpoint throw a given route.
15+
* Gerencianet API. After client's credentials
16+
* are validated a client Object send a given request body to a given endpoint
17+
* throw a given route.
1718
*
1819
* @author Filipe Mata
1920
*
@@ -24,10 +25,10 @@ public class APIRequest {
2425
private String route;
2526
private JSONObject body;
2627

27-
public APIRequest(String method, String route, JSONObject body, Config config) throws Exception {
28+
public APIRequest(String method, String route, JSONObject body, JSONObject auth, Config config) throws Exception {
2829
this.route = route;
29-
String authenticateRoute = config.getEndpoints().getJSONObject("authorize").getString("route");
30-
String authenticateMethod = config.getEndpoints().getJSONObject("authorize").getString("method");
30+
String authenticateRoute = auth.getString("route");
31+
String authenticateMethod = auth.getString("method");
3132
this.authenticator = new Auth(config.getOptions(), authenticateMethod, authenticateRoute);
3233

3334
String url = config.getOptions().getString("baseUri") + route;
@@ -42,6 +43,7 @@ public APIRequest(String method, String route, JSONObject body, Config config) t
4243

4344
if (config.getOptions().has("headers")) {
4445
this.requester.addHeader("x-skip-mtls-checking", config.getOptions().getString("headers"));
46+
this.requester.addHeader("x-idempotency-key", config.getOptions().getString("headers"));
4547
}
4648

4749
this.body = body;
@@ -56,10 +58,8 @@ public APIRequest(Auth auth, Request request, JSONObject body) {
5658
public JSONObject send() throws AuthorizationException, GerencianetException, IOException {
5759
Date expiredDate = this.authenticator.getExpires();
5860
if (this.authenticator.getExpires() == null || expiredDate.compareTo(new Date()) <= 0) {
59-
6061
this.authenticator.authorize();
6162
}
62-
6363
this.requester.addHeader("Authorization", "Bearer " + this.authenticator.getAccessToken());
6464
try {
6565
return this.requester.send(this.body);
@@ -69,6 +69,20 @@ public JSONObject send() throws AuthorizationException, GerencianetException, IO
6969
}
7070
}
7171

72+
public String sendString() throws AuthorizationException, GerencianetException, IOException {
73+
Date expiredDate = this.authenticator.getExpires();
74+
if (this.authenticator.getExpires() == null || expiredDate.compareTo(new Date()) <= 0) {
75+
this.authenticator.authorize();
76+
}
77+
this.requester.addHeader("Authorization", "Bearer " + this.authenticator.getAccessToken());
78+
try {
79+
return this.requester.sendString(this.body);
80+
} catch (AuthorizationException e) {
81+
this.authenticator.authorize();
82+
return this.requester.sendString(body);
83+
}
84+
}
85+
7286
public Request getRequester() {
7387
return requester;
7488
}

src/main/java/br/com/gerencianet/gnsdk/Auth.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public Auth(JSONObject credentials, String method, String authorizeRoute) throws
3131
throw new Exception("Client_Id or Client_Secret not found");
3232
}
3333

34-
if (credentials.has("certificadoPix")) {
35-
System.setProperty("javax.net.ssl.keyStore", credentials.getString("certificadoPix"));
34+
if (credentials.has("certificate")) {
35+
System.setProperty("javax.net.ssl.keyStore", credentials.getString("certificate"));
3636
}
3737

3838
String url = credentials.getString("baseUri") + authorizeRoute;

src/main/java/br/com/gerencianet/gnsdk/Config.java

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,19 @@
1111
*
1212
*/
1313
public class Config {
14-
private final static String version = "1.0.2";
14+
private final static String version = "2.0.0";
1515
private JSONObject conf = new JSONObject();
1616
private JSONObject endpoints = new JSONObject();
1717
private JSONObject urls = new JSONObject();
18+
private JSONObject options = new JSONObject();
1819

1920
public Config(JSONObject options, JSONObject config) throws Exception {
20-
21-
if (config.has("ENDPOINTS")) {
22-
this.endpoints = (JSONObject) config.get("ENDPOINTS");
23-
if (setPix(options)) {
24-
if (this.endpoints.has("PIX")) {
25-
this.endpoints = (JSONObject) this.endpoints.get("PIX");
26-
}
27-
} else {
28-
if (this.endpoints.has("DEFAULT")) {
29-
this.endpoints = (JSONObject) this.endpoints.get("DEFAULT");
30-
}
31-
}
32-
} else
33-
throw new Exception("Problems to get ENDPOINTS in file config.json");
34-
35-
if (config.has("URL")) {
36-
this.urls = (JSONObject) config.get("URL");
37-
if (setPix(options)) {
38-
if (this.urls.has("PIX")) {
39-
this.urls = (JSONObject) this.urls.get("PIX");
40-
}
41-
} else if (this.urls.has("DEFAULT")) {
42-
this.urls = (JSONObject) this.urls.get("DEFAULT");
43-
}
44-
} else
45-
throw new Exception("Problems to get URLs in file config.json");
46-
47-
this.setConf(options);
21+
this.endpoints = config;
22+
this.options = options;
4823
}
4924

5025
public JSONObject getEndpoints() {
51-
return endpoints;
26+
return (JSONObject)endpoints.get("APIs");
5227
}
5328

5429
public JSONObject getUrls() {
@@ -71,15 +46,13 @@ public void setConf(JSONObject options) {
7146
this.conf.put("clientId", options.getString("client_id"));
7247
if (options.has("client_secret"))
7348
this.conf.put("clientSecret", options.getString("client_secret"));
74-
if (options.has("pix_cert"))
75-
this.conf.put("certificadoPix", options.getString("pix_cert"));
49+
if (options.has("certificate"))
50+
this.conf.put("certificate", options.getString("certificate"));
7651
if (options.has("partner_token"))
7752
this.conf.put("partnerToken", options.getString("partner_token"));
7853
if (options.has("url")) {
7954
this.conf.put("baseUri", options.getString("url"));
80-
}
81-
82-
else {
55+
} else {
8356
String baseUri = this.urls.getString("production");
8457
if (this.conf.getBoolean("sandbox") == true)
8558
baseUri = this.urls.getString("sandbox");
@@ -90,6 +63,10 @@ public void setConf(JSONObject options) {
9063
if (options.has("x-skip-mtls-checking")) {
9164
this.conf.put("headers", options.getString("x-skip-mtls-checking"));
9265
}
66+
67+
if (options.has("x-idempotency-key")) {
68+
this.conf.put("headers", options.getString("x-idempotency-key"));
69+
}
9370
}
9471

9572
public JSONObject getOptions() {
@@ -100,8 +77,9 @@ public static String getVersion() {
10077
return Config.version;
10178
}
10279

103-
public boolean setPix(JSONObject options) {
104-
return options.has("pix_cert");
80+
public void setURLs(JSONObject parURLs) {
81+
this.urls = parURLs;
82+
this.setConf(this.options);
10583
}
10684

10785
}

0 commit comments

Comments
 (0)