From 12e857bee42090845db96d82874877761b5732b3 Mon Sep 17 00:00:00 2001 From: Eric Zimmerman Date: Fri, 16 Sep 2011 11:55:20 -0700 Subject: [PATCH 1/2] Forgot the AddOn wrapper in the last commit. --- src/com/kwanzoo/recurly/AddOn.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/com/kwanzoo/recurly/AddOn.java diff --git a/src/com/kwanzoo/recurly/AddOn.java b/src/com/kwanzoo/recurly/AddOn.java new file mode 100644 index 0000000..eeda085 --- /dev/null +++ b/src/com/kwanzoo/recurly/AddOn.java @@ -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; +} \ No newline at end of file From 113328aa7aae3f8757649eb408d4dee993ea4f52 Mon Sep 17 00:00:00 2001 From: Eric Zimmerman Date: Fri, 16 Sep 2011 13:02:59 -0700 Subject: [PATCH 2/2] Added AddOn Wrapper for subscription and Updated Base to allow for unique sub-domains --- src/com/kwanzoo/recurly/Base.java | 16 +++++++++++++--- src/com/kwanzoo/recurly/Subscription.java | 6 ++++++ src/com/kwanzoo/recurly/test/RecurlyTest.java | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/com/kwanzoo/recurly/Base.java b/src/com/kwanzoo/recurly/Base.java index 67b0cc5..1df62a8 100755 --- a/src/com/kwanzoo/recurly/Base.java +++ b/src/com/kwanzoo/recurly/Base.java @@ -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; @@ -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; @@ -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() { @@ -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){ @@ -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)); } @@ -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{ diff --git a/src/com/kwanzoo/recurly/Subscription.java b/src/com/kwanzoo/recurly/Subscription.java index ae92947..3d5906c 100644 --- a/src/com/kwanzoo/recurly/Subscription.java +++ b/src/com/kwanzoo/recurly/Subscription.java @@ -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; @@ -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 addOns; + @XmlElement(name="state") public String state; diff --git a/src/com/kwanzoo/recurly/test/RecurlyTest.java b/src/com/kwanzoo/recurly/test/RecurlyTest.java index 5894cce..fea8b6d 100755 --- a/src/com/kwanzoo/recurly/test/RecurlyTest.java +++ b/src/com/kwanzoo/recurly/test/RecurlyTest.java @@ -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();