Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #92 from moip/release/v3.4.0
Browse files Browse the repository at this point in the history
[RELEASE]  3.4.0
  • Loading branch information
caiogaspar authored Nov 8, 2017
2 parents 6cb00c6 + c7802d3 commit 5ecdc2d
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 19 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
<a name="v3.4.0"></a>
# [](https://github.com/moip/moip-sdk-java/compare/v3.3.0...v3.4.0) (2017-11-08)


### Features

* **Order:** adding OrderStatus to Order object ([71a42d8](https://github.com/moip/moip-sdk-java/commit/71a42d8))
* **CreditCardRequest:** Add id property, getter and setter ([bb59c12](https://github.com/moip/moip-sdk-java/commit/bb59c12))
* **Amount:** Added fees, refunds, liquid, currency properties and getters for them ([e90fce0](https://github.com/moip/moip-sdk-java/commit/e90fce0))
* **BankAccount** Add method to delete a bank account. ([113ff51](https://github.com/moip/moip-sdk-java/commit/113ff51))
* **BankAccount** Add method to update a bank account. ([b99fd12](https://github.com/moip/moip-sdk-java/commit/b99fd12))


<a name="v3.3.0"></a>
# [](https://github.com/moip/moip-sdk-java/compare/v3.2.0...v3.3.0) (2017-10-10)

Expand Down
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
- [Criação](#criação-6)
- [Consulta](#consulta-7)
- [Verifica se usuário já possui Conta Moip](#verifica-se-usuário-já-possui-conta-moip)
- [Contas Bancárias](#contas-bancárias)
- [Criação](#criação-7)
- [Consulta](#consulta-8)
- [Exclusão](#exclusão-1)
- [Atualização](#atualização)
- [Listagem](#listagem-1)
- [Custódia](#custódia)
- [Pagamento com custódia](#pagamento-com-custódia)
- [Liberação de custódia](#liberação-de-custódia)
Expand All @@ -78,7 +84,7 @@ Adicionar no seu pom.xml:
<dependency>
<groupId>br.com.moip</groupId>
<artifactId>java-sdk</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>
</dependency>

```
Expand Down Expand Up @@ -630,6 +636,56 @@ System.out.println(account);
api.account().checkAccountExists("123.456.798-91");
```

## Contas Bancárias
### Criação
```java
BankAccount createdBankAccount = api.create("MPA-E0BAC6D15696",
new BankAccountRequest()
.bankNumber("237")
.agencyNumber("12346")
.agencyCheckNumber("0")
.accountNumber("12345679")
.accountCheckNumber("7")
.checking()
.holder(new HolderRequest()
.fullname("Vagner")
.taxDocument(TaxDocumentRequest.cpf("22222222222"))
)
);
```
### Consulta
```java
BankAccount createdBankAccount = api.get("BKA-E0BAC6D15696");
```
### Exclusão
```java
api.delete("BKA-E0BAC6D15696");
```
### Atualização
```java
BankAccount createdBankAccount = api.update("BKA-E0BAC6D15696",
new BankAccountRequest()
.bankNumber("237")
.agencyNumber("12345")
.agencyCheckNumber("8")
.accountNumber("12345678")
.accountCheckNumber("8")
.checking()
.holder(
new HolderRequest()
.fullname("Demo Moip")
.taxDocument(
TaxDocumentRequest.cpf("62213453322")
)
)
);
```

### Listagem
```java
List<BankAccount> createdBankAccounts = api.getList("MPA-E0BAC6D15696");
```

## Custódia
### Pagamento com custódia
```java
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'signing'

group = 'br.com.moip'
archivesBaseName = "java-sdk"
version = '3.3.0'
version = '3.4.0'

description = "Moip v2 SDK"

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/br/com/moip/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public <T> T post(final String path, final Object object, final Class<T> type, C
return doRequest("POST", path, object, type, contentType);
}

public <T> T put(final String path, final Object object, final Class<T> type) {
return doRequest("PUT", path, object, type, ContentType.APPLICATION_JSON);
}

public <T> T get(String path, Class<T> type) {
return doRequest("GET", path, null, type, ContentType.APPLICATION_JSON);
}
Expand Down
26 changes: 22 additions & 4 deletions src/main/java/br/com/moip/api/BankAccountsAPI.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package br.com.moip.api;

import java.util.Arrays;
import java.util.List;

import br.com.moip.Client;
import br.com.moip.exception.ValidationException;
import br.com.moip.request.BankAccountRequest;
import br.com.moip.resource.BankAccount;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class BankAccountsAPI {

private final Client client;
Expand All @@ -29,5 +29,23 @@ public List<BankAccount> getList(final String moipAccount) {

return Arrays.asList(bankAccounts);
}

public BankAccount update(final String id, final BankAccountRequest bankAccountRequest) {
return client.put(String.format("/v2/bankaccounts/%s", id), bankAccountRequest, BankAccount.class);
}

public Boolean delete(final String id) {
try {
client.delete(String.format("/v2/bankaccounts/%s", id), BankAccount.class);

return true;
} catch (ValidationException e) {
if (e.getResponseCode() != 404) {
throw new ValidationException(e.getResponseCode(), e.getResponseStatus(), e.getError());
}
}
return false;
}


}
11 changes: 11 additions & 0 deletions src/main/java/br/com/moip/request/CreditCardRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class CreditCardRequest {

private String id;
private String hash;
private String number;
private String expirationMonth;
Expand All @@ -10,6 +11,16 @@ public class CreditCardRequest {
private Boolean store;
private HolderRequest holder;

public String getId() {
return id;
}

public CreditCardRequest id(final String id) {
this.id = id;

return this;
}

public String getHash() {
return hash;
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/br/com/moip/resource/Amount.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,40 @@
public class Amount {

private Integer total;
private Integer fees;
private Integer refunds;
private Integer liquid;
private String currency;

public Integer getTotal() {
return total;
}

public Integer getFees() {
return fees;
}

public Integer getRefunds() {
return refunds;
}

public Integer getLiquid() {
return liquid;
}

public String getCurrency() {
return currency;
}

@Override
public String toString() {
return new StringBuilder("Amount{")
.append("total=").append(total)
.append(", fees=").append(fees)
.append(", refunds=").append(refunds)
.append(", liquid=").append(liquid)
.append(", currency='").append(currency)
.append('\'')
.append('}').toString();
}
}
9 changes: 9 additions & 0 deletions src/main/java/br/com/moip/resource/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Order {

private String id;
private Amount amount;
private OrderStatus status;
private String ownId;
private final List<Item> items;
private Customer customer;
Expand Down Expand Up @@ -48,6 +49,14 @@ public OrderLinks getLinks() {
return _links;
}

public OrderStatus getStatus() {
return status;
}

public void setStatus(OrderStatus status) {
this.status = status;
}

public Order(){
items = new ArrayList<Item>();
}
Expand Down
52 changes: 39 additions & 13 deletions src/test/java/br/com/moip/api/BankAccountAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ public void setUp() {
public void shouldCreateBankAccount() {

BankAccount createdBankAccount = api.create("MPA-E0BAC6D15696",
new BankAccountRequest()
.bankNumber("237")
.agencyNumber("12346")
.agencyCheckNumber("0")
.accountNumber("12345679")
.accountCheckNumber("7")
.checking()
.holder(new HolderRequest()
.fullname("Vagner")
.taxDocument(TaxDocumentRequest.cpf("22222222222")
)
)
new BankAccountRequest()
.bankNumber("237")
.agencyNumber("12346")
.agencyCheckNumber("0")
.accountNumber("12345679")
.accountCheckNumber("7")
.checking()
.holder(new HolderRequest()
.fullname("Vagner")
.taxDocument(TaxDocumentRequest.cpf("22222222222")
)
)
);
assertTrue(createdBankAccount.getId().startsWith("BKA-"));
}
Expand All @@ -58,7 +58,6 @@ public void shouldCreateBankAccount() {
public void shouldGetOneAccount() {
BankAccount createdBankAccount = api.get("BKA-P9O93Z6PKUTI");
assertEquals("BKA-P9O93Z6PKUTI", createdBankAccount.getId());

}

@Play("bankaccounts/getlist")
Expand All @@ -72,4 +71,31 @@ public void shouldGetAccountList() {
assertEquals("BKA-WX44D0AEV2NH", createdBankAccounts.get(3).getId());
}

@Play("bankaccounts/update")
@Test
public void shouldUpdateBankAccount() {
BankAccount createdBankAccount = api.update("BKA-E0BAC6D15696",
new BankAccountRequest()
.bankNumber("237")
.agencyNumber("12345")
.agencyCheckNumber("8")
.accountNumber("12345678")
.accountCheckNumber("8")
.checking()
.holder(
new HolderRequest()
.fullname("Demo Moip")
.taxDocument(
TaxDocumentRequest.cpf("62213453322")
)
)
);
assertTrue(createdBankAccount.getId().startsWith("BKA-"));
}

@Play("bankaccounts/delete")
@Test
public void shouldDeleteBankAccount() {
assertTrue(api.delete("BKA-E0BAC6D15696"));
}
}
2 changes: 2 additions & 0 deletions src/test/java/br/com/moip/api/OrderAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import br.com.moip.request.CheckoutPreferencesRequest;
import br.com.moip.request.InstallmentRequest;
import br.com.moip.resource.Order;
import br.com.moip.resource.OrderStatus;
import br.com.moip.response.OrderListResponse;
import com.rodrigosaito.mockwebserver.player.Play;
import com.rodrigosaito.mockwebserver.player.Player;
Expand Down Expand Up @@ -48,6 +49,7 @@ public void testGet() {
Order order = api.get("ORD-HCOWQ2QJKTAT");

assertEquals("ORD-HCOWQ2QJKTAT", order.getId());
assertEquals(OrderStatus.CREATED, order.getStatus());
}

@Play("orders/create")
Expand Down
13 changes: 13 additions & 0 deletions src/test/resources/plays/bankaccounts/delete.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
!play
interactions:
-
request:
uri: /v2/bankaccounts/BKA-E0BAC6D15696
headers:
Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg==
method: DELETE
response:
status: 200
headers:
"Content-Type": application/json
body: |
15 changes: 15 additions & 0 deletions src/test/resources/plays/bankaccounts/update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
!play
interactions:
-
request:
uri: /v2/bankaccounts/BKA-E0BAC6D15696
headers:
"Content-Type": application/json
Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg==
method: PUT
response:
status: 201
headers:
"Content-Type": application/json
body: |
{ "id": "BKA-E0BAC6D15696","agencyNumber": 12345,"holder": {"taxDocument": {"number": "622.134.533-22","type": "CPF"},"fullname": "Demo Moip"},"accountNumber": 12345678,"status": "NOT_VERIFIED","createdAt": "2015-10-29T15:50:27.746-02:00","accountCheckNumber": "8","_links": {"self": {"href": "https://sandbox.moip.com.br/v2/accounts/MPA-8307EF11B83E/bankaccounts"}},"bankName": "BANCO BRADESCO S.A.","type": "CHECKING","agencyCheckNumber": "8","bankNumber": "237"}

0 comments on commit 5ecdc2d

Please sign in to comment.