001/* 002 * Copyright 2010-2014 Ning, Inc. 003 * Copyright 2014-2015 The Billing Project, LLC 004 * 005 * The Billing Project licenses this file to you under the Apache License, version 2.0 006 * (the "License"); you may not use this file except in compliance with the 007 * License. You may obtain a copy of the License at: 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 014 * License for the specific language governing permissions and limitations 015 * under the License. 016 */ 017 018package com.ning.billing.recurly.model; 019 020import javax.xml.bind.annotation.XmlElement; 021import javax.xml.bind.annotation.XmlElementWrapper; 022import javax.xml.bind.annotation.XmlRootElement; 023 024import com.google.common.base.Objects; 025 026@XmlRootElement(name = "subscription") 027public class AbstractSubscription extends RecurlyObject { 028 029 public static final String SUBSCRIPTION_RESOURCE = "/subscriptions"; 030 031 @XmlElement(name = "unit_amount_in_cents") 032 protected Integer unitAmountInCents; 033 034 @XmlElement(name = "quantity") 035 protected Integer quantity; 036 037 @XmlElementWrapper(name = "subscription_add_ons") 038 @XmlElement(name = "subscription_add_on") 039 protected SubscriptionAddOns addOns; 040 041 @XmlElementWrapper(name = "custom_fields") 042 @XmlElement(name = "custom_field") 043 protected CustomFields customFields; 044 045 @XmlElement(name = "plan_code") 046 private String planCode; 047 048 public String getPlanCode() { 049 return planCode; 050 } 051 052 public void setPlanCode(final String planCode) { 053 this.planCode = stringOrNull(planCode); 054 } 055 056 public CustomFields getCustomFields() { 057 return customFields; 058 } 059 060 public void setCustomFields(final CustomFields customFields) { 061 this.customFields = customFields; 062 } 063 064 public Integer getUnitAmountInCents() { 065 return unitAmountInCents; 066 } 067 068 public void setUnitAmountInCents(final Object unitAmountInCents) { 069 this.unitAmountInCents = integerOrNull(unitAmountInCents); 070 } 071 072 public Integer getQuantity() { 073 return quantity; 074 } 075 076 public void setQuantity(final Object quantity) { 077 this.quantity = integerOrNull(quantity); 078 } 079 080 public SubscriptionAddOns getAddOns() { 081 return addOns; 082 } 083 084 public void setAddOns(final SubscriptionAddOns addOns) { 085 this.addOns = addOns; 086 } 087 088 @Override 089 public boolean equals(final Object o) { 090 if (this == o) return true; 091 if (o == null || getClass() != o.getClass()) return false; 092 093 final AbstractSubscription that = (AbstractSubscription) o; 094 095 if (addOns != null ? !addOns.equals(that.addOns) : that.addOns != null) { 096 return false; 097 } 098 if (planCode != null ? !planCode.equals(that.planCode) : that.planCode != null) { 099 return false; 100 } 101 if (quantity != null ? !quantity.equals(that.quantity) : that.quantity != null) { 102 return false; 103 } 104 if (unitAmountInCents != null ? !unitAmountInCents.equals(that.unitAmountInCents) : that.unitAmountInCents != null) { 105 return false; 106 } 107 108 return true; 109 } 110 111 @Override 112 public int hashCode() { 113 return Objects.hashCode( 114 unitAmountInCents, 115 quantity, 116 addOns, 117 planCode, 118 customFields 119 ); 120 } 121}