Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split de cobranças #18

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
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.6-SNAPSHOT</version>
<version>1.7-SNAPSHOT</version>
</dependency>
```

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.6-SNAPSHOT</version>
<version>1.7-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.6-SNAPSHOT</version>
<version>1.7-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
Expand Down
47 changes: 39 additions & 8 deletions src/main/java/io/github/jpdev/asaassdk/doc/Examples.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.github.jpdev.asaassdk.http.Asaas;
import io.github.jpdev.asaassdk.rest.accounts.Account;
import io.github.jpdev.asaassdk.rest.accounts.AccountCreator;
import io.github.jpdev.asaassdk.rest.action.ResourceSet;
import io.github.jpdev.asaassdk.rest.bill.Bill;
import io.github.jpdev.asaassdk.rest.commons.DeletedResource;
Expand All @@ -18,6 +17,7 @@
import io.github.jpdev.asaassdk.rest.myaccount.status.MyAccountStatus;
import io.github.jpdev.asaassdk.rest.notification.NotificationConfig;
import io.github.jpdev.asaassdk.rest.payment.Payment;
import io.github.jpdev.asaassdk.rest.payment.children.SplitSetting;
import io.github.jpdev.asaassdk.rest.payment.enums.PaymentLinkChargeType;
import io.github.jpdev.asaassdk.rest.payment.enums.PaymentStatus;
import io.github.jpdev.asaassdk.rest.payment.identificationfield.PaymentIdentificationField;
Expand All @@ -36,24 +36,39 @@
import io.github.jpdev.asaassdk.rest.subscription.SubscriptionCycle;
import io.github.jpdev.asaassdk.rest.transfer.Transfer;
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;
import io.github.jpdev.asaassdk.rest.webhook.WebhookReader;
import io.github.jpdev.asaassdk.utils.BillingType;
import io.github.jpdev.asaassdk.utils.Money;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

public class Examples {

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

private static void splittedPayment() {
Account account = createFirstAccountIfNecessary();

SplitSetting split1 = new SplitSetting()
.setWalletId(account.getWalletId())
.setFixedValue(Money.create(10));

CustomerAccount customerAccount = CustomerAccount.reader().read().getData().get(0);

Payment payment = Payment.creator()
.setCustomer(customerAccount.id)
.setBillingType(BillingType.PIX)
.setDueDate(new Date())
.addSplit(split1)
.setValue(Money.create(100))
.setDescription("Teste")
.create();

System.out.println(payment.getSplit().get(0).getId().toString());
}

private static void paging() {
Expand Down Expand Up @@ -305,4 +320,20 @@ private static void subscription() {
.setDescription("Teste")
.create();
}

private static Account createFirstAccountIfNecessary() {
List<Account> accounts = Account.reader().read().getData();
if (accounts.isEmpty()) {
return Account.creator()
.setName("Teste sub conta")
.setBirthDate(new Date())
.setCompanyType("LIMITED")
.setEmail("[email protected]")
.setPostalCode("36572122")
.setIncomeValue(Money.create(1000))
.setCpfCnpj("87.326.705/0001-81")
.create();
}
return accounts.get(0);
}
}
2 changes: 2 additions & 0 deletions src/main/java/io/github/jpdev/asaassdk/http/Domain.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public enum Domain {
CUSTOMER_ACCOUNT_NOTIFICATIONS("customers/$id/notifications"),
PAYMENT_STATUS("payments/$id/status"),
PAYMENT_RESTORE("payments/$id/restore"),
PAYMENT_SPLIT_RECEIVED("payments/splits/received"),
PAYMENT_SPLIT_PAID("payments/splits/paid"),
INSTALLMENT("installments"),
FINANCE_BALANCE("finance/balance"),
PAYMENT_LINK("paymentLinks"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public static AccountFetcher fetcher(String id) {
return new AccountFetcher(id);
}

public static AccountReader reader() {
return new AccountReader();
}

public String getObject() {
return object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.github.jpdev.asaassdk.http.Domain;
import io.github.jpdev.asaassdk.rest.action.Creator;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

Expand All @@ -22,6 +23,7 @@ public class AccountCreator extends Creator<Account> {
String complement;
String province;
String postalCode;
BigDecimal incomeValue;
List<Webhook> webhooks;

public String getName() {
Expand Down Expand Up @@ -159,6 +161,15 @@ public AccountCreator setWebhooks(List<Webhook> webhooks) {
return this;
}

public AccountCreator setIncomeValue(BigDecimal incomeValue) {
this.incomeValue = incomeValue;
return this;
}

public BigDecimal getIncomeValue() {
return incomeValue;
}

@Override
public String getResourceUrl() {
return Domain.ACCOUNT.toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.jpdev.asaassdk.rest.accounts;

import io.github.jpdev.asaassdk.http.Domain;
import io.github.jpdev.asaassdk.rest.action.Reader;

public class AccountReader extends Reader<Account> {

@Override
public String getResourceUrl() {
return Domain.ACCOUNT.toString();
}

@Override
public Class<Account> getResourceClass() {
return Account.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public static CustomerAccountFetcher fetcher(String id) {
return new CustomerAccountFetcher(id);
}

public static CustomerAccountReader reader() {
return new CustomerAccountReader();
}

public String getObject() {
return object;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.jpdev.asaassdk.rest.customeraccount;

import io.github.jpdev.asaassdk.http.Domain;
import io.github.jpdev.asaassdk.rest.action.Reader;

public class CustomerAccountReader extends Reader<CustomerAccount> {

@Override
public String getResourceUrl() {
return Domain.CUSTOMER_ACCOUNT.toString();
}

@Override
public Class<CustomerAccount> getResourceClass() {
return CustomerAccount.class;
}
}
12 changes: 12 additions & 0 deletions src/main/java/io/github/jpdev/asaassdk/rest/payment/Payment.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.jpdev.asaassdk.rest.payment.delete.PaymentDeleter;
import io.github.jpdev.asaassdk.rest.payment.identificationfield.PaymentIdentificationFieldFetcher;
import io.github.jpdev.asaassdk.rest.payment.restore.PaymentRestorer;
import io.github.jpdev.asaassdk.rest.paymentsplit.Split;
import io.github.jpdev.asaassdk.rest.payment.status.PaymentStatusFetcher;
import io.github.jpdev.asaassdk.utils.BillingType;
import io.github.jpdev.asaassdk.rest.payment.enums.PaymentStatus;
Expand All @@ -14,6 +15,7 @@

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
public class Payment {
Expand Down Expand Up @@ -57,6 +59,7 @@ public class Payment {
private boolean postalService;
private Object custody; // You may need to define a specific type for this property
private Object refunds; // You may need to define a specific type for this property
private List<Split> split;

public static PaymentCreator creator() {
return new PaymentCreator();
Expand Down Expand Up @@ -427,4 +430,13 @@ public Payment setInstallment(String installment) {
this.installment = installment;
return this;
}

public List<Split> getSplit() {
return split;
}

public Payment setSplit(List<Split> split) {
this.split = split;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import io.github.jpdev.asaassdk.http.Domain;
import io.github.jpdev.asaassdk.rest.action.Creator;
import io.github.jpdev.asaassdk.rest.payment.children.DiscountSetting;
import io.github.jpdev.asaassdk.rest.payment.children.SplitSetting;
import io.github.jpdev.asaassdk.utils.BillingType;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;

public class PaymentCreator extends Creator<Payment> {
Expand All @@ -26,6 +28,8 @@ public class PaymentCreator extends Creator<Payment> {
Integer installmentCount;
BigDecimal installmentValue;

ArrayList<SplitSetting> split;

public String getCustomer() {
return customer;
}
Expand Down Expand Up @@ -116,6 +120,21 @@ public PaymentCreator setInstallmentValue(BigDecimal installmentValue) {
return this;
}

public PaymentCreator setSplit(ArrayList<SplitSetting> split) {
this.split = split;
return this;
}

public PaymentCreator addSplit(SplitSetting split) {
if (this.split == null) this.split = new ArrayList<>();
this.split.add(split);
return this;
}

public ArrayList<SplitSetting> getSplit() {
return split;
}

@Override
public String getResourceUrl() {
return Domain.PAYMENT.toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.github.jpdev.asaassdk.rest.payment.children;

import java.math.BigDecimal;

public class SplitSetting {

String walletId;
BigDecimal fixedValue;
BigDecimal percentualValue;

public SplitSetting setWalletId(String walletId) {
this.walletId = walletId;
return this;
}

public SplitSetting setFixedValue(BigDecimal fixedValue) {
if (percentualValue != null) throw new IllegalArgumentException("Cannot set both fixedValue and percentualValue");

this.fixedValue = fixedValue;
return this;
}

public SplitSetting setPercentualValue(BigDecimal percentualValue) {
if (fixedValue != null) throw new IllegalArgumentException("Cannot set both fixedValue and percentualValue");

this.percentualValue = percentualValue;
return this;
}

public String getWalletId() {
return walletId;
}

public BigDecimal getFixedValue() {
return fixedValue;
}

public BigDecimal getPercentualValue() {
return percentualValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.jpdev.asaassdk.rest.paymentsplit;

import io.github.jpdev.asaassdk.http.Domain;
import io.github.jpdev.asaassdk.rest.action.Fetcher;
import io.github.jpdev.asaassdk.rest.action.Reader;

public class PaymentSplitPaidFetcher extends Fetcher<Split> {

private final String id;

public PaymentSplitPaidFetcher(String id) {
this.id = id;
}

@Override
public String getResourceUrl() {
return Domain.PAYMENT_SPLIT_PAID.addPathVariable(this.id);
}

@Override
public Class<Split> getResourceClass() {
return Split.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.jpdev.asaassdk.rest.paymentsplit;

import io.github.jpdev.asaassdk.http.Domain;
import io.github.jpdev.asaassdk.rest.action.Reader;

public class PaymentSplitPaidReader extends Reader<Split> {

@Override
public String getResourceUrl() {
return Domain.PAYMENT_SPLIT_PAID.toString();
}

@Override
public Class<Split> getResourceClass() {
return Split.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.jpdev.asaassdk.rest.paymentsplit;

import io.github.jpdev.asaassdk.http.Domain;
import io.github.jpdev.asaassdk.rest.action.Fetcher;

public class PaymentSplitReceivedFetcher extends Fetcher<Split> {

private final String id;

public PaymentSplitReceivedFetcher(String id) {
this.id = id;
}

@Override
public String getResourceUrl() {
return Domain.PAYMENT_SPLIT_RECEIVED.addPathVariable(this.id);
}

@Override
public Class<Split> getResourceClass() {
return Split.class;
}
}
Loading