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

Commit

Permalink
[RELEASE] v3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joaolucasl authored Oct 16, 2017
2 parents c3eecac + b2674c5 commit 6cb00c6
Show file tree
Hide file tree
Showing 16 changed files with 481 additions and 7 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
<a name="v3.3.0"></a>
# [](https://github.com/moip/moip-sdk-java/compare/v3.2.0...v3.3.0) (2017-10-10)


### Features

* **Multipayment:** Added method 'cancelPreAuthorized' to cancel pre authorized payments ([be2fc6c](https://github.com/moip/moip-sdk-java/commit/be2fc6c))
* **Multipayment:** Added method 'capture' ([0a634c3](https://github.com/moip/moip-sdk-java/commit/0a634c3))
* **Order:** added method to get an order list ([8602c59](https://github.com/moip/moip-sdk-java/commit/8602c59))



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

Expand All @@ -16,7 +28,7 @@

### Features

* Create structure to HATEOAS links in Payment and fix toString methods to some Link Resources ([cf6c46f](https://github.com/caiogaspar/moip-sdk-java/commit/cf6c46f))
* Create structure to HATEOAS links in Payment and fix toString methods to some Link Resources ([cf6c46f](https://github.com/moip/moip-sdk-java/commit/cf6c46f))


<a name="v3.0.0"></a>
Expand Down
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
- [Pedidos](#pedidos)
- [Criação](#criação)
- [Consulta](#consulta)
- [Pedido Específico](#pedido-específico)
- [Todos os Pedidos](#todos-os-pedidos)
- [Sem Filtro](#sem-filtro)
- [Com Filtros](#com-filtros)
- [Com Paginação](#com-paginação)
- [Consulta Valor Específico](#consulta-valor-específico)
- [Pagamentos](#pagamentos)
- [Criação](#criação-1)
- [Cartão de Crédito](#cartão-de-crédito)
Expand Down Expand Up @@ -47,6 +53,8 @@
- [Cartão de Crédito](#cartão-de-crédito-1)
- [Boleto Bancário](#boleto-bancário)
- [Consulta](#consulta-6)
- [Capturar multipagamento pré-autorizado](#capturar-multipagamento-pré-autorizado)
- [Cancelar multipagamento pré-autorizado](#cancelar-multipagamento-pré-autorizado)
- [Conta Moip](#conta-moip)
- [Criação](#criação-6)
- [Consulta](#consulta-7)
Expand All @@ -70,7 +78,7 @@ Adicionar no seu pom.xml:
<dependency>
<groupId>br.com.moip</groupId>
<artifactId>java-sdk</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
</dependency>

```
Expand Down Expand Up @@ -124,12 +132,46 @@ Order createdOrder = api.order().create(new OrderRequest()
```

### Consulta
#### Pedido Específico
```java
String orderId = "ORD-HPMZSOM611M2";
Order order = api.order().get(orderId);
System.out.println(order.toString());
```

#### Todos os Pedidos
##### Sem Filtro
```java
OrderListResponse orders = api.order().list();
```

##### Com Filtros
```java
Filters filters = new Filters()
.between("amount", "1000", "10000")
.in("status", status);
OrderListResponse orders = api.order().list(filters);
```

##### Com Paginação
```java
OrderListResponse orders = api.order().list(new Pagination(10,0));
```

##### Consulta Valor Específico
```java
OrderListResponse orders = api.order().list("josé silva");
```

> Também é possível usar paginação, filtros e consulta de valor específico juntos
```java
Filters filters = new Filters()
.between("amount", "1000", "10000")
.in("status", status);
OrderListResponse orders = api.order().list(new Pagination(10,0), filters, "josé silva");
```

## Pagamentos

### Criação
Expand Down Expand Up @@ -501,6 +543,18 @@ Multipayment multipayment = api.multipayment().get("MPY-OUGA0AHH2BOF");
System.out.println(multipayment);
```

### Capturar multipagamento pré-autorizado
```java
Multipayment capturedMultipayment = api.multipayment().capture("MPY-UGZLJMVJ37LX");
System.out.println(capturedMultipayment);
```

### Cancelar multipagamento pré-autorizado
```java
Multipayment cancelledMultipayment = api.multipayment().cancelPreAuthorized("MPY-YDNM3U17OSDD");
System.out.println(cancelledMultipayment);
```

## Conta Moip
### Criação
```java
Expand Down
3 changes: 2 additions & 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.2.0'
version = '3.3.0'

description = "Moip v2 SDK"

Expand All @@ -19,6 +19,7 @@ dependencies {
compile group: "org.slf4j", name: "slf4j-api", version: "1.7.12"
compile group: "com.google.code.gson", name: "gson", version: "2.4"
compile group: "org.apache.httpcomponents", name: "httpclient", version: "4.5.3"
compile group: "org.apache.commons", name: "commons-lang3", version: "3.6"

testCompile group: "org.slf4j", name: "slf4j-simple", version: "1.7.12"
testCompile group: "com.github.rodrigosaito", name: "mockwebserver-player", version: "1.1.0"
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/br/com/moip/api/MultipaymentAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ public MultipaymentAPI(final Client client) {
}

public Multipayment create(PaymentRequest multipayment) {
return client.post("/v2/multiorders/" + multipayment.getOrderId() + "/multipayments", multipayment, Multipayment.class);
return client.post(String.format("/v2/multiorders/%s/multipayments", multipayment.getOrderId()), multipayment, Multipayment.class);
}

public Multipayment get(String multipaymentId) {
return client.get("/v2/multipayments/" + multipaymentId, Multipayment.class);
return client.get(String.format("/v2/multipayments/%s", multipaymentId), Multipayment.class);
}

public Multipayment capture(String multipaymentId) {
return client.post(String.format("/v2/multipayments/%s/capture", multipaymentId), null, Multipayment.class);
}

public Multipayment cancelPreAuthorized(String multipaymentId) {
return client.post(String.format("/v2/multipayments/%s/void", multipaymentId), null, Multipayment.class);
}

}
53 changes: 51 additions & 2 deletions src/main/java/br/com/moip/api/OrderAPI.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,71 @@
package br.com.moip.api;

import br.com.moip.Client;
import br.com.moip.api.filter.Filters;
import br.com.moip.api.filter.Pagination;
import br.com.moip.request.OrderRequest;
import br.com.moip.resource.Order;
import br.com.moip.response.OrderListResponse;
import br.com.moip.util.QueryStringFactory;

import java.util.HashMap;
import java.util.Map;

public class OrderAPI {

private final Client client;

private static final String PATH = "/v2/orders";

public OrderAPI(final Client client) {
this.client = client;
}

public Order create(final OrderRequest order) {
return client.post("/v2/orders", order, Order.class);
return client.post(PATH, order, Order.class);
}

public Order get(final String id) {
return client.get("/v2/orders/" + id, Order.class);
return client.get(String.format("%s/%s", PATH, id), Order.class);
}

public OrderListResponse list() {
return client.get(PATH, OrderListResponse.class);
}

public OrderListResponse list(final Pagination pagination) {
String path = new QueryStringFactory(PATH, pagination, null, null).generate();

return client.get(path, OrderListResponse.class);
}

public OrderListResponse list(final Filters filters) {
return client.get(new QueryStringFactory(PATH, null, filters, null).generate(), OrderListResponse.class);
}

public OrderListResponse list(final String queryParam) {
return client.get(new QueryStringFactory(PATH, null, null, hashParams(queryParam)).generate(), OrderListResponse.class);
}

public OrderListResponse list(final Pagination pagination, final Filters filters) {
return client.get(new QueryStringFactory(PATH, pagination, filters, null).generate(), OrderListResponse.class);
}

public OrderListResponse list(final Pagination pagination, final String queryParam) {
return client.get(new QueryStringFactory(PATH, pagination, null, hashParams(queryParam)).generate(), OrderListResponse.class);
}

public OrderListResponse list(final Filters filters, final String queryParam) {
return client.get(new QueryStringFactory(PATH, null, filters, hashParams(queryParam)).generate(), OrderListResponse.class);
}

public OrderListResponse list(final Pagination pagination, final Filters filters, final String qParam) {
return client.get(new QueryStringFactory(PATH, pagination, filters, hashParams(qParam)).generate(), OrderListResponse.class);
}

private Map<String, String> hashParams(final String queryParam) {
return new HashMap<String, String>() {{
put("q", queryParam);
}};
}
}
47 changes: 47 additions & 0 deletions src/main/java/br/com/moip/api/filter/Filters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package br.com.moip.api.filter;

import org.apache.commons.lang3.StringUtils;

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

public class Filters {

private List<String> filters = new ArrayList<>();

public Filters greaterThan(String field, String value) {
filters.add(String.format("%s::gt(%s)", field, value));

return this;
}

public Filters greaterThanOrEqual(String field, String value) {
filters.add(String.format("%s::ge(%s)", field, value));

return this;
}

public Filters lessThan(String field, String value) {
filters.add(String.format("%s::lt(%s)", field, value));

return this;
}

public Filters between(String field, String value1, String value2) {
filters.add(String.format("%s::bt(%s,%s)", field, value1, value2));

return this;
}

public Filters in (String field, List<String> values) {
filters.add(String.format("%s::in(%s)", field, StringUtils.join(values, ",")));

return this;
}

@Override
public String toString() {
return StringUtils.join(filters, "|");
}

}
5 changes: 5 additions & 0 deletions src/main/java/br/com/moip/api/filter/Pagination.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ public Pagination(){

}

public Pagination (int limit, int offset) {
this.limit = limit;
this.offset = offset;
}

public Pagination(final String url) {
String[] params = url.split("&");
String limit = params[0].split("=")[1];
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/br/com/moip/response/OrderListResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package br.com.moip.response;

import br.com.moip.resource.Links;
import br.com.moip.resource.Order;
import br.com.moip.resource.invoice.Summary;

import java.util.List;

public class OrderListResponse {

public static final String NEXT = "next";
public static final String PREVIOUS = "previous";

private List<Order> orders;
private Summary summary;
private Links links;

public String next() {
return links.getLinks().get(NEXT).toString();
}

public String previous() {
return links.getLinks().get(PREVIOUS).toString();
}

public List<Order> getOrders() {
return orders;
}

public Summary getSummary() {
return summary;
}

public void setSummary(Summary summary) {
this.summary = summary;
}

@Override
public String toString() {
return new StringBuilder("OrderListResponse{")
.append("summary=").append(summary)
.append(", orders=").append(orders)
.append('}').toString();
}
}
Loading

0 comments on commit 6cb00c6

Please sign in to comment.