diff --git a/pom.xml b/pom.xml
index 961cc2b..914f1de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.chargify
chargify-sdk
- 0.2.8
+ 0.3.0
jar
Chargify SDK for Java
@@ -75,6 +75,14 @@
1.2.3
+
+
+ org.projectlombok
+ lombok
+ 1.18.12
+ provided
+
+
junit
junit
diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java
index 8f62159..3e5bfbb 100644
--- a/src/main/java/com/chargify/Chargify.java
+++ b/src/main/java/com/chargify/Chargify.java
@@ -3,6 +3,7 @@
import com.chargify.model.Allocation;
import com.chargify.model.Component;
import com.chargify.model.ComponentPricePointUpdate;
+import com.chargify.model.CreateSubscription;
import com.chargify.model.Customer;
import com.chargify.model.Metadata;
import com.chargify.model.Product;
@@ -38,7 +39,7 @@ public interface Chargify
Product archiveProductById( String id );
- Subscription createSubscription( Subscription subscription );
+ Subscription createSubscription( CreateSubscription subscription );
Subscription findSubscriptionById( String id );
diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java
index db65199..7c42121 100644
--- a/src/main/java/com/chargify/ChargifyService.java
+++ b/src/main/java/com/chargify/ChargifyService.java
@@ -5,6 +5,7 @@
import com.chargify.model.Allocation;
import com.chargify.model.Component;
import com.chargify.model.ComponentPricePointUpdate;
+import com.chargify.model.CreateSubscription;
import com.chargify.model.Customer;
import com.chargify.model.Metadata;
import com.chargify.model.Migration;
@@ -20,6 +21,7 @@
import com.chargify.model.wrappers.AnyComponentWrapper;
import com.chargify.model.wrappers.ComponentPricePointUpdatesWrapper;
import com.chargify.model.wrappers.ComponentWrapper;
+import com.chargify.model.wrappers.CreateSubscriptionWrapper;
import com.chargify.model.wrappers.CustomerWrapper;
import com.chargify.model.wrappers.MetadataWrapper;
import com.chargify.model.wrappers.MeteredComponentWrapper;
@@ -200,10 +202,9 @@ public Product archiveProductById( String id )
}
@Override
- public Subscription createSubscription( Subscription subscription )
+ public Subscription createSubscription( CreateSubscription subscription )
{
- return httpClient.postForObject( "/subscriptions.json",
- new SubscriptionWrapper( subscription ), SubscriptionWrapper.class )
+ return httpClient.postForObject( "/subscriptions.json", new CreateSubscriptionWrapper( subscription ), SubscriptionWrapper.class )
.getSubscription();
}
diff --git a/src/main/java/com/chargify/model/Component.java b/src/main/java/com/chargify/model/Component.java
index cdc0486..c1b613a 100644
--- a/src/main/java/com/chargify/model/Component.java
+++ b/src/main/java/com/chargify/model/Component.java
@@ -20,10 +20,11 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
import java.io.Serializable;
-import java.util.Arrays;
+@Data
@JsonInclude( JsonInclude.Include.NON_NULL )
public class Component implements Serializable
{
@@ -60,163 +61,7 @@ public class Component implements Serializable
private Boolean taxable;
- private String description;
+ private Boolean recurring;
- public String getId()
- {
- return id;
- }
-
- public void setId( String id )
- {
- this.id = id;
- }
-
- public String getName()
- {
- return name;
- }
-
- public void setName( String name )
- {
- this.name = name;
- }
-
- public String getPricingScheme()
- {
- return pricingScheme;
- }
-
- public void setPricingScheme( String pricingScheme )
- {
- this.pricingScheme = pricingScheme;
- }
-
- public String getUnitName()
- {
- return unitName;
- }
-
- public void setUnitName( String unitName )
- {
- this.unitName = unitName;
- }
-
- public Double getUnitPrice()
- {
- return unitPrice;
- }
-
- public void setUnitPrice( Double unitPrice )
- {
- this.unitPrice = unitPrice;
- }
-
- public String getProductFamilyId()
- {
- return productFamilyId;
- }
-
- public void setProductFamilyId( String productFamilyId )
- {
- this.productFamilyId = productFamilyId;
- }
-
- public ComponentKind getKind()
- {
- return kind;
- }
-
- public void setKind( ComponentKind kind )
- {
- this.kind = kind;
- }
-
- public Boolean getArchived()
- {
- return archived;
- }
-
- public void setArchived( Boolean archived )
- {
- this.archived = archived;
- }
-
- public Boolean getTaxable()
- {
- return taxable;
- }
-
- public void setTaxable( Boolean taxable )
- {
- this.taxable = taxable;
- }
-
- public String getDescription()
- {
- return description;
- }
-
- public void setDescription( String description )
- {
- this.description = description;
- }
-
- public Price[] getPrices()
- {
- return prices;
- }
-
- public void setPrices( Price[] prices )
- {
- this.prices = prices;
- }
-
- public PricePoint[] getPricePoints()
- {
- return pricePoints;
- }
-
- public void setPricePoints( PricePoint[] pricePoints )
- {
- this.pricePoints = pricePoints;
- }
-
- public String toString()
- {
- return "Component{" +
- "id='" + id + '\'' +
- ", name='" + name + '\'' +
- ", pricingScheme='" + pricingScheme + '\'' +
- ", unitName='" + unitName + '\'' +
- ", unitPrice=" + unitPrice +
- ", productFamilyId='" + productFamilyId + '\'' +
- ", prices=" + Arrays.toString( prices ) +
- ", pricePoints=" + Arrays.toString( pricePoints ) +
- ", kind=" + kind +
- ", archived=" + archived +
- ", taxable=" + taxable +
- ", description='" + description + '\'' +
- '}';
- }
-
- public String getDefaultPricePointName()
- {
- return defaultPricePointName;
- }
-
- public void setDefaultPricePointName( String defaultPricePointName )
- {
- this.defaultPricePointName = defaultPricePointName;
- }
-
- public String getDefaultPricePointHandle()
- {
- return defaultPricePointHandle;
- }
-
- public void setDefaultPricePointHandle( String defaultPricePointHandle )
- {
- this.defaultPricePointHandle = defaultPricePointHandle;
- }
+ private String description;
}
diff --git a/src/main/java/com/chargify/model/CreateSubscription.java b/src/main/java/com/chargify/model/CreateSubscription.java
new file mode 100644
index 0000000..fc6f744
--- /dev/null
+++ b/src/main/java/com/chargify/model/CreateSubscription.java
@@ -0,0 +1,69 @@
+package com.chargify.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.time.ZonedDateTime;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+@Data
+@JsonInclude( JsonInclude.Include.NON_NULL )
+public class CreateSubscription implements Serializable
+{
+
+ @JsonProperty( "product_handle" )
+ private String productHandle;
+
+ @JsonProperty( "product_id" )
+ private String productId;
+
+ @JsonProperty( "product_price_point_handle" )
+ private String productPricePointHandle;
+
+ @JsonProperty( "product_price_point_id" )
+ private String productPricePointId;
+
+ @JsonProperty( "coupon_code" )
+ private String couponCode;
+
+ @JsonProperty( "payment_collection_method" )
+ private String paymentCollectionMethod;
+
+ @JsonProperty( "receives_invoice_emails" )
+ private Boolean receivesInvoiceEmails;
+
+ @JsonProperty( "net_terms" )
+ private String netTerms;
+
+ @JsonProperty( "customer_id" )
+ private String customerId;
+
+ @JsonProperty( "customer_reference" )
+ private String customerReference;
+
+ @JsonProperty( "next_billing_at" )
+ private ZonedDateTime nextBillingAt;
+
+ @JsonProperty( "stored_credential_transaction_id" )
+ private Integer storedCredentialTransactionId;
+
+ @JsonProperty( "sales_rep_id" )
+ private Integer salesRepId;
+
+ @JsonProperty( "payment_profile_id" )
+ private String paymentProfileId;
+
+ private String reference;
+
+ @JsonProperty( "customer_attributes" )
+ private Customer customerAttributes;
+
+ private List components;
+
+ private Map metafields = new HashMap<>();
+}
diff --git a/src/main/java/com/chargify/model/Subscription.java b/src/main/java/com/chargify/model/Subscription.java
index 3d63a39..8e5db04 100644
--- a/src/main/java/com/chargify/model/Subscription.java
+++ b/src/main/java/com/chargify/model/Subscription.java
@@ -20,6 +20,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
import java.io.Serializable;
import java.time.ZonedDateTime;
@@ -28,6 +29,7 @@
import java.util.List;
import java.util.Map;
+@Data
@JsonInclude( JsonInclude.Include.NON_NULL )
public class Subscription implements Serializable
{
@@ -162,517 +164,4 @@ public class Subscription implements Serializable
private List components;
private Map metafields = new HashMap<>();
-
- public String getId()
- {
- return id;
- }
-
- public void setId( String id )
- {
- this.id = id;
- }
-
- public String getState()
- {
- return state;
- }
-
- public void setState( String state )
- {
- this.state = state;
- }
-
- public Integer getBalanceInCents()
- {
- return balanceInCents;
- }
-
- public void setBalanceInCents( Integer balanceInCents )
- {
- this.balanceInCents = balanceInCents;
- }
-
- public Integer getTotalRevenueInCents()
- {
- return totalRevenueInCents;
- }
-
- public void setTotalRevenueInCents( Integer totalRevenueInCents )
- {
- this.totalRevenueInCents = totalRevenueInCents;
- }
-
- public Integer getProductPriceInCents()
- {
- return productPriceInCents;
- }
-
- public void setProductPriceInCents( Integer productPriceInCents )
- {
- this.productPriceInCents = productPriceInCents;
- }
-
- public Integer getProductVersionNumber()
- {
- return productVersionNumber;
- }
-
- public void setProductVersionNumber( Integer productVersionNumber )
- {
- this.productVersionNumber = productVersionNumber;
- }
-
- public Date getCurrentPeriodEndsAt()
- {
- return currentPeriodEndsAt;
- }
-
- public void setCurrentPeriodEndsAt( Date currentPeriodEndsAt )
- {
- this.currentPeriodEndsAt = currentPeriodEndsAt;
- }
-
- public Date getTrialStartedAt()
- {
- return trialStartedAt;
- }
-
- public void setTrialStartedAt( Date trialStartedAt )
- {
- this.trialStartedAt = trialStartedAt;
- }
-
- public Date getTrialEndedAt()
- {
- return trialEndedAt;
- }
-
- public void setTrialEndedAt( Date trialEndedAt )
- {
- this.trialEndedAt = trialEndedAt;
- }
-
- public Date getActivatedAt()
- {
- return activatedAt;
- }
-
- public void setActivatedAt( Date activatedAt )
- {
- this.activatedAt = activatedAt;
- }
-
- public Date getExpiresAt()
- {
- return expiresAt;
- }
-
- public void setExpiresAt( Date expiresAt )
- {
- this.expiresAt = expiresAt;
- }
-
- public Date getCreatedAt()
- {
- return createdAt;
- }
-
- public void setCreatedAt( Date createdAt )
- {
- this.createdAt = createdAt;
- }
-
- public Date getUpdatedAt()
- {
- return updatedAt;
- }
-
- public void setUpdatedAt( Date updatedAt )
- {
- this.updatedAt = updatedAt;
- }
-
- public String getCancellationMessage()
- {
- return cancellationMessage;
- }
-
- public void setCancellationMessage( String cancellationMessage )
- {
- this.cancellationMessage = cancellationMessage;
- }
-
- public String getCancellationMethod()
- {
- return cancellationMethod;
- }
-
- public void setCancellationMethod( String cancellationMethod )
- {
- this.cancellationMethod = cancellationMethod;
- }
-
- public Boolean getCancelAtEndOfPeriod()
- {
- return cancelAtEndOfPeriod;
- }
-
- public void setCancelAtEndOfPeriod( Boolean cancelAtEndOfPeriod )
- {
- this.cancelAtEndOfPeriod = cancelAtEndOfPeriod;
- }
-
- public Date getCanceledAt()
- {
- return canceledAt;
- }
-
- public void setCanceledAt( Date canceledAt )
- {
- this.canceledAt = canceledAt;
- }
-
- public Date getCurrentPeriodStartedAt()
- {
- return currentPeriodStartedAt;
- }
-
- public void setCurrentPeriodStartedAt( Date currentPeriodStartedAt )
- {
- this.currentPeriodStartedAt = currentPeriodStartedAt;
- }
-
- public String getPreviousState()
- {
- return previousState;
- }
-
- public void setPreviousState( String previousState )
- {
- this.previousState = previousState;
- }
-
- public Integer getSignupPaymentId()
- {
- return signupPaymentId;
- }
-
- public void setSignupPaymentId( Integer signupPaymentId )
- {
- this.signupPaymentId = signupPaymentId;
- }
-
- public String getSignupRevenue()
- {
- return signupRevenue;
- }
-
- public void setSignupRevenue( String signupRevenue )
- {
- this.signupRevenue = signupRevenue;
- }
-
- public Date getDelayedCancelAt()
- {
- return delayedCancelAt;
- }
-
- public void setDelayedCancelAt( Date delayedCancelAt )
- {
- this.delayedCancelAt = delayedCancelAt;
- }
-
- public String getCouponCode()
- {
- return couponCode;
- }
-
- public void setCouponCode( String couponCode )
- {
- this.couponCode = couponCode;
- }
-
- public String getPaymentCollectionMethod()
- {
- return paymentCollectionMethod;
- }
-
- public void setPaymentCollectionMethod( String paymentCollectionMethod )
- {
- this.paymentCollectionMethod = paymentCollectionMethod;
- }
-
- public String getSnapDay()
- {
- return snapDay;
- }
-
- public void setSnapDay( String snapDay )
- {
- this.snapDay = snapDay;
- }
-
- public String getReasonCode()
- {
- return reasonCode;
- }
-
- public void setReasonCode( String reasonCode )
- {
- this.reasonCode = reasonCode;
- }
-
- public Customer getCustomer()
- {
- return customer;
- }
-
- public void setCustomer( Customer customer )
- {
- this.customer = customer;
- }
-
- public Product getProduct()
- {
- return product;
- }
-
- public void setProduct( Product product )
- {
- this.product = product;
- }
-
- public CreditCard getCreditCard()
- {
- return creditCard;
- }
-
- public void setCreditCard( CreditCard creditCard )
- {
- this.creditCard = creditCard;
- }
-
- public String getPaymentType()
- {
- return paymentType;
- }
-
- public void setPaymentType( String paymentType )
- {
- this.paymentType = paymentType;
- }
-
- public String getReferralCode()
- {
- return referralCode;
- }
-
- public void setReferralCode( String referralCode )
- {
- this.referralCode = referralCode;
- }
-
- public String getNextProductId()
- {
- return nextProductId;
- }
-
- public void setNextProductId( String nextProductId )
- {
- this.nextProductId = nextProductId;
- }
-
- public Integer getCouponUseCount()
- {
- return couponUseCount;
- }
-
- public void setCouponUseCount( Integer couponUseCount )
- {
- this.couponUseCount = couponUseCount;
- }
-
- public Integer getCouponUsesAllowed()
- {
- return couponUsesAllowed;
- }
-
- public void setCouponUsesAllowed( Integer couponUsesAllowed )
- {
- this.couponUsesAllowed = couponUsesAllowed;
- }
-
- public String getProductId()
- {
- return productId;
- }
-
- public void setProductId( String productId )
- {
- this.productId = productId;
- }
-
- public String getCustomerId()
- {
- return customerId;
- }
-
- public void setCustomerId( String customerId )
- {
- this.customerId = customerId;
- }
-
- public String getCustomerReference()
- {
- return customerReference;
- }
-
- public void setCustomerReference( String customerReference )
- {
- this.customerReference = customerReference;
- }
-
- public String getProductHandle()
- {
- return productHandle;
- }
-
- public void setProductHandle( String productHandle )
- {
- this.productHandle = productHandle;
- }
-
- public Customer getCustomerAttributes()
- {
- return customerAttributes;
- }
-
- public void setCustomerAttributes( Customer customerAttributes )
- {
- this.customerAttributes = customerAttributes;
- }
-
- public boolean isProductChangeDelayed()
- {
- return productChangeDelayed;
- }
-
- public void setProductChangeDelayed( boolean productChangeDelayed )
- {
- this.productChangeDelayed = productChangeDelayed;
- }
-
- public Map getMetafields()
- {
- return metafields;
- }
-
- public void setMetafields( Map metafields )
- {
- this.metafields = metafields;
- }
-
- public List getComponents()
- {
- return components;
- }
-
- public void setComponents( List components )
- {
- this.components = components;
- }
-
- public String getPaymentProfileId()
- {
- return paymentProfileId;
- }
-
- public void setPaymentProfileId( String paymentProfileId )
- {
- this.paymentProfileId = paymentProfileId;
- }
-
- public ZonedDateTime getNextBillingAt()
- {
- return nextBillingAt;
- }
-
- public void setNextBillingAt( ZonedDateTime nextBillingAt )
- {
- this.nextBillingAt = nextBillingAt;
- }
-
- public ZonedDateTime getNextAssessmentAt()
- {
- return nextAssessmentAt;
- }
-
- public void setNextAssessmentAt( ZonedDateTime nextAssessmentAt )
- {
- this.nextAssessmentAt = nextAssessmentAt;
- }
-
- public String getReference()
- {
- return reference;
- }
-
- public void setReference( String reference )
- {
- this.reference = reference;
- }
-
- @Override
- public String toString()
- {
- return "Subscription{" +
- "id='" + id + '\'' +
- ", state='" + state + '\'' +
- ", balanceInCents=" + balanceInCents +
- ", totalRevenueInCents=" + totalRevenueInCents +
- ", productPriceInCents=" + productPriceInCents +
- ", productVersionNumber=" + productVersionNumber +
- ", currentPeriodEndsAt=" + currentPeriodEndsAt +
- ", nextAssessmentAt=" + nextAssessmentAt +
- ", nextBillingAt=" + nextBillingAt +
- ", trialStartedAt=" + trialStartedAt +
- ", trialEndedAt=" + trialEndedAt +
- ", activatedAt=" + activatedAt +
- ", expiresAt=" + expiresAt +
- ", createdAt=" + createdAt +
- ", updatedAt=" + updatedAt +
- ", cancellationMessage='" + cancellationMessage + '\'' +
- ", cancellationMethod='" + cancellationMethod + '\'' +
- ", cancelAtEndOfPeriod=" + cancelAtEndOfPeriod +
- ", canceledAt=" + canceledAt +
- ", currentPeriodStartedAt=" + currentPeriodStartedAt +
- ", customerAttributes=" + customerAttributes +
- ", customerId='" + customerId + '\'' +
- ", customerReference='" + customerReference + '\'' +
- ", productChangeDelayed=" + productChangeDelayed +
- ", previousState='" + previousState + '\'' +
- ", productHandle='" + productHandle + '\'' +
- ", productId='" + productId + '\'' +
- ", signupPaymentId=" + signupPaymentId +
- ", signupRevenue='" + signupRevenue + '\'' +
- ", delayedCancelAt=" + delayedCancelAt +
- ", couponCode='" + couponCode + '\'' +
- ", paymentCollectionMethod='" + paymentCollectionMethod + '\'' +
- ", paymentProfileId='" + paymentProfileId + '\'' +
- ", snapDay='" + snapDay + '\'' +
- ", reasonCode='" + reasonCode + '\'' +
- ", customer=" + customer +
- ", product=" + product +
- ", creditCard=" + creditCard +
- ", paymentType='" + paymentType + '\'' +
- ", referralCode='" + referralCode + '\'' +
- ", reference='" + reference + '\'' +
- ", nextProductId='" + nextProductId + '\'' +
- ", couponUseCount=" + couponUseCount +
- ", couponUsesAllowed=" + couponUsesAllowed +
- ", components=" + components +
- ", metafields=" + metafields +
- '}';
- }
}
diff --git a/src/main/java/com/chargify/model/wrappers/CreateSubscriptionWrapper.java b/src/main/java/com/chargify/model/wrappers/CreateSubscriptionWrapper.java
new file mode 100644
index 0000000..8a939f4
--- /dev/null
+++ b/src/main/java/com/chargify/model/wrappers/CreateSubscriptionWrapper.java
@@ -0,0 +1,22 @@
+package com.chargify.model.wrappers;
+
+import com.chargify.model.CreateSubscription;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+
+public final class CreateSubscriptionWrapper
+{
+ private final CreateSubscription subscription;
+
+ @JsonCreator
+ public CreateSubscriptionWrapper( @JsonProperty( "subscription" ) CreateSubscription wrappedSubscription )
+ {
+ this.subscription = wrappedSubscription;
+ }
+
+ public CreateSubscription getSubscription()
+ {
+ return subscription;
+ }
+}
diff --git a/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java b/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java
index ac3fb8f..872c119 100644
--- a/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java
+++ b/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java
@@ -1,5 +1,6 @@
package com.chargify;
+import com.chargify.model.CreateSubscription;
import com.chargify.model.Customer;
import com.chargify.model.Product;
import com.chargify.model.ProductFamily;
@@ -37,7 +38,7 @@ public static void setup()
customer = chargify.createCustomer( new Customer( randomName(), randomName(), randomEmail() ) );
- final Subscription subscription = new Subscription();
+ final CreateSubscription subscription = new CreateSubscription();
subscription.setProductId( SubscriptionDelayedChangeTest.initialProduct.getId() );
subscription.setCustomerId( customer.getId() );
SubscriptionDelayedChangeTest.subscription = chargify.createSubscription( subscription );
diff --git a/src/test/java/com/chargify/SubscriptionsTest.java b/src/test/java/com/chargify/SubscriptionsTest.java
index 727a4c1..78e927f 100644
--- a/src/test/java/com/chargify/SubscriptionsTest.java
+++ b/src/test/java/com/chargify/SubscriptionsTest.java
@@ -1,5 +1,6 @@
package com.chargify;
+import com.chargify.model.CreateSubscription;
import com.chargify.model.Customer;
import com.chargify.model.Product;
import com.chargify.model.ProductFamily;
@@ -47,7 +48,7 @@ public static void setup()
customerUnderTest = chargify.createCustomer( new Customer( "Andy", "Panda",
"andypanda@example.com" ) );
- final Subscription subscription = new Subscription();
+ final CreateSubscription subscription = new CreateSubscription();
subscription.setProductId( productUnderTest.getId() );
subscription.setCustomerId( customerUnderTest.getId() );
subscriptionUnderTest = chargify.createSubscription( subscription );