Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

MOAR REFACTORS #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/br/com/moip/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public SubscriberAPI subscriber() {
return new SubscriberAPI(client);
}

public SubscriptionsAPI subscriptions() {
return new SubscriptionsAPI(client);
public SubscriptionAPI subscriptions() {
return new SubscriptionAPI(client);
}
}
5 changes: 5 additions & 0 deletions src/main/java/br/com/moip/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public <T> T put(final String path, final Object object, final Class<T> type) {
return doRequest(props);
}

public <T> T put(final String path, final Class<T> type) {
RequestProps props = RequestPropsBuilder.requestPropsBuilder().method("PUT").path(path).type(type).contentType(ContentType.APPLICATION_JSON);
return doRequest(props);
}

public <T> T get(String path, Class<T> type) {
RequestProps props = RequestPropsBuilder.requestPropsBuilder().method("GET").path(path).type(type).contentType(ContentType.APPLICATION_JSON);
return doRequest(props);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/br/com/moip/api/SubscriberAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ public Subscriber get(String code) {
* @return
* Return 200 OK if everything was right
*/
public Message updateSubscriber (Subscriber sub) {
public Message update(Subscriber sub) {
return client.put(String.format("/assinaturas/v1/customers/%s", sub.getCode()), sub, Message.class);
}

/**
* This method will update a Subscriber's Billing Info, if it exist
* @param sub
* The sub that will be updated
* This method will update a Subscriber's Billing Info, if it exists
* @param code the subscriber code
* @param billingInfo the new subscriber billing info
* @return
* Return 200 OK if everything was right
*/
public Message updateSubscriberBillingInfo (Subscriber sub) {
return client.put(String.format("/assinaturas/v1/customers/%s/billing_infos", sub.getCode()), sub.getBillingInfo(), Message.class);
public Message updateBillingInfo(String code, BillingInfo billingInfo) {
return client.put(String.format("/assinaturas/v1/customers/%s/billing_infos", code), billingInfo, Message.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@
* @version 0.1
*/

public class SubscriptionsAPI {
public class SubscriptionAPI {
private final Client client;

/**
* Client that will make the request
* @param client
*/
public SubscriptionsAPI(Client client) {
public SubscriptionAPI(Client client) {
this.client = client;
}

/**
* This methods create a new Subscriptions
* @param subs
* The parameter is the Plan that will be created
* @return
* Return the Subscriptions with the ID auto generated from the WireCard API
* @param newCustomer indicates whether the customer is new or not
* @param subs the subscription to be created
* @return generated subscription
*/
public SubscriptionResponse create(SubscriptionRequest subs) {
return client.post("/assinaturas/v1/subscriptions", subs, SubscriptionResponse.class);
public SubscriptionResponse create(boolean newCustomer, SubscriptionRequest subs) {
return client.post(String.format("/assinaturas/v1/subscriptions?new_customer=%s", newCustomer), subs, SubscriptionResponse.class);
}

/**
Expand Down Expand Up @@ -61,7 +60,7 @@ public SubscriptionResponse get(String code) {
* @return
* Return nothing, but it will verify the response code if 200 it suspend successfully
*/
public Message suspendSubscriptions (SubscriptionRequest subs) {
public Message suspend(SubscriptionRequest subs) {
return client.put(String.format("/assinaturas/v1/subscriptions/%s/suspend", subs.getCode()), subs, Message.class);
}

Expand All @@ -72,18 +71,17 @@ public Message suspendSubscriptions (SubscriptionRequest subs) {
* @return
* Return void, the way to know if everything goes will is by the answer from the API 200 = OK
*/
public Message reactiveSubscriptions (SubscriptionRequest subs) {
public Message reactivate(SubscriptionRequest subs) {
return client.put(String.format("/assinaturas/v1/subscriptions/%s/activate", subs.getCode()), subs, Message.class);
}

/**
* This method inactive the received Plan using the WireCard API
* @param subs
* The plan to be desactivated
* @param code the code of the subscription to be cancelled
* @return
*/
public Message cancelSubscriptions (SubscriptionRequest subs) {
return client.put(String.format("/assinaturas/v1/subscriptions/%s/cancel", subs.getCode()), subs, Message.class);
public Message cancel(String code) {
return client.put(String.format("/assinaturas/v1/subscriptions/%s/cancel", code), Message.class);
}

/**
Expand All @@ -93,7 +91,7 @@ public Message cancelSubscriptions (SubscriptionRequest subs) {
* @return
* Return 200 OK if everithing was right
*/
public Message updateSubscriptionPlan (SubscriptionRequest subs) {
public Message update(SubscriptionRequest subs) {
return client.put(String.format("/assinaturas/v1/subscriptions/%s", subs.getCode()), subs, Message.class);
}
}
6 changes: 3 additions & 3 deletions src/main/java/br/com/moip/api/SubscriptionPlanAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public SubscriptionPlan get(String code) {
* @return
* Return nothing, but it will verify the response code if 200 it activated successfully
*/
public SubscriptionPlan activateSubscriptionPlan (SubscriptionPlan plan) {
public SubscriptionPlan activate(SubscriptionPlan plan) {
return client.put(String.format("/assinaturas/v1/plans/%s/activate", plan.getCode()), plan, SubscriptionPlan.class);
}

Expand All @@ -72,7 +72,7 @@ public SubscriptionPlan activateSubscriptionPlan (SubscriptionPlan plan) {
* The plan to be desactivated
* @return
*/
public SubscriptionPlan desactivateSubscriptionPlan (SubscriptionPlan plan) {
public SubscriptionPlan deactivate(SubscriptionPlan plan) {
return client.put(String.format("/assinaturas/v1/plans/%s/inactivate", plan.getCode()), plan, SubscriptionPlan.class);
}

Expand All @@ -83,7 +83,7 @@ public SubscriptionPlan desactivateSubscriptionPlan (SubscriptionPlan plan) {
* @return
* Return 200 OK if everithing was right
*/
public SubscriptionPlan updateSubscriptionPlan (SubscriptionPlan plan) {
public SubscriptionPlan update(SubscriptionPlan plan) {
return client.put(String.format("/assinaturas/v1/plans/%s", plan.getCode()), plan, SubscriptionPlan.class);
}
}
20 changes: 20 additions & 0 deletions src/main/java/br/com/moip/resource/links/SubscriptionLinks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package br.com.moip.resource.links;

import com.google.gson.annotations.SerializedName;

public class SubscriptionLinks {
private Boleto boleto;

public Boleto getBoleto() {
return boleto;
}

public static class Boleto {
@SerializedName("redirect_href")
private String redirectHref;

public String getRedirectHref() {
return redirectHref;
}
}
}
7 changes: 3 additions & 4 deletions src/main/java/br/com/moip/response/Response.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package br.com.moip.response;

import br.com.moip.resource.Alert;
import br.com.moip.resource.Message;

/**
* This class implements the basis that all responses could have from WireCard API
Expand All @@ -12,7 +11,7 @@

public class Response {
private Error[] errors;
private Message message;
private String message;
private Alert[] alerts;

boolean hasErrors() {
Expand Down Expand Up @@ -47,11 +46,11 @@ public void setErrors(Error[] errors) {
this.errors = errors;
}

public Message getMessage() {
public String getMessage() {
return message;
}

public void setMessage(Message message) {
public void setMessage(String message) {
this.message = message;
}

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/br/com/moip/response/SubscriptionResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import br.com.moip.resource.*;
import br.com.moip.resource.Error;
import br.com.moip.resource.links.SubscriptionLinks;
import com.google.gson.annotations.SerializedName;

public class SubscriptionResponse extends Response{
Expand Down Expand Up @@ -47,6 +48,11 @@ public class SubscriptionResponse extends Response{
*/
private InvoiceSubscription invoice;

/**
* Description: If the subscription was made with Boleto, this property is returned
*/
private SubscriptionLinks _links;

public SubscriptionResponse() {
}

Expand Down Expand Up @@ -115,4 +121,8 @@ public InvoiceSubscription getInvoice() {
public void setInvoice(InvoiceSubscription invoice) {
this.invoice = invoice;
}

public SubscriptionLinks getLinks() {
return _links;
}
}