diff --git a/src/main/java/io/github/jpdev/asaassdk/http/ApacheHttpClient.java b/src/main/java/io/github/jpdev/asaassdk/http/ApacheHttpClient.java index 05fd384..ae4833a 100644 --- a/src/main/java/io/github/jpdev/asaassdk/http/ApacheHttpClient.java +++ b/src/main/java/io/github/jpdev/asaassdk/http/ApacheHttpClient.java @@ -18,6 +18,7 @@ public class ApacheHttpClient { private final String accessToken; private final CloseableHttpClient httpclient; + private final static String ACCESS_TOKEN_HEADER = "access_token"; public ApacheHttpClient(String acessToken) { this.accessToken = acessToken; @@ -27,7 +28,7 @@ public ApacheHttpClient(String acessToken) { public Response get(String url) throws ConnectionException { try { HttpGet httpGet = new HttpGet(url); - httpGet.addHeader("access_token", accessToken); + httpGet.addHeader(ACCESS_TOKEN_HEADER, accessToken); CloseableHttpResponse response = httpclient.execute(httpGet); StatusLine status = response.getStatusLine(); @@ -51,7 +52,7 @@ public Response get(String url) throws ConnectionException { public Response delete(String url) { try { HttpDelete httpDelete = new HttpDelete(url); - httpDelete.addHeader("access_token", accessToken); + httpDelete.addHeader(ACCESS_TOKEN_HEADER, accessToken); CloseableHttpResponse response = httpclient.execute(httpDelete); StatusLine status = response.getStatusLine(); @@ -73,7 +74,7 @@ public Response delete(String url) { public Response post(String url, String body) throws ConnectionException { try { HttpPost httpPost = new HttpPost(url); - httpPost.addHeader("access_token", accessToken); + httpPost.addHeader(ACCESS_TOKEN_HEADER, accessToken); StringEntity entity = new StringEntity(body); httpPost.setEntity(entity); @@ -99,7 +100,7 @@ public Response post(String url, String body) throws ConnectionException { public Response put(String url, String body) throws ConnectionException { try { HttpPut httpPost = new HttpPut(url); - httpPost.addHeader("access_token", accessToken); + httpPost.addHeader(ACCESS_TOKEN_HEADER, accessToken); StringEntity entity = new StringEntity(body); httpPost.setEntity(entity); diff --git a/src/main/java/io/github/jpdev/asaassdk/http/Domain.java b/src/main/java/io/github/jpdev/asaassdk/http/Domain.java index 9f4daa9..14a173d 100644 --- a/src/main/java/io/github/jpdev/asaassdk/http/Domain.java +++ b/src/main/java/io/github/jpdev/asaassdk/http/Domain.java @@ -26,7 +26,8 @@ public enum Domain { COMMERCIAL_INFO("myAccount/commercialInfo"), ACCOUNT_NUMBER("myAccount/accountNumber"), FEE("myAccount/fees"), - STATUS("myAccount/status"); + STATUS("myAccount/status"), + ACCOUNT("accounts"); private final String value; diff --git a/src/main/java/io/github/jpdev/asaassdk/rest/accounts/Account.java b/src/main/java/io/github/jpdev/asaassdk/rest/accounts/Account.java new file mode 100644 index 0000000..655866b --- /dev/null +++ b/src/main/java/io/github/jpdev/asaassdk/rest/accounts/Account.java @@ -0,0 +1,253 @@ +package io.github.jpdev.asaassdk.rest.accounts; + +public class Account { + + public String object; + public String id; + public String name; + public String tradingName; + public String email; + public String loginEmail; + public String phone; + public String mobilePhone; + public String address; + public String addressNumber; + public String complement; + public String province; + public String postalCode; + public String cpfCnpj; + public Object birthDate; + public String personType; + public String companyType; + public int city; + public String state; + public String country; + public String site; + public String apiKey; + public String walletId; + public AccountNumber accountNumber; + + public static AccountCreator creator() { + return new AccountCreator(); + } + + public static AccountFetcher fetcher(String id) { + return new AccountFetcher(id); + } + + public String getObject() { + return object; + } + + public Account setObject(String object) { + this.object = object; + return this; + } + + public String getId() { + return id; + } + + public Account setId(String id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public Account setName(String name) { + this.name = name; + return this; + } + + public String getTradingName() { + return tradingName; + } + + public Account setTradingName(String tradingName) { + this.tradingName = tradingName; + return this; + } + + public String getEmail() { + return email; + } + + public Account setEmail(String email) { + this.email = email; + return this; + } + + public String getLoginEmail() { + return loginEmail; + } + + public Account setLoginEmail(String loginEmail) { + this.loginEmail = loginEmail; + return this; + } + + public String getPhone() { + return phone; + } + + public Account setPhone(String phone) { + this.phone = phone; + return this; + } + + public String getMobilePhone() { + return mobilePhone; + } + + public Account setMobilePhone(String mobilePhone) { + this.mobilePhone = mobilePhone; + return this; + } + + public String getAddress() { + return address; + } + + public Account setAddress(String address) { + this.address = address; + return this; + } + + public String getAddressNumber() { + return addressNumber; + } + + public Account setAddressNumber(String addressNumber) { + this.addressNumber = addressNumber; + return this; + } + + public String getComplement() { + return complement; + } + + public Account setComplement(String complement) { + this.complement = complement; + return this; + } + + public String getProvince() { + return province; + } + + public Account setProvince(String province) { + this.province = province; + return this; + } + + public String getPostalCode() { + return postalCode; + } + + public Account setPostalCode(String postalCode) { + this.postalCode = postalCode; + return this; + } + + public String getCpfCnpj() { + return cpfCnpj; + } + + public Account setCpfCnpj(String cpfCnpj) { + this.cpfCnpj = cpfCnpj; + return this; + } + + public Object getBirthDate() { + return birthDate; + } + + public Account setBirthDate(Object birthDate) { + this.birthDate = birthDate; + return this; + } + + public String getPersonType() { + return personType; + } + + public Account setPersonType(String personType) { + this.personType = personType; + return this; + } + + public String getCompanyType() { + return companyType; + } + + public Account setCompanyType(String companyType) { + this.companyType = companyType; + return this; + } + + public int getCity() { + return city; + } + + public Account setCity(int city) { + this.city = city; + return this; + } + + public String getState() { + return state; + } + + public Account setState(String state) { + this.state = state; + return this; + } + + public String getCountry() { + return country; + } + + public Account setCountry(String country) { + this.country = country; + return this; + } + + public String getSite() { + return site; + } + + public Account setSite(String site) { + this.site = site; + return this; + } + + public String getApiKey() { + return apiKey; + } + + public Account setApiKey(String apiKey) { + this.apiKey = apiKey; + return this; + } + + public String getWalletId() { + return walletId; + } + + public Account setWalletId(String walletId) { + this.walletId = walletId; + return this; + } + + public AccountNumber getAccountNumber() { + return accountNumber; + } + + public Account setAccountNumber(AccountNumber accountNumber) { + this.accountNumber = accountNumber; + return this; + } +} diff --git a/src/main/java/io/github/jpdev/asaassdk/rest/accounts/AccountCreator.java b/src/main/java/io/github/jpdev/asaassdk/rest/accounts/AccountCreator.java new file mode 100644 index 0000000..f14f64f --- /dev/null +++ b/src/main/java/io/github/jpdev/asaassdk/rest/accounts/AccountCreator.java @@ -0,0 +1,171 @@ +package io.github.jpdev.asaassdk.rest.accounts; + +import io.github.jpdev.asaassdk.http.Domain; +import io.github.jpdev.asaassdk.rest.action.Creator; + +import java.util.Date; +import java.util.List; + +public class AccountCreator extends Creator { + + String name; + String email; + String loginEmail; + String cpfCnpj; + Date birthDate; + String companyType; + String phone; + String mobilePhone; + String site; + String address; + String addressNumber; + String complement; + String province; + String postalCode; + List webhooks; + + public String getName() { + return name; + } + + public AccountCreator setName(String name) { + this.name = name; + return this; + } + + public String getEmail() { + return email; + } + + public AccountCreator setEmail(String email) { + this.email = email; + return this; + } + + public String getLoginEmail() { + return loginEmail; + } + + public AccountCreator setLoginEmail(String loginEmail) { + this.loginEmail = loginEmail; + return this; + } + + public String getCpfCnpj() { + return cpfCnpj; + } + + public AccountCreator setCpfCnpj(String cpfCnpj) { + this.cpfCnpj = cpfCnpj; + return this; + } + + public Date getBirthDate() { + return birthDate; + } + + public AccountCreator setBirthDate(Date birthDate) { + this.birthDate = birthDate; + return this; + } + + public String getCompanyType() { + return companyType; + } + + public AccountCreator setCompanyType(String companyType) { + this.companyType = companyType; + return this; + } + + public String getPhone() { + return phone; + } + + public AccountCreator setPhone(String phone) { + this.phone = phone; + return this; + } + + public String getMobilePhone() { + return mobilePhone; + } + + public AccountCreator setMobilePhone(String mobilePhone) { + this.mobilePhone = mobilePhone; + return this; + } + + public String getSite() { + return site; + } + + public AccountCreator setSite(String site) { + this.site = site; + return this; + } + + public String getAddress() { + return address; + } + + public AccountCreator setAddress(String address) { + this.address = address; + return this; + } + + public String getAddressNumber() { + return addressNumber; + } + + public AccountCreator setAddressNumber(String addressNumber) { + this.addressNumber = addressNumber; + return this; + } + + public String getComplement() { + return complement; + } + + public AccountCreator setComplement(String complement) { + this.complement = complement; + return this; + } + + public String getProvince() { + return province; + } + + public AccountCreator setProvince(String province) { + this.province = province; + return this; + } + + public String getPostalCode() { + return postalCode; + } + + public AccountCreator setPostalCode(String postalCode) { + this.postalCode = postalCode; + return this; + } + + public List getWebhooks() { + return webhooks; + } + + public AccountCreator setWebhooks(List webhooks) { + this.webhooks = webhooks; + return this; + } + + @Override + public String getResourceUrl() { + return Domain.ACCOUNT.toString(); + } + + @Override + public Class getResourceClass() { + return Account.class; + } +} diff --git a/src/main/java/io/github/jpdev/asaassdk/rest/accounts/AccountFetcher.java b/src/main/java/io/github/jpdev/asaassdk/rest/accounts/AccountFetcher.java new file mode 100644 index 0000000..47aeb42 --- /dev/null +++ b/src/main/java/io/github/jpdev/asaassdk/rest/accounts/AccountFetcher.java @@ -0,0 +1,23 @@ +package io.github.jpdev.asaassdk.rest.accounts; + +import io.github.jpdev.asaassdk.http.Domain; +import io.github.jpdev.asaassdk.rest.action.Fetcher; + +public class AccountFetcher extends Fetcher { + + private final String id; + + public AccountFetcher(String id) { + this.id = id; + } + + @Override + public String getResourceUrl() { + return Domain.ACCOUNT.addPathVariable(this.id); + } + + @Override + public Class getResourceClass() { + return Account.class; + } +} diff --git a/src/main/java/io/github/jpdev/asaassdk/rest/accounts/AccountNumber.java b/src/main/java/io/github/jpdev/asaassdk/rest/accounts/AccountNumber.java new file mode 100644 index 0000000..d591f78 --- /dev/null +++ b/src/main/java/io/github/jpdev/asaassdk/rest/accounts/AccountNumber.java @@ -0,0 +1,35 @@ +package io.github.jpdev.asaassdk.rest.accounts; + +public class AccountNumber { + + public String agency; + public String account; + public String accountDigit; + + public String getAgency() { + return agency; + } + + public AccountNumber setAgency(String agency) { + this.agency = agency; + return this; + } + + public String getAccount() { + return account; + } + + public AccountNumber setAccount(String account) { + this.account = account; + return this; + } + + public String getAccountDigit() { + return accountDigit; + } + + public AccountNumber setAccountDigit(String accountDigit) { + this.accountDigit = accountDigit; + return this; + } +} diff --git a/src/main/java/io/github/jpdev/asaassdk/rest/accounts/Webhook.java b/src/main/java/io/github/jpdev/asaassdk/rest/accounts/Webhook.java new file mode 100644 index 0000000..bc7e1af --- /dev/null +++ b/src/main/java/io/github/jpdev/asaassdk/rest/accounts/Webhook.java @@ -0,0 +1,65 @@ +package io.github.jpdev.asaassdk.rest.accounts; + +public class Webhook { + + String url; + String email; + Integer apiVersion; + boolean enabled; + boolean interrupted; + String authToken; + + public String getUrl() { + return url; + } + + public Webhook setUrl(String url) { + this.url = url; + return this; + } + + public String getEmail() { + return email; + } + + public Webhook setEmail(String email) { + this.email = email; + return this; + } + + public Integer getApiVersion() { + return apiVersion; + } + + public Webhook setApiVersion(Integer apiVersion) { + this.apiVersion = apiVersion; + return this; + } + + public boolean isEnabled() { + return enabled; + } + + public Webhook setEnabled(boolean enabled) { + this.enabled = enabled; + return this; + } + + public boolean isInterrupted() { + return interrupted; + } + + public Webhook setInterrupted(boolean interrupted) { + this.interrupted = interrupted; + return this; + } + + public String getAuthToken() { + return authToken; + } + + public Webhook setAuthToken(String authToken) { + this.authToken = authToken; + return this; + } +} diff --git a/src/main/java/io/github/jpdev/asaassdk/rest/accounts/WebhookType.java b/src/main/java/io/github/jpdev/asaassdk/rest/accounts/WebhookType.java new file mode 100644 index 0000000..b7c5201 --- /dev/null +++ b/src/main/java/io/github/jpdev/asaassdk/rest/accounts/WebhookType.java @@ -0,0 +1,12 @@ +package io.github.jpdev.asaassdk.rest.accounts; + +public enum WebhookType { + + PAYMENT, + INVOICE, + TRANSFER, + BILL, + RECEIVABLE_ANTICIPATION, + MOBILE_PHONE_RECHARGE, + ACCOUNT_STATUS +} diff --git a/src/main/java/io/github/jpdev/asaassdk/rest/action/Creator.java b/src/main/java/io/github/jpdev/asaassdk/rest/action/Creator.java index 8fabb43..2c6f3e2 100644 --- a/src/main/java/io/github/jpdev/asaassdk/rest/action/Creator.java +++ b/src/main/java/io/github/jpdev/asaassdk/rest/action/Creator.java @@ -18,16 +18,16 @@ public T create() { public T create(final AsaasRestClient client) { Response response = client.post(getResourceUrl(), JsonUtil.toJSON(this)); - return parseResponse(response); + return parseResponse(client, response); } - private T parseResponse(Response response) { + private T parseResponse(AsaasRestClient client, Response response) { if (response.getStatusCode() == 400) { throw new ApiException(400, response.getContent()); } try { - return objectMapper.readValue(response.getContent(), getResourceClass()); + return client.getObjectMapper().readValue(response.getContent(), getResourceClass()); } catch (Exception e) { throw new RuntimeException("Error parsing response", e); }