├── src
├── main
│ └── java
│ │ └── com
│ │ └── iugu
│ │ ├── utils
│ │ └── ConvertionUtils.java
│ │ ├── serializers
│ │ ├── JsonFormat.java
│ │ └── DateSerializer.java
│ │ ├── model
│ │ ├── Credit.java
│ │ ├── Feature.java
│ │ ├── Price.java
│ │ ├── Transfer.java
│ │ ├── MarketPlace.java
│ │ ├── CustomVariable.java
│ │ ├── Logs.java
│ │ ├── Item.java
│ │ ├── Data.java
│ │ ├── SubItem.java
│ │ ├── PaymentToken.java
│ │ ├── Payer.java
│ │ ├── Address.java
│ │ ├── PaymentMethod.java
│ │ ├── Plan.java
│ │ ├── Charge.java
│ │ ├── Customer.java
│ │ ├── Subscription.java
│ │ └── Invoice.java
│ │ ├── exceptions
│ │ └── IuguException.java
│ │ ├── enums
│ │ ├── Currency.java
│ │ ├── ItemType.java
│ │ ├── IntervalType.java
│ │ └── PayableWith.java
│ │ ├── IuguConfiguration.java
│ │ ├── responses
│ │ ├── CustomVariableResponse.java
│ │ ├── VariableResponse.java
│ │ ├── BankSlipResponse.java
│ │ ├── PaymentTokenResponse.java
│ │ ├── PriceResponse.java
│ │ ├── LogResponse.java
│ │ ├── CustomerResponse.java
│ │ ├── ExtraInfoResponse.java
│ │ ├── SubItemResponse.java
│ │ ├── FeatureResponse.java
│ │ ├── PlanResponse.java
│ │ ├── ItemResponse.java
│ │ ├── ChargeResponse.java
│ │ ├── SubscriptionResponse.java
│ │ └── InvoiceResponse.java
│ │ ├── Authenticator.java
│ │ └── services
│ │ ├── PaymentTokenService.java
│ │ ├── ChargeService.java
│ │ ├── PaymentMethodService.java
│ │ ├── CustomerService.java
│ │ ├── PlanService.java
│ │ ├── InvoiceService.java
│ │ └── SubscriptionService.java
└── test
│ └── java
│ └── com
│ └── iugu
│ └── iugu_java
│ └── AppTest.java
├── pom.xml
├── .gitignore
└── README.md
/src/main/java/com/iugu/utils/ConvertionUtils.java:
--------------------------------------------------------------------------------
1 | package com.iugu.utils;
2 |
3 | public abstract class ConvertionUtils {
4 | public static String booleanToString(boolean Value) {
5 | return Boolean.toString(Value);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/serializers/JsonFormat.java:
--------------------------------------------------------------------------------
1 | package com.iugu.serializers;
2 |
3 | import java.lang.annotation.Retention;
4 | import java.lang.annotation.RetentionPolicy;
5 |
6 | @Retention(RetentionPolicy.RUNTIME)
7 | public @interface JsonFormat {
8 |
9 | String value();
10 |
11 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/Credit.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | public class Credit {
4 |
5 | public Credit(Integer quantity) {
6 | this.quantity = quantity;
7 | }
8 |
9 | private Integer quantity;
10 |
11 | public Integer getQuantity() {
12 | return quantity;
13 | }
14 |
15 | public void setQuantity(Integer quantity) {
16 | this.quantity = quantity;
17 | }
18 |
19 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/exceptions/IuguException.java:
--------------------------------------------------------------------------------
1 | package com.iugu.exceptions;
2 |
3 | public class IuguException extends Exception {
4 | private static final long serialVersionUID = 8701207870125630038L;
5 |
6 | public IuguException(String Message, int ResponseCode, String ResponseText) {
7 | super(Message + " - StatusCode: [" + ResponseCode + "] / ResponseText: [" + ResponseText + "]");
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/enums/Currency.java:
--------------------------------------------------------------------------------
1 | package com.iugu.enums;
2 |
3 | import org.codehaus.jackson.annotate.JsonValue;
4 |
5 | public enum Currency {
6 |
7 | BRL("BRL");
8 |
9 | private String value;
10 |
11 | private Currency(String value) {
12 | this.value = value;
13 | }
14 |
15 | @JsonValue
16 | public String getValue() {
17 | return value;
18 | }
19 |
20 | public void setValue(String value) {
21 | this.value = value;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/enums/ItemType.java:
--------------------------------------------------------------------------------
1 | package com.iugu.enums;
2 |
3 | import org.codehaus.jackson.annotate.JsonValue;
4 |
5 | public enum ItemType {
6 |
7 | CREDIT_CARD("credit_card");
8 |
9 | private String value;
10 |
11 | private ItemType(String value) {
12 | this.value = value;
13 | }
14 |
15 | @JsonValue
16 | public String getValue() {
17 | return value;
18 | }
19 |
20 | public void setValue(String value) {
21 | this.value = value;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/enums/IntervalType.java:
--------------------------------------------------------------------------------
1 | package com.iugu.enums;
2 |
3 | import org.codehaus.jackson.annotate.JsonValue;
4 |
5 | public enum IntervalType {
6 |
7 | WEEKS("weeks"), MONTHS("months");
8 |
9 | private String value;
10 |
11 | private IntervalType(String value) {
12 | this.value = value;
13 | }
14 |
15 | @JsonValue
16 | public String getValue() {
17 | return value;
18 | }
19 |
20 | public void setValue(String value) {
21 | this.value = value;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/enums/PayableWith.java:
--------------------------------------------------------------------------------
1 | package com.iugu.enums;
2 |
3 | import org.codehaus.jackson.annotate.JsonValue;
4 |
5 | public enum PayableWith {
6 |
7 | CREDIT_CARD("credit_card"), ALL("all"), BANK_SLIP("bank_slip");
8 |
9 | private String value;
10 |
11 | private PayableWith(String value) {
12 | this.value = value;
13 | }
14 |
15 | @JsonValue
16 | public String getValue() {
17 | return value;
18 | }
19 |
20 | public void setValue(String value) {
21 | this.value = value;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/Feature.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | public class Feature {
4 |
5 | private String name;
6 |
7 | private String identifier;
8 |
9 | private int value;
10 |
11 | public Feature(String name, String identifier, int value){
12 | this.name = name;
13 | this.identifier = identifier;
14 | this.value = value;
15 | }
16 |
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | public String getIdentifier() {
22 | return identifier;
23 | }
24 |
25 | public int getValue() {
26 | return value;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/Price.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | import org.codehaus.jackson.annotate.JsonProperty;
4 |
5 | import com.iugu.enums.Currency;
6 |
7 | public class Price {
8 |
9 | private Currency currency;
10 |
11 | @JsonProperty("value_cents")
12 | private int valueCents;
13 |
14 | public Price(Currency currency, int valueCents) {
15 | this.currency = currency;
16 | this.valueCents = valueCents;
17 | }
18 |
19 | public Currency getCurrency() {
20 | return currency;
21 | }
22 |
23 | public int getValueCents() {
24 | return valueCents;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/Transfer.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | import org.codehaus.jackson.annotate.JsonProperty;
4 |
5 | public class Transfer {
6 |
7 | @JsonProperty("receiver_id")
8 | private String receiverId;
9 |
10 | @JsonProperty("amount_cents")
11 | private int amountCents;
12 |
13 | public Transfer(String receiverId, int amountCents) {
14 | this.receiverId = receiverId;
15 | this.amountCents = amountCents;
16 | }
17 |
18 | public String getReceiverId() {
19 | return receiverId;
20 | }
21 |
22 | public int getAmountCents() {
23 | return amountCents;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/MarketPlace.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | import org.codehaus.jackson.annotate.JsonProperty;
4 |
5 | public class MarketPlace {
6 |
7 | private String name;
8 |
9 | @JsonProperty("comission_percent")
10 | private double commissionPercent;
11 |
12 | public String getName() {
13 | return name;
14 | }
15 |
16 | public void setName(String name) {
17 | this.name = name;
18 | }
19 |
20 | public double getCommissionPercent() {
21 | return commissionPercent;
22 | }
23 |
24 | public void setCommissionPercent(double commissionPercent) {
25 | this.commissionPercent = commissionPercent;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/IuguConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.iugu;
2 |
3 | import javax.ws.rs.client.Client;
4 | import javax.ws.rs.client.ClientBuilder;
5 |
6 | public class IuguConfiguration {
7 |
8 | private final static String URL = "https://api.iugu.com/v1";
9 | private final String tokenId;
10 |
11 | public IuguConfiguration(String token) {
12 | tokenId = token;
13 | }
14 |
15 | public Client getNewClient() {
16 | return ClientBuilder.newClient().register(new Authenticator(tokenId, ""));
17 | }
18 |
19 | public Client getNewClientNotAuth() {
20 | return ClientBuilder.newClient();
21 | }
22 |
23 | public static String url(String endpoint) {
24 | return URL + endpoint;
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/CustomVariable.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | import org.codehaus.jackson.annotate.JsonProperty;
4 |
5 | public class CustomVariable {
6 |
7 | public CustomVariable(String name, String value) {
8 | this.name = name;
9 | this.value = value;
10 | }
11 |
12 | private String name;
13 |
14 | private String value;
15 |
16 | @JsonProperty("_destroy")
17 | private Boolean destroy;
18 |
19 | public String getName() {
20 | return name;
21 | }
22 |
23 | public String getValue() {
24 | return value;
25 | }
26 |
27 | public Boolean getDestroy() {
28 | return destroy;
29 | }
30 |
31 | public void setDestroy(Boolean destroy) {
32 | this.destroy = destroy;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/Logs.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | import org.codehaus.jackson.annotate.JsonProperty;
4 |
5 | public class Logs {
6 |
7 | public Logs(String description, String notes) {
8 | this.description = description;
9 | this.notes = notes;
10 | }
11 |
12 | private String description;
13 |
14 | private String notes;
15 |
16 | @JsonProperty("_destroy")
17 | private Boolean destroy;
18 |
19 | public Boolean getDestroy() {
20 | return destroy;
21 | }
22 |
23 | public void setDestroy(Boolean destroy) {
24 | this.destroy = destroy;
25 | }
26 |
27 | public String getDescription() {
28 | return description;
29 | }
30 |
31 | public String getNotes() {
32 | return notes;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/responses/CustomVariableResponse.java:
--------------------------------------------------------------------------------
1 | package com.iugu.responses;
2 |
3 | import org.codehaus.jackson.annotate.JsonIgnoreProperties;
4 |
5 | @JsonIgnoreProperties(ignoreUnknown = true)
6 | public class CustomVariableResponse {
7 |
8 | private String id;
9 |
10 | private String name;
11 |
12 | private String value;
13 |
14 | public String getId() {
15 | return id;
16 | }
17 |
18 | public void setId(String id) {
19 | this.id = id;
20 | }
21 |
22 | public String getName() {
23 | return name;
24 | }
25 |
26 | public void setName(String name) {
27 | this.name = name;
28 | }
29 |
30 | public String getValue() {
31 | return value;
32 | }
33 |
34 | public void setValue(String value) {
35 | this.value = value;
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/responses/VariableResponse.java:
--------------------------------------------------------------------------------
1 | package com.iugu.responses;
2 |
3 | import org.codehaus.jackson.annotate.JsonIgnoreProperties;
4 |
5 | @JsonIgnoreProperties(ignoreUnknown = true)
6 | public class VariableResponse {
7 |
8 | private String id;
9 |
10 | private String variable;
11 |
12 | private String value;
13 |
14 | public String getId() {
15 | return id;
16 | }
17 |
18 | public void setId(String id) {
19 | this.id = id;
20 | }
21 |
22 | public String getVariable() {
23 | return variable;
24 | }
25 |
26 | public void setVariable(String variable) {
27 | this.variable = variable;
28 | }
29 |
30 | public String getValue() {
31 | return value;
32 | }
33 |
34 | public void setValue(String value) {
35 | this.value = value;
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/src/test/java/com/iugu/iugu_java/AppTest.java:
--------------------------------------------------------------------------------
1 | package com.iugu.iugu_java;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple App.
9 | */
10 | public class AppTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public AppTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( AppTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testApp()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/responses/BankSlipResponse.java:
--------------------------------------------------------------------------------
1 | package com.iugu.responses;
2 |
3 | import org.codehaus.jackson.annotate.JsonIgnoreProperties;
4 | import org.codehaus.jackson.annotate.JsonProperty;
5 |
6 | @JsonIgnoreProperties(ignoreUnknown = true)
7 | public class BankSlipResponse {
8 |
9 | @JsonProperty("digitable_line")
10 | private String digitableLine;
11 |
12 | @JsonProperty("barcode_data")
13 | private String barcodeData;
14 |
15 | private String barcode;
16 |
17 | public String getDigitableLine() {
18 | return digitableLine;
19 | }
20 |
21 | public void setDigitableLine(String digitableLine) {
22 | this.digitableLine = digitableLine;
23 | }
24 |
25 | public String getBarcodeData() {
26 | return barcodeData;
27 | }
28 |
29 | public void setBarcodeData(String barcodeData) {
30 | this.barcodeData = barcodeData;
31 | }
32 |
33 | public String getBarcode() {
34 | return barcode;
35 | }
36 |
37 | public void setBarcode(String barcode) {
38 | this.barcode = barcode;
39 | }
40 |
41 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/Item.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 |
4 | import org.codehaus.jackson.annotate.JsonProperty;
5 |
6 | public class Item {
7 |
8 | private String description;
9 |
10 | private Integer quantity;
11 |
12 | @JsonProperty("price_cents")
13 | private Integer priceCents;
14 |
15 | public Item(String description, Integer quantity, Integer priceCents) {
16 | this.description = description;
17 | this.quantity = quantity;
18 | this.priceCents = priceCents;
19 | }
20 |
21 | public String getDescription() {
22 | return description;
23 | }
24 |
25 | public void setDescription(String description) {
26 | this.description = description;
27 | }
28 |
29 | public Integer getQuantity() {
30 | return quantity;
31 | }
32 |
33 | public void setQuantity(Integer quantity) {
34 | this.quantity = quantity;
35 | }
36 |
37 | public Integer getPriceCents() {
38 | return priceCents;
39 | }
40 |
41 | public void setPrice_cents(Integer priceCents) {
42 | this.priceCents = priceCents;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/responses/PaymentTokenResponse.java:
--------------------------------------------------------------------------------
1 | package com.iugu.responses;
2 |
3 | import org.codehaus.jackson.annotate.JsonIgnoreProperties;
4 | import org.codehaus.jackson.annotate.JsonProperty;
5 |
6 | @JsonIgnoreProperties(ignoreUnknown = true)
7 | public class PaymentTokenResponse {
8 |
9 | @JsonProperty("id")
10 | private String id;
11 |
12 | @JsonProperty("method")
13 | private String method;
14 |
15 | @JsonProperty("test")
16 | private Boolean isTest;
17 |
18 | @JsonProperty("extra_info")
19 | private ExtraInfoResponse extraInfo;
20 |
21 | public String getId() {
22 | return id;
23 | }
24 |
25 | public String getMethod() {
26 | return method;
27 | }
28 |
29 | public Boolean getTest() {
30 | return isTest;
31 | }
32 |
33 | public ExtraInfoResponse getExtraInfo() {
34 | return extraInfo;
35 | }
36 |
37 | @Override
38 | public String toString() {
39 | return "PaymentTokenResponse{" +
40 | "id='" + id + '\'' +
41 | ", method='" + method + '\'' +
42 | ", isTest=" + isTest +
43 | ", extraInfo=" + extraInfo +
44 | '}';
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/responses/PriceResponse.java:
--------------------------------------------------------------------------------
1 | package com.iugu.responses;
2 |
3 | import org.codehaus.jackson.annotate.JsonIgnoreProperties;
4 | import org.codehaus.jackson.annotate.JsonProperty;
5 |
6 | @JsonIgnoreProperties(ignoreUnknown = true)
7 | public class PriceResponse {
8 |
9 | private String id;
10 |
11 | private String currency;
12 |
13 | @JsonProperty("plan_id")
14 | private String planId;
15 |
16 | @JsonProperty("value_cents")
17 | private Integer valueCents;
18 |
19 | public String getId() {
20 | return id;
21 | }
22 |
23 | public void setId(String id) {
24 | this.id = id;
25 | }
26 |
27 | public String getCurrency() {
28 | return currency;
29 | }
30 |
31 | public void setCurrency(String currency) {
32 | this.currency = currency;
33 | }
34 |
35 | public String getPlanId() {
36 | return planId;
37 | }
38 |
39 | public void setPlanId(String planId) {
40 | this.planId = planId;
41 | }
42 |
43 | public Integer getValueCents() {
44 | return valueCents;
45 | }
46 |
47 | public void setValueCents(Integer valueCents) {
48 | this.valueCents = valueCents;
49 | }
50 |
51 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/Data.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | import org.codehaus.jackson.annotate.JsonProperty;
4 |
5 | public class Data {
6 |
7 | public Data(String number, String verificationValue, String firstName, String lastName, String month, String year) {
8 | this.number = number;
9 | this.verificationValue = verificationValue;
10 | this.firstName = firstName;
11 | this.lastName = lastName;
12 | this.month = month;
13 | this.year = year;
14 | }
15 |
16 | String number;
17 |
18 | @JsonProperty("verification_value")
19 | String verificationValue;
20 |
21 | @JsonProperty("first_name")
22 | String firstName;
23 |
24 | @JsonProperty("last_name")
25 | String lastName;
26 |
27 | String month;
28 |
29 | String year;
30 |
31 | public String getNumber() {
32 | return number;
33 | }
34 |
35 | public String getVerificationValue() {
36 | return verificationValue;
37 | }
38 |
39 | public String getFirstName() {
40 | return firstName;
41 | }
42 |
43 | public String getLastName() {
44 | return lastName;
45 | }
46 |
47 | public String getMonth() {
48 | return month;
49 | }
50 |
51 | public String getYear() {
52 | return year;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/SubItem.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | import org.codehaus.jackson.annotate.JsonProperty;
4 |
5 | public class SubItem {
6 |
7 | private String description;
8 |
9 | private Integer quantity;
10 |
11 | @JsonProperty("price_cents")
12 | private Integer priceCents;
13 |
14 | private boolean recurrent;
15 |
16 | public SubItem(String description, Integer quantity, Integer priceCents) {
17 | this.description = description;
18 | this.quantity = quantity;
19 | this.priceCents = priceCents;
20 | }
21 |
22 | public String getDescription() {
23 | return description;
24 | }
25 |
26 | public Integer getQuantity() {
27 | return quantity;
28 | }
29 |
30 | public Integer getPriceCents() {
31 | return priceCents;
32 | }
33 |
34 | public boolean isRecurrent() {
35 | return recurrent;
36 | }
37 |
38 | public void setRecurrent(boolean recurrent) {
39 | this.recurrent = recurrent;
40 | }
41 |
42 | @Override
43 | public String toString() {
44 | return "SubItem{" +
45 | "description='" + description + '\'' +
46 | ", quantity=" + quantity +
47 | ", priceCents=" + priceCents +
48 | ", recurrent=" + recurrent +
49 | '}';
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.iugu
6 | iugu-java
7 | 0.0.1-SNAPSHOT
8 | jar
9 |
10 | iugu-java
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 | 1.7
16 | 1.7
17 |
18 |
19 |
20 |
21 | org.jboss.resteasy
22 | resteasy-client
23 | 3.0.14.Final
24 |
25 |
26 |
27 | org.jboss.resteasy
28 | resteasy-jackson-provider
29 | 2.3.2.Final
30 |
31 |
32 |
33 | junit
34 | junit
35 | 4.12
36 | test
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/Authenticator.java:
--------------------------------------------------------------------------------
1 | package com.iugu;
2 |
3 | import java.io.IOException;
4 | import java.io.UnsupportedEncodingException;
5 |
6 | import javax.ws.rs.client.ClientRequestContext;
7 | import javax.ws.rs.client.ClientRequestFilter;
8 | import javax.ws.rs.core.MultivaluedMap;
9 | import java.util.Base64;
10 |
11 | public class Authenticator implements ClientRequestFilter {
12 |
13 | private final String user;
14 | private final String password;
15 |
16 | public Authenticator(String user, String password) {
17 | this.user = user;
18 | this.password = password;
19 | }
20 |
21 | public void filter(ClientRequestContext requestContext) throws IOException {
22 | MultivaluedMap headers = requestContext.getHeaders();
23 | final String basicAuthentication = getBasicAuthentication();
24 | headers.add("Authorization", basicAuthentication);
25 | }
26 |
27 | private String getBasicAuthentication() {
28 | String token = this.user + ":" + this.password;
29 | try {
30 | return "Basic " + Base64.getEncoder().encodeToString(token.getBytes("UTF-8"));
31 | } catch (UnsupportedEncodingException ex) {
32 | throw new IllegalStateException("Cannot encode with UTF-8", ex);
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/responses/LogResponse.java:
--------------------------------------------------------------------------------
1 | package com.iugu.responses;
2 |
3 | import org.codehaus.jackson.annotate.JsonIgnoreProperties;
4 | import org.codehaus.jackson.annotate.JsonProperty;
5 |
6 | @JsonIgnoreProperties(ignoreUnknown = true)
7 | public class LogResponse {
8 |
9 | private String id;
10 |
11 | private String description;
12 |
13 | private String notes;
14 |
15 | @JsonProperty("created_at")
16 | private String createdAt;
17 |
18 | public String getId() {
19 | return id;
20 | }
21 |
22 | public void setId(String id) {
23 | this.id = id;
24 | }
25 |
26 | public String getDescription() {
27 | return description;
28 | }
29 |
30 | public void setDescription(String description) {
31 | this.description = description;
32 | }
33 |
34 | public String getNotes() {
35 | return notes;
36 | }
37 |
38 | public void setNotes(String notes) {
39 | this.notes = notes;
40 | }
41 |
42 | public String getCreatedAt() {
43 | return createdAt;
44 | }
45 |
46 | public void setCreatedAt(String createdAt) {
47 | this.createdAt = createdAt;
48 | }
49 |
50 | @Override
51 | public String toString() {
52 | return "LogResponse{" +
53 | "id='" + id + '\'' +
54 | ", description='" + description + '\'' +
55 | ", notes='" + notes + '\'' +
56 | ", createdAt='" + createdAt + '\'' +
57 | '}';
58 | }
59 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/services/PaymentTokenService.java:
--------------------------------------------------------------------------------
1 | package com.iugu.services;
2 |
3 | import com.iugu.IuguConfiguration;
4 | import com.iugu.exceptions.IuguException;
5 | import com.iugu.model.PaymentToken;
6 | import com.iugu.responses.PaymentTokenResponse;
7 |
8 | import javax.ws.rs.client.Entity;
9 | import javax.ws.rs.core.MediaType;
10 | import javax.ws.rs.core.Response;
11 |
12 | public class PaymentTokenService {
13 |
14 | private IuguConfiguration iugu;
15 | private final String CREATE_URL = IuguConfiguration.url("/payment_token");
16 |
17 | public PaymentTokenService(IuguConfiguration iuguConfiguration) {
18 | this.iugu = iuguConfiguration;
19 | }
20 |
21 | public PaymentTokenResponse create(PaymentToken paymentToken) throws IuguException {
22 | Response response = this.iugu.getNewClientNotAuth().target(CREATE_URL).request().post(Entity.entity(paymentToken, MediaType.APPLICATION_JSON));
23 |
24 | int ResponseStatus = response.getStatus();
25 | String ResponseText = null;
26 |
27 | if (ResponseStatus == 200)
28 | return response.readEntity(PaymentTokenResponse.class);
29 |
30 | // Error Happened
31 | if (response.hasEntity())
32 | ResponseText = response.readEntity(String.class);
33 |
34 | response.close();
35 |
36 | throw new IuguException("Error creating token!", ResponseStatus, ResponseText);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/PaymentToken.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 |
4 | import com.iugu.enums.PayableWith;
5 | import org.codehaus.jackson.annotate.JsonProperty;
6 |
7 | public class PaymentToken {
8 |
9 | @JsonProperty("account_id")
10 | private String accountId;
11 |
12 | @JsonProperty("method")
13 | private PayableWith payableWith;
14 |
15 | @JsonProperty("test")
16 | private Boolean isTest;
17 |
18 | @JsonProperty("data")
19 | private Data data;
20 |
21 | public String getAccountId() {
22 | return accountId;
23 | }
24 |
25 | public void setAccountId(String accountId) {
26 | this.accountId = accountId;
27 | }
28 |
29 | public PayableWith getPayableWith() {
30 | return payableWith;
31 | }
32 |
33 | public void setPayableWith(PayableWith payableWith) {
34 | this.payableWith = payableWith;
35 | }
36 |
37 | public Boolean getTest() {
38 | return isTest;
39 | }
40 |
41 | public void setTest(Boolean test) {
42 | isTest = test;
43 | }
44 |
45 | public Data getData() {
46 | return data;
47 | }
48 |
49 | public void setData(Data data) {
50 | this.data = data;
51 | }
52 |
53 | @Override
54 | public String toString() {
55 | return "PaymentToken{" +
56 | "accountId='" + accountId + '\'' +
57 | ", payableWith=" + payableWith +
58 | ", isTest=" + isTest +
59 | ", data=" + data +
60 | '}';
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/services/ChargeService.java:
--------------------------------------------------------------------------------
1 | package com.iugu.services;
2 |
3 | import com.iugu.IuguConfiguration;
4 | import com.iugu.exceptions.IuguException;
5 | import com.iugu.model.Charge;
6 | import com.iugu.responses.ChargeResponse;
7 |
8 | import javax.ws.rs.client.Entity;
9 | import javax.ws.rs.core.MediaType;
10 | import javax.ws.rs.core.Response;
11 |
12 | public class ChargeService {
13 |
14 | private IuguConfiguration iugu;
15 | private final String CREATE_URL = IuguConfiguration.url("/charge");
16 |
17 | public ChargeService(IuguConfiguration iuguConfiguration) {
18 | this.iugu = iuguConfiguration;
19 | }
20 |
21 | public ChargeResponse create(Charge charge) throws IuguException {
22 | Response response = this.iugu.getNewClient().target(CREATE_URL).request().post(Entity.entity(charge, MediaType.APPLICATION_JSON));
23 |
24 | int ResponseStatus = response.getStatus();
25 | String ResponseText = null;
26 |
27 | if (ResponseStatus == 200)
28 | return response.readEntity(ChargeResponse.class);
29 |
30 | // Error Happened
31 | if (response.hasEntity())
32 | ResponseText = response.readEntity(String.class);
33 |
34 | response.close();
35 |
36 | throw new IuguException("Error creating charge!", ResponseStatus, ResponseText);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/responses/CustomerResponse.java:
--------------------------------------------------------------------------------
1 | package com.iugu.responses;
2 |
3 | import java.util.List;
4 |
5 | import org.codehaus.jackson.annotate.JsonIgnoreProperties;
6 | import org.codehaus.jackson.annotate.JsonProperty;
7 |
8 | @JsonIgnoreProperties(ignoreUnknown = true)
9 | public class CustomerResponse {
10 |
11 | private String id;
12 |
13 | private String email;
14 |
15 | private String name;
16 |
17 | private String notes;
18 |
19 | @JsonProperty("custom_variables")
20 | private List customVariables;
21 |
22 | public String getId() {
23 | return id;
24 | }
25 |
26 | public void setId(String id) {
27 | this.id = id;
28 | }
29 |
30 | public String getEmail() {
31 | return email;
32 | }
33 |
34 | public void setEmail(String email) {
35 | this.email = email;
36 | }
37 |
38 | public String getName() {
39 | return name;
40 | }
41 |
42 | public void setName(String name) {
43 | this.name = name;
44 | }
45 |
46 | public String getNotes() {
47 | return notes;
48 | }
49 |
50 | public void setNotes(String notes) {
51 | this.notes = notes;
52 | }
53 |
54 | public List getCustomVariables() {
55 | return customVariables;
56 | }
57 |
58 | public void setCustomVariables(List customVariables) {
59 | this.customVariables = customVariables;
60 | }
61 |
62 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 | .classpath
3 | .settings/
4 |
5 | # Package Files #
6 | *.jar
7 | *.war
8 | *.ear
9 |
10 | # Maven
11 | target/
12 | pom.xml.tag
13 | pom.xml.releaseBackup
14 | pom.xml.versionsBackup
15 | pom.xml.next
16 | release.properties
17 | dependency-reduced-pom.xml
18 | buildNumber.properties
19 |
20 |
21 | # Created by https://www.gitignore.io/api/eclipse
22 |
23 | ### Eclipse ###
24 |
25 | .metadata
26 | bin/
27 | tmp/
28 | *.tmp
29 | *.bak
30 | *.swp
31 | *~.nib
32 | local.properties
33 | .settings/
34 | .loadpath
35 | .recommenders
36 |
37 | # Eclipse Core
38 | .project
39 |
40 | # External tool builders
41 | .externalToolBuilders/
42 |
43 | # Locally stored "Eclipse launch configurations"
44 | *.launch
45 |
46 | # PyDev specific (Python IDE for Eclipse)
47 | *.pydevproject
48 |
49 | # CDT-specific (C/C++ Development Tooling)
50 | .cproject
51 |
52 | # JDT-specific (Eclipse Java Development Tools)
53 | .classpath
54 |
55 | # Java annotation processor (APT)
56 | .factorypath
57 |
58 | # PDT-specific (PHP Development Tools)
59 | .buildpath
60 |
61 | # sbteclipse plugin
62 | .target
63 |
64 | # Tern plugin
65 | .tern-project
66 |
67 | # TeXlipse plugin
68 | .texlipse
69 |
70 | # STS (Spring Tool Suite)
71 | .springBeans
72 |
73 | # Code Recommenders
74 | .recommenders/
75 |
76 | .idea/
77 | iugu-java.iml
78 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/responses/ExtraInfoResponse.java:
--------------------------------------------------------------------------------
1 | package com.iugu.responses;
2 |
3 | import org.codehaus.jackson.annotate.JsonIgnoreProperties;
4 | import org.codehaus.jackson.annotate.JsonProperty;
5 |
6 | @JsonIgnoreProperties(ignoreUnknown = true)
7 | public class ExtraInfoResponse {
8 |
9 | @JsonProperty("brand")
10 | private Object brand;
11 |
12 | @JsonProperty("holder_name")
13 | private Object holderName;
14 |
15 | @JsonProperty("display_number")
16 | private Object displayNumber;
17 |
18 | @JsonProperty("bin")
19 | private Object bin;
20 |
21 | @JsonProperty("month")
22 | private Integer month;
23 |
24 | @JsonProperty("year")
25 | private Integer year;
26 |
27 | public Object getBrand() {
28 | return brand;
29 | }
30 |
31 | public Object getHolderName() {
32 | return holderName;
33 | }
34 |
35 | public Object getDisplayNumber() {
36 | return displayNumber;
37 | }
38 |
39 | public Object getBin() {
40 | return bin;
41 | }
42 |
43 | public Integer getMonth() {
44 | return month;
45 | }
46 |
47 | public Integer getYear() {
48 | return year;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return "ExtraInfo{" +
54 | "brand=" + brand +
55 | ", holderName=" + holderName +
56 | ", displayNumber=" + displayNumber +
57 | ", bin=" + bin +
58 | ", month=" + month +
59 | ", year=" + year +
60 | '}';
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/services/PaymentMethodService.java:
--------------------------------------------------------------------------------
1 | package com.iugu.services;
2 |
3 | import com.iugu.IuguConfiguration;
4 | import com.iugu.exceptions.IuguException;
5 | import com.iugu.model.PaymentMethod;
6 | import com.iugu.model.PaymentToken;
7 | import com.iugu.responses.PaymentTokenResponse;
8 |
9 | import javax.ws.rs.client.Entity;
10 | import javax.ws.rs.core.MediaType;
11 | import javax.ws.rs.core.Response;
12 |
13 |
14 | public class PaymentMethodService {
15 |
16 | private IuguConfiguration iugu;
17 | private final String DEFAULT_PAYMENT_URL = IuguConfiguration.url("/customers/%s/payment_methods");
18 |
19 | public PaymentMethodService(IuguConfiguration iuguConfiguration) {
20 | this.iugu = iuguConfiguration;
21 | }
22 |
23 | public String setDefault(String customerId, PaymentMethod paymentMethod) throws IuguException {
24 | Response response = this.iugu.getNewClient().target(String.format(DEFAULT_PAYMENT_URL, customerId)).request().post(Entity.entity(paymentMethod, MediaType.APPLICATION_JSON));
25 |
26 | int ResponseStatus = response.getStatus();
27 | String ResponseText = null;
28 |
29 | if (ResponseStatus == 200)
30 | return response.readEntity(String.class);
31 |
32 | // Error Happened
33 | if (response.hasEntity())
34 | ResponseText = response.readEntity(String.class);
35 |
36 | response.close();
37 |
38 | throw new IuguException("Error set default payment!", ResponseStatus, ResponseText);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/serializers/DateSerializer.java:
--------------------------------------------------------------------------------
1 | package com.iugu.serializers;
2 |
3 | import java.io.IOException;
4 | import java.lang.reflect.AnnotatedElement;
5 | import java.text.SimpleDateFormat;
6 | import java.util.Date;
7 |
8 | import org.codehaus.jackson.JsonGenerator;
9 | import org.codehaus.jackson.map.BeanProperty;
10 | import org.codehaus.jackson.map.ContextualSerializer;
11 | import org.codehaus.jackson.map.JsonMappingException;
12 | import org.codehaus.jackson.map.JsonSerializer;
13 | import org.codehaus.jackson.map.SerializationConfig;
14 | import org.codehaus.jackson.map.SerializerProvider;
15 |
16 | public class DateSerializer extends JsonSerializer implements ContextualSerializer {
17 |
18 | private final String format;
19 |
20 | private DateSerializer(final String format) {
21 | this.format = format;
22 | }
23 |
24 | public DateSerializer() {
25 | this.format = null;
26 | }
27 |
28 | @Override
29 | public void serialize(final Date value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException {
30 | jgen.writeString(new SimpleDateFormat(format).format(value));
31 | }
32 |
33 | @Override
34 | public JsonSerializer createContextual(final SerializationConfig serializationConfig, final BeanProperty beanProperty) throws JsonMappingException {
35 | final AnnotatedElement annotated = beanProperty.getMember().getAnnotated();
36 | return new DateSerializer(annotated.getAnnotation(JsonFormat.class).value());
37 | }
38 |
39 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/responses/SubItemResponse.java:
--------------------------------------------------------------------------------
1 | package com.iugu.responses;
2 |
3 | import org.codehaus.jackson.annotate.JsonIgnoreProperties;
4 | import org.codehaus.jackson.annotate.JsonProperty;
5 |
6 | @JsonIgnoreProperties(ignoreUnknown = true)
7 | public class SubItemResponse {
8 |
9 | private String id;
10 |
11 | private String description;
12 |
13 | private Integer quantity;
14 |
15 | @JsonProperty("price_cents")
16 | private Integer priceCents;
17 |
18 | private String price;
19 |
20 | private String total;
21 |
22 | public String getId() {
23 | return id;
24 | }
25 |
26 | public void setId(String id) {
27 | this.id = id;
28 | }
29 |
30 | public String getDescription() {
31 | return description;
32 | }
33 |
34 | public void setDescription(String description) {
35 | this.description = description;
36 | }
37 |
38 | public Integer getQuantity() {
39 | return quantity;
40 | }
41 |
42 | public void setQuantity(Integer quantity) {
43 | this.quantity = quantity;
44 | }
45 |
46 | public Integer getPriceCents() {
47 | return priceCents;
48 | }
49 |
50 | public void setPriceCents(Integer priceCents) {
51 | this.priceCents = priceCents;
52 | }
53 |
54 | public String getPrice() {
55 | return price;
56 | }
57 |
58 | public void setPrice(String price) {
59 | this.price = price;
60 | }
61 |
62 | public String getTotal() {
63 | return total;
64 | }
65 |
66 | public void setTotal(String total) {
67 | this.total = total;
68 | }
69 |
70 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/Payer.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | import java.io.Serializable;
4 |
5 | import org.codehaus.jackson.annotate.JsonProperty;
6 |
7 | public class Payer implements Serializable {
8 |
9 | private static final long serialVersionUID = 3266886175287194L;
10 |
11 | @JsonProperty("cpf_cnpj")
12 | private String cpfCnpj;
13 |
14 | private String name;
15 |
16 | @JsonProperty("phone_prefix")
17 | private String phonePrefix;
18 |
19 | private String phone;
20 |
21 | private String email;
22 |
23 | private Address address;
24 |
25 | public String getCpfCnpj() {
26 | return cpfCnpj;
27 | }
28 |
29 | public void setCpfCnpj(String cpfCnpj) {
30 | this.cpfCnpj = cpfCnpj;
31 | }
32 |
33 | public String getName() {
34 | return name;
35 | }
36 |
37 | public void setName(String name) {
38 | this.name = name;
39 | }
40 |
41 | public String getPhonePrefix() {
42 | return phonePrefix;
43 | }
44 |
45 | public void setPhonePrefix(String phonePrefix) {
46 | this.phonePrefix = phonePrefix;
47 | }
48 |
49 | public String getPhone() {
50 | return phone;
51 | }
52 |
53 | public void setPhone(String phone) {
54 | this.phone = phone;
55 | }
56 |
57 | public String getEmail() {
58 | return email;
59 | }
60 |
61 | public void setEmail(String email) {
62 | this.email = email;
63 | }
64 |
65 | public Address getAddress() {
66 | return address;
67 | }
68 |
69 | public void setAddress(Address address) {
70 | this.address = address;
71 | }
72 |
73 | public static long getSerialversionuid() {
74 | return serialVersionUID;
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/responses/FeatureResponse.java:
--------------------------------------------------------------------------------
1 | package com.iugu.responses;
2 |
3 | import org.codehaus.jackson.annotate.JsonIgnoreProperties;
4 | import org.codehaus.jackson.annotate.JsonProperty;
5 |
6 | @JsonIgnoreProperties(ignoreUnknown = true)
7 | public class FeatureResponse {
8 |
9 | private String id;
10 |
11 | private String identifier;
12 |
13 | private Boolean important;
14 |
15 | private String name;
16 |
17 | @JsonProperty("plan_id")
18 | private String planId;
19 |
20 | private Integer position;
21 |
22 | private Integer value;
23 |
24 | public String getId() {
25 | return id;
26 | }
27 |
28 | public void setId(String id) {
29 | this.id = id;
30 | }
31 |
32 | public String getIdentifier() {
33 | return identifier;
34 | }
35 |
36 | public void setIdentifier(String identifier) {
37 | this.identifier = identifier;
38 | }
39 |
40 | public Boolean getImportant() {
41 | return important;
42 | }
43 |
44 | public void setImportant(Boolean important) {
45 | this.important = important;
46 | }
47 |
48 | public String getName() {
49 | return name;
50 | }
51 |
52 | public void setName(String name) {
53 | this.name = name;
54 | }
55 |
56 | public String getPlanId() {
57 | return planId;
58 | }
59 |
60 | public void setPlanId(String planId) {
61 | this.planId = planId;
62 | }
63 |
64 | public Integer getPosition() {
65 | return position;
66 | }
67 |
68 | public void setPosition(Integer position) {
69 | this.position = position;
70 | }
71 |
72 | public Integer getValue() {
73 | return value;
74 | }
75 |
76 | public void setValue(Integer value) {
77 | this.value = value;
78 | }
79 |
80 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/responses/PlanResponse.java:
--------------------------------------------------------------------------------
1 | package com.iugu.responses;
2 |
3 | import java.util.List;
4 |
5 | import org.codehaus.jackson.annotate.JsonIgnoreProperties;
6 | import org.codehaus.jackson.annotate.JsonProperty;
7 |
8 | @JsonIgnoreProperties(ignoreUnknown = true)
9 | public class PlanResponse {
10 |
11 | private String id;
12 |
13 | private String name;
14 |
15 | private String identifier;
16 |
17 | private String interval;
18 |
19 | @JsonProperty("interval_type")
20 | private String intervalType;
21 |
22 | private List prices;
23 |
24 | private List features;
25 |
26 | public String getId() {
27 | return id;
28 | }
29 |
30 | public void setId(String id) {
31 | this.id = id;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public void setName(String name) {
39 | this.name = name;
40 | }
41 |
42 | public String getIdentifier() {
43 | return identifier;
44 | }
45 |
46 | public void setIdentifier(String identifier) {
47 | this.identifier = identifier;
48 | }
49 |
50 | public String getInterval() {
51 | return interval;
52 | }
53 |
54 | public void setInterval(String interval) {
55 | this.interval = interval;
56 | }
57 |
58 | public String getIntervalType() {
59 | return intervalType;
60 | }
61 |
62 | public void setIntervalType(String intervalType) {
63 | this.intervalType = intervalType;
64 | }
65 |
66 | public List getPrices() {
67 | return prices;
68 | }
69 |
70 | public void setPrices(List prices) {
71 | this.prices = prices;
72 | }
73 |
74 | public List getFeatures() {
75 | return features;
76 | }
77 |
78 | public void setFeatures(List features) {
79 | this.features = features;
80 | }
81 |
82 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/Address.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | import java.io.Serializable;
4 |
5 | import org.codehaus.jackson.annotate.JsonProperty;
6 |
7 | public class Address implements Serializable {
8 |
9 | private static final long serialVersionUID = 3266886175287194L;
10 |
11 | @JsonProperty("zip_code")
12 | private String zipCode;
13 |
14 | private String street;
15 |
16 | private String number;
17 |
18 | private String district;
19 |
20 | private String city;
21 |
22 | private String state;
23 |
24 | private String country;
25 |
26 | private String complement;
27 |
28 | public String getZipCode() {
29 | return zipCode;
30 | }
31 |
32 | public void setZipCode(String zipCode) {
33 | this.zipCode = zipCode;
34 | }
35 |
36 | public String getStreet() {
37 | return street;
38 | }
39 |
40 | public void setStreet(String street) {
41 | this.street = street;
42 | }
43 |
44 | public String getNumber() {
45 | return number;
46 | }
47 |
48 | public void setNumber(String number) {
49 | this.number = number;
50 | }
51 |
52 | public String getDistrict() {
53 | return district;
54 | }
55 |
56 | public void setDistrict(String district) {
57 | this.district = district;
58 | }
59 |
60 | public String getCity() {
61 | return city;
62 | }
63 |
64 | public void setCity(String city) {
65 | this.city = city;
66 | }
67 |
68 | public String getState() {
69 | return state;
70 | }
71 |
72 | public void setState(String state) {
73 | this.state = state;
74 | }
75 |
76 | public String getCountry() {
77 | return country;
78 | }
79 |
80 | public void setCountry(String country) {
81 | this.country = country;
82 | }
83 |
84 | public String getComplement() {
85 | return complement;
86 | }
87 |
88 | public void setComplement(String complement) {
89 | this.complement = complement;
90 | }
91 |
92 | public static long getSerialversionuid() {
93 | return serialVersionUID;
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/PaymentMethod.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | import java.util.List;
4 |
5 | import org.codehaus.jackson.annotate.JsonProperty;
6 |
7 | import com.iugu.enums.ItemType;
8 |
9 | public class PaymentMethod {
10 |
11 | public PaymentMethod(String description, String token, Boolean isDefault) {
12 | this.description = description;
13 | this.token = token;
14 | this.isDefault=isDefault;
15 | }
16 |
17 | public PaymentMethod(String description, Data data, Boolean isDefault) {
18 | this.description = description;
19 | this.data = data;
20 | this.isDefault = isDefault;
21 | }
22 |
23 | private String description;
24 |
25 | private Data data;
26 |
27 | @JsonProperty("item_type")
28 | private ItemType itemType;
29 |
30 | private String token;
31 |
32 | @JsonProperty("set_as_default")
33 | private Boolean isDefault;
34 |
35 | public String getDescription() {
36 | return description;
37 | }
38 |
39 | public void setDescription(String description) {
40 | this.description = description;
41 | }
42 |
43 | public Data getData() {
44 | return data;
45 | }
46 |
47 | public void setData(Data data) {
48 | this.data = data;
49 | }
50 |
51 | public ItemType getItemType() {
52 | return itemType;
53 | }
54 |
55 | public void setItemType(ItemType itemType) {
56 | this.itemType = itemType;
57 | }
58 |
59 | public String getToken() {
60 | return token;
61 | }
62 |
63 | public void setToken(String token) {
64 | this.token = token;
65 | }
66 |
67 | public Boolean getDefault() {
68 | return isDefault;
69 | }
70 |
71 | public void setDefault(Boolean aDefault) {
72 | isDefault = aDefault;
73 | }
74 |
75 | @Override
76 | public String toString() {
77 | return "PaymentMethod{" +
78 | "description='" + description + '\'' +
79 | ", data=" + data +
80 | ", itemType=" + itemType +
81 | ", token='" + token + '\'' +
82 | ", isDefault=" + isDefault +
83 | '}';
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/responses/ItemResponse.java:
--------------------------------------------------------------------------------
1 | package com.iugu.responses;
2 |
3 | import java.util.Date;
4 |
5 | import org.codehaus.jackson.annotate.JsonIgnoreProperties;
6 | import org.codehaus.jackson.annotate.JsonProperty;
7 | import org.codehaus.jackson.map.annotate.JsonSerialize;
8 |
9 | import com.iugu.serializers.DateSerializer;
10 | import com.iugu.serializers.JsonFormat;
11 |
12 | @JsonIgnoreProperties(ignoreUnknown = true)
13 | public class ItemResponse {
14 |
15 | private String id;
16 |
17 | private String description;
18 |
19 | private Integer quantity;
20 |
21 | @JsonProperty("price_cents")
22 | private Integer priceCents;
23 |
24 | @JsonProperty("created_at")
25 | private String createdAt;
26 |
27 | @JsonProperty("updated_at")
28 | @JsonFormat("yyyy-MM-dd'T'HH:mm:ssZ") @JsonSerialize(using = DateSerializer.class)
29 | private Date updatedAt;
30 |
31 | private String price;
32 |
33 | public String getId() {
34 | return id;
35 | }
36 |
37 | public void setId(String id) {
38 | this.id = id;
39 | }
40 |
41 | public String getDescription() {
42 | return description;
43 | }
44 |
45 | public void setDescription(String description) {
46 | this.description = description;
47 | }
48 |
49 | public Integer getQuantity() {
50 | return quantity;
51 | }
52 |
53 | public void setQuantity(Integer quantity) {
54 | this.quantity = quantity;
55 | }
56 |
57 | public Integer getPriceCents() {
58 | return priceCents;
59 | }
60 |
61 | public void setPriceCents(Integer priceCents) {
62 | this.priceCents = priceCents;
63 | }
64 |
65 | public String getCreatedAt() {
66 | return createdAt;
67 | }
68 |
69 | public void setCreatedAt(String createdAt) {
70 | this.createdAt = createdAt;
71 | }
72 |
73 | public Date getUpdatedAt() {
74 | return updatedAt;
75 | }
76 |
77 | public void setUpdatedAt(Date updatedAt) {
78 | this.updatedAt = updatedAt;
79 | }
80 |
81 | public String getPrice() {
82 | return price;
83 | }
84 |
85 | public void setPrice(String price) {
86 | this.price = price;
87 | }
88 |
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/Plan.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | import java.util.List;
4 |
5 | import org.codehaus.jackson.annotate.JsonProperty;
6 |
7 | import com.iugu.enums.Currency;
8 | import com.iugu.enums.IntervalType;
9 | import com.iugu.enums.PayableWith;
10 |
11 | public class Plan {
12 |
13 | private String name;
14 |
15 | private String identifier;
16 |
17 | private String interval;
18 |
19 | @JsonProperty("interval_type")
20 | private IntervalType intervalType;
21 |
22 | private Currency currency;
23 |
24 | @JsonProperty("value_cents")
25 | private int valueCents;
26 |
27 | @JsonProperty("payable_with")
28 | private PayableWith payableWith;
29 |
30 | private List prices;
31 |
32 | private List features;
33 |
34 | public Plan(String name, String identifier, String interval, IntervalType intervalType, Currency currency,
35 | int valueCents) {
36 | this.name = name;
37 | this.identifier = identifier;
38 | this.interval = interval;
39 | this.intervalType = intervalType;
40 | this.currency = currency;
41 | this.valueCents = valueCents;
42 | }
43 |
44 | public String getName() {
45 | return name;
46 | }
47 |
48 | public String getIdentifier() {
49 | return identifier;
50 | }
51 |
52 | public String getInterval() {
53 | return interval;
54 | }
55 |
56 | public IntervalType getIntervalType() {
57 | return intervalType;
58 | }
59 |
60 | public Currency getCurrency() {
61 | return currency;
62 | }
63 |
64 | public int getValueCents() {
65 | return valueCents;
66 | }
67 |
68 | public PayableWith getPayableWith() {
69 | return payableWith;
70 | }
71 |
72 | public void setPayableWith(PayableWith payableWith) {
73 | this.payableWith = payableWith;
74 | }
75 |
76 | public List getPrices() {
77 | return prices;
78 | }
79 |
80 | public void setPrices(List prices) {
81 | this.prices = prices;
82 | }
83 |
84 | public List getFeatures() {
85 | return features;
86 | }
87 |
88 | public void setFeatures(List features) {
89 | this.features = features;
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/responses/ChargeResponse.java:
--------------------------------------------------------------------------------
1 | package com.iugu.responses;
2 |
3 | import org.codehaus.jackson.annotate.JsonIgnoreProperties;
4 | import org.codehaus.jackson.annotate.JsonProperty;
5 |
6 | @JsonIgnoreProperties(ignoreUnknown = true)
7 | public class ChargeResponse {
8 |
9 | @JsonProperty("message")
10 | private String message;
11 | @JsonProperty("success")
12 | private Boolean success;
13 | @JsonProperty("url")
14 | private String url;
15 | @JsonProperty("pdf")
16 | private String pdf;
17 | @JsonProperty("invoice_id")
18 | private String invoiceId;
19 | @JsonProperty("LR")
20 | private String lr;
21 |
22 | public String getMessage() {
23 | return message;
24 | }
25 |
26 | public void setMessage(String message) {
27 | this.message = message;
28 | }
29 |
30 | public Boolean getSuccess() {
31 | return success;
32 | }
33 |
34 | public void setSuccess(Boolean success) {
35 | this.success = success;
36 | }
37 |
38 | public String getUrl() {
39 | return url;
40 | }
41 |
42 | public void setUrl(String url) {
43 | this.url = url;
44 | }
45 |
46 | public String getPdf() {
47 | return pdf;
48 | }
49 |
50 | public void setPdf(String pdf) {
51 | this.pdf = pdf;
52 | }
53 |
54 | public String getInvoiceId() {
55 | return invoiceId;
56 | }
57 |
58 | public void setInvoiceId(String invoiceId) {
59 | this.invoiceId = invoiceId;
60 | }
61 |
62 | public String getLr() {
63 | return lr;
64 | }
65 |
66 | public void setLr(String lr) {
67 | this.lr = lr;
68 | }
69 |
70 | @Override
71 | public String toString() {
72 | return "ChargeResponse{" +
73 | "message='" + message + '\'' +
74 | ", success=" + success +
75 | ", url='" + url + '\'' +
76 | ", pdf='" + pdf + '\'' +
77 | ", invoiceId='" + invoiceId + '\'' +
78 | ", lr='" + lr + '\'' +
79 | '}';
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/Charge.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 |
4 | import org.codehaus.jackson.annotate.JsonProperty;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | public class Charge {
10 |
11 | @JsonProperty("token")
12 | private String token;
13 |
14 | @JsonProperty("invoice_id")
15 | private String invoiceId;
16 |
17 | @JsonProperty("customer_id")
18 | private String customerId;
19 |
20 | @JsonProperty("email")
21 | private String email;
22 |
23 | private List- items = new ArrayList<>();
24 |
25 | @JsonProperty("payer")
26 | private Payer payer;
27 |
28 | public Charge() {
29 | }
30 |
31 | public Charge(String token, String invoiceId) {
32 | this.token = token;
33 | this.invoiceId = invoiceId;
34 | }
35 |
36 | public Charge(String token, String invoiceId, String customerId) {
37 | this.token = token;
38 | this.invoiceId = invoiceId;
39 | this.customerId = customerId;
40 | }
41 |
42 | public Charge(String token, String email, List
- items, Payer payer) {
43 | this.token = token;
44 | this.email = email;
45 | this.items = items;
46 | this.payer = payer;
47 | }
48 |
49 | public String getToken() {
50 | return token;
51 | }
52 |
53 | public void setToken(String token) {
54 | this.token = token;
55 | }
56 |
57 | public String getInvoiceId() {
58 | return invoiceId;
59 | }
60 |
61 | public void setInvoiceId(String invoiceId) {
62 | this.invoiceId = invoiceId;
63 | }
64 |
65 | public String getCustomerId() {
66 | return customerId;
67 | }
68 |
69 | public void setCustomerId(String customerId) {
70 | this.customerId = customerId;
71 | }
72 |
73 | public String getEmail() {
74 | return email;
75 | }
76 |
77 | public void setEmail(String email) {
78 | this.email = email;
79 | }
80 |
81 | public List
- getItems() {
82 | return items;
83 | }
84 |
85 | public void setItems(List
- items) {
86 | this.items = items;
87 | }
88 |
89 | public Payer getPayer() {
90 | return payer;
91 | }
92 |
93 | public void setPayer(Payer payer) {
94 | this.payer = payer;
95 | }
96 |
97 | @Override
98 | public String toString() {
99 | return "Charge{" +
100 | "token='" + token + '\'' +
101 | ", invoiceId='" + invoiceId + '\'' +
102 | ", customerId='" + customerId + '\'' +
103 | ", email='" + email + '\'' +
104 | ", items=" + items +
105 | ", payer=" + payer +
106 | '}';
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # iugu-java
2 | ## Biblioteca de Java para Iugu.com (Java Library for Iugu.com)
3 | ###### Criando um Invoice (Creating a new Invoice)
4 |
5 | ```
6 | IuguConfiguration iuguConfiguration = new IuguConfiguration("CLIENTTOKEN");
7 | InvoiceResponse response;
8 |
9 | try {
10 | response = new InvoiceService(iuguConfiguration).create(new Invoice("SOMEEMAIL@XXXX.XXXXX", new Date(), new Item("teste", 1, 100)));
11 |
12 | // Retorna ID do Invoice criado (Returns the ID of the created invoice)
13 | System.out.println(response.getId());
14 | }
15 | catch (IuguException e) {
16 | // TODO Auto-generated catch block
17 | e.printStackTrace();
18 | }
19 | ```
20 |
21 | ###### Criando um pagamento (Creating a new Payment)
22 | ```
23 | try {
24 | IuguConfiguration iuguConfiguration = new IuguConfiguration("CLIENTTOKEN");
25 |
26 | //token cartão
27 | PaymentToken paymentToken = new PaymentToken();
28 | paymentToken.setAccountId("xxxxx");
29 | paymentToken.setPayableWith(PayableWith.CREDIT_CARD);
30 |
31 | paymentToken.setTest(Boolean.TRUE);
32 | paymentToken.setData(new Data("4111111111111111","123","Joao","Mateus","12","2019"));
33 |
34 | PaymentTokenResponse paymentTokenResponse = new PaymentTokenService(iuguConfiguration).create(paymentToken);/
35 | } catch (IuguException e) {
36 | // TODO Auto-generated catch block
37 | e.printStackTrace();
38 | }
39 | ```
40 |
41 | ###### Criando um cliente (Creating a new Customer)
42 | ```
43 | try {
44 | IuguConfiguration iuguConfiguration = new IuguConfiguration("CLIENTTOKEN");
45 |
46 | Customer customerIugu = new Customer("email@email.com","Name");
47 | customerIugu.setNotes("more");
48 | customerIugu.setCpfCnpj("xxx.xxx.xxx-xx");
49 | customerIugu.setCcEmails("");
50 | customerIugu.setZipCode("xxxxx-xxx");
51 | customerIugu.setNumber(234);
52 | customerIugu.setStreet("xxxxxxx");
53 | customerIugu.setCity("xxxxxx");
54 | customerIugu.setState("xx");
55 | customerIugu.setDistrict("xxx");
56 | customerIugu.setComplement("");
57 | //customerIugu.setCustomVariables();
58 |
59 | CustomerResponse customerResponse = new CustomerService(iuguConfiguration).create(customerIugu);
60 | } catch (IuguException e) {
61 | // TODO Auto-generated catch block
62 | e.printStackTrace();
63 | }
64 | ```
65 |
66 | ###### Criando uma cobrança (Creating a new Charge)
67 | ```
68 | try {
69 | IuguConfiguration iuguConfiguration = new IuguConfiguration("CLIENTTOKEN");
70 | ChargeResponse response;
71 | Charge charge = new Charge("IUGUJS_TOKEN", "INVOICEID");
72 | response = new ChargeService(iuguConfiguration).create(charge);
73 | System.out.println(" Charge : {\n\t: "+response.getMessage()+"\n\t: "+response.getSuccess()+"\n\t: "+response.getUrl()+"\n\t: "+response.getPdf()+"\n\t: "+response.getInvoiceId()+"\n}");
74 | } catch (IuguException e) {
75 | // TODO Auto-generated catch block
76 | e.printStackTrace();
77 | }
78 | ```
79 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/Customer.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | import org.codehaus.jackson.annotate.JsonProperty;
7 |
8 | public class Customer implements Serializable {
9 |
10 | private static final long serialVersionUID = 3266886175287194L;
11 |
12 | public Customer(String email, String name) {
13 | this.email = email;
14 | this.name = name;
15 | }
16 |
17 | private String email;
18 |
19 | private String name;
20 |
21 | private String notes;
22 |
23 | @JsonProperty("cpf_cnpj")
24 | private String cpfCnpj;
25 |
26 | @JsonProperty("cc_emails")
27 | private String ccEmails;
28 |
29 | @JsonProperty("zip_code")
30 | private String zipCode;
31 |
32 | private Integer number;
33 |
34 | private String street;
35 |
36 | private String city;
37 |
38 | private String state;
39 |
40 | private String district;
41 |
42 | private String complement;
43 |
44 | @JsonProperty("custom_variables")
45 | private List customVariables;
46 |
47 | public String getEmail() {
48 | return email;
49 | }
50 |
51 | public void setEmail(String email) {
52 | this.email = email;
53 | }
54 |
55 | public String getName() {
56 | return name;
57 | }
58 |
59 | public void setName(String name) {
60 | this.name = name;
61 | }
62 |
63 | public String getNotes() {
64 | return notes;
65 | }
66 |
67 | public void setNotes(String notes) {
68 | this.notes = notes;
69 | }
70 |
71 | public String getCpfCnpj() {
72 | return cpfCnpj;
73 | }
74 |
75 | public void setCpfCnpj(String cpfCnpj) {
76 | this.cpfCnpj = cpfCnpj;
77 | }
78 |
79 | public String getCcEmails() {
80 | return ccEmails;
81 | }
82 |
83 | public void setCcEmails(String ccEmails) {
84 | this.ccEmails = ccEmails;
85 | }
86 |
87 | public String getZipCode() {
88 | return zipCode;
89 | }
90 |
91 | public void setZipCode(String zipCode) {
92 | this.zipCode = zipCode;
93 | }
94 |
95 | public Integer getNumber() {
96 | return number;
97 | }
98 |
99 | public void setNumber(Integer number) {
100 | this.number = number;
101 | }
102 |
103 | public String getStreet() {
104 | return street;
105 | }
106 |
107 | public void setStreet(String street) {
108 | this.street = street;
109 | }
110 |
111 | public String getCity() {
112 | return city;
113 | }
114 |
115 | public void setCity(String city) {
116 | this.city = city;
117 | }
118 |
119 | public String getState() {
120 | return state;
121 | }
122 |
123 | public void setState(String state) {
124 | this.state = state;
125 | }
126 |
127 | public String getDistrict() {
128 | return district;
129 | }
130 |
131 | public void setDistrict(String district) {
132 | this.district = district;
133 | }
134 |
135 | public String getComplement() {
136 | return complement;
137 | }
138 |
139 | public void setComplement(String complement) {
140 | this.complement = complement;
141 | }
142 |
143 | public List getCustomVariables() {
144 | return customVariables;
145 | }
146 |
147 | public void setCustomVariables(List customVariables) {
148 | this.customVariables = customVariables;
149 | }
150 |
151 | public static long getSerialversionuid() {
152 | return serialVersionUID;
153 | }
154 |
155 | }
156 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/services/CustomerService.java:
--------------------------------------------------------------------------------
1 | package com.iugu.services;
2 |
3 | import javax.ws.rs.client.Entity;
4 | import javax.ws.rs.core.MediaType;
5 | import javax.ws.rs.core.Response;
6 |
7 | import com.iugu.IuguConfiguration;
8 | import com.iugu.exceptions.IuguException;
9 | import com.iugu.model.Customer;
10 | import com.iugu.responses.CustomerResponse;
11 |
12 | public class CustomerService {
13 |
14 | private IuguConfiguration iugu;
15 | private final String CREATE_URL = IuguConfiguration.url("/customers");
16 | private final String FIND_URL = IuguConfiguration.url("/customers/%s");
17 | private final String CHANGE_URL = IuguConfiguration.url("/customers/%s");
18 | private final String REMOVE_URL = IuguConfiguration.url("/customers/%s");
19 |
20 | public CustomerService(IuguConfiguration iuguConfiguration) {
21 | this.iugu = iuguConfiguration;
22 | }
23 |
24 | public CustomerResponse create(Customer customer) throws IuguException {
25 | Response response = this.iugu.getNewClient().target(CREATE_URL).request().post(Entity.entity(customer, MediaType.APPLICATION_JSON));
26 |
27 | int ResponseStatus = response.getStatus();
28 | String ResponseText = null;
29 |
30 | if (ResponseStatus == 200)
31 | return response.readEntity(CustomerResponse.class);
32 |
33 | // Error Happened
34 | if (response.hasEntity())
35 | ResponseText = response.readEntity(String.class);
36 |
37 | response.close();
38 |
39 | throw new IuguException("Error creating customer!", ResponseStatus, ResponseText);
40 | }
41 |
42 | public CustomerResponse find(String id) throws IuguException {
43 | Response response = this.iugu.getNewClient().target(String.format(FIND_URL, id)).request().get();
44 |
45 | int ResponseStatus = response.getStatus();
46 | String ResponseText = null;
47 |
48 | if (ResponseStatus == 200)
49 | return response.readEntity(CustomerResponse.class);
50 |
51 | // Error Happened
52 | if (response.hasEntity())
53 | ResponseText = response.readEntity(String.class);
54 |
55 | response.close();
56 |
57 | throw new IuguException("Error finding customer!", ResponseStatus, ResponseText);
58 | }
59 |
60 | public CustomerResponse change(String id, Customer customer) throws IuguException {
61 | Response response = this.iugu.getNewClient().target(String.format(CHANGE_URL, id)).request().put(Entity.entity(customer, MediaType.APPLICATION_JSON));
62 |
63 | int ResponseStatus = response.getStatus();
64 | String ResponseText = null;
65 |
66 | if (ResponseStatus == 200)
67 | return response.readEntity(CustomerResponse.class);
68 |
69 | // Error Happened
70 | if (response.hasEntity())
71 | ResponseText = response.readEntity(String.class);
72 |
73 | response.close();
74 |
75 | throw new IuguException("Error changing customer!", ResponseStatus, ResponseText);
76 | }
77 |
78 | public CustomerResponse remove(String id) throws IuguException {
79 | Response response = this.iugu.getNewClient().target(String.format(REMOVE_URL, id)).request().delete();
80 |
81 | int ResponseStatus = response.getStatus();
82 | String ResponseText = null;
83 |
84 | if (ResponseStatus == 200)
85 | return response.readEntity(CustomerResponse.class);
86 |
87 | // Error Happened
88 | if (response.hasEntity())
89 | ResponseText = response.readEntity(String.class);
90 |
91 | response.close();
92 |
93 | throw new IuguException("Error removing customer!", ResponseStatus, ResponseText);
94 | }
95 |
96 | // TODO Listar os clientes
97 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/Subscription.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | import java.util.Date;
4 | import java.util.List;
5 |
6 | import com.iugu.serializers.DateSerializer;
7 | import com.iugu.serializers.JsonFormat;
8 | import org.codehaus.jackson.annotate.JsonProperty;
9 |
10 | import com.iugu.enums.PayableWith;
11 | import org.codehaus.jackson.map.annotate.JsonSerialize;
12 |
13 | public class Subscription {
14 |
15 | public Subscription(String customerId) {
16 | this.customerId = customerId;
17 |
18 | }
19 |
20 | @JsonProperty("customer_id")
21 | private String customerId;
22 |
23 | public String getCustomerId() {
24 | return customerId;
25 | }
26 |
27 | @JsonProperty("plan_identifier")
28 | public String planIdentifier;
29 |
30 | @JsonProperty("expires_at")
31 | @JsonFormat("yyyy-MM-dd'T'HH:mm:ssZ") @JsonSerialize(using = DateSerializer.class)
32 | public Date expiresAt;
33 |
34 | @JsonProperty("only_on_charge_success")
35 | public String onlyOnChargeSuccess;
36 |
37 | @JsonProperty("payable_with")
38 | public PayableWith payableWith;
39 |
40 | @JsonProperty("credits_based")
41 | public boolean creditsBased;
42 |
43 | @JsonProperty("price_cents")
44 | public int priceCents;
45 |
46 | @JsonProperty("credits_cycle")
47 | public int creditsCycle;
48 |
49 | @JsonProperty("credits_min")
50 | public int creditsMin;
51 |
52 | @JsonProperty("custom_variables")
53 | public List customVariables;
54 |
55 | @JsonProperty("subitems")
56 | public List subItems;
57 |
58 | public String getPlanIdentifier() {
59 | return planIdentifier;
60 | }
61 |
62 | public void setPlanIdentifier(String planIdentifier) {
63 | this.planIdentifier = planIdentifier;
64 | }
65 |
66 | public Date getExpiresAt() {
67 | return expiresAt;
68 | }
69 |
70 | public void setExpiresAt(Date expiresAt) {
71 | this.expiresAt = expiresAt;
72 | }
73 |
74 | public String getOnlyOnChargeSucess() {
75 | return onlyOnChargeSucess;
76 | }
77 |
78 | public void setOnlyOnChargeSucess(String onlyOnChargeSucess) {
79 | this.onlyOnChargeSucess = onlyOnChargeSucess;
80 | }
81 |
82 | public PayableWith getPayableWith() {
83 | return payableWith;
84 | }
85 |
86 | public void setPayableWith(PayableWith payableWith) {
87 | this.payableWith = payableWith;
88 | }
89 |
90 | public boolean isCreditsBased() {
91 | return creditsBased;
92 | }
93 |
94 | public void setCreditsBased(boolean creditsBased) {
95 | this.creditsBased = creditsBased;
96 | }
97 |
98 | public int getPriceCents() {
99 | return priceCents;
100 | }
101 |
102 | public void setPriceCents(int priceCents) {
103 | this.priceCents = priceCents;
104 | }
105 |
106 | public int getCreditsCycle() {
107 | return creditsCycle;
108 | }
109 |
110 | public void setCreditsCycle(int creditsCycle) {
111 | this.creditsCycle = creditsCycle;
112 | }
113 |
114 | public int getCreditsMin() {
115 | return creditsMin;
116 | }
117 |
118 | public void setCreditsMin(int creditsMin) {
119 | this.creditsMin = creditsMin;
120 | }
121 |
122 | public List getCustomVariables() {
123 | return customVariables;
124 | }
125 |
126 | public void setCustomVariables(List customVariables) {
127 | this.customVariables = customVariables;
128 | }
129 |
130 | public List getSubItems() {
131 | return subItems;
132 | }
133 |
134 | public void setSubItems(List subItems) {
135 | this.subItems = subItems;
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/src/main/java/com/iugu/services/PlanService.java:
--------------------------------------------------------------------------------
1 | package com.iugu.services;
2 |
3 | import javax.ws.rs.client.Entity;
4 | import javax.ws.rs.core.MediaType;
5 | import javax.ws.rs.core.Response;
6 |
7 | import com.iugu.IuguConfiguration;
8 | import com.iugu.exceptions.IuguException;
9 | import com.iugu.model.Plan;
10 | import com.iugu.responses.PlanResponse;
11 |
12 | public class PlanService {
13 |
14 | private IuguConfiguration iugu;
15 | private final String CREATE_URL = IuguConfiguration.url("/plans");
16 | private final String FIND_URL = IuguConfiguration.url("/plans/%s");
17 | private final String FIND_BY_IDENTIFIER_URL = IuguConfiguration.url("/plans/identifier/%s");
18 | private final String CHANGE_URL = IuguConfiguration.url("/plans/%s");
19 | private final String REMOVE_URL = IuguConfiguration.url("/plans/%s");
20 |
21 | public PlanService(IuguConfiguration iuguConfiguration) {
22 | this.iugu = iuguConfiguration;
23 | }
24 |
25 | public PlanResponse create(Plan plan) throws IuguException {
26 | Response response = this.iugu.getNewClient().target(CREATE_URL).request().post(Entity.entity(plan, MediaType.APPLICATION_JSON));
27 |
28 | int ResponseStatus = response.getStatus();
29 | String ResponseText = null;
30 |
31 | if (ResponseStatus == 200)
32 | return response.readEntity(PlanResponse.class);
33 |
34 | // Error Happened
35 | if (response.hasEntity())
36 | ResponseText = response.readEntity(String.class);
37 |
38 | response.close();
39 |
40 | throw new IuguException("Error creating plan!", ResponseStatus, ResponseText);
41 | }
42 |
43 | public PlanResponse find(String id) throws IuguException {
44 | Response response = this.iugu.getNewClient().target(String.format(FIND_URL, id)).request().get();
45 |
46 | int ResponseStatus = response.getStatus();
47 | String ResponseText = null;
48 |
49 | if (ResponseStatus == 200)
50 | return response.readEntity(PlanResponse.class);
51 |
52 | // Error Happened
53 | if (response.hasEntity())
54 | ResponseText = response.readEntity(String.class);
55 |
56 | response.close();
57 |
58 | throw new IuguException("Error finding plan!", ResponseStatus, ResponseText);
59 | }
60 |
61 | public PlanResponse findByIdentifier(String id) throws IuguException {
62 | Response response = this.iugu.getNewClient().target(String.format(FIND_BY_IDENTIFIER_URL, id)).request().get();
63 |
64 | int ResponseStatus = response.getStatus();
65 | String ResponseText = null;
66 |
67 | if (ResponseStatus == 200)
68 | return response.readEntity(PlanResponse.class);
69 |
70 | // Error Happened
71 | if (response.hasEntity())
72 | ResponseText = response.readEntity(String.class);
73 |
74 | response.close();
75 |
76 | throw new IuguException("Error finding plan by identifier!", ResponseStatus, ResponseText);
77 | }
78 |
79 | public PlanResponse change(String id, Plan plan) throws IuguException {
80 | Response response = this.iugu.getNewClient().target(String.format(CHANGE_URL, id)).request().put(Entity.entity(plan, MediaType.APPLICATION_JSON));
81 |
82 | int ResponseStatus = response.getStatus();
83 | String ResponseText = null;
84 |
85 | if (ResponseStatus == 200)
86 | return response.readEntity(PlanResponse.class);
87 |
88 | // Error Happened
89 | if (response.hasEntity())
90 | ResponseText = response.readEntity(String.class);
91 |
92 | response.close();
93 |
94 | throw new IuguException("Error changing plan!", ResponseStatus, ResponseText);
95 |
96 | }
97 |
98 | public PlanResponse remove(String id) throws IuguException {
99 | Response response = this.iugu.getNewClient().target(String.format(REMOVE_URL, id)).request().delete();
100 |
101 | int ResponseStatus = response.getStatus();
102 | String ResponseText = null;
103 |
104 | if (ResponseStatus == 200)
105 | return response.readEntity(PlanResponse.class);
106 |
107 | // Error Happened
108 | if (response.hasEntity())
109 | ResponseText = response.readEntity(String.class);
110 |
111 | response.close();
112 |
113 | throw new IuguException("Error removing plan!", ResponseStatus, ResponseText);
114 | }
115 |
116 | // TODO Listar os planos
117 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/model/Invoice.java:
--------------------------------------------------------------------------------
1 | package com.iugu.model;
2 |
3 | import java.io.Serializable;
4 | import java.util.ArrayList;
5 | import java.util.Arrays;
6 | import java.util.Date;
7 | import java.util.List;
8 |
9 | import org.codehaus.jackson.annotate.JsonProperty;
10 | import org.codehaus.jackson.map.annotate.JsonSerialize;
11 |
12 | import com.iugu.enums.PayableWith;
13 | import com.iugu.serializers.DateSerializer;
14 | import com.iugu.serializers.JsonFormat;
15 |
16 | public class Invoice implements Serializable {
17 |
18 | private static final long serialVersionUID = 1719931730355279382L;
19 |
20 | public Invoice(String email, Date dueDate, Item... items) {
21 | this.email = email;
22 | this.dueDate = dueDate;
23 | this.items.addAll(Arrays.asList(items)); // FIXME Tratar null pointer
24 | }
25 |
26 | private String email;
27 |
28 | @JsonProperty("cc_emails")
29 | private String ccEmails;
30 |
31 | @JsonProperty("due_date")
32 | @JsonFormat("dd/MM/yyyy")
33 | @JsonSerialize(using = DateSerializer.class)
34 | private Date dueDate;
35 |
36 | private List
- items = new ArrayList<>();
37 |
38 | @JsonProperty("return_url")
39 | private String returnUrl;
40 |
41 | @JsonProperty("expired_url")
42 | private String expiredUrl;
43 |
44 | @JsonProperty("notification_url")
45 | private String notificationUrl;
46 |
47 | private Boolean fines;
48 |
49 | @JsonProperty("late_payment_fine")
50 | private Double latePaymentFine;
51 |
52 | @JsonProperty("per_day_interest")
53 | private Double perDayInterest;
54 |
55 | @JsonProperty("discount_cents")
56 | private Integer discountCents;
57 |
58 | @JsonProperty("customer_id")
59 | private String customerId;
60 |
61 | @JsonProperty("ignore_due_email")
62 | private Boolean ignoreDueEmail;
63 |
64 | @JsonProperty("subscription_id")
65 | private String subscriptionId;
66 |
67 | @JsonProperty("payable_with")
68 | private PayableWith payableWith;
69 |
70 | @JsonProperty("credits")
71 | private Integer credits;
72 |
73 | private List logs;
74 |
75 | @JsonProperty("custom_variables")
76 | private List customVariables;
77 |
78 | private Payer payer;
79 |
80 | @JsonProperty("early_payment_discount")
81 | private Boolean earlyPaymentDiscount;
82 |
83 | @JsonProperty("early_payment_discount_days")
84 | private Integer earlyPaymentDiscountDays;
85 |
86 | @JsonProperty("early_payment_discount_percent")
87 | private Integer earlyPaymentDiscountPercent;
88 |
89 | public String getEmail() {
90 | return email;
91 | }
92 |
93 | public void setEmail(String email) {
94 | this.email = email;
95 | }
96 |
97 | public String getCcEmails() {
98 | return ccEmails;
99 | }
100 |
101 | public void setCcEmails(String ccEmails) {
102 | this.ccEmails = ccEmails;
103 | }
104 |
105 | public Date getDueDate() {
106 | return dueDate;
107 | }
108 |
109 | public void setDueDate(Date dueDate) {
110 | this.dueDate = dueDate;
111 | }
112 |
113 | public List
- getItems() {
114 | return items;
115 | }
116 |
117 | public void setItems(List
- items) {
118 | this.items = items;
119 | }
120 |
121 | public String getReturnUrl() {
122 | return returnUrl;
123 | }
124 |
125 | public void setReturnUrl(String returnUrl) {
126 | this.returnUrl = returnUrl;
127 | }
128 |
129 | public String getExpiredUrl() {
130 | return expiredUrl;
131 | }
132 |
133 | public void setExpiredUrl(String expiredUrl) {
134 | this.expiredUrl = expiredUrl;
135 | }
136 |
137 | public String getNotificationUrl() {
138 | return notificationUrl;
139 | }
140 |
141 | public void setNotificationUrl(String notificationUrl) {
142 | this.notificationUrl = notificationUrl;
143 | }
144 |
145 | public Boolean getFines() {
146 | return fines;
147 | }
148 |
149 | public void setFines(Boolean fines) {
150 | this.fines = fines;
151 | }
152 |
153 | public Double getLatePaymentFine() {
154 | return latePaymentFine;
155 | }
156 |
157 | public void setLatePaymentFine(Double latePaymentFine) {
158 | this.latePaymentFine = latePaymentFine;
159 | }
160 |
161 | public Double getPerDayInterest() {
162 | return perDayInterest;
163 | }
164 |
165 | public void setPerDayInterest(Double perDayInterest) {
166 | this.perDayInterest = perDayInterest;
167 | }
168 |
169 | public Integer getDiscountCents() {
170 | return discountCents;
171 | }
172 |
173 | public void setDiscountCents(Integer discountCents) {
174 | this.discountCents = discountCents;
175 | }
176 |
177 | public String getCustomerId() {
178 | return customerId;
179 | }
180 |
181 | public void setCustomerId(String customerId) {
182 | this.customerId = customerId;
183 | }
184 |
185 | public Boolean getIgnoreDueEmail() {
186 | return ignoreDueEmail;
187 | }
188 |
189 | public void setIgnoreDueEmail(Boolean ignoreDueEmail) {
190 | this.ignoreDueEmail = ignoreDueEmail;
191 | }
192 |
193 | public String getSubscriptionId() {
194 | return subscriptionId;
195 | }
196 |
197 | public void setSubscriptionId(String subscriptionId) {
198 | this.subscriptionId = subscriptionId;
199 | }
200 |
201 | public PayableWith getPayableWith() {
202 | return payableWith;
203 | }
204 |
205 | public void setPayableWith(PayableWith payableWith) {
206 | this.payableWith = payableWith;
207 | }
208 |
209 | public Integer getCredits() {
210 | return credits;
211 | }
212 |
213 | public void setCredits(Integer credits) {
214 | this.credits = credits;
215 | }
216 |
217 | public List getLogs() {
218 | return logs;
219 | }
220 |
221 | public void setLogs(List logs) {
222 | this.logs = logs;
223 | }
224 |
225 | public List getCustomVariables() {
226 | return customVariables;
227 | }
228 |
229 | public void setCustomVariables(List customVariables) {
230 | this.customVariables = customVariables;
231 | }
232 |
233 | public Payer getPayer() {
234 | return payer;
235 | }
236 |
237 | public void setPayer(Payer payer) {
238 | this.payer = payer;
239 | }
240 |
241 | public Boolean getEarlyPaymentDiscount() {
242 | return earlyPaymentDiscount;
243 | }
244 |
245 | public void setEarlyPaymentDiscount(Boolean earlyPaymentDiscount) {
246 | this.earlyPaymentDiscount = earlyPaymentDiscount;
247 | }
248 |
249 | public Integer getEarlyPaymentDiscountDays() {
250 | return earlyPaymentDiscountDays;
251 | }
252 |
253 | public void setEarlyPaymentDiscountDays(Integer earlyPaymentDiscountDays) {
254 | this.earlyPaymentDiscountDays = earlyPaymentDiscountDays;
255 | }
256 |
257 | public Integer getEarlyPaymentDiscountPercent() {
258 | return earlyPaymentDiscountPercent;
259 | }
260 |
261 | public void setEarlyPaymentDiscountPercent(Integer earlyPaymentDiscountPercent) {
262 | this.earlyPaymentDiscountPercent = earlyPaymentDiscountPercent;
263 | }
264 |
265 | public static long getSerialversionuid() {
266 | return serialVersionUID;
267 | }
268 |
269 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/responses/SubscriptionResponse.java:
--------------------------------------------------------------------------------
1 | package com.iugu.responses;
2 |
3 | import java.util.Date;
4 | import java.util.List;
5 |
6 | import org.codehaus.jackson.annotate.JsonIgnoreProperties;
7 | import org.codehaus.jackson.annotate.JsonProperty;
8 | import org.codehaus.jackson.map.annotate.JsonSerialize;
9 |
10 | import com.iugu.serializers.DateSerializer;
11 | import com.iugu.serializers.JsonFormat;
12 |
13 | @JsonIgnoreProperties(ignoreUnknown = true)
14 | public class SubscriptionResponse {
15 |
16 | private String id;
17 |
18 | private Boolean suspended;
19 |
20 | @JsonProperty("plan_identifier")
21 | private String planIdentifier;
22 |
23 | @JsonProperty("price_cents")
24 | private Integer priceCents;
25 |
26 | private String currency;
27 |
28 | //TODO Features
29 | @JsonProperty("expires_at")
30 | @JsonFormat("yyyy-MM-dd'T'HH:mm:ssZ") @JsonSerialize(using = DateSerializer.class)
31 | private Date expiresAt;
32 |
33 | @JsonProperty("customer_name")
34 | private String customerName;
35 |
36 | @JsonProperty("customer_email")
37 | private String customerEmail;
38 |
39 | @JsonProperty("cycled_at")
40 | @JsonFormat("yyyy-MM-dd'T'HH:mm:ssZ") @JsonSerialize(using = DateSerializer.class)
41 | private Date cycledAt;
42 |
43 | @JsonProperty("credits_min")
44 | private Integer creditsMin;
45 |
46 | //TODO Credits Cycle
47 |
48 | @JsonProperty("customer_id")
49 | private String customerId;
50 |
51 | @JsonProperty("plan_name")
52 | private String planName;
53 |
54 | @JsonProperty("customer_ref")
55 | private String customerRef;
56 |
57 | @JsonProperty("plan_ref")
58 | private String planRef;
59 |
60 | private Boolean active;
61 |
62 | @JsonProperty("in_trial")
63 | private Boolean inTrial;
64 |
65 | private Integer credits;
66 |
67 | @JsonProperty("credits_based")
68 | private Boolean creditsBased;
69 |
70 | //TODO Recent Invoices
71 |
72 | private List subitems;
73 |
74 | private List logs;
75 |
76 | @JsonProperty("custom_variables")
77 | private List customVariables;
78 |
79 | public String getId() {
80 | return id;
81 | }
82 |
83 | public void setId(String id) {
84 | this.id = id;
85 | }
86 |
87 | public Boolean getSuspended() {
88 | return suspended;
89 | }
90 |
91 | public void setSuspended(Boolean suspended) {
92 | this.suspended = suspended;
93 | }
94 |
95 | public String getPlanIdentifier() {
96 | return planIdentifier;
97 | }
98 |
99 | public void setPlanIdentifier(String planIdentifier) {
100 | this.planIdentifier = planIdentifier;
101 | }
102 |
103 | public Integer getPriceCents() {
104 | return priceCents;
105 | }
106 |
107 | public void setPriceCents(Integer priceCents) {
108 | this.priceCents = priceCents;
109 | }
110 |
111 | public String getCurrency() {
112 | return currency;
113 | }
114 |
115 | public void setCurrency(String currency) {
116 | this.currency = currency;
117 | }
118 |
119 | public Date getExpiresAt() {
120 | return expiresAt;
121 | }
122 |
123 | public void setExpiresAt(Date expiresAt) {
124 | this.expiresAt = expiresAt;
125 | }
126 |
127 | public String getCustomerName() {
128 | return customerName;
129 | }
130 |
131 | public void setCustomerName(String customerName) {
132 | this.customerName = customerName;
133 | }
134 |
135 | public String getCustomerEmail() {
136 | return customerEmail;
137 | }
138 |
139 | public void setCustomerEmail(String customerEmail) {
140 | this.customerEmail = customerEmail;
141 | }
142 |
143 | public Date getCycledAt() {
144 | return cycledAt;
145 | }
146 |
147 | public void setCycledAt(Date cycledAt) {
148 | this.cycledAt = cycledAt;
149 | }
150 |
151 | public Integer getCreditsMin() {
152 | return creditsMin;
153 | }
154 |
155 | public void setCreditsMin(Integer creditsMin) {
156 | this.creditsMin = creditsMin;
157 | }
158 |
159 | public String getCustomerId() {
160 | return customerId;
161 | }
162 |
163 | public void setCustomerId(String customerId) {
164 | this.customerId = customerId;
165 | }
166 |
167 | public String getPlanName() {
168 | return planName;
169 | }
170 |
171 | public void setPlanName(String planName) {
172 | this.planName = planName;
173 | }
174 |
175 | public String getCustomerRef() {
176 | return customerRef;
177 | }
178 |
179 | public void setCustomerRef(String customerRef) {
180 | this.customerRef = customerRef;
181 | }
182 |
183 | public String getPlanRef() {
184 | return planRef;
185 | }
186 |
187 | public void setPlanRef(String planRef) {
188 | this.planRef = planRef;
189 | }
190 |
191 | public Boolean getActive() {
192 | return active;
193 | }
194 |
195 | public void setActive(Boolean active) {
196 | this.active = active;
197 | }
198 |
199 | public Boolean getInTrial() {
200 | return inTrial;
201 | }
202 |
203 | public void setInTrial(Boolean inTrial) {
204 | this.inTrial = inTrial;
205 | }
206 |
207 | public Integer getCredits() {
208 | return credits;
209 | }
210 |
211 | public void setCredits(Integer credits) {
212 | this.credits = credits;
213 | }
214 |
215 | public Boolean getCreditsBased() {
216 | return creditsBased;
217 | }
218 |
219 | public void setCreditsBased(Boolean creditsBased) {
220 | this.creditsBased = creditsBased;
221 | }
222 |
223 | public List getSubitems() {
224 | return subitems;
225 | }
226 |
227 | public void setSubitems(List subitems) {
228 | this.subitems = subitems;
229 | }
230 |
231 | public List getLogs() {
232 | return logs;
233 | }
234 |
235 | public void setLogs(List logs) {
236 | this.logs = logs;
237 | }
238 |
239 | public List getCustomVariables() {
240 | return customVariables;
241 | }
242 |
243 | public void setCustomVariables(List customVariables) {
244 | this.customVariables = customVariables;
245 | }
246 |
247 | @Override
248 | public String toString() {
249 | return "SubscriptionResponse{" +
250 | "id='" + id + '\'' +
251 | ", suspended=" + suspended +
252 | ", planIdentifier='" + planIdentifier + '\'' +
253 | ", priceCents=" + priceCents +
254 | ", currency='" + currency + '\'' +
255 | ", expiresAt=" + expiresAt +
256 | ", customerName='" + customerName + '\'' +
257 | ", customerEmail='" + customerEmail + '\'' +
258 | ", cycledAt=" + cycledAt +
259 | ", creditsMin=" + creditsMin +
260 | ", customerId='" + customerId + '\'' +
261 | ", planName='" + planName + '\'' +
262 | ", customerRef='" + customerRef + '\'' +
263 | ", planRef='" + planRef + '\'' +
264 | ", active=" + active +
265 | ", inTrial=" + inTrial +
266 | ", credits=" + credits +
267 | ", creditsBased=" + creditsBased +
268 | ", subitems=" + subitems +
269 | ", logs=" + logs +
270 | ", customVariables=" + customVariables +
271 | '}';
272 | }
273 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/services/InvoiceService.java:
--------------------------------------------------------------------------------
1 | package com.iugu.services;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.Date;
5 |
6 | import javax.ws.rs.client.Entity;
7 | import javax.ws.rs.core.Form;
8 | import javax.ws.rs.core.MediaType;
9 | import javax.ws.rs.core.Response;
10 |
11 | import com.iugu.IuguConfiguration;
12 | import com.iugu.exceptions.IuguException;
13 | import com.iugu.model.Invoice;
14 | import com.iugu.responses.InvoiceResponse;
15 | import com.iugu.utils.ConvertionUtils;
16 |
17 | public class InvoiceService {
18 |
19 | private IuguConfiguration iugu;
20 | private final String CREATE_URL = IuguConfiguration.url("/invoices");
21 | private final String FIND_URL = IuguConfiguration.url("/invoices/%s");
22 | private final String DUPLICATE_URL = IuguConfiguration.url("/invoices/%s/duplicate");
23 | private final String REMOVE_URL = IuguConfiguration.url("/invoices/%s");
24 | private final String CANCEL_URL = IuguConfiguration.url("/invoices/%s/cancel");
25 | private final String REFUND_URL = IuguConfiguration.url("/invoices/%s/refund");
26 | private final String FIND_CUSTOMER_URL=IuguConfiguration.url("/invoices?customer_id=%s");
27 |
28 | public InvoiceService(IuguConfiguration iuguConfiguration) {
29 | this.iugu = iuguConfiguration;
30 | }
31 |
32 | public InvoiceResponse create(Invoice invoice) throws IuguException {
33 | Response response = this.iugu.getNewClient().target(CREATE_URL).request().post(Entity.entity(invoice, MediaType.APPLICATION_JSON));
34 |
35 | int ResponseStatus = response.getStatus();
36 | String ResponseText = null;
37 |
38 | if (ResponseStatus == 200)
39 | return response.readEntity(InvoiceResponse.class);
40 |
41 | // Error Happened
42 | if (response.hasEntity())
43 | ResponseText = response.readEntity(String.class);
44 |
45 | response.close();
46 |
47 | throw new IuguException("Error creating invoice!", ResponseStatus, ResponseText);
48 | }
49 |
50 | public InvoiceResponse find(String id) throws IuguException {
51 | Response response = this.iugu.getNewClient().target(String.format(FIND_URL, id)).request().get();
52 |
53 | int ResponseStatus = response.getStatus();
54 | String ResponseText = null;
55 |
56 | if (ResponseStatus == 200)
57 | return response.readEntity(InvoiceResponse.class);
58 |
59 | // Error Happened
60 | if (response.hasEntity())
61 | ResponseText = response.readEntity(String.class);
62 |
63 | response.close();
64 |
65 | throw new IuguException("Error finding invoice with id: " + id, ResponseStatus, ResponseText);
66 | }
67 |
68 | public InvoiceResponse duplicate(String id, Date date) throws IuguException {
69 | SimpleDateFormat sm = new SimpleDateFormat("dd/MM/yyyy");
70 | Form form = new Form();
71 |
72 | form.param("due_date", sm.format(date));
73 |
74 | Response response = this.iugu.getNewClient().target(String.format(DUPLICATE_URL, id)).request().post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
75 |
76 | int ResponseStatus = response.getStatus();
77 | String ResponseText = null;
78 |
79 | if (ResponseStatus == 200)
80 | return response.readEntity(InvoiceResponse.class);
81 |
82 | // Error Happened
83 | if (response.hasEntity())
84 | ResponseText = response.readEntity(String.class);
85 |
86 | response.close();
87 |
88 | throw new IuguException("Error duplicating invoice with id: " + id, ResponseStatus, ResponseText);
89 | }
90 |
91 | public InvoiceResponse duplicate(String id, Date date, boolean ignoreCanceledEmail, boolean currentFinesOption) throws IuguException {
92 | SimpleDateFormat sm = new SimpleDateFormat("dd/MM/yyyy");
93 | Form form = new Form();
94 |
95 | form.param("due_date", sm.format(date));
96 | form.param("ignore_canceled_email", ConvertionUtils.booleanToString(ignoreCanceledEmail));
97 | form.param("current_fines_option", ConvertionUtils.booleanToString(currentFinesOption));
98 |
99 | Response response = this.iugu.getNewClient().target(String.format(DUPLICATE_URL, id)).request().post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
100 |
101 | int ResponseStatus = response.getStatus();
102 | String ResponseText = null;
103 |
104 | if (response.getStatus() == 200)
105 | return response.readEntity(InvoiceResponse.class);
106 |
107 | // Error Happened
108 | if (response.hasEntity())
109 | ResponseText = response.readEntity(String.class);
110 |
111 | response.close();
112 |
113 | throw new IuguException("Error duplicating invoice with id: " + id, ResponseStatus, ResponseText);
114 | }
115 |
116 | public InvoiceResponse remove(String id) throws IuguException {
117 | Response response = this.iugu.getNewClient().target(String.format(REMOVE_URL, id)).request().delete();
118 |
119 | int ResponseStatus = response.getStatus();
120 | String ResponseText = null;
121 |
122 | if (ResponseStatus == 200)
123 | return response.readEntity(InvoiceResponse.class);
124 |
125 | // Error Happened
126 | if (response.hasEntity())
127 | ResponseText = response.readEntity(String.class);
128 |
129 | response.close();
130 |
131 | throw new IuguException("Error removing invoice with id: " + id, ResponseStatus, ResponseText);
132 | }
133 |
134 | public InvoiceResponse cancel(String id) throws IuguException {
135 | Response response = this.iugu.getNewClient().target(String.format(CANCEL_URL, id)).request().put(null);
136 |
137 | int ResponseStatus = response.getStatus();
138 | String ResponseText = null;
139 |
140 | if (ResponseStatus == 200)
141 | return response.readEntity(InvoiceResponse.class);
142 |
143 | // Error Happened
144 | if (response.hasEntity())
145 | ResponseText = response.readEntity(String.class);
146 |
147 | response.close();
148 |
149 | throw new IuguException("Error canceling invoice with id: " + id, ResponseStatus, ResponseText);
150 |
151 | }
152 |
153 | public InvoiceResponse refund(String id) throws IuguException {
154 | Response response = this.iugu.getNewClient().target(String.format(REFUND_URL, id)).request().post(null);
155 |
156 | int ResponseStatus = response.getStatus();
157 | String ResponseText = null;
158 |
159 | if (ResponseStatus == 200)
160 | return response.readEntity(InvoiceResponse.class);
161 |
162 | // Error Happened
163 | if (response.hasEntity())
164 | ResponseText = response.readEntity(String.class);
165 |
166 | response.close();
167 |
168 | throw new IuguException("Error refunding invoice with id: " + id, ResponseStatus, ResponseText);
169 | }
170 |
171 | public InvoiceResponse findByCustomerId(String id) throws IuguException {
172 | Response response = this.iugu.getNewClient().target(String.format(FIND_CUSTOMER_URL, id)).request().get();
173 |
174 | int ResponseStatus = response.getStatus();
175 | String ResponseText = null;
176 |
177 | if (ResponseStatus == 200)
178 | return response.readEntity(InvoiceResponse.class);
179 |
180 | // Error Happened
181 | if (response.hasEntity())
182 | ResponseText = response.readEntity(String.class);
183 |
184 | response.close();
185 |
186 | throw new IuguException("Error finding invoice with customerId: " + id, ResponseStatus, ResponseText);
187 | }
188 |
189 | // TODO Listar as faturas
190 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/services/SubscriptionService.java:
--------------------------------------------------------------------------------
1 | package com.iugu.services;
2 |
3 | import javax.ws.rs.client.Entity;
4 | import javax.ws.rs.core.MediaType;
5 | import javax.ws.rs.core.Response;
6 |
7 | import com.iugu.IuguConfiguration;
8 | import com.iugu.exceptions.IuguException;
9 | import com.iugu.model.Credit;
10 | import com.iugu.model.Subscription;
11 | import com.iugu.responses.SubscriptionResponse;
12 |
13 | public class SubscriptionService {
14 |
15 | private IuguConfiguration iugu;
16 | private final String CREATE_URL = IuguConfiguration.url("/subscriptions");
17 | private final String FIND_URL = IuguConfiguration.url("/subscriptions/%s");
18 | private final String CHANGE_URL = IuguConfiguration.url("/subscriptions/%s");
19 | private final String REMOVE_URL = IuguConfiguration.url("/subscriptions/%s");
20 | private final String SUSPEND_URL = IuguConfiguration.url("/subscriptions/%s/suspend");
21 | private final String ACTIVATE_URL = IuguConfiguration.url("/subscriptions/%s/activate");
22 | private final String CHANGE_SUBSCRIPTION_PLAN_URL = IuguConfiguration.url("/subscriptions/%s/change_plan/%s");
23 | private final String ADD_CREDITS_URL = IuguConfiguration.url("/subscriptions/%s/add_credits");
24 | private final String REMOVE_CREDITS_URL = IuguConfiguration.url("/subscriptions/%s/remove_credits");
25 |
26 | public SubscriptionService(IuguConfiguration iuguConfiguration) {
27 | this.iugu = iuguConfiguration;
28 | }
29 |
30 | public SubscriptionResponse create(Subscription subscription) throws IuguException {
31 | Response response = this.iugu.getNewClient().target(CREATE_URL).request().post(Entity.entity(subscription, MediaType.APPLICATION_JSON));
32 |
33 | int ResponseStatus = response.getStatus();
34 | String ResponseText = null;
35 |
36 | if (ResponseStatus == 200)
37 | return response.readEntity(SubscriptionResponse.class);
38 |
39 | // Error Happened
40 | if (response.hasEntity())
41 | ResponseText = response.readEntity(String.class);
42 |
43 | response.close();
44 |
45 | throw new IuguException("Error creating subscription!", ResponseStatus, ResponseText);
46 | }
47 |
48 | public SubscriptionResponse find(String id) throws IuguException {
49 | Response response = this.iugu.getNewClient().target(String.format(FIND_URL, id)).request().get();
50 |
51 | int ResponseStatus = response.getStatus();
52 | String ResponseText = null;
53 |
54 | if (ResponseStatus == 200)
55 | return response.readEntity(SubscriptionResponse.class);
56 |
57 | // Error Happened
58 | if (response.hasEntity())
59 | ResponseText = response.readEntity(String.class);
60 |
61 | response.close();
62 |
63 | throw new IuguException("Error finding subscription!", ResponseStatus, ResponseText);
64 | }
65 |
66 | public SubscriptionResponse change(String id, Subscription subscription) throws IuguException {
67 | Response response = this.iugu.getNewClient().target(String.format(CHANGE_URL, id)).request().put(Entity.entity(subscription, MediaType.APPLICATION_JSON));
68 |
69 | int ResponseStatus = response.getStatus();
70 | String ResponseText = null;
71 |
72 | if (ResponseStatus == 200)
73 | return response.readEntity(SubscriptionResponse.class);
74 |
75 | // Error Happened
76 | if (response.hasEntity())
77 | ResponseText = response.readEntity(String.class);
78 |
79 | response.close();
80 |
81 | throw new IuguException("Error changing subscription!", ResponseStatus, ResponseText);
82 | }
83 |
84 | public SubscriptionResponse remove(String id) throws IuguException {
85 | Response response = this.iugu.getNewClient().target(String.format(REMOVE_URL, id)).request().delete();
86 |
87 | int ResponseStatus = response.getStatus();
88 | String ResponseText = null;
89 |
90 | if (ResponseStatus == 200)
91 | return response.readEntity(SubscriptionResponse.class);
92 |
93 | // Error Happened
94 | if (response.hasEntity())
95 | ResponseText = response.readEntity(String.class);
96 |
97 | response.close();
98 |
99 | throw new IuguException("Error removing subscription!", ResponseStatus, ResponseText);
100 | }
101 |
102 | public SubscriptionResponse suspend(String id) throws IuguException {
103 | Response response = this.iugu.getNewClient().target(String.format(SUSPEND_URL, id)).request().post(null);
104 |
105 | int ResponseStatus = response.getStatus();
106 | String ResponseText = null;
107 |
108 | if (ResponseStatus == 200)
109 | return response.readEntity(SubscriptionResponse.class);
110 |
111 | // Error Happened
112 | if (response.hasEntity())
113 | ResponseText = response.readEntity(String.class);
114 |
115 | response.close();
116 |
117 | throw new IuguException("Error suspending subscription!", ResponseStatus, ResponseText);
118 | }
119 |
120 | public SubscriptionResponse activate(String id) throws IuguException {
121 | Response response = this.iugu.getNewClient().target(String.format(ACTIVATE_URL, id)).request().post(null);
122 |
123 | int ResponseStatus = response.getStatus();
124 | String ResponseText = null;
125 |
126 | if (ResponseStatus == 200)
127 | return response.readEntity(SubscriptionResponse.class);
128 |
129 | // Error Happened
130 | if (response.hasEntity())
131 | ResponseText = response.readEntity(String.class);
132 |
133 | response.close();
134 |
135 | throw new IuguException("Error activating subscription!", ResponseStatus, ResponseText);
136 | }
137 |
138 | public SubscriptionResponse changePlan(String id, String planIdentifier) throws IuguException {
139 | Response response = this.iugu.getNewClient().target(String.format(CHANGE_SUBSCRIPTION_PLAN_URL, id, planIdentifier)).request().post(null);
140 |
141 | int ResponseStatus = response.getStatus();
142 | String ResponseText = null;
143 |
144 | if (ResponseStatus == 200)
145 | return response.readEntity(SubscriptionResponse.class);
146 |
147 | // Error Happened
148 | if (response.hasEntity())
149 | ResponseText = response.readEntity(String.class);
150 |
151 | response.close();
152 |
153 | throw new IuguException("Error changing subscription plan!", ResponseStatus, ResponseText);
154 | }
155 |
156 | public SubscriptionResponse addCredits(String id, Credit credit) throws IuguException {
157 | Response response = this.iugu.getNewClient().target(String.format(ADD_CREDITS_URL, id)).request().post(Entity.entity(credit, MediaType.APPLICATION_JSON));
158 |
159 | int ResponseStatus = response.getStatus();
160 | String ResponseText = null;
161 |
162 | if (ResponseStatus == 200)
163 | return response.readEntity(SubscriptionResponse.class);
164 |
165 | // Error Happened
166 | if (response.hasEntity())
167 | ResponseText = response.readEntity(String.class);
168 |
169 | response.close();
170 |
171 | throw new IuguException("Error adding credits to subscription!", ResponseStatus, ResponseText);
172 | }
173 |
174 | public SubscriptionResponse removeCredits(String id, Credit credit) throws IuguException {
175 | Response response = this.iugu.getNewClient().target(String.format(REMOVE_CREDITS_URL, id)).request().post(Entity.entity(credit, MediaType.APPLICATION_JSON));
176 |
177 | int ResponseStatus = response.getStatus();
178 | String ResponseText = null;
179 |
180 | if (ResponseStatus == 200)
181 | return response.readEntity(SubscriptionResponse.class);
182 |
183 | // Error Happened
184 | if (response.hasEntity())
185 | ResponseText = response.readEntity(String.class);
186 |
187 | response.close();
188 |
189 | throw new IuguException("Error removing credits from subscription!", ResponseStatus, ResponseText);
190 | }
191 |
192 | // TODO Listar as assinaturas
193 |
194 | }
--------------------------------------------------------------------------------
/src/main/java/com/iugu/responses/InvoiceResponse.java:
--------------------------------------------------------------------------------
1 | package com.iugu.responses;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 | import java.util.List;
6 |
7 | import org.codehaus.jackson.annotate.JsonIgnoreProperties;
8 | import org.codehaus.jackson.annotate.JsonProperty;
9 | import org.codehaus.jackson.map.annotate.JsonSerialize;
10 |
11 | import com.iugu.serializers.DateSerializer;
12 | import com.iugu.serializers.JsonFormat;
13 |
14 | @JsonIgnoreProperties(ignoreUnknown = true)
15 | public class InvoiceResponse implements Serializable {
16 |
17 | private static final long serialVersionUID = -4229186497940178039L;
18 |
19 | private String id;
20 |
21 | @JsonProperty("due_date")
22 | @JsonFormat("yyyy-MM-dd")
23 | @JsonSerialize(using = DateSerializer.class)
24 | private String dueDate;
25 |
26 | private String currency;
27 |
28 | @JsonProperty("discount_cents")
29 | private Integer discountCents;
30 |
31 | private String email;
32 |
33 | @JsonProperty("items_total_cents")
34 | private Integer itemsTotalCents;
35 |
36 | @JsonProperty("notification_url")
37 | private String notificationUrl;
38 |
39 | @JsonProperty("return_url")
40 | private String returnUrl;
41 |
42 | private String status;
43 |
44 | @JsonProperty("tax_cents")
45 | private Integer taxCents;
46 |
47 | @JsonProperty("updated_at")
48 | @JsonFormat("yyyy-MM-dd'T'HH:mm:ssZ")
49 | @JsonSerialize(using = DateSerializer.class)
50 | private Date updatedAt;
51 |
52 | @JsonProperty("total_cents")
53 | private Integer totalCents;
54 |
55 | @JsonProperty("paid_at")
56 | private Date paidAt;
57 |
58 | @JsonProperty("secure_id")
59 | private String secureId;
60 |
61 | @JsonProperty("secure_url")
62 | private String secureUrl;
63 |
64 | @JsonProperty("customer_id")
65 | private String customerId;
66 |
67 | @JsonProperty("user_id")
68 | private Long userId;
69 |
70 | @JsonProperty("total")
71 | private String total;
72 |
73 | @JsonProperty("total_paid")
74 | private String totalPaid;
75 |
76 | @JsonProperty("total_on_occurrence_day")
77 | private String totalOnOccurrenceDay;
78 |
79 | @JsonProperty("taxes_paid")
80 | private String taxesPaid;
81 |
82 | private String interest;
83 |
84 | private String discount;
85 |
86 | private Boolean refundable;
87 |
88 | private String installments;
89 |
90 | @JsonProperty("bank_slip")
91 | private BankSlipResponse bankSlip;
92 |
93 | private List items;
94 |
95 | private List variables;
96 |
97 | private List logs;
98 |
99 | public String getId() {
100 | return id;
101 | }
102 |
103 | public void setId(String id) {
104 | this.id = id;
105 | }
106 |
107 | public String getDueDate() {
108 | return dueDate;
109 | }
110 |
111 | public void setDueDate(String dueDate) {
112 | this.dueDate = dueDate;
113 | }
114 |
115 | public String getCurrency() {
116 | return currency;
117 | }
118 |
119 | public void setCurrency(String currency) {
120 | this.currency = currency;
121 | }
122 |
123 | public Integer getDiscountCents() {
124 | return discountCents;
125 | }
126 |
127 | public void setDiscountCents(Integer discountCents) {
128 | this.discountCents = discountCents;
129 | }
130 |
131 | public String getEmail() {
132 | return email;
133 | }
134 |
135 | public void setEmail(String email) {
136 | this.email = email;
137 | }
138 |
139 | public Integer getItemsTotalCents() {
140 | return itemsTotalCents;
141 | }
142 |
143 | public void setItemsTotalCents(Integer itemsTotalCents) {
144 | this.itemsTotalCents = itemsTotalCents;
145 | }
146 |
147 | public String getNotificationUrl() {
148 | return notificationUrl;
149 | }
150 |
151 | public void setNotificationUrl(String notificationUrl) {
152 | this.notificationUrl = notificationUrl;
153 | }
154 |
155 | public String getReturnUrl() {
156 | return returnUrl;
157 | }
158 |
159 | public void setReturnUrl(String returnUrl) {
160 | this.returnUrl = returnUrl;
161 | }
162 |
163 | public String getStatus() {
164 | return status;
165 | }
166 |
167 | public void setStatus(String status) {
168 | this.status = status;
169 | }
170 |
171 | public Integer getTaxCents() {
172 | return taxCents;
173 | }
174 |
175 | public void setTaxCents(Integer taxCents) {
176 | this.taxCents = taxCents;
177 | }
178 |
179 | public Date getUpdatedAt() {
180 | return updatedAt;
181 | }
182 |
183 | public void setUpdatedAt(Date updatedAt) {
184 | this.updatedAt = updatedAt;
185 | }
186 |
187 | public Integer getTotalCents() {
188 | return totalCents;
189 | }
190 |
191 | public void setTotalCents(Integer totalCents) {
192 | this.totalCents = totalCents;
193 | }
194 |
195 | public Date getPaidAt() {
196 | return paidAt;
197 | }
198 |
199 | public void setPaidAt(Date paidAt) {
200 | this.paidAt = paidAt;
201 | }
202 |
203 | public String getSecureId() {
204 | return secureId;
205 | }
206 |
207 | public void setSecureId(String secureId) {
208 | this.secureId = secureId;
209 | }
210 |
211 | public String getSecureUrl() {
212 | return secureUrl;
213 | }
214 |
215 | public void setSecureUrl(String secureUrl) {
216 | this.secureUrl = secureUrl;
217 | }
218 |
219 | public String getCustomerId() {
220 | return customerId;
221 | }
222 |
223 | public void setCustomerId(String customerId) {
224 | this.customerId = customerId;
225 | }
226 |
227 | public Long getUserId() {
228 | return userId;
229 | }
230 |
231 | public void setUserId(Long userId) {
232 | this.userId = userId;
233 | }
234 |
235 | public String getTaxesPaid() {
236 | return taxesPaid;
237 | }
238 |
239 | public void setTaxesPaid(String taxesPaid) {
240 | this.taxesPaid = taxesPaid;
241 | }
242 |
243 | public String getInterest() {
244 | return interest;
245 | }
246 |
247 | public void setInterest(String interest) {
248 | this.interest = interest;
249 | }
250 |
251 | public String getDiscount() {
252 | return discount;
253 | }
254 |
255 | public void setDiscount(String discount) {
256 | this.discount = discount;
257 | }
258 |
259 | public Boolean getRefundable() {
260 | return refundable;
261 | }
262 |
263 | public void setRefundable(Boolean refundable) {
264 | this.refundable = refundable;
265 | }
266 |
267 | public String getInstallments() {
268 | return installments;
269 | }
270 |
271 | public void setInstallments(String installments) {
272 | this.installments = installments;
273 | }
274 |
275 | public BankSlipResponse getBankSlip() {
276 | return bankSlip;
277 | }
278 |
279 | public void setBankSlip(BankSlipResponse bankSlip) {
280 | this.bankSlip = bankSlip;
281 | }
282 |
283 | public List getItems() {
284 | return items;
285 | }
286 |
287 | public void setItems(List items) {
288 | this.items = items;
289 | }
290 |
291 | public List getVariables() {
292 | return variables;
293 | }
294 |
295 | public void setVariables(List variables) {
296 | this.variables = variables;
297 | }
298 |
299 | public List getLogs() {
300 | return logs;
301 | }
302 |
303 | public void setLogs(List logs) {
304 | this.logs = logs;
305 | }
306 |
307 | public String getTotalPaid() {
308 | return totalPaid;
309 | }
310 |
311 | public void setTotalPaid(String totalPaid) {
312 | this.totalPaid = totalPaid;
313 | }
314 |
315 | public String getTotalOnOccurrenceDay() {
316 | return totalOnOccurrenceDay;
317 | }
318 |
319 | public void setTotalOnOccurrenceDay(String totalOnOccurrenceDay) {
320 | this.totalOnOccurrenceDay = totalOnOccurrenceDay;
321 | }
322 |
323 | public String getTotal() {
324 | return total;
325 | }
326 |
327 | public void setTotal(String total) {
328 | this.total = total;
329 | }
330 |
331 | }
--------------------------------------------------------------------------------