Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/main/java/com/abacatepay/AbacatePay.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
import com.abacatepay.clients.factories.AbacatePayClientFactory;
import com.abacatepay.model.IAbacatePay;
import com.abacatepay.model.IAbacatePayBilling;
import com.abacatepay.model.IAbacatePayWithdraw;
import com.abacatepay.model.billing.CreateBillingData;
import com.abacatepay.model.billing.CreateBillingResponse;
import com.abacatepay.model.billing.ListBillingResponse;
import com.abacatepay.model.withdraw.payloads.request.CreateWithdrawRequest;
import com.abacatepay.model.withdraw.payloads.response.CreateWithdrawResponse;
import com.abacatepay.model.withdraw.payloads.response.ListWithdrawResponse;
import com.abacatepay.model.withdraw.payloads.response.WithdrawResponse;
import feign.FeignException;
import feign.RequestInterceptor;

Expand All @@ -22,7 +27,7 @@ public AbacatePay(String apiKey) {
this.apiKey = apiKey;
this.client = AbacatePayClientFactory.create(API_BASE_URL, requestInterceptor());

//TODO: Pegar a versão do SDK dinamicamente
// TODO: Pegar a versão do SDK dinamicamente
this.userAgent = "Java SDK (1.0.0)";
}

Expand Down Expand Up @@ -64,4 +69,38 @@ public ListBillingResponse list() {

return new AbacatePayBilling();
}

@Override
public IAbacatePayWithdraw withdraw() {
class AbacatePayWithdraw implements IAbacatePayWithdraw {
@Override
public CreateWithdrawResponse createWithdraw(CreateWithdrawRequest body) {
try {
return client.createWithdraw(body);
} catch (IllegalArgumentException | FeignException e) {
return new CreateWithdrawResponse(e.getMessage());
}
}

@Override
public ListWithdrawResponse listWithdraw() {
try {
return client.listWithdraw();
} catch (IllegalArgumentException | FeignException e) {
return new ListWithdrawResponse(e.getMessage());
}
}

@Override
public WithdrawResponse getWithdraw(String externalId) {
try {
return client.getWithdraw(externalId);
} catch (IllegalArgumentException | FeignException e) {
return new WithdrawResponse(e.getMessage());
}
}
}

return new AbacatePayWithdraw();
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/abacatepay/clients/AbacatePayClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import com.abacatepay.model.billing.CreateBillingData;
import com.abacatepay.model.billing.CreateBillingResponse;
import com.abacatepay.model.billing.ListBillingResponse;
import com.abacatepay.model.withdraw.payloads.request.CreateWithdrawRequest;
import com.abacatepay.model.withdraw.payloads.response.CreateWithdrawResponse;
import com.abacatepay.model.withdraw.payloads.response.ListWithdrawResponse;
import com.abacatepay.model.withdraw.payloads.response.WithdrawResponse;
import feign.Param;
import feign.RequestLine;

public interface AbacatePayClient {
Expand All @@ -12,4 +17,13 @@ public interface AbacatePayClient {

@RequestLine("POST /billing/create")
CreateBillingResponse create(CreateBillingData body);

@RequestLine("POST /withdraw/create")
CreateWithdrawResponse createWithdraw(CreateWithdrawRequest body);

@RequestLine("GET /withdraw/list")
ListWithdrawResponse listWithdraw();

@RequestLine("GET /withdraw/get?externalId={externalId}")
WithdrawResponse getWithdraw(@Param("externalId") String externalId);
}
2 changes: 2 additions & 0 deletions src/main/java/com/abacatepay/model/IAbacatePay.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

public interface IAbacatePay {
IAbacatePayBilling billing();

IAbacatePayWithdraw withdraw();
}
14 changes: 14 additions & 0 deletions src/main/java/com/abacatepay/model/IAbacatePayWithdraw.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.abacatepay.model;

import com.abacatepay.model.withdraw.payloads.request.CreateWithdrawRequest;
import com.abacatepay.model.withdraw.payloads.response.CreateWithdrawResponse;
import com.abacatepay.model.withdraw.payloads.response.ListWithdrawResponse;
import com.abacatepay.model.withdraw.payloads.response.WithdrawResponse;

public interface IAbacatePayWithdraw {
CreateWithdrawResponse createWithdraw(CreateWithdrawRequest body);

ListWithdrawResponse listWithdraw();

WithdrawResponse getWithdraw(String externalId);
}
26 changes: 26 additions & 0 deletions src/main/java/com/abacatepay/model/withdraw/Withdraw.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.abacatepay.model.withdraw;

import java.time.LocalDateTime;

import com.abacatepay.model.withdraw.enums.StatusWithdraw;
import com.abacatepay.model.withdraw.enums.WithdrawKind;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.Builder;
import lombok.Data;

@Builder
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class Withdraw {
private String id;
private StatusWithdraw status;
private boolean devMode;
private String receiptUrl;
private WithdrawKind kind;
private Double amount;
private Integer platformFee;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private String externalId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.abacatepay.model.withdraw.enums;

public enum MethodWithdraw {
PIX("PIX");

private final String valueMethod;

MethodWithdraw(final String valueMethod) {
this.valueMethod = valueMethod;
}

public String getValueMethod() {
return valueMethod;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.abacatepay.model.withdraw.enums;

public enum StatusWithdraw {
PENDING("PENDING"),
EXPIRED("EXPIRED"),
CANCELLED("CANCELLED"),
COMPLETE("COMPLETE"),
REFUNDED("REFUNDED");

private final String valueMethod;

StatusWithdraw(final String valueMethod) {
this.valueMethod = valueMethod;
}

public String getValueMethod() {
return valueMethod;
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/abacatepay/model/withdraw/enums/TypeKeyPix.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.abacatepay.model.withdraw.enums;

public enum TypeKeyPix {
CPF("CPF"),
CNPJ("CNPJ"),
PHONE("PHONE"),
EMAIL("EMAIL"),
RANDOM("RANDOM");

private final String valueMethod;

TypeKeyPix(final String valueMethod) {
this.valueMethod = valueMethod;
}

public String getValueMethod() {
return valueMethod;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.abacatepay.model.withdraw.enums;

public enum WithdrawKind {
PAYMENT("PAYMENT"),
WITHDRAW("WITHDRAW");

private final String valueMethod;

WithdrawKind(final String valueMethod) {
this.valueMethod = valueMethod;
}

public String getValueMethod() {
return valueMethod;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.abacatepay.model.withdraw.payloads.request;

import com.abacatepay.model.withdraw.enums.MethodWithdraw;
import com.abacatepay.model.withdraw.enums.TypeKeyPix;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Builder;
import lombok.Data;

@Builder
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class CreateWithdrawRequest {
@JsonProperty(required = true)
private String externalId;
@JsonProperty(required = true)
private MethodWithdraw method;
@JsonProperty(required = true)
private Double amount;
@JsonProperty(required = false)
private String description;
@JsonProperty(required = true)
private Pix pix;

@Builder
@Data
static class Pix {
private TypeKeyPix type;
private String key;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.abacatepay.model.withdraw.payloads.response;

import com.abacatepay.model.withdraw.Withdraw;
import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class CreateWithdrawResponse {
@JsonInclude(JsonInclude.Include.NON_NULL)
private String error;

@JsonInclude(JsonInclude.Include.NON_NULL)
private Withdraw withdraw;

public CreateWithdrawResponse(String error) {
this.error = error;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.abacatepay.model.withdraw.payloads.response;

import java.util.List;

import com.abacatepay.model.withdraw.Withdraw;
import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class ListWithdrawResponse {
@JsonInclude(JsonInclude.Include.NON_NULL)
private List<Withdraw> withdrawals;
@JsonInclude(JsonInclude.Include.NON_NULL)
private String error;

public ListWithdrawResponse(final String error) {
this.error = error;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.abacatepay.model.withdraw.payloads.response;

import com.abacatepay.model.withdraw.Withdraw;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Data
public class WithdrawResponse {
@JsonInclude(JsonInclude.Include.NON_NULL)
private Withdraw withdraw;
@JsonInclude(JsonInclude.Include.NON_NULL)
private String error;

public WithdrawResponse(final String error) {
this.error = error;
}
}
Loading