Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added transparent post api wrappers and more regular api wrappers for…

… invoices, payments etc.
  • Loading branch information...
commit 313eb50a644c03ec075d59000eb067723f263a22 1 parent 2c09613
@thobach thobach authored
View
8 README.md
@@ -7,13 +7,13 @@ The Recurly Java Client library is an open source wrapper library to talk to Rec
Usage
-----
-Please refer to the JUnit test cases in [RecurlyTest](http://github.com/gslab/recurly-client-java/blob/master/src/com/kwanzoo/recurly/test/RecurlyTest.java)
+Please refer to the JUnit test cases in [RecurlyTest](https://github.com/thobach/recurly-client-java/blob/master/src/com/kwanzoo/recurly/test/RecurlyTest.java)
Installation
------------
-Just add the latest jar(under [dist/](http://github.com/gslab/recurly-client-java/blob/master/dist/recurly-client-java-SNAPSHOT.jar)) to your classpath.
+Just add the latest jar(under [dist/](https://github.com/thobach/recurly-client-java/blob/master/dist/recurly-client-java-SNAPSHOT.jar)) to your classpath.
Dependencies
@@ -24,6 +24,6 @@ This wrapper relies on the excellent [Jersey REST client API](https://jersey.dev
Developed By
-------------
-This code was developed by Manoj Mathai, GSLab, for Kwanzoo Inc.
-
+The initial code was developed by Manoj Mathai, GSLab, for Kwanzoo Inc.
+The Transparent Post API and further API integration was done by Thomas Bachmann, Mambu GmbH.
View
BIN  dist/recurly-client-java-SNAPSHOT.jar
Binary file not shown
View
4 src/com/kwanzoo/recurly/Base.java 100644 → 100755
@@ -92,6 +92,10 @@ private static WebResource getNewWebResource(){
return webResource.path(path).header("Authorization", base64AuthStr).accept(MediaType.APPLICATION_XML_TYPE);
}
+ public static WebResource.Builder getWebResourceBuilderHtml(final String path) {
+ return webResource.path(path).header("Authorization", base64AuthStr).accept(MediaType.TEXT_HTML);
+ }
+
//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){
base64AuthStr = new String(Base64.encode(recurlyUsername + ":" + recurlyPassword));
View
0  src/com/kwanzoo/recurly/BillingInfo.java 100644 → 100755
File mode changed
View
50 src/com/kwanzoo/recurly/Charge.java
@@ -0,0 +1,50 @@
+package com.kwanzoo.recurly;
+
+import java.util.Date;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "charge")
+public class Charge extends Base {
+
+ private static String resourceName = "charges";
+
+ @XmlElement(name = "amount_in_cents")
+ public Integer amount_in_cents;
+
+ @XmlElement(name = "description")
+ public String description;
+
+ @XmlElement(name = "id")
+ public String id;
+
+ @XmlElement(name = "account_code")
+ public String account_code;
+
+ @XmlElement(name = "start_date")
+ public Date start_date;
+
+ @XmlElement(name = "end_date")
+ public Date end_date;
+
+ @XmlElement(name = "created_at")
+ public Date created_at;
+
+ @Override
+ protected String getResourcePath() {
+ return Account.pluralResourceName + "/" + account_code + "/" + resourceName;
+ }
+
+ @Override
+ protected String getResourceCreationPath() {
+ return getResourcePath();
+ }
+
+ public Charge() {
+ }
+
+ public Charge(final String accountCode) {
+ this.account_code = accountCode;
+ }
+}
View
29 src/com/kwanzoo/recurly/Invoice.java
@@ -0,0 +1,29 @@
+package com.kwanzoo.recurly;
+
+import java.util.Date;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "invoice")
+public class Invoice {
+
+ @XmlElement(name = "subtotal_in_cents")
+ public Integer subtotal_in_cents;
+
+ @XmlElement(name = "total_in_cents")
+ public Integer total_in_cents;
+
+ @XmlElement(name = "id")
+ public String id;
+
+ @XmlElement(name = "account_code")
+ public String account_code;
+
+ @XmlElement(name = "invoice_number")
+ public Integer invoice_number;
+
+ @XmlElement(name = "date")
+ public Date date;
+
+}
View
87 src/com/kwanzoo/recurly/InvoiceDetailed.java
@@ -0,0 +1,87 @@
+package com.kwanzoo.recurly;
+
+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.UniformInterfaceException;
+
+@XmlRootElement(name = "invoice")
+public class InvoiceDetailed extends Base {
+
+ private static String resourceName = "invoices";
+
+ @XmlElement(name = "subtotal_in_cents")
+ public Integer subtotal_in_cents;
+
+ @XmlElement(name = "total_in_cents")
+ public Integer total_in_cents;
+
+ @XmlElement(name = "vat_amount_in_cents")
+ public Integer vat_amount_in_cents;
+
+ @XmlElement(name = "paid_in_cents")
+ public Integer paid_in_cents;
+
+ @XmlElement(name = "total_due_in_cents")
+ public Integer total_due_in_cents;
+
+ @XmlElement(name = "discount_in_cents")
+ public Integer discount_in_cents;
+
+ @XmlElement(name = "id")
+ public String id;
+
+ @XmlElement(name = "account_code")
+ public String account_code;
+
+ @XmlElement(name = "invoice_number")
+ public Integer invoice_number;
+
+ @XmlElement(name = "vat_number")
+ public String vat_number;
+
+ @XmlElement(name = "status")
+ public String status;
+
+ @XmlElementWrapper(name = "payments")
+ @XmlElement(name = "payment")
+ public List<Payment> payment;
+
+ @XmlElementWrapper(name = "line_items")
+ @XmlElement(name = "line_item")
+ public List<LineItem> line_item;
+
+ @Override
+ protected String getResourcePath() {
+ return resourceName + "/" + id;
+ }
+
+ protected static String getResourcePath(String invoiceId) {
+ return resourceName + "/" + invoiceId;
+ }
+
+ @Override
+ protected String getResourceCreationPath() {
+ return getResourcePath();
+ }
+
+ public InvoiceDetailed() {
+ }
+
+ public InvoiceDetailed(final String invoice_id) {
+ this.id = invoice_id;
+ }
+
+ public static InvoiceDetailed get(final String invoiceId) throws Exception{
+ try{
+ return getWebResourceBuilder(getResourcePath(invoiceId)).get(InvoiceDetailed.class);
+ }
+ catch(final UniformInterfaceException uie){
+ throwStatusBasedException(uie.getResponse());
+ return null;
+ }
+ }
+}
View
45 src/com/kwanzoo/recurly/Invoices.java
@@ -0,0 +1,45 @@
+package com.kwanzoo.recurly;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import com.sun.jersey.api.client.UniformInterfaceException;
+
+@XmlRootElement(name = "invoices")
+public class Invoices extends Base {
+
+ private static String resourceName = "invoices";
+
+ @XmlElement(name = "invoice")
+ public List<Invoice> invoice;
+
+ public String account_code;
+
+ @Override
+ protected String getResourcePath() {
+ return Account.pluralResourceName + "/" + account_code + "/" + resourceName;
+ }
+
+ private static String getResourcePath(String accountCode) {
+ return Account.pluralResourceName + "/" + accountCode + "/" + resourceName;
+ }
+
+ @Override
+ protected String getResourceCreationPath() {
+ return getResourcePath();
+ }
+
+ public Invoices() {
+ }
+
+ public static Invoices get(final String accountCode) throws Exception {
+ try {
+ return getWebResourceBuilder(getResourcePath(accountCode)).get(Invoices.class);
+ } catch (final UniformInterfaceException uie) {
+ throwStatusBasedException(uie.getResponse());
+ return null;
+ }
+ }
+}
View
34 src/com/kwanzoo/recurly/LineItem.java
@@ -0,0 +1,34 @@
+package com.kwanzoo.recurly;
+
+import java.util.Date;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "line_item")
+public class LineItem {
+
+ @XmlElement(name = "id")
+ public String id;
+
+ @XmlElement(name="type")
+ public String type;
+
+ @XmlElement(name = "description")
+ public String description;
+
+ @XmlElement(name = "applied_coupon_code")
+ public String applied_coupon_code;
+
+ @XmlElement(name = "amount_in_cents")
+ public Integer amount_in_cents;
+
+ @XmlElement(name = "start_date")
+ public Date start_date;
+
+ @XmlElement(name = "end_date")
+ public Date end_date;
+
+ @XmlElement(name = "created_at")
+ public Date created_at;
+}
View
25 src/com/kwanzoo/recurly/Payment.java
@@ -0,0 +1,25 @@
+package com.kwanzoo.recurly;
+
+import java.util.Date;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "payment")
+public class Payment {
+
+ @XmlElement(name = "id")
+ public String id;
+
+ @XmlElement(name = "reference")
+ public String reference;
+
+ @XmlElement(name = "message")
+ public String message;
+
+ @XmlElement(name = "amount_in_cents")
+ public Integer amount_in_cents;
+
+ @XmlElement(name = "date")
+ public Date date;
+}
View
100 src/com/kwanzoo/recurly/Transaction.java
@@ -0,0 +1,100 @@
+package com.kwanzoo.recurly;
+
+import java.util.Date;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import com.sun.jersey.api.client.GenericType;
+import com.sun.jersey.api.client.UniformInterfaceException;
+
+@XmlRootElement(name = "transaction")
+public class Transaction extends Base{
+
+ private static String resourceName = "transaction";
+
+ @XmlAttribute(name = "type")
+ public String type;
+
+ @XmlElement(name = "id")
+ public String id;
+
+ @XmlElement(name = "account_code")
+ public String accountCode;
+
+ @XmlElement(name = "action")
+ public String action;
+
+ @XmlElement(name = "date")
+ public Date date;
+
+ @XmlElement(name = "amount_in_cents")
+ public Integer amountInCents;
+
+ @XmlElement(name = "status")
+ public String status;
+
+ @XmlElement(name = "message")
+ public String message;
+
+ @XmlElement(name = "reference")
+ public String reference;
+
+ @XmlElement(name = "cvv_result")
+ public String cvvResult;
+
+ @XmlElement(name = "avs_result")
+ public String avs_result;
+
+ @XmlElement(name = "avs_result_street")
+ public String avs_result_street;
+
+ @XmlElement(name = "avs_result_postal")
+ public String avs_result_postal;
+
+ @XmlElement(name = "test")
+ public Boolean test;
+
+ @XmlElement(name = "voidable")
+ public Boolean voidable;
+
+ @XmlElement(name = "refundable")
+ public Boolean refundable;
+
+ @XmlElement(name = "credit_card")
+ public CreditCard credit_card;
+
+ @XmlElement(name = "account")
+ public Account account;
+
+ private static String getResourcePath(String accountCode){
+ return Account.pluralResourceName + "/" + accountCode + "/" + resourceName;
+ }
+
+ public static Transaction get(final String accountCode) throws Exception{
+ try{
+ return getWebResourceBuilder(getResourcePath(accountCode)).get(new GenericType<Transaction>(){});
+ }
+ catch(final UniformInterfaceException uie){
+ throwStatusBasedException(uie.getResponse());
+ return null;
+ }
+ }
+
+ @Override
+ protected String getResourcePath() {
+ return getResourcePath(accountCode);
+ }
+
+ @Override
+ protected String getResourceCreationPath() {
+ return getResourcePath();
+ }
+
+ public Transaction(){}
+
+ public Transaction(final String accountCode){
+ this.accountCode = accountCode;
+ }
+}
View
65 src/com/kwanzoo/recurly/TransparentResult.java
@@ -0,0 +1,65 @@
+package com.kwanzoo.recurly;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
+
+@XmlRootElement(name = "subscription")
+public class TransparentResult extends Subscription {
+
+ private static String transparentName = "transparent";
+ private static String resourceName = "results";
+ private String resultCode;
+
+ public static Subscription get(final String resultCode) throws Exception {
+ try {
+ ClientResponse cr = getWebResourceBuilderHtml(getResourcePath(resultCode)).get(ClientResponse.class);
+ return cr.getEntity(Subscription.class);
+ } catch (final UniformInterfaceException uie) {
+ throwStatusBasedException(uie.getResponse());
+ return null;
+ }
+ }
+
+ public static BillingInfo getBillingInfo(final String resultCode) throws Exception {
+ try {
+ ClientResponse cr = getWebResourceBuilderHtml(getResourcePath(resultCode)).get(ClientResponse.class);
+ return cr.getEntity(BillingInfo.class);
+ } catch (final UniformInterfaceException uie) {
+ throwStatusBasedException(uie.getResponse());
+ return null;
+ }
+ }
+
+ public static Transaction getTransactionInfo(final String resultCode) throws Exception {
+ try {
+ ClientResponse cr = getWebResourceBuilderHtml(getResourcePath(resultCode)).get(ClientResponse.class);
+ return cr.getEntity(Transaction.class);
+ } catch (final UniformInterfaceException uie) {
+ throwStatusBasedException(uie.getResponse());
+ return null;
+ }
+ }
+
+ private static String getResourcePath(String resultCode) {
+ return transparentName + "/" + resourceName + "/" + resultCode;
+ }
+
+ @Override
+ protected String getResourcePath() {
+ return transparentName + "/" + resourceName + "/" + resultCode;
+ }
+
+ @Override
+ protected String getResourceCreationPath() {
+ return getResourcePath();
+ }
+
+ public TransparentResult() {
+ }
+
+ public TransparentResult(final String resultCode) {
+ this.resultCode = resultCode;
+ }
+}
View
181 src/com/kwanzoo/recurly/test/RecurlyTest.java 100644 → 100755
@@ -13,42 +13,63 @@
import com.kwanzoo.recurly.Account;
import com.kwanzoo.recurly.Base;
import com.kwanzoo.recurly.BillingInfo;
+import com.kwanzoo.recurly.Charge;
import com.kwanzoo.recurly.CreditCard;
+import com.kwanzoo.recurly.InvoiceDetailed;
+import com.kwanzoo.recurly.Invoices;
import com.kwanzoo.recurly.Subscription;
+import com.kwanzoo.recurly.TransparentResult;
-public class RecurlyTest extends TestCase{
- private String getRandStr(final int n){
+public class RecurlyTest extends TestCase {
+
+ private String plan1 = "test_plan1";
+ private String plan2 = "test_plan2";
+ private String plan3 = "test_plan3";
+
+ private String existingTransparentPostResult = "";
+
+ private String getRandStr(final int n) {
return RandomStringUtils.randomAlphanumeric(n);
}
- /*private String getRandNum(final int n){
+ private String getRandNumber(final int n) {
return RandomStringUtils.randomNumeric(n);
- }*/
+ }
@Override
- public void setUp(){
+ public void setUp() {
Properties p = new Properties();
- try{
+ try {
p.load(new FileInputStream(System.getProperty("user.home") + "/" + "recurly_auth"));
String username = p.getProperty("recurly_username");
String password = p.getProperty("recurly_password");
Base.setAuth(username, password);
- }
- catch(IOException e){
+ } catch (IOException e) {
e.printStackTrace();
}
- }
+ }
- //Manipulate Accounts
- @Test public void test1() throws Exception{
+ @Test
+ public void test0() throws Exception {
+ if (!"".equals(existingTransparentPostResult)) {
+ Subscription result = TransparentResult.get(existingTransparentPostResult);
+ assertEquals("pending", result.state);
+ } else {
+ fail("create a transparent post demo and setup the transparent post result");
+ }
+ }
+
+ // Manipulate Accounts
+ @Test
+ public void test1() throws Exception {
- //create fresh account
+ // create fresh account
final String accountCode = getRandStr(5);
String username = getRandStr(5);
String firstName = getRandStr(5);
- String lastName = getRandStr(5);
- String email = getRandStr(5)+"@site.com";
- String companyName = getRandStr(5);
+ String lastName = getRandStr(5);
+ String email = getRandStr(5) + "@site.com";
+ String companyName = getRandStr(5);
Account account = new Account();
@@ -57,11 +78,11 @@ public void setUp(){
account.firstName = firstName;
account.lastName = lastName;
account.email = email;
- account.companyName = companyName;
+ account.companyName = companyName;
account.create();
- //check if find works
+ // check if find works
account = Account.get(accountCode);
assertEquals(accountCode, account.accountCode);
@@ -71,18 +92,18 @@ public void setUp(){
assertEquals(email, account.email);
assertEquals(companyName, account.companyName);
- //check if update works
+ // check if update works
username = getRandStr(5);
firstName = getRandStr(5);
lastName = getRandStr(5);
- email = getRandStr(5)+"@site.com";
- companyName = getRandStr(5);
+ email = getRandStr(5) + "@site.com";
+ companyName = getRandStr(5);
account.username = username;
account.firstName = firstName;
account.lastName = lastName;
account.email = email;
- account.companyName = companyName;
+ account.companyName = companyName;
account.update();
@@ -94,17 +115,26 @@ public void setUp(){
assertEquals(lastName, account.lastName);
assertEquals(email, account.email);
assertEquals(companyName, account.companyName);
+
+ Charge charge = new Charge(accountCode);
+ charge.amount_in_cents = 500;
+ charge.description = "first charge";
+ charge.create();
+
+ // cleanup
+ account.delete();
}
- //Manipulate billing info
- @Test public void test2() throws Exception{
+ // Manipulate billing info
+ @Test
+ public void test2() throws Exception {
- //create fresh account
+ // create fresh account
final String accountCode = getRandStr(5);
final String username = getRandStr(5);
String firstName = getRandStr(5);
- String lastName = getRandStr(5);
- final String email = getRandStr(5)+"@site.com";
+ String lastName = getRandStr(5);
+ final String email = getRandStr(5) + "@site.com";
final String companyName = getRandStr(5);
Account account = new Account();
@@ -114,15 +144,15 @@ public void setUp(){
account.firstName = firstName;
account.lastName = lastName;
account.email = email;
- account.companyName = companyName;
+ account.companyName = companyName;
account.create();
account = Account.get(accountCode);
- //check if adding billing info for a fresh account works
- final String number = "1"; //bogus credit card number accepted by test gateway
- String verificationValue = getRandStr(4);
+ // check if adding billing info for a fresh account works
+ final String number = "1"; // bogus credit card number accepted by test gateway
+ String verificationValue = getRandNumber(4);
Integer expirationMonth = (new Random()).nextInt(12) + 1;
Integer expirationYear = 2012 + (new Random()).nextInt(20);
@@ -137,7 +167,7 @@ public void setUp(){
String ipAddress = "127.0.0.1";
CreditCard creditCard = new CreditCard();
-
+
creditCard.number = number;
creditCard.verificationValue = verificationValue;
creditCard.expirationMonth = expirationMonth;
@@ -151,7 +181,7 @@ public void setUp(){
billingInfo.city = city;
billingInfo.state = state;
billingInfo.zip = zip;
- billingInfo.country = country;
+ billingInfo.country = country;
billingInfo.ipAddress = ipAddress;
billingInfo.creditCard = creditCard;
@@ -163,21 +193,21 @@ public void setUp(){
assertEquals(lastName, billingInfo.lastName);
assertEquals(address1, billingInfo.address1);
assertEquals(address2, billingInfo.address2);
- assertEquals(city, billingInfo.city );
+ assertEquals(city, billingInfo.city);
assertEquals(state, billingInfo.state);
assertEquals(zip, billingInfo.zip);
assertEquals(country, billingInfo.country);
assertEquals(ipAddress, billingInfo.ipAddress);
- //Recurly returns empty for both the fields below
- //assertEquals(billingInfo.creditCard.number);
- //assertEquals(billingInfo.creditCard.verificationValue);
+ // Recurly returns empty for both the fields below
+ // assertEquals(billingInfo.creditCard.number);
+ // assertEquals(billingInfo.creditCard.verificationValue);
assertEquals(expirationMonth, billingInfo.creditCard.expirationMonth);
assertEquals(expirationYear, billingInfo.creditCard.expirationYear);
- //check if updating billing info of an account that already has billing info works
- verificationValue = getRandStr(4);
+ // check if updating billing info of an account that already has billing info works
+ verificationValue = getRandNumber(4);
expirationMonth = (new Random()).nextInt(12) + 1;
expirationYear = 2012 + (new Random()).nextInt(20);
@@ -188,7 +218,7 @@ public void setUp(){
city = "Some City";
state = "NJ";
zip = "94105";
- country = "IN";
+ country = "IN";
ipAddress = "127.0.0.1";
creditCard = new CreditCard();
@@ -217,22 +247,26 @@ public void setUp(){
assertEquals(lastName, billingInfo.lastName);
assertEquals(address1, billingInfo.address1);
assertEquals(address2, billingInfo.address2);
- assertEquals(city, billingInfo.city );
+ assertEquals(city, billingInfo.city);
assertEquals(state, billingInfo.state);
assertEquals(zip, billingInfo.zip);
assertEquals(country, billingInfo.country);
assertEquals(ipAddress, billingInfo.ipAddress);
+ // cleanup
+ account.delete();
+
}
- //Manipulate subscriptions
- @Test public void test3() throws Exception{
- //create fresh account
+ // Manipulate subscriptions
+ @Test
+ public void test3() throws Exception {
+ // create fresh account
final String accountCode = getRandStr(5);
final String username = getRandStr(5);
String firstName = getRandStr(5);
- String lastName = getRandStr(5);
- final String email = getRandStr(5)+"@site.com";
+ String lastName = getRandStr(5);
+ final String email = getRandStr(5) + "@site.com";
final String companyName = getRandStr(5);
Account account = new Account();
@@ -242,21 +276,21 @@ public void setUp(){
account.firstName = firstName;
account.lastName = lastName;
account.email = email;
- account.companyName = companyName;
+ account.companyName = companyName;
account.create();
account = Account.get(accountCode);
- //subscribe to plan1
- final String number = "1";
- final String verificationValue = getRandStr(4);
+ // subscribe to plan1
+ final String number = "1";
+ final String verificationValue = getRandNumber(4);
final Integer expirationMonth = (new Random()).nextInt(12);
final Integer expirationYear = 2011 + (new Random()).nextInt(20);
firstName = account.firstName;
lastName = account.lastName;
-
+
final String address1 = getRandStr(10);
final String address2 = getRandStr(10);
final String city = "San Fransisco";
@@ -279,13 +313,13 @@ public void setUp(){
billingInfo.city = city;
billingInfo.state = state;
billingInfo.zip = zip;
- billingInfo.country = country;
+ billingInfo.country = country;
billingInfo.ipAddress = ipAddress;
billingInfo.creditCard = creditCard;
account.billingInfo = billingInfo;
- String planCode = "testplan1"; //one of the plans defined in your recurly account
+ String planCode = plan2; // one of the plans defined in your recurly account
Integer quantity = 1;
Subscription subscription = new Subscription(accountCode);
@@ -295,7 +329,7 @@ public void setUp(){
subscription.create();
- //TODO: get subscription and check with asserts
+ // TODO: get subscription and check with asserts
subscription = Subscription.get(accountCode);
assertEquals(accountCode, subscription.accountCode);
@@ -308,22 +342,26 @@ public void setUp(){
assertEquals(lastName, billingInfo.lastName);
assertEquals(address1, billingInfo.address1);
assertEquals(address2, billingInfo.address2);
- assertEquals(city, billingInfo.city );
+ assertEquals(city, billingInfo.city);
assertEquals(state, billingInfo.state);
assertEquals(zip, billingInfo.zip);
assertEquals(country, billingInfo.country);
assertEquals(ipAddress, billingInfo.ipAddress);
- //Recurly returns a null for both the fields below.
- //assertEquals(billingInfo.creditCard.number);
- //assertEquals(billingInfo.creditCard.verificationValue);
+ // Recurly returns a null for both the fields below.
+ // assertEquals(billingInfo.creditCard.number);
+ // assertEquals(billingInfo.creditCard.verificationValue);
assertEquals(expirationMonth, billingInfo.creditCard.expirationMonth);
assertEquals(expirationYear, billingInfo.creditCard.expirationYear);
- //downgrade check
+ // invoice check
+ Invoices invoices = Invoices.get(accountCode);
+ assertEquals(1, invoices.invoice.size());
+
+ // downgrade check
- planCode = "testplan0"; // a plan with lesser features/rate than testplan1
+ planCode = plan1; // a plan with lesser features/rate than testplan1
quantity = 2;
subscription = new Subscription(accountCode);
@@ -340,13 +378,17 @@ public void setUp(){
assertEquals("active", subscription.state);
assertEquals(quantity, subscription.quantity);
- //upgrade check
+ // invoice check
+ invoices = Invoices.get(accountCode);
+ assertEquals(2, invoices.invoice.size());
- planCode = "testplan2"; // a plan with better features/rate than testplan1
+ // upgrade check
+
+ planCode = plan3; // a plan with better features/rate than testplan1
quantity = 3;
subscription = new Subscription(accountCode);
- subscription.timeframe = "now"; //immediate upgrade
+ subscription.timeframe = "now"; // immediate upgrade
subscription.planCode = planCode;
subscription.quantity = quantity;
@@ -359,12 +401,25 @@ public void setUp(){
assertEquals("active", subscription.state);
assertEquals(quantity, subscription.quantity);
- //cancel & check with asserts
+ // invoice check
+ invoices = Invoices.get(accountCode);
+ assertEquals(3, invoices.invoice.size());
+
+ // detailed invoice check
+ InvoiceDetailed invoiceDetailed = InvoiceDetailed.get(invoices.invoice.get(2).id);
+ assertEquals(invoices.invoice.get(2).id, invoiceDetailed.id);
+ assertEquals(1, invoiceDetailed.payment.size());
+ assertEquals(1, invoiceDetailed.line_item.size());
+
+ // cancel & check with asserts
subscription = new Subscription(accountCode);
subscription.delete();
subscription = Subscription.get(accountCode);
assertEquals("canceled", subscription.state);
+
+ account.delete();
}
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.