Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit e81bd7c

Browse files
authored
[RELEASE] v1.0.0-beta
1 parent 19315a2 commit e81bd7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+5498
-83
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# moip-sdk-java-2
1+
# moip-sdk-java
22

33
<img src="https://user-images.githubusercontent.com/32847427/42348249-1e007adc-807f-11e8-975f-5075ec3b13ab.png" align="left" />

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apply plugin: 'signing'
44

55
group 'br.com.moip'
66
archivesBaseName = "sdk-java"
7-
version '0.1.0'
7+
version '1.0.0-beta'
88

99
description = "Java SDK for Moip APIs integration"
1010

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,66 @@
11
package br.com.moip.api;
22

3-
import br.com.moip.models.Customer;
4-
import br.com.moip.models.Order;
5-
import br.com.moip.models.Payment;
6-
import br.com.moip.models.Refund;
7-
import br.com.moip.models.NotificationPreference;
8-
import br.com.moip.models.Webhook;
3+
import br.com.moip.models.Customers;
4+
import br.com.moip.models.Orders;
5+
import br.com.moip.models.Payments;
6+
import br.com.moip.models.Refunds;
7+
import br.com.moip.models.NotificationPreferences;
8+
import br.com.moip.models.Webhooks;
9+
import br.com.moip.models.Accounts;
10+
import br.com.moip.models.Connect;
11+
import br.com.moip.models.Multiorders;
12+
import br.com.moip.models.Multipayments;
13+
import br.com.moip.models.BankAccounts;
14+
import br.com.moip.models.Balances;
15+
import br.com.moip.models.Entries;
16+
import br.com.moip.models.Transfers;
17+
import br.com.moip.models.Escrows;
918

1019
public class APIResources {
1120

12-
private static Customer customerInstance = new Customer();
13-
private static Order orderInstance = new Order();
14-
private static Payment paymentInstance = new Payment();
15-
private static Refund refundInstance = new Refund();
16-
private static NotificationPreference notificationPreferenceInstance = new NotificationPreference();
17-
private static Webhook webhookInstance = new Webhook();
21+
private static Customers customerInstance = new Customers();
22+
private static Orders orderInstance = new Orders();
23+
private static Payments paymentInstance = new Payments();
24+
private static Refunds refundInstance = new Refunds();
25+
private static NotificationPreferences notificationPreferenceInstance = new NotificationPreferences();
26+
private static Webhooks webhookInstance = new Webhooks();
27+
private static Accounts accountInstance = new Accounts();
28+
private static Connect connectInstance = new Connect();
29+
private static Multiorders multiorderInstance = new Multiorders();
30+
private static Multipayments multipaymentsInstance = new Multipayments();
31+
private static BankAccounts bankAccountsInstance = new BankAccounts();
32+
private static Balances balancesInstance = new Balances();
33+
private static Entries entriesInstance = new Entries();
34+
private static Transfers transfersInstance = new Transfers();
35+
private static Escrows escrowsInstance = new Escrows();
1836

19-
/**
20-
* This method is used to get a instance of customer object.
21-
*
22-
* @return {@code Customer}
23-
*/
24-
public static Customer customers() { return customerInstance; }
37+
public static Customers customers() { return customerInstance; }
2538

26-
public static Order orders() { return orderInstance; }
39+
public static Orders orders() { return orderInstance; }
2740

28-
public static Payment payments() { return paymentInstance; }
41+
public static Payments payments() { return paymentInstance; }
2942

30-
public static Refund refunds() { return refundInstance; }
43+
public static Refunds refunds() { return refundInstance; }
3144

32-
public static NotificationPreference notificationPreferences() { return notificationPreferenceInstance; }
45+
public static NotificationPreferences notificationPreferences() { return notificationPreferenceInstance; }
3346

34-
public static Webhook webhooks() { return webhookInstance; }
47+
public static Webhooks webhooks() { return webhookInstance; }
48+
49+
public static Accounts accounts() { return accountInstance; }
50+
51+
public static Connect connect() { return connectInstance; }
52+
53+
public static Multiorders multiorders() { return multiorderInstance; }
54+
55+
public static Multipayments multipayments() { return multipaymentsInstance; }
56+
57+
public static BankAccounts bankAccounts() { return bankAccountsInstance; }
58+
59+
public static Balances balances() { return balancesInstance; }
60+
61+
public static Entries entries() { return entriesInstance; }
62+
63+
public static Transfers transfers() { return transfersInstance; }
64+
65+
public static Escrows escrows() { return escrowsInstance; }
3566
}

src/main/java/br/com/moip/api/request/RequestMaker.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ public Map<String, Object> doRequest(final RequestProperties requestProps) {
9292
LOGGER.debug("---> {} {}", requestProps.method, connection.getURL().toString());
9393
logHeaders(connection.getRequestProperties().entrySet());
9494

95-
// Verificar essa parte do código, pois o objeto serializado deve ser um Map, não mais um String
96-
9795
if (requestProps.body != null) {
9896
connection.setDoOutput(true);
9997
String body = tools.getBody(requestProps.body, requestProps.contentType);
@@ -108,8 +106,6 @@ public Map<String, Object> doRequest(final RequestProperties requestProps) {
108106
wr.close();
109107
}
110108

111-
// ----------------------------------------------------------------------------------------------
112-
113109
LOGGER.debug("---> END HTTP");
114110

115111
int responseCode = connection.getResponseCode();

src/main/java/br/com/moip/api/response/Response.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ public class Response extends HashMap<String, Object> {
2323
* @return {@code Map}
2424
*/
2525
public Map<String, Object> jsonToMap(String json) {
26+
27+
/*
28+
* This if block treats the /v2/accounts/exists response. Currently the endpoint returns the status
29+
* code on its response body, breaking the JSON conversion.
30+
*/
31+
if ("200".equals(json)) {
32+
this.responseBody.put("code", 200);
33+
return this.responseBody;
34+
}
35+
36+
if ("400".equals(json)) {
37+
this.responseBody.put("code", 400);
38+
return this.responseBody;
39+
}
40+
41+
if ("404".equals(json)) {
42+
this.responseBody.put("code", 404);
43+
return this.responseBody;
44+
}
45+
2646
if (!json.equals("")) {
2747
ObjectMapper mapper = new ObjectMapper();
2848
try {
@@ -49,11 +69,3 @@ public List<Map<String, Object>> jsonToList(String json) {
4969
return this.responseBodyList;
5070
}
5171
}
52-
53-
/* Este método resolve grande parte do problema, porém não resolve o problema por completo.
54-
* Precisamos fazer com que cada nó do JSON se converta em um objeto do seu respectivo model.
55-
* Ex: o nó "taxDocument" precisa ser convertido em um objeto da classe TaxDocument.
56-
*
57-
* Talvez seja possível trabalhar com o [type], o atributo da classe RequestProperties, que tem
58-
* como objetivo indicar a qual classe/model aquele objeto pertence.
59-
*/
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
package br.com.moip.models;
2+
3+
import br.com.moip.api.request.RequestMaker;
4+
import br.com.moip.api.request.RequestProperties;
5+
import br.com.moip.api.request.RequestPropertiesBuilder;
6+
import org.apache.http.entity.ContentType;
7+
8+
import java.util.List;
9+
import java.util.Map;
10+
11+
public class Accounts {
12+
13+
private static final String ENDPOINT = "/v2/accounts";
14+
private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON;
15+
private RequestMaker requestMaker;
16+
17+
/**
18+
* This method is used to validate the argument of bellow method, if probably it's a tax document or not.
19+
*
20+
* @param argument
21+
* {@code String} the received argument.
22+
*
23+
* @return {@code boolean}
24+
*/
25+
private boolean isTaxDocument(String argument) {
26+
try {
27+
Integer.parseInt(argument.substring(0,1));
28+
} catch (Exception ex) {
29+
return false;
30+
}
31+
return true;
32+
}
33+
34+
/**
35+
* This method allows you to check if a person already has a Moip account, by it's tax document or e-mail.
36+
* The tax document must be write with punctuation, for example: 123.456.789-00.
37+
*
38+
* @param argument
39+
* {@code String} the person's tax document or e-mail.
40+
*
41+
* @param setup
42+
* {@code Setup} the setup object.
43+
*
44+
* @return {@code Map<String, Object>}
45+
*/
46+
public Map<String, Object> checkExistence(String argument, Setup setup) {
47+
this.requestMaker = new RequestMaker(setup);
48+
String argumentType;
49+
50+
if (isTaxDocument(argument)) argumentType = "tax_document";
51+
52+
else argumentType = "email";
53+
54+
RequestProperties props = new RequestPropertiesBuilder()
55+
.method("GET")
56+
.endpoint(String.format("%s/exists?%s=%s", ENDPOINT, argumentType, argument))
57+
.type(Accounts.class)
58+
.contentType(CONTENT_TYPE)
59+
.build();
60+
61+
return this.requestMaker.doRequest(props);
62+
}
63+
64+
/**
65+
* This method allows you to create a Moip account (classical or transparent). To differentiate the
66+
* two accounts types you have to set the boolean attribute {@code transparentAccount}, <b>true</b> value
67+
* (you will create a transparent accounts) or <b>false</b> value (you will create a classical accounts).
68+
*
69+
* @param body
70+
* {@code Map<String, Object>} the request body.
71+
*
72+
* @param setup
73+
* {@code Setup} the setup object.
74+
*
75+
* @return {@code Map<String, Object>}
76+
*/
77+
public Map<String, Object> create(Map<String, Object> body, Setup setup) {
78+
this.requestMaker = new RequestMaker(setup);
79+
RequestProperties props = new RequestPropertiesBuilder()
80+
.method("POST")
81+
.endpoint(ENDPOINT)
82+
.body(body)
83+
.type(Accounts.class)
84+
.contentType(CONTENT_TYPE)
85+
.build();
86+
87+
return this.requestMaker.doRequest(props);
88+
}
89+
90+
/**
91+
* This method is used to get a created accounts by Moip account external ID.
92+
*
93+
* @param id
94+
* {@code String} the Moip account external ID.
95+
*
96+
* @param setup
97+
* {@code Setup} the setup object.
98+
*
99+
* @return {@code Map<String, Object>}
100+
*/
101+
public Map<String, Object> get(String id, Setup setup) {
102+
this.requestMaker = new RequestMaker(setup);
103+
RequestProperties props = new RequestPropertiesBuilder()
104+
.method("GET")
105+
.endpoint(String.format("%s/%s", ENDPOINT, id))
106+
.type(Accounts.class)
107+
.contentType(CONTENT_TYPE)
108+
.build();
109+
110+
return this.requestMaker.doRequest(props);
111+
}
112+
113+
/**
114+
* This method is used to get the Basic Auth keys and the public key of a Moip account.
115+
*
116+
* @param setup
117+
* {@code Setup} the setup object.
118+
*
119+
* @return {@code Map<String, Object>}
120+
*/
121+
public Map<String, Object> getKeys(Setup setup) {
122+
this.requestMaker = new RequestMaker(setup);
123+
RequestProperties props = new RequestPropertiesBuilder()
124+
.method("GET")
125+
.endpoint("/v2/keys")
126+
.type(Accounts.class)
127+
.contentType(CONTENT_TYPE)
128+
.build();
129+
130+
return this.requestMaker.doRequest(props);
131+
}
132+
133+
/**
134+
* This method allows you to create a bank account to a Moip account. You can use a bank account to make
135+
* transfers and refunds on Moip.
136+
*
137+
* @param body
138+
* {@code Map<String, Object>} the request body.
139+
*
140+
* @param moipAccountId
141+
* {@code String} the Moip account external ID.
142+
*
143+
* @param setup
144+
* {@code Setup} the setup object.
145+
*
146+
* @return {@code Map<String, Object>}
147+
*/
148+
public Map<String, Object> createBankAccount(Map<String, Object> body, String moipAccountId, Setup setup) {
149+
this.requestMaker = new RequestMaker(setup);
150+
RequestProperties props = new RequestPropertiesBuilder()
151+
.method("POST")
152+
.endpoint(String.format("%s/%s/bankaccounts", ENDPOINT, moipAccountId))
153+
.body(body)
154+
.type(Accounts.class)
155+
.contentType(CONTENT_TYPE)
156+
.build();
157+
158+
return this.requestMaker.doRequest(props);
159+
}
160+
161+
/**
162+
* This method allows you to list all bank account of a Moip account.
163+
*
164+
* @param moipAccountId
165+
* {@code String} the Moip account external ID.
166+
*
167+
* @param setup
168+
* {@code Setup} the setup object.
169+
*
170+
* @return {@code Map<String, Object>}
171+
*/
172+
public List<Map<String, Object>> listBankAccounts(String moipAccountId, Setup setup) {
173+
this.requestMaker = new RequestMaker(setup);
174+
RequestProperties props = new RequestPropertiesBuilder()
175+
.method("GET")
176+
.endpoint(String.format("%s/%s/bankaccounts", ENDPOINT, moipAccountId))
177+
.type(BankAccounts.class)
178+
.contentType(CONTENT_TYPE)
179+
.build();
180+
181+
return this.requestMaker.getList(props);
182+
}
183+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package br.com.moip.models;
2+
3+
import br.com.moip.api.request.RequestMaker;
4+
import br.com.moip.api.request.RequestProperties;
5+
import br.com.moip.api.request.RequestPropertiesBuilder;
6+
import org.apache.http.entity.ContentType;
7+
8+
import java.util.Map;
9+
10+
public class Balances {
11+
12+
private static final String ENDPOINT = "/v2/balances";
13+
private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON;
14+
private RequestMaker requestMaker;
15+
16+
/**
17+
* This method is used to get the balances values of a Moip account (unavailable, future, current). The
18+
* request uses the accept version {@code 2.1}.
19+
*
20+
* @param setup
21+
* {@code Setup} the setup object.
22+
*
23+
* @return {@code Map<String, Object>}
24+
*/
25+
public Map<String, Object> get(Setup setup) {
26+
this.requestMaker = new RequestMaker(setup);
27+
RequestProperties props = new RequestPropertiesBuilder()
28+
.method("GET")
29+
.endpoint(ENDPOINT)
30+
.type(Balances.class)
31+
.contentType(CONTENT_TYPE)
32+
.accept("2.1")
33+
.build();
34+
35+
return this.requestMaker.doRequest(props);
36+
}
37+
}

0 commit comments

Comments
 (0)