Permalink
Browse files

Add support for the new invoice format.

  • Loading branch information...
1 parent 222b3da commit 40ce5bcf2cf43b20222f4bf4e116acb16f306195 @boucher boucher committed Oct 30, 2012
View
@@ -1 +1 @@
-1.1.7
+1.1.8
@@ -2,7 +2,7 @@
public abstract class Stripe
{
- public static final String API_BASE = "https://api.stripe.com/v1";
- public static final String VERSION = "1.1.7";
+ public static final String API_BASE = "https://api.stripe.com";
+ public static final String VERSION = "1.1.8";
public static String apiKey;
}
@@ -23,7 +23,7 @@
Long periodStart;
Long periodEnd;
Discount discount;
- InvoiceLines lines;
+ InvoiceLineItemCollection lines;
Boolean livemode;
Integer attemptCount;
@@ -163,14 +163,10 @@ public void setDiscount(Discount discount) {
this.discount = discount;
}
- public InvoiceLines getLines() {
+ public InvoiceLineItemCollection getLines() {
return lines;
}
- public void setLines(InvoiceLines lines) {
- this.lines = lines;
- }
-
public Boolean getLivemode() {
return livemode;
}
@@ -0,0 +1,56 @@
+package com.stripe.model;
+
+import java.util.List;
+
+public class InvoiceLineItem extends StripeObject {
+ String id;
+ String type;
+ Boolean livemode;
+ Integer amount;
+ String currency;
+ Boolean proration;
+ InvoiceLineItemPeriod period;
+ Integer quantity;
+ Plan plan;
+ String description;
+
+ public String getId() {
+ return this.id;
+ }
+
+ public String getType() {
+ return this.type;
+ }
+
+ public Boolean getLivemode() {
+ return this.livemode;
+ }
+
+ public Integer getAmount() {
+ return this.amount;
+ }
+
+ public String getCurrency() {
+ return this.currency;
+ }
+
+ public Boolean getProration() {
+ return this.proration;
+ }
+
+ public InvoiceLineItemPeriod getPeriod() {
+ return this.period;
+ }
+
+ public Integer getQuantity() {
+ return this.quantity;
+ }
+
+ public Plan getPlan() {
+ return this.plan;
+ }
+
+ public String getDescription() {
+ return this.description;
+ }
+}
@@ -0,0 +1,35 @@
+package com.stripe.model;
+
+import java.util.List;
+import java.util.Map;
+
+import com.stripe.exception.StripeException;
+import com.stripe.net.APIResource;
+import com.stripe.Stripe;
+
+public class InvoiceLineItemCollection extends APIResource {
+ List<InvoiceLineItem> data;
+ Integer count;
+ String url;
+
+ public List<InvoiceLineItem> getData() {
+ return data;
+ }
+
+ public String getURL() {
+ return url;
+ }
+
+ public Integer getCount() {
+ return count;
+ }
+
+ public InvoiceLineItemCollection all(Map<String, Object> params) throws StripeException {
+ return all(params, null);
+ }
+
+ public InvoiceLineItemCollection all(Map<String, Object> params, String apiKey) throws StripeException {
+ String url = String.format("%s%s", Stripe.API_BASE, this.getURL());
+ return request(RequestMethod.GET, url, params, InvoiceLineItemCollection.class, apiKey);
+ }
+}
@@ -1,6 +1,6 @@
package com.stripe.model;
-public class InvoiceLineSubscriptionPeriod extends StripeObject {
+public class InvoiceLineItemPeriod extends StripeObject {
Long start;
Long end;
@@ -1,26 +0,0 @@
-package com.stripe.model;
-
-public class InvoiceLineSubscription extends StripeObject {
- Plan plan;
- Integer amount;
- InvoiceLineSubscriptionPeriod period;
-
- public Plan getPlan() {
- return plan;
- }
- public void setPlan(Plan plan) {
- this.plan = plan;
- }
- public Integer getAmount() {
- return amount;
- }
- public void setAmount(Integer amount) {
- this.amount = amount;
- }
- public InvoiceLineSubscriptionPeriod getPeriod() {
- return period;
- }
- public void setPeriod(InvoiceLineSubscriptionPeriod period) {
- this.period = period;
- }
-}
@@ -1,21 +0,0 @@
-package com.stripe.model;
-
-import java.util.List;
-
-public class InvoiceLines extends StripeObject {
- List<InvoiceItem> invoiceitems;
- List<InvoiceLineSubscription> subscriptions;
-
- public List<InvoiceItem> getInvoiceitems() {
- return invoiceitems;
- }
- public void setInvoiceitems(List<InvoiceItem> invoiceitems) {
- this.invoiceitems = invoiceitems;
- }
- public List<InvoiceLineSubscription> getSubscriptions() {
- return subscriptions;
- }
- public void setSubscriptions(List<InvoiceLineSubscription> subscriptions) {
- this.subscriptions = subscriptions;
- }
-}
@@ -37,7 +37,7 @@
create();
private static String className(Class<?> clazz) { return clazz.getSimpleName().toLowerCase().replace("$",""); }
- protected static String singleClassURL(Class<?> clazz) { return String.format("%s/%s", Stripe.API_BASE, className(clazz)); }
+ protected static String singleClassURL(Class<?> clazz) { return String.format("%s/v1/%s", Stripe.API_BASE, className(clazz)); }
protected static String classURL(Class<?> clazz) { return String.format("%ss", singleClassURL(clazz)); }
protected static String instanceURL(Class<?> clazz, String id) { return String.format("%s/%s", classURL(clazz), id); }
@@ -25,6 +25,7 @@
import com.stripe.model.DeletedInvoiceItem;
import com.stripe.model.DeletedPlan;
import com.stripe.model.Invoice;
+import com.stripe.model.InvoiceLineItemCollection;
import com.stripe.model.InvoiceItem;
import com.stripe.model.Event;
import com.stripe.model.Fee;
@@ -322,8 +323,11 @@ public void testInvalidCard() throws StripeException {
Map<String, Object> listParams = new HashMap<String, Object>();
listParams.put("count", 1);
Invoice createdInvoice = Invoice.all(listParams).getData().get(0);
- Invoice retrievedInvoice = Invoice.retrieve(createdInvoice.getId());
- assertEquals(createdInvoice.getId(), retrievedInvoice.getId());
+ Invoice retrievedInvoice = Invoice.retrieve(createdInvoice.getId());
+ assertEquals(createdInvoice.getId(), retrievedInvoice.getId());
+
+ InvoiceLineItemCollection lines = retrievedInvoice.getLines().all(listParams);
+ assertFalse(lines == null);
}
@Test public void testInvoiceRetrieveForCustomer() throws StripeException {
@@ -343,6 +347,10 @@ public void testInvalidCard() throws StripeException {
upcomingParams.put("customer", customer.getId());
Invoice upcomingInvoice = Invoice.upcoming(upcomingParams);
assertFalse(upcomingInvoice.getAttempted());
+
+ Map<String, Object> listParams = new HashMap<String, Object>();
+ InvoiceLineItemCollection lines = upcomingInvoice.getLines().all(listParams);
+ assertFalse(lines == null);
}
@Test public void testTokenCreate() throws StripeException {

0 comments on commit 40ce5bc

Please sign in to comment.