Skip to content

Commit

Permalink
Merge pull request #16 from jpdev01/release
Browse files Browse the repository at this point in the history
1.6 snapshot
  • Loading branch information
jpdev01 authored Nov 17, 2024
2 parents 6df6183 + 7aef279 commit c021ae5
Show file tree
Hide file tree
Showing 17 changed files with 462 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The recommended way to use the AWS SDK for Java in your project is to consume it
<dependency>
<groupId>io.github.jpdev01</groupId>
<artifactId>asaassdk</artifactId>
<version>1.5-SNAPSHOT</version>
<version>1.6-SNAPSHOT</version>
</dependency>
```

Expand Down
15 changes: 15 additions & 0 deletions docs/pix_transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ Transfer transfer = Transfer.pixManualCreator()
.create();
```

### Pix Recorrente
```java
PixRecurring recurring = new PixRecurring()
.setFrequency(PixRecurringFrequency.MONTHLY)
.setQuantity(2);

Transfer transfer = Transfer.pixAddressKeyCreator()
.setPixAddressKey("+5547999999999")
.setValue(Money.create(0.01))
.setDescription("teste")
.setPixAddressKeyType(PixAddressKeyType.PHONE)
.setRecurring(recurring)
.create();
```

## Pagar um QR Code Pix
```java
final String examplePayload = "00020101021226730014br.gov.bcb.pix2551pix-h.asaas.com/pixqrcode/cobv/pay_76575613967995145204000053039865802BR5905ASAAS6009Joinville61088922827162070503***63045E7A";
Expand Down
2 changes: 1 addition & 1 deletion docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The recommended way to use the AWS SDK for Java in your project is to consume it
<dependency>
<groupId>io.github.jpdev01</groupId>
<artifactId>asaassdk</artifactId>
<version>1.5-SNAPSHOT</version>
<version>1.6-SNAPSHOT</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.jpdev01</groupId>
<artifactId>asaassdk</artifactId>
<version>1.5-SNAPSHOT</version>
<version>1.6-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
Expand Down
29 changes: 22 additions & 7 deletions src/main/java/io/github/jpdev/asaassdk/doc/Examples.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
import io.github.jpdev.asaassdk.rest.subscription.Subscription;
import io.github.jpdev.asaassdk.rest.subscription.SubscriptionCycle;
import io.github.jpdev.asaassdk.rest.transfer.Transfer;
import io.github.jpdev.asaassdk.rest.transfer.children.BankAccountSetting;
import io.github.jpdev.asaassdk.rest.transfer.children.BankAccountType;
import io.github.jpdev.asaassdk.rest.transfer.children.BankSetting;
import io.github.jpdev.asaassdk.rest.transfer.children.*;
import io.github.jpdev.asaassdk.rest.webhook.Event;
import io.github.jpdev.asaassdk.rest.webhook.SendType;
import io.github.jpdev.asaassdk.rest.webhook.Webhook;
Expand All @@ -49,7 +47,8 @@
public class Examples {

public static void main(String[] args) {
Asaas.init(Secret.getAccessToken()); // Initialize the SDK with your access token
Asaas.initSandbox(Secret.getAccessToken()); // Initialize the SDK with your access token
transfer();
}

private static void pixTransaction() {
Expand Down Expand Up @@ -77,15 +76,16 @@ private static void decodePixQrCode() {
}

private static void transfer() {
ResourceSet<Transfer> transferList = Transfer.reader().read();
Transfer transfer = Transfer.pixAddressKeyCreator()
.setPixAddressKey("PIX_KEY")
.setPixAddressKey("+5547999999999")
.setValue(Money.create(0.01))
.setDescription("teste")
.setPixAddressKeyType(PixAddressKeyType.CPF)
.setPixAddressKeyType(PixAddressKeyType.PHONE)
.create();
System.out.println(transfer.getValue().toString());

ResourceSet<Transfer> transferList = Transfer.reader().read();

Date birthDate = new Date();
BankAccountSetting bankAccountSetting = new BankAccountSetting()
.setBank(
Expand Down Expand Up @@ -117,6 +117,21 @@ private static void transfer() {
.create();
}

private static void recurringTransfer() {
PixRecurring recurring = new PixRecurring()
.setFrequency(PixRecurringFrequency.MONTHLY)
.setQuantity(2);

Transfer transfer = Transfer.pixAddressKeyCreator()
.setPixAddressKey("+5547999999999")
.setValue(Money.create(0.01))
.setDescription("teste")
.setPixAddressKeyType(PixAddressKeyType.PHONE)
.setRecurring(recurring)
.create();
System.out.println(transfer.getRecurring());
}

private static void bill() {
Bill bill = Bill.creator()
.setIdentificationField("25794150099003551916515000211407100000000000000")
Expand Down
47 changes: 22 additions & 25 deletions src/main/java/io/github/jpdev/asaassdk/http/ApacheHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,15 @@ public Response get(String url) throws ConnectionException {
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader(ACCESS_TOKEN_HEADER, accessToken);
CloseableHttpResponse response = httpclient.execute(httpGet);

StatusLine status = response.getStatusLine();
if (status.getStatusCode() != HttpStatus.SC_OK) {
throw new ConnectionException(status.getStatusCode(), status.getReasonPhrase());
}
checkResponseCode(response.getStatusLine());

HttpEntity entity = response.getEntity();
String responseBody = EntityUtils.toString(entity);

return new Response(
responseBody,
response.getStatusLine().getStatusCode()
response.getStatusLine().getStatusCode(),
response.getAllHeaders()
);
} catch (IOException ex) {
Logger.getLogger(ApacheHttpClient.class.getName()).log(Level.SEVERE, null, ex);
Expand All @@ -67,16 +64,14 @@ public Response delete(String url) {
HttpDelete httpDelete = new HttpDelete(url);
httpDelete.addHeader(ACCESS_TOKEN_HEADER, accessToken);
CloseableHttpResponse response = httpclient.execute(httpDelete);
checkResponseCode(response.getStatusLine());

StatusLine status = response.getStatusLine();
if (status.getStatusCode() != HttpStatus.SC_OK) {
throw new ConnectionException(status.getStatusCode(), status.getReasonPhrase());
}
HttpEntity entity = response.getEntity();
String responseBody = EntityUtils.toString(entity);
return new Response(
responseBody,
response.getStatusLine().getStatusCode()
response.getStatusLine().getStatusCode(),
response.getAllHeaders()
);
} catch (IOException ex) {
Logger.getLogger(ApacheHttpClient.class.getName()).log(Level.SEVERE, null, ex);
Expand All @@ -93,16 +88,12 @@ public Response post(String url, String body) throws ConnectionException {
httpPost.setEntity(entity);

CloseableHttpResponse response = httpclient.execute(httpPost);

StatusLine status = response.getStatusLine();

if (status.getStatusCode() != HttpStatus.SC_OK && status.getStatusCode() != HttpStatus.SC_BAD_REQUEST) {
throw new ConnectionException(status.getStatusCode(), status.getReasonPhrase());
}
checkResponseCode(response.getStatusLine());

return new Response(
EntityUtils.toString(response.getEntity()),
response.getStatusLine().getStatusCode()
response.getStatusLine().getStatusCode(),
response.getAllHeaders()
);
} catch (IOException ex) {
Logger.getLogger(ApacheHttpClient.class.getName()).log(Level.SEVERE, null, ex);
Expand All @@ -119,21 +110,27 @@ public Response put(String url, String body) throws ConnectionException {
httpPost.setEntity(entity);

CloseableHttpResponse response = httpclient.execute(httpPost);

StatusLine status = response.getStatusLine();

if (status.getStatusCode() != HttpStatus.SC_OK && status.getStatusCode() != HttpStatus.SC_BAD_REQUEST) {
throw new ConnectionException(status.getStatusCode(), status.getReasonPhrase());
}
checkResponseCode(response.getStatusLine());

return new Response(
EntityUtils.toString(response.getEntity()),
response.getStatusLine().getStatusCode()
response.getStatusLine().getStatusCode(),
response.getAllHeaders()
);
} catch (IOException ex) {
Logger.getLogger(ApacheHttpClient.class.getName()).log(Level.SEVERE, null, ex);
throw new ConnectionException(HttpStatus.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
}
}

private void checkResponseCode(StatusLine status) {
if (status.getStatusCode() != HttpStatus.SC_OK && status.getStatusCode() != HttpStatus.SC_BAD_REQUEST) {
String message = status.getReasonPhrase();
if (message == null || message.isEmpty()) {
message = "Erro ao realizar requisição, status: " + status.getStatusCode();
}
throw new ConnectionException(status.getStatusCode(), message);
}
}

}
6 changes: 4 additions & 2 deletions src/main/java/io/github/jpdev/asaassdk/http/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ public RateLimitData getRateLimit() {
}

private String findHeaderValue(String key) {
Optional<Header> headerEncontrado = Arrays.stream(headers)
if (headers == null) return null;

Optional<Header> headerValue = Arrays.stream(headers)
.filter(header -> header.getName().equals(key))
.findFirst();
return headerEncontrado.map(NameValuePair::getValue).orElse(null);
return headerValue.map(NameValuePair::getValue).orElse(null);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.github.jpdev.asaassdk.rest.action;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.github.jpdev.asaassdk.exception.ApiException;
import io.github.jpdev.asaassdk.http.Asaas;
import io.github.jpdev.asaassdk.rest.ApiResource;
import io.github.jpdev.asaassdk.utils.JsonUtil;
import io.github.jpdev.asaassdk.http.AsaasRestClient;
import io.github.jpdev.asaassdk.http.Response;
import org.apache.http.HttpStatus;

public abstract class Creator<T> {

Expand All @@ -19,8 +21,8 @@ public T create(final AsaasRestClient client) {
}

private T parseResponse(AsaasRestClient client, Response response) {
if (response.getStatusCode() == 400) {
throw new ApiException(400, response.getContent());
if (response.getStatusCode() == HttpStatus.SC_BAD_REQUEST) {
throw new ApiException(HttpStatus.SC_BAD_REQUEST, response.getContent());
}

try {
Expand All @@ -34,7 +36,9 @@ private T parseResponse(AsaasRestClient client, Response response) {
}
}

@JsonIgnore
public abstract String getResourceUrl();

@JsonIgnore
public abstract Class<T> getResourceClass();
}
Loading

0 comments on commit c021ae5

Please sign in to comment.