Skip to content

Commit 7c5731c

Browse files
Added Statements API endpoints
1 parent b35c52e commit 7c5731c

File tree

10 files changed

+541
-352
lines changed

10 files changed

+541
-352
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
# 1.2.2
2+
3+
- Added Statements API endpoints and examples
4+
- Added endpoint and example to resend Pix webhook
5+
- Added a new endpoint to Replace recurring payment parcel - Open Finance
6+
- Pix sending route updated to v3
7+
18
# 1.2.1
29

3-
- Added new endpoints for Pix API through Open Finance (Scheduled payments and Recurent payments)
10+
- Added new endpoints for Pix API through Open Finance (Scheduled payments and Recurrent payments)
411
- Added a new endpoint to list charges
512
- Added a new endpoint for modify subscription data
613

README-en.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ For more informations about [parameters](http://dev.sejaefi.com.br) and [values]
2222
**Via gradle:**
2323

2424
```gradle
25-
implementation 'br.com.efipay.efisdk:sdk-java-apis-efi:1.2.1'
25+
implementation 'br.com.efipay.efisdk:sdk-java-apis-efi:1.2.2'
2626
```
2727

2828
**Via maven:**
@@ -31,7 +31,7 @@ implementation 'br.com.efipay.efisdk:sdk-java-apis-efi:1.2.1'
3131
<dependency>
3232
    <groupId>br.com.efipay.efisdk</groupId>
3333
<artifactId>sdk-java-apis-efi</artifactId>
34-
<version>1.2.1</version>
34+
<version>1.2.2</version>
3535
</dependency>
3636
```
3737

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Para mais informações sobre [parâmetros](http://sejaefi.com.br/api) e [valore
2323
**Via gradle:**
2424

2525
```gradle
26-
implementation 'br.com.efipay.efisdk:sdk-java-apis-efi:1.2.1'
26+
implementation 'br.com.efipay.efisdk:sdk-java-apis-efi:1.2.2'
2727
```
2828

2929
**Via maven:**
@@ -32,7 +32,7 @@ implementation 'br.com.efipay.efisdk:sdk-java-apis-efi:1.2.1'
3232
<dependency>
3333
<groupId>br.com.efipay.efisdk</groupId>
3434
<artifactId>sdk-java-apis-efi</artifactId>
35-
<version>1.2.1</version>
35+
<version>1.2.2</version>
3636
</dependency>
3737
```
3838

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>br.com.efipay.efisdk</groupId>
55
<artifactId>sdk-java-apis-efi</artifactId>
6-
<version>1.2.1</version>
6+
<version>1.2.2</version>
77

88
<name>SDK JAVA APIS EFI</name>
99
<description>Java SDK for integrating with Efí API</description>

src/main/java/br/com/efi/efisdk/APIRequest.java

Lines changed: 105 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -5,93 +5,119 @@
55
import java.net.URL;
66
import java.util.Date;
77

8+
import org.json.JSONArray;
89
import org.json.JSONObject;
910

1011
import br.com.efi.efisdk.exceptions.AuthorizationException;
1112
import br.com.efi.efisdk.exceptions.EfiPayException;
1213

1314
/**
14-
* This class instance a Auth Object, to authenticate client credentials in
15-
* efi 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.
18-
*
15+
* This class instance a Auth Object, to authenticate client credentials in efi
16+
* API. After client's credentials are validated a client Object send a given
17+
* request body to a given endpoint throw a given route.
18+
*
1919
* @author Consultoria Técnica
2020
*
2121
*/
2222
public class APIRequest {
23-
private Request requester;
24-
private Auth authenticator;
25-
private String route;
26-
private JSONObject body;
27-
28-
public APIRequest(String method, String route, JSONObject body, JSONObject auth, Config config) throws Exception {
29-
this.route = route;
30-
String authenticateRoute = auth.getString("route");
31-
String authenticateMethod = auth.getString("method");
32-
this.authenticator = new Auth(config.getOptions(), authenticateMethod, authenticateRoute);
33-
34-
String url = config.getOptions().getString("baseUri") + route;
35-
URL link = new URL(url);
36-
HttpURLConnection client = (HttpURLConnection) link.openConnection();
37-
38-
this.requester = new Request(method, client);
39-
40-
if (config.getOptions().has("partnerToken")) {
41-
this.requester.addHeader("partner-token", config.getOptions().getString("partnerToken"));
42-
}
43-
44-
if (config.getOptions().has("headers")) {
45-
this.requester.addHeader("x-skip-mtls-checking", config.getOptions().getString("headers"));
46-
this.requester.addHeader("x-idempotency-key", config.getOptions().getString("headers"));
47-
}
48-
49-
this.body = body;
50-
}
51-
52-
public APIRequest(Auth auth, Request request, JSONObject body) {
53-
this.authenticator = auth;
54-
this.requester = request;
55-
this.body = body;
56-
}
57-
58-
public JSONObject send() throws AuthorizationException, EfiPayException, IOException {
59-
Date expiredDate = this.authenticator.getExpires();
60-
if (this.authenticator.getExpires() == null || expiredDate.compareTo(new Date()) <= 0) {
61-
this.authenticator.authorize();
62-
}
63-
this.requester.addHeader("Authorization", "Bearer " + this.authenticator.getAccessToken());
64-
try {
65-
return this.requester.send(this.body);
66-
} catch (AuthorizationException e) {
67-
this.authenticator.authorize();
68-
return this.requester.send(body);
69-
}
70-
}
71-
72-
public String sendString() throws AuthorizationException, EfiPayException, 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-
86-
public Request getRequester() {
87-
return requester;
88-
}
89-
90-
public String getRoute() {
91-
return route;
92-
}
93-
94-
public JSONObject getBody() {
95-
return body;
96-
}
23+
24+
private Request requester;
25+
private Auth authenticator;
26+
private String route;
27+
private JSONObject body;
28+
private JSONArray bodyArray;
29+
30+
public APIRequest(String method, String route, JSONObject body, JSONObject auth, Config config) throws Exception {
31+
this.route = route;
32+
String authenticateRoute = auth.getString("route");
33+
String authenticateMethod = auth.getString("method");
34+
this.authenticator = new Auth(config.getOptions(), authenticateMethod, authenticateRoute);
35+
36+
String url = config.getOptions().getString("baseUri") + route;
37+
URL link = new URL(url);
38+
HttpURLConnection client = (HttpURLConnection) link.openConnection();
39+
40+
this.requester = new Request(method, client);
41+
42+
if (config.getOptions().has("partnerToken")) {
43+
this.requester.addHeader("partner-token", config.getOptions().getString("partnerToken"));
44+
}
45+
46+
if (config.getOptions().has("headers")) {
47+
this.requester.addHeader("x-skip-mtls-checking", config.getOptions().getString("headers"));
48+
this.requester.addHeader("x-idempotency-key", config.getOptions().getString("headers"));
49+
}
50+
51+
this.body = body;
52+
}
53+
54+
public APIRequest(String method, String route, JSONArray bodyArray, JSONObject auth, Config config) throws Exception {
55+
this.route = route;
56+
String authenticateRoute = auth.getString("route");
57+
String authenticateMethod = auth.getString("method");
58+
this.authenticator = new Auth(config.getOptions(), authenticateMethod, authenticateRoute);
59+
60+
String url = config.getOptions().getString("baseUri") + route;
61+
URL link = new URL(url);
62+
HttpURLConnection client = (HttpURLConnection) link.openConnection();
63+
64+
this.requester = new Request(method, client);
65+
this.bodyArray = bodyArray;
66+
}
67+
68+
public APIRequest(Auth auth, Request request, JSONObject body) {
69+
this.authenticator = auth;
70+
this.requester = request;
71+
this.body = body;
72+
}
73+
74+
public JSONObject send() throws AuthorizationException, EfiPayException, IOException {
75+
Date expiredDate = this.authenticator.getExpires();
76+
if (this.authenticator.getExpires() == null || expiredDate.compareTo(new Date()) <= 0) {
77+
this.authenticator.authorize();
78+
}
79+
this.requester.addHeader("Authorization", "Bearer " + this.authenticator.getAccessToken());
80+
try {
81+
return this.requester.send(this.body);
82+
} catch (AuthorizationException e) {
83+
this.authenticator.authorize();
84+
return this.requester.send(body);
85+
}
86+
}
87+
88+
public String sendString() throws AuthorizationException, EfiPayException, IOException {
89+
Date expiredDate = this.authenticator.getExpires();
90+
if (this.authenticator.getExpires() == null || expiredDate.compareTo(new Date()) <= 0) {
91+
this.authenticator.authorize();
92+
}
93+
this.requester.addHeader("Authorization", "Bearer " + this.authenticator.getAccessToken());
94+
try {
95+
return this.requester.sendString(this.body);
96+
} catch (AuthorizationException e) {
97+
this.authenticator.authorize();
98+
return this.requester.sendString(body);
99+
}
100+
}
101+
102+
public JSONArray sendArray() throws AuthorizationException, EfiPayException, IOException {
103+
Date expiredDate = this.authenticator.getExpires();
104+
if (this.authenticator.getExpires() == null || expiredDate.compareTo(new Date()) <= 0) {
105+
this.authenticator.authorize();
106+
}
107+
this.requester.addHeader("Authorization", "Bearer " + this.authenticator.getAccessToken());
108+
109+
return this.requester.sendArray(this.bodyArray);
110+
}
111+
112+
public Request getRequester() {
113+
return requester;
114+
}
115+
116+
public String getRoute() {
117+
return route;
118+
}
119+
120+
public JSONObject getBody() {
121+
return body;
122+
}
97123
}

src/main/java/br/com/efi/efisdk/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*/
1313
public class Config {
14-
private final static String version = "1.2.1";
14+
private final static String version = "1.2.2";
1515
private JSONObject conf = new JSONObject();
1616
private JSONObject endpoints = new JSONObject();
1717
private JSONObject urls = new JSONObject();

0 commit comments

Comments
 (0)