-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
109 additions
and
15 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
17 changes: 17 additions & 0 deletions
17
src/main/java/io/github/jpdev/asaassdk/rest/customeraccount/CustomerAccountReader.java
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,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; | ||
} | ||
} |
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,15 +1,16 @@ | ||
package io.github.jpdev.asaassdk.utils; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.RoundingMode; | ||
|
||
public class Money { | ||
|
||
public static BigDecimal create(BigDecimal bigDecimal) { | ||
bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP); | ||
return bigDecimal; | ||
public static BigDecimal create(BigDecimal originalValue) { | ||
return originalValue.setScale(2, RoundingMode.HALF_UP); | ||
} | ||
|
||
public static BigDecimal create(double value) { | ||
return create(new BigDecimal(value)); | ||
BigDecimal parsed = new BigDecimal(value); | ||
return create(parsed); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ithub/jpdev/asaassdk/AsaasClientMock.java → ...ithub/jpdev/asaassdk/AsaasClientMock.java
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
73 changes: 73 additions & 0 deletions
73
src/test/java/integration/io/github/jpdev/asaassdk/rest/payment/PaymentTest.java
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,73 @@ | ||
package integration.io.github.jpdev.asaassdk.rest.payment; | ||
|
||
import integration.io.github.jpdev.asaassdk.AsaasClientMock; | ||
import io.github.jpdev.asaassdk.rest.customeraccount.CustomerAccount; | ||
import io.github.jpdev.asaassdk.rest.payment.Payment; | ||
import io.github.jpdev.asaassdk.utils.BillingType; | ||
import io.github.jpdev.asaassdk.utils.Money; | ||
import org.junit.jupiter.api.*; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class PaymentTest { | ||
|
||
@BeforeAll | ||
static void setup() { | ||
AsaasClientMock.create(); | ||
} | ||
|
||
@Test | ||
@Tag("integration") | ||
@DisplayName("Integração | Criação de cobrança Pix") | ||
@Order(1) | ||
void testCreatePixKey() { | ||
CustomerAccount customerAccount = CustomerAccount.reader().read().getData().stream().findFirst().orElse(null); | ||
if (customerAccount == null) { | ||
customerAccount = CustomerAccount.creator() | ||
.setName("Teste unitário") | ||
.setCpfCnpj("06928316000124") | ||
.setEmail("[email protected]") | ||
.create(); | ||
} | ||
|
||
BigDecimal value = Money.create(5.01); | ||
Date dueDate = getDueDate(); | ||
String description = "Teste unitário"; | ||
String externalReference = UUID.randomUUID().toString(); | ||
|
||
Payment payment = Payment.creator() | ||
.setBillingType(BillingType.PIX) | ||
.setCustomer(customerAccount.getId()) | ||
.setValue(value) | ||
.setDueDate(dueDate) | ||
.setDescription(description) | ||
.setExternalReference(externalReference) | ||
.create(); | ||
|
||
assertNotNull(payment, "Cobrança não criada."); | ||
assertEquals(BillingType.PIX, payment.getBillingType(), "Tipo de cobrança incorreto."); | ||
assertEquals(value, Money.create(payment.getValue()), "Valor da cobrança incorreto."); | ||
assertEquals(dueDate, payment.getDueDate(), "Data de vencimento incorreta."); | ||
assertEquals(description, payment.getDescription(), "Descrição da cobrança incorreta."); | ||
assertEquals(externalReference, payment.getExternalReference(), "Referência externa incorreta."); | ||
} | ||
|
||
private Date getDueDate() { | ||
Calendar calendar = Calendar.getInstance(); | ||
calendar.setTime(new Date()); | ||
calendar.add(Calendar.DAY_OF_MONTH, 1); | ||
|
||
calendar.set(Calendar.HOUR_OF_DAY, 0); | ||
calendar.set(Calendar.MINUTE, 0); | ||
calendar.set(Calendar.SECOND, 0); | ||
calendar.set(Calendar.MILLISECOND, 0); | ||
|
||
return calendar.getTime(); | ||
} | ||
} |
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
5 changes: 3 additions & 2 deletions
5
...github/jpdev/asaassdk/http/AsaasTest.java → ...github/jpdev/asaassdk/http/AsaasTest.java
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