This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
5,498 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# moip-sdk-java-2 | ||
# moip-sdk-java | ||
|
||
<img src="https://user-images.githubusercontent.com/32847427/42348249-1e007adc-807f-11e8-975f-5075ec3b13ab.png" align="left" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,66 @@ | ||
package br.com.moip.api; | ||
|
||
import br.com.moip.models.Customer; | ||
import br.com.moip.models.Order; | ||
import br.com.moip.models.Payment; | ||
import br.com.moip.models.Refund; | ||
import br.com.moip.models.NotificationPreference; | ||
import br.com.moip.models.Webhook; | ||
import br.com.moip.models.Customers; | ||
import br.com.moip.models.Orders; | ||
import br.com.moip.models.Payments; | ||
import br.com.moip.models.Refunds; | ||
import br.com.moip.models.NotificationPreferences; | ||
import br.com.moip.models.Webhooks; | ||
import br.com.moip.models.Accounts; | ||
import br.com.moip.models.Connect; | ||
import br.com.moip.models.Multiorders; | ||
import br.com.moip.models.Multipayments; | ||
import br.com.moip.models.BankAccounts; | ||
import br.com.moip.models.Balances; | ||
import br.com.moip.models.Entries; | ||
import br.com.moip.models.Transfers; | ||
import br.com.moip.models.Escrows; | ||
|
||
public class APIResources { | ||
|
||
private static Customer customerInstance = new Customer(); | ||
private static Order orderInstance = new Order(); | ||
private static Payment paymentInstance = new Payment(); | ||
private static Refund refundInstance = new Refund(); | ||
private static NotificationPreference notificationPreferenceInstance = new NotificationPreference(); | ||
private static Webhook webhookInstance = new Webhook(); | ||
private static Customers customerInstance = new Customers(); | ||
private static Orders orderInstance = new Orders(); | ||
private static Payments paymentInstance = new Payments(); | ||
private static Refunds refundInstance = new Refunds(); | ||
private static NotificationPreferences notificationPreferenceInstance = new NotificationPreferences(); | ||
private static Webhooks webhookInstance = new Webhooks(); | ||
private static Accounts accountInstance = new Accounts(); | ||
private static Connect connectInstance = new Connect(); | ||
private static Multiorders multiorderInstance = new Multiorders(); | ||
private static Multipayments multipaymentsInstance = new Multipayments(); | ||
private static BankAccounts bankAccountsInstance = new BankAccounts(); | ||
private static Balances balancesInstance = new Balances(); | ||
private static Entries entriesInstance = new Entries(); | ||
private static Transfers transfersInstance = new Transfers(); | ||
private static Escrows escrowsInstance = new Escrows(); | ||
|
||
/** | ||
* This method is used to get a instance of customer object. | ||
* | ||
* @return {@code Customer} | ||
*/ | ||
public static Customer customers() { return customerInstance; } | ||
public static Customers customers() { return customerInstance; } | ||
|
||
public static Order orders() { return orderInstance; } | ||
public static Orders orders() { return orderInstance; } | ||
|
||
public static Payment payments() { return paymentInstance; } | ||
public static Payments payments() { return paymentInstance; } | ||
|
||
public static Refund refunds() { return refundInstance; } | ||
public static Refunds refunds() { return refundInstance; } | ||
|
||
public static NotificationPreference notificationPreferences() { return notificationPreferenceInstance; } | ||
public static NotificationPreferences notificationPreferences() { return notificationPreferenceInstance; } | ||
|
||
public static Webhook webhooks() { return webhookInstance; } | ||
public static Webhooks webhooks() { return webhookInstance; } | ||
|
||
public static Accounts accounts() { return accountInstance; } | ||
|
||
public static Connect connect() { return connectInstance; } | ||
|
||
public static Multiorders multiorders() { return multiorderInstance; } | ||
|
||
public static Multipayments multipayments() { return multipaymentsInstance; } | ||
|
||
public static BankAccounts bankAccounts() { return bankAccountsInstance; } | ||
|
||
public static Balances balances() { return balancesInstance; } | ||
|
||
public static Entries entries() { return entriesInstance; } | ||
|
||
public static Transfers transfers() { return transfersInstance; } | ||
|
||
public static Escrows escrows() { return escrowsInstance; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
package br.com.moip.models; | ||
|
||
import br.com.moip.api.request.RequestMaker; | ||
import br.com.moip.api.request.RequestProperties; | ||
import br.com.moip.api.request.RequestPropertiesBuilder; | ||
import org.apache.http.entity.ContentType; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class Accounts { | ||
|
||
private static final String ENDPOINT = "/v2/accounts"; | ||
private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; | ||
private RequestMaker requestMaker; | ||
|
||
/** | ||
* This method is used to validate the argument of bellow method, if probably it's a tax document or not. | ||
* | ||
* @param argument | ||
* {@code String} the received argument. | ||
* | ||
* @return {@code boolean} | ||
*/ | ||
private boolean isTaxDocument(String argument) { | ||
try { | ||
Integer.parseInt(argument.substring(0,1)); | ||
} catch (Exception ex) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* This method allows you to check if a person already has a Moip account, by it's tax document or e-mail. | ||
* The tax document must be write with punctuation, for example: 123.456.789-00. | ||
* | ||
* @param argument | ||
* {@code String} the person's tax document or e-mail. | ||
* | ||
* @param setup | ||
* {@code Setup} the setup object. | ||
* | ||
* @return {@code Map<String, Object>} | ||
*/ | ||
public Map<String, Object> checkExistence(String argument, Setup setup) { | ||
this.requestMaker = new RequestMaker(setup); | ||
String argumentType; | ||
|
||
if (isTaxDocument(argument)) argumentType = "tax_document"; | ||
|
||
else argumentType = "email"; | ||
|
||
RequestProperties props = new RequestPropertiesBuilder() | ||
.method("GET") | ||
.endpoint(String.format("%s/exists?%s=%s", ENDPOINT, argumentType, argument)) | ||
.type(Accounts.class) | ||
.contentType(CONTENT_TYPE) | ||
.build(); | ||
|
||
return this.requestMaker.doRequest(props); | ||
} | ||
|
||
/** | ||
* This method allows you to create a Moip account (classical or transparent). To differentiate the | ||
* two accounts types you have to set the boolean attribute {@code transparentAccount}, <b>true</b> value | ||
* (you will create a transparent accounts) or <b>false</b> value (you will create a classical accounts). | ||
* | ||
* @param body | ||
* {@code Map<String, Object>} the request body. | ||
* | ||
* @param setup | ||
* {@code Setup} the setup object. | ||
* | ||
* @return {@code Map<String, Object>} | ||
*/ | ||
public Map<String, Object> create(Map<String, Object> body, Setup setup) { | ||
this.requestMaker = new RequestMaker(setup); | ||
RequestProperties props = new RequestPropertiesBuilder() | ||
.method("POST") | ||
.endpoint(ENDPOINT) | ||
.body(body) | ||
.type(Accounts.class) | ||
.contentType(CONTENT_TYPE) | ||
.build(); | ||
|
||
return this.requestMaker.doRequest(props); | ||
} | ||
|
||
/** | ||
* This method is used to get a created accounts by Moip account external ID. | ||
* | ||
* @param id | ||
* {@code String} the Moip account external ID. | ||
* | ||
* @param setup | ||
* {@code Setup} the setup object. | ||
* | ||
* @return {@code Map<String, Object>} | ||
*/ | ||
public Map<String, Object> get(String id, Setup setup) { | ||
this.requestMaker = new RequestMaker(setup); | ||
RequestProperties props = new RequestPropertiesBuilder() | ||
.method("GET") | ||
.endpoint(String.format("%s/%s", ENDPOINT, id)) | ||
.type(Accounts.class) | ||
.contentType(CONTENT_TYPE) | ||
.build(); | ||
|
||
return this.requestMaker.doRequest(props); | ||
} | ||
|
||
/** | ||
* This method is used to get the Basic Auth keys and the public key of a Moip account. | ||
* | ||
* @param setup | ||
* {@code Setup} the setup object. | ||
* | ||
* @return {@code Map<String, Object>} | ||
*/ | ||
public Map<String, Object> getKeys(Setup setup) { | ||
this.requestMaker = new RequestMaker(setup); | ||
RequestProperties props = new RequestPropertiesBuilder() | ||
.method("GET") | ||
.endpoint("/v2/keys") | ||
.type(Accounts.class) | ||
.contentType(CONTENT_TYPE) | ||
.build(); | ||
|
||
return this.requestMaker.doRequest(props); | ||
} | ||
|
||
/** | ||
* This method allows you to create a bank account to a Moip account. You can use a bank account to make | ||
* transfers and refunds on Moip. | ||
* | ||
* @param body | ||
* {@code Map<String, Object>} the request body. | ||
* | ||
* @param moipAccountId | ||
* {@code String} the Moip account external ID. | ||
* | ||
* @param setup | ||
* {@code Setup} the setup object. | ||
* | ||
* @return {@code Map<String, Object>} | ||
*/ | ||
public Map<String, Object> createBankAccount(Map<String, Object> body, String moipAccountId, Setup setup) { | ||
this.requestMaker = new RequestMaker(setup); | ||
RequestProperties props = new RequestPropertiesBuilder() | ||
.method("POST") | ||
.endpoint(String.format("%s/%s/bankaccounts", ENDPOINT, moipAccountId)) | ||
.body(body) | ||
.type(Accounts.class) | ||
.contentType(CONTENT_TYPE) | ||
.build(); | ||
|
||
return this.requestMaker.doRequest(props); | ||
} | ||
|
||
/** | ||
* This method allows you to list all bank account of a Moip account. | ||
* | ||
* @param moipAccountId | ||
* {@code String} the Moip account external ID. | ||
* | ||
* @param setup | ||
* {@code Setup} the setup object. | ||
* | ||
* @return {@code Map<String, Object>} | ||
*/ | ||
public List<Map<String, Object>> listBankAccounts(String moipAccountId, Setup setup) { | ||
this.requestMaker = new RequestMaker(setup); | ||
RequestProperties props = new RequestPropertiesBuilder() | ||
.method("GET") | ||
.endpoint(String.format("%s/%s/bankaccounts", ENDPOINT, moipAccountId)) | ||
.type(BankAccounts.class) | ||
.contentType(CONTENT_TYPE) | ||
.build(); | ||
|
||
return this.requestMaker.getList(props); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package br.com.moip.models; | ||
|
||
import br.com.moip.api.request.RequestMaker; | ||
import br.com.moip.api.request.RequestProperties; | ||
import br.com.moip.api.request.RequestPropertiesBuilder; | ||
import org.apache.http.entity.ContentType; | ||
|
||
import java.util.Map; | ||
|
||
public class Balances { | ||
|
||
private static final String ENDPOINT = "/v2/balances"; | ||
private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; | ||
private RequestMaker requestMaker; | ||
|
||
/** | ||
* This method is used to get the balances values of a Moip account (unavailable, future, current). The | ||
* request uses the accept version {@code 2.1}. | ||
* | ||
* @param setup | ||
* {@code Setup} the setup object. | ||
* | ||
* @return {@code Map<String, Object>} | ||
*/ | ||
public Map<String, Object> get(Setup setup) { | ||
this.requestMaker = new RequestMaker(setup); | ||
RequestProperties props = new RequestPropertiesBuilder() | ||
.method("GET") | ||
.endpoint(ENDPOINT) | ||
.type(Balances.class) | ||
.contentType(CONTENT_TYPE) | ||
.accept("2.1") | ||
.build(); | ||
|
||
return this.requestMaker.doRequest(props); | ||
} | ||
} |
Oops, something went wrong.