Skip to content
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
16 changes: 16 additions & 0 deletions src/com/kwanzoo/recurly/AddOn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.kwanzoo.recurly;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="add_on")
public class AddOn{
@XmlElement(name="add_on_code")
public String addOnCode;

@XmlElement(name="unit_amount_in_cents")
public Integer unitAmountInCents;

@XmlElement(name="quantity")
public Integer quantity;
}
16 changes: 13 additions & 3 deletions src/com/kwanzoo/recurly/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;


import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
Expand Down Expand Up @@ -30,7 +31,10 @@
import com.sun.jersey.core.util.Base64;

public abstract class Base{
private static final String BaseURI = "https://app.recurly.com";
private static String protocol = "https://";
private static String subdomain = "app";
private static String domain = "recurly.com";
//private static String BaseURI = protocol + subdomain + "." + domain;
private static final WebResource webResource;
private static String base64AuthStr = "";
private static final int UNPROCESSABLE_ENTITY_HTTP_CODE = 422;
Expand Down Expand Up @@ -72,6 +76,10 @@ private static SSLContext getSSLContext(){
}
return context;
}

private static String getBaseURI() {
return protocol + subdomain + "." + domain;
}

private static HostnameVerifier getHostNameVerifier(){
return new HostnameVerifier() {
Expand All @@ -85,7 +93,7 @@ public boolean verify(final String hostname, final SSLSession sslSession) {
private static WebResource getNewWebResource(){
final ClientConfig config = new DefaultClientConfig();
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(getHostNameVerifier(), getSSLContext()));
return Client.create(config).resource(BaseURI);
return Client.create(config).resource(getBaseURI());
}

public static WebResource.Builder getWebResourceBuilder(final String path){
Expand All @@ -97,7 +105,8 @@ public static WebResource.Builder getWebResourceBuilderHtml(final String path) {
}

//This method needs to be invoked only once, just before performing the first recurly operation
public static void setAuth(final String recurlyUsername, final String recurlyPassword){
public static void setAuth(final String recurlySubdomain, final String recurlyUsername, final String recurlyPassword){
subdomain = recurlySubdomain;
base64AuthStr = new String(Base64.encode(recurlyUsername + ":" + recurlyPassword));
}

Expand Down Expand Up @@ -146,6 +155,7 @@ else if(status.equals(ClientResponse.Status.SERVICE_UNAVAILABLE)){
protected abstract String getResourcePath();
protected abstract String getResourceCreationPath();


//default implementations for create, update and delete operation on a resource.
//read operations are static methods within respective resource classes.
public void create() throws Exception{
Expand Down
6 changes: 6 additions & 0 deletions src/com/kwanzoo/recurly/Subscription.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.kwanzoo.recurly;

import java.util.Date;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import com.sun.jersey.api.client.GenericType;
Expand Down Expand Up @@ -33,6 +35,10 @@ public class Subscription extends Base{
@XmlElement(name="plan")
public Plan plan;

@XmlElementWrapper(name = "add_ons")
@XmlElement(name = "add_on")
public List<AddOn> addOns;

@XmlElement(name="state")
public String state;

Expand Down
2 changes: 1 addition & 1 deletion src/com/kwanzoo/recurly/test/RecurlyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void setUp() {

currentYear = Integer.parseInt(new SimpleDateFormat("yyyy").format(new Date()));

Base.setAuth(username, password);
Base.setAuth("app", username, password);
}
catch (IOException e) {
e.printStackTrace();
Expand Down