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 org.joda.time.DateTime; 021 022import javax.xml.bind.annotation.XmlElement; 023import javax.xml.bind.annotation.XmlRootElement; 024import javax.xml.bind.annotation.XmlTransient; 025 026import com.google.common.base.Objects; 027 028@XmlRootElement(name = "redemption") 029public class Redemption extends RecurlyObject { 030 031 @XmlTransient 032 public static final String REDEEM_RESOURCE = "/redeem"; 033 034 @XmlTransient 035 public static final String REDEMPTION_RESOURCE = "/redemption"; 036 037 @XmlTransient 038 public static final String REDEMPTIONS_RESOURCE = "/redemptions"; 039 040 @XmlElement(name = "uuid") 041 private String uuid; 042 043 @XmlElement(name = "account_code") 044 private String accountCode; 045 046 @XmlElement(name = "subscription_uuid") 047 private String subscriptionUuid; 048 049 @XmlElement(name = "coupon") 050 private Coupon coupon; 051 052 @XmlElement(name = "account") 053 private Account account; 054 055 @XmlElement(name = "single_use") 056 private Boolean singleUse; 057 058 @XmlElement(name = "total_discounted_in_cents") 059 private Integer totalDiscountedInCents; 060 061 @XmlElement(name = "currency") 062 private String currency; 063 064 @XmlElement(name = "state") 065 private String state; 066 067 @XmlElement(name = "coupon_code") 068 private String couponCode; 069 070 @XmlElement(name = "created_at") 071 private DateTime createdAt; 072 073 @XmlElement(name = "updated_at") 074 private DateTime updatedAt; 075 076 public String getAccountCode() { 077 return accountCode; 078 } 079 080 public void setAccountCode(final Object accountCode) { 081 this.accountCode = stringOrNull(accountCode); 082 } 083 084 public String getSubscriptionUuid() { 085 return subscriptionUuid; 086 } 087 088 public void setSubscriptionUuid(final Object subscriptionUuid) { 089 this.subscriptionUuid = stringOrNull(subscriptionUuid); 090 } 091 092 public Coupon getCoupon() { 093 if (coupon != null && coupon.getCouponCode() == null) { 094 coupon = fetch(coupon, Coupon.class); 095 } 096 return coupon; 097 } 098 099 public void setCoupon(final Coupon coupon) { 100 this.coupon = coupon; 101 } 102 103 public Account getAccount() { 104 if (account != null && account.getCreatedAt() == null) { 105 account = fetch(account, Account.class); 106 } 107 return account; 108 } 109 110 public void setAccount(final Account account) { 111 this.account = account; 112 } 113 114 public Boolean getSingleUse() { 115 return singleUse; 116 } 117 118 public void setSingleUse(final Object singleUse) { 119 this.singleUse = booleanOrNull(singleUse); 120 } 121 122 public Integer getTotalDiscountedInCents() { 123 return totalDiscountedInCents; 124 } 125 126 public void setTotalDiscountedInCents(final Object totalDiscountedInCents) { 127 this.totalDiscountedInCents = integerOrNull(totalDiscountedInCents); 128 } 129 130 public String getCurrency() { 131 return currency; 132 } 133 134 public void setCurrency(final Object currency) { 135 this.currency = stringOrNull(currency); 136 } 137 138 public String getState() { 139 return state; 140 } 141 142 public void setState(final Object state) { 143 this.state = stringOrNull(state); 144 } 145 146 public String getCouponCode() { 147 return couponCode; 148 } 149 150 public void setCouponCode(final Object couponCode) { 151 this.couponCode = stringOrNull(couponCode); 152 } 153 154 public String getUuid() { 155 return uuid; 156 } 157 158 public void setUuid(final Object uuid) { 159 this.uuid = stringOrNull(uuid); 160 } 161 162 public DateTime getCreatedAt() { 163 return createdAt; 164 } 165 166 public void setCreatedAt(final Object createdAt) { 167 this.createdAt = dateTimeOrNull(createdAt); 168 } 169 170 public DateTime getUpdatedAt() { 171 return updatedAt; 172 } 173 174 public void setUpdatedAt(final Object updatedAt) { 175 this.updatedAt = dateTimeOrNull(updatedAt); 176 } 177 178 @Override 179 public String toString() { 180 final StringBuilder sb = new StringBuilder(); 181 sb.append("Redemption"); 182 sb.append("{accountCode=").append(accountCode); 183 sb.append(", subscriptionUuid=").append(subscriptionUuid); 184 sb.append(", coupon=").append(coupon); 185 sb.append(", account=").append(account); 186 sb.append(", uuid=").append(uuid); 187 sb.append(", single_use=").append(singleUse); 188 sb.append(", totalDiscountedInCents=").append(totalDiscountedInCents); 189 sb.append(", currency='").append(currency).append('\''); 190 sb.append(", state='").append(state).append('\''); 191 sb.append(", couponCode='").append(couponCode).append('\''); 192 sb.append(", createdAt=").append(createdAt); 193 sb.append(", updatedAt=").append(updatedAt); 194 sb.append('}'); 195 return sb.toString(); 196 } 197 198 @Override 199 public boolean equals(final Object o) { 200 if (this == o) return true; 201 if (o == null || getClass() != o.getClass()) return false; 202 203 final Redemption that = (Redemption) o; 204 205 if (accountCode != null ? !accountCode.equals(that.accountCode) : that.accountCode != null) { 206 return false; 207 } 208 if (subscriptionUuid != null ? !subscriptionUuid.equals(that.subscriptionUuid) : that.subscriptionUuid != null) { 209 return false; 210 } 211 if (coupon != null ? !coupon.equals(that.coupon) : that.coupon != null) { 212 return false; 213 } 214 if (account != null ? !account.equals(that.account) : that.account != null) { 215 return false; 216 } 217 if (singleUse != null ? !singleUse.equals(that.singleUse) : that.singleUse != null) { 218 return false; 219 } 220 if (totalDiscountedInCents != null ? 221 !totalDiscountedInCents.equals(that.totalDiscountedInCents) : that.totalDiscountedInCents != null) { 222 return false; 223 } 224 if (currency != null ? !currency.equals(that.currency) : that.currency != null) { 225 return false; 226 } 227 if (state != null ? !state.equals(that.state) : that.state != null) { 228 return false; 229 } 230 if (couponCode != null ? !couponCode.equals(that.couponCode) : that.couponCode != null) { 231 return false; 232 } 233 if (createdAt != null ? createdAt.compareTo(that.createdAt) != 0 : that.createdAt != null) { 234 return false; 235 } 236 if (updatedAt != null ? updatedAt.compareTo(that.updatedAt) != 0 : that.updatedAt != null) { 237 return false; 238 } 239 if (uuid != null ? !uuid.equals(that.uuid) : that.uuid != null) { 240 return false; 241 } 242 243 return true; 244 } 245 246 @Override 247 public int hashCode() { 248 return Objects.hashCode( 249 accountCode, 250 subscriptionUuid, 251 coupon, 252 account, 253 singleUse, 254 totalDiscountedInCents, 255 currency, 256 state, 257 couponCode, 258 uuid, 259 createdAt, 260 updatedAt 261 ); 262 } 263 264}